MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / from_config

Method from_config

diffusers/src/diffusers/configuration_utils.py:188–275  ·  view source on GitHub ↗

r""" Instantiate a Python class from a config dictionary. Parameters: config (`Dict[str, Any]`): A config dictionary from which the Python class is instantiated. Make sure to only load configuration files of compatible classes.

(cls, config: Union[FrozenDict, Dict[str, Any]] = None, return_unused_kwargs=False, **kwargs)

Source from the content-addressed store, hash-verified

186
187 @classmethod
188 def from_config(cls, config: Union[FrozenDict, Dict[str, Any]] = None, return_unused_kwargs=False, **kwargs):
189 r"""
190 Instantiate a Python class from a config dictionary.
191
192 Parameters:
193 config (`Dict[str, Any]`):
194 A config dictionary from which the Python class is instantiated. Make sure to only load configuration
195 files of compatible classes.
196 return_unused_kwargs (`bool`, *optional*, defaults to `False`):
197 Whether kwargs that are not consumed by the Python class should be returned or not.
198 kwargs (remaining dictionary of keyword arguments, *optional*):
199 Can be used to update the configuration object (after it is loaded) and initiate the Python class.
200 `**kwargs` are passed directly to the underlying scheduler/model's `__init__` method and eventually
201 overwrite the same named arguments in `config`.
202
203 Returns:
204 [`ModelMixin`] or [`SchedulerMixin`]:
205 A model or scheduler object instantiated from a config dictionary.
206
207 Examples:
208
209 ```python
210 >>> from diffusers import DDPMScheduler, DDIMScheduler, PNDMScheduler
211
212 >>> # Download scheduler from huggingface.co and cache.
213 >>> scheduler = DDPMScheduler.from_pretrained("google/ddpm-cifar10-32")
214
215 >>> # Instantiate DDIM scheduler class with same config as DDPM
216 >>> scheduler = DDIMScheduler.from_config(scheduler.config)
217
218 >>> # Instantiate PNDM scheduler class with same config as DDPM
219 >>> scheduler = PNDMScheduler.from_config(scheduler.config)
220 ```
221 """
222 # <===== TO BE REMOVED WITH DEPRECATION
223 # TODO(Patrick) - make sure to remove the following lines when config=="model_path" is deprecated
224 if "pretrained_model_name_or_path" in kwargs:
225 config = kwargs.pop("pretrained_model_name_or_path")
226
227 if config is None:
228 raise ValueError("Please make sure to provide a config as the first positional argument.")
229 # ======>
230
231 if not isinstance(config, dict):
232 deprecation_message = "It is deprecated to pass a pretrained model name or path to `from_config`."
233 if "Scheduler" in cls.__name__:
234 deprecation_message += (
235 f"If you were trying to load a scheduler, please use {cls}.from_pretrained(...) instead."
236 " Otherwise, please make sure to pass a configuration dictionary instead. This functionality will"
237 " be removed in v1.0.0."
238 )
239 elif "Model" in cls.__name__:
240 deprecation_message += (
241 f"If you were trying to load a model, please use {cls}.load_config(...) followed by"
242 f" {cls}.from_config(...) instead. Otherwise, please make sure to pass a configuration dictionary"
243 " instead. This functionality will be removed in v1.0.0."
244 )
245 deprecate("config-passed-as-path", "1.0.0", deprecation_message, standard_warn=False)

Callers 1

from_configMethod · 0.45

Calls 5

deprecateFunction · 0.85
load_configMethod · 0.80
extract_init_dictMethod · 0.80
register_to_configMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected