MCPcopy Create free account
hub / github.com/SooLab/CGFormer / from_dict

Method from_dict

bert/configuration_utils.py:269–304  ·  view source on GitHub ↗

Constructs a `Config` from a Python dictionary of parameters. Args: config_dict (:obj:`Dict[str, any]`): Dictionary that will be used to instantiate the configuration object. Such a dictionary can be retrieved from a pre-trained checkpoin

(cls, config_dict: Dict, **kwargs)

Source from the content-addressed store, hash-verified

267
268 @classmethod
269 def from_dict(cls, config_dict: Dict, **kwargs) -> "PretrainedConfig":
270 """
271 Constructs a `Config` from a Python dictionary of parameters.
272
273 Args:
274 config_dict (:obj:`Dict[str, any]`):
275 Dictionary that will be used to instantiate the configuration object. Such a dictionary can be retrieved
276 from a pre-trained checkpoint by leveraging the :func:`~transformers.PretrainedConfig.get_config_dict`
277 method.
278 kwargs (:obj:`Dict[str, any]`):
279 Additional parameters from which to initialize the configuration object.
280
281 Returns:
282 :class:`PretrainedConfig`: An instance of a configuration object
283 """
284 return_unused_kwargs = kwargs.pop("return_unused_kwargs", False)
285
286 config = cls(**config_dict)
287
288 if hasattr(config, "pruned_heads"):
289 config.pruned_heads = dict((int(key), value) for key, value in config.pruned_heads.items())
290
291 # Update config with kwargs if needed
292 to_remove = []
293 for key, value in kwargs.items():
294 if hasattr(config, key):
295 setattr(config, key, value)
296 to_remove.append(key)
297 for key in to_remove:
298 kwargs.pop(key, None)
299
300 logger.info("Model config %s", str(config))
301 if return_unused_kwargs:
302 return config, kwargs
303 else:
304 return config
305
306 @classmethod
307 def from_json_file(cls, json_file: str) -> "PretrainedConfig":

Callers 1

from_pretrainedMethod · 0.80

Calls 1

itemsMethod · 0.80

Tested by

no test coverage detected