@@ -81,18 +81,17 @@ def __setitem__(self, name, value):
81
81
82
82
class ConfigMixin :
83
83
r"""
84
- Base class for all configuration classes. Stores all configuration parameters under `self.config` Also handles all
85
- methods for loading/downloading/saving classes inheriting from [`ConfigMixin`] with
86
- - [`~ConfigMixin.from_config`]
87
- - [`~ConfigMixin.save_config`]
84
+ Base class for all configuration classes. All configuration parameters are stored under `self.config`. Also
85
+ provides the [`~ConfigMixin.from_config`] and [`~ConfigMixin.save_config`] methods for loading, downloading, and
86
+ saving classes that inherit from [`ConfigMixin`].
88
87
89
88
Class attributes:
90
89
- **config_name** (`str`) -- A filename under which the config should stored when calling
91
90
[`~ConfigMixin.save_config`] (should be overridden by parent class).
92
91
- **ignore_for_config** (`List[str]`) -- A list of attributes that should not be saved in the config (should be
93
92
overridden by subclass).
94
93
- **has_compatibles** (`bool`) -- Whether the class has compatible classes (should be overridden by subclass).
95
- - **_deprecated_kwargs** (`List[str]`) -- Keyword arguments that are deprecated. Note that the init function
94
+ - **_deprecated_kwargs** (`List[str]`) -- Keyword arguments that are deprecated. Note that the ` init` function
96
95
should only have a `kwargs` argument if at least one argument is deprecated (should be overridden by
97
96
subclass).
98
97
"""
@@ -139,12 +138,12 @@ def __getattr__(self, name: str) -> Any:
139
138
140
139
def save_config (self , save_directory : Union [str , os .PathLike ], push_to_hub : bool = False , ** kwargs ):
141
140
"""
142
- Save a configuration object to the directory `save_directory`, so that it can be re-loaded using the
141
+ Save a configuration object to the directory specified in `save_directory` so that it can be reloaded using the
143
142
[`~ConfigMixin.from_config`] class method.
144
143
145
144
Args:
146
145
save_directory (`str` or `os.PathLike`):
147
- Directory where the configuration JSON file will be saved (will be created if it does not exist).
146
+ Directory where the configuration JSON file is saved (will be created if it does not exist).
148
147
"""
149
148
if os .path .isfile (save_directory ):
150
149
raise AssertionError (f"Provided path ({ save_directory } ) should be a directory, not a file" )
@@ -164,15 +163,14 @@ def from_config(cls, config: Union[FrozenDict, Dict[str, Any]] = None, return_un
164
163
165
164
Parameters:
166
165
config (`Dict[str, Any]`):
167
- A config dictionary from which the Python class will be instantiated. Make sure to only load
168
- configuration files of compatible classes.
166
+ A config dictionary from which the Python class is instantiated. Make sure to only load configuration
167
+ files of compatible classes.
169
168
return_unused_kwargs (`bool`, *optional*, defaults to `False`):
170
169
Whether kwargs that are not consumed by the Python class should be returned or not.
171
-
172
170
kwargs (remaining dictionary of keyword arguments, *optional*):
173
171
Can be used to update the configuration object (after it is loaded) and initiate the Python class.
174
- `**kwargs` are directly passed to the underlying scheduler/model's `__init__` method and eventually
175
- overwrite same named arguments in `config`.
172
+ `**kwargs` are passed directly to the underlying scheduler/model's `__init__` method and eventually
173
+ overwrite the same named arguments in `config`.
176
174
177
175
Returns:
178
176
[`ModelMixin`] or [`SchedulerMixin`]:
@@ -280,16 +278,16 @@ def load_config(
280
278
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
281
279
cached versions if they exist.
282
280
resume_download (`bool`, *optional*, defaults to `False`):
283
- Whether or not to resume downloading the model weights and configuration files. If set to False, any
281
+ Whether or not to resume downloading the model weights and configuration files. If set to ` False` , any
284
282
incompletely downloaded files are deleted.
285
283
proxies (`Dict[str, str]`, *optional*):
286
284
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
287
285
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
288
286
output_loading_info(`bool`, *optional*, defaults to `False`):
289
287
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
290
- local_files_only(`bool`, *optional*, defaults to `False`):
291
- Whether to only load local model weights and configuration files or not. If set to True, the model
292
- won’ t be downloaded from the Hub.
288
+ local_files_only (`bool`, *optional*, defaults to `False`):
289
+ Whether to only load local model weights and configuration files or not. If set to ` True` , the model
290
+ won' t be downloaded from the Hub.
293
291
use_auth_token (`str` or *bool*, *optional*):
294
292
The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
295
293
`diffusers-cli login` (stored in `~/.huggingface`) is used.
@@ -307,14 +305,6 @@ def load_config(
307
305
`dict`:
308
306
A dictionary of all the parameters stored in a JSON configuration file.
309
307
310
- <Tip>
311
-
312
- To use private or [gated models](https://huggingface.co/docs/hub/models-gated#gated-models), log-in with
313
- `huggingface-cli login`. You can also activate the special
314
- ["offline-mode"](https://huggingface.co/transformers/installation.html#offline-mode) to use this method in a
315
- firewalled environment.
316
-
317
- </Tip>
318
308
"""
319
309
cache_dir = kwargs .pop ("cache_dir" , DIFFUSERS_CACHE )
320
310
force_download = kwargs .pop ("force_download" , False )
@@ -536,10 +526,11 @@ def config(self) -> Dict[str, Any]:
536
526
537
527
def to_json_string (self ) -> str :
538
528
"""
539
- Serializes this instance to a JSON string.
529
+ Serializes the configuration instance to a JSON string.
540
530
541
531
Returns:
542
- `str`: String containing all the attributes that make up this configuration instance in JSON format.
532
+ `str`:
533
+ String containing all the attributes that make up the configuration instance in JSON format.
543
534
"""
544
535
config_dict = self ._internal_dict if hasattr (self , "_internal_dict" ) else {}
545
536
config_dict ["_class_name" ] = self .__class__ .__name__
@@ -560,11 +551,11 @@ def to_json_saveable(value):
560
551
561
552
def to_json_file (self , json_file_path : Union [str , os .PathLike ]):
562
553
"""
563
- Save this instance to a JSON file.
554
+ Save the configuration instance's parameters to a JSON file.
564
555
565
556
Args:
566
557
json_file_path (`str` or `os.PathLike`):
567
- Path to the JSON file in which this configuration instance's parameters will be saved .
558
+ Path to the JSON file to save a configuration instance's parameters.
568
559
"""
569
560
with open (json_file_path , "w" , encoding = "utf-8" ) as writer :
570
561
writer .write (self .to_json_string ())
0 commit comments