MCPcopy Index your code
hub / github.com/SooLab/CGFormer / from_pretrained

Method from_pretrained

bert/modeling_utils.py:510–812  ·  view source on GitHub ↗

r"""Instantiate a pretrained pytorch model from a pre-trained model configuration. The model is set in evaluation mode by default using ``model.eval()`` (Dropout modules are deactivated) To train the model, you should first set it back in training mode with ``model.train()``

(cls, pretrained_model_name_or_path, *model_args, **kwargs)

Source from the content-addressed store, hash-verified

508
509 @classmethod
510 def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
511 r"""Instantiate a pretrained pytorch model from a pre-trained model configuration.
512
513 The model is set in evaluation mode by default using ``model.eval()`` (Dropout modules are deactivated)
514 To train the model, you should first set it back in training mode with ``model.train()``
515
516 The warning ``Weights from XXX not initialized from pretrained model`` means that the weights of XXX do not come pre-trained with the rest of the model.
517 It is up to you to train those weights with a downstream fine-tuning task.
518
519 The warning ``Weights from XXX not used in YYY`` means that the layer XXX is not used by YYY, therefore those weights are discarded.
520
521 Parameters:
522 pretrained_model_name_or_path: either:
523 - a string with the `shortcut name` of a pre-trained model to load from cache or download, e.g.: ``bert-base-uncased``.
524 - a string with the `identifier name` of a pre-trained model that was user-uploaded to our S3, e.g.: ``dbmdz/bert-base-german-cased``.
525 - a path to a `directory` containing model weights saved using :func:`~transformers.PreTrainedModel.save_pretrained`, e.g.: ``./my_model_directory/``.
526 - a path or url to a `tensorflow index checkpoint file` (e.g. `./tf_model/model.ckpt.index`). In this case, ``from_tf`` should be set to True and a configuration object should be provided as ``config`` argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
527 - None if you are both providing the configuration and state dictionary (resp. with keyword arguments ``config`` and ``state_dict``)
528
529 model_args: (`optional`) Sequence of positional arguments:
530 All remaning positional arguments will be passed to the underlying model's ``__init__`` method
531
532 config: (`optional`) one of:
533 - an instance of a class derived from :class:`~transformers.PretrainedConfig`, or
534 - a string valid as input to :func:`~transformers.PretrainedConfig.from_pretrained()`
535
536 Configuration for the model to use instead of an automatically loaded configuation. Configuration can be automatically loaded when:
537 - the model is a model provided by the library (loaded with the ``shortcut-name`` string of a pretrained model), or
538 - the model was saved using :func:`~transformers.PreTrainedModel.save_pretrained` and is reloaded by suppling the save directory.
539 - the model is loaded by suppling a local directory as ``pretrained_model_name_or_path`` and a configuration JSON file named `config.json` is found in the directory.
540
541 state_dict: (`optional`) dict:
542 an optional state dictionnary for the model to use instead of a state dictionary loaded from saved weights file.
543 This option can be used if you want to create a model from a pretrained configuration but load your own weights.
544 In this case though, you should check if using :func:`~transformers.PreTrainedModel.save_pretrained` and :func:`~transformers.PreTrainedModel.from_pretrained` is not a simpler option.
545
546 cache_dir: (`optional`) string:
547 Path to a directory in which a downloaded pre-trained model
548 configuration should be cached if the standard cache should not be used.
549
550 force_download: (`optional`) boolean, default False:
551 Force to (re-)download the model weights and configuration files and override the cached versions if they exists.
552
553 resume_download: (`optional`) boolean, default False:
554 Do not delete incompletely recieved file. Attempt to resume the download if such a file exists.
555
556 proxies: (`optional`) dict, default None:
557 A dictionary of proxy servers to use by protocol or endpoint, e.g.: {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.
558 The proxies are used on each request.
559
560 output_loading_info: (`optional`) boolean:
561 Set to ``True`` to also return a dictionnary containing missing keys, unexpected keys and error messages.
562
563 kwargs: (`optional`) Remaining dictionary of keyword arguments:
564 Can be used to update the configuration object (after it being loaded) and initiate the model. (e.g. ``output_attention=True``). Behave differently depending on whether a `config` is provided or automatically loaded:
565
566 - If a configuration is provided with ``config``, ``**kwargs`` will be directly passed to the underlying model's ``__init__`` method (we assume all relevant updates to the configuration have already been done)
567 - If a configuration is not provided, ``kwargs`` will be first passed to the configuration class initialization function (:func:`~transformers.PretrainedConfig.from_pretrained`). Each key of ``kwargs`` that corresponds to a configuration attribute will be used to override said attribute with the supplied ``kwargs`` value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model's ``__init__`` function.

Callers 2

dataset.pyFile · 0.45
__init__Method · 0.45

Calls 8

is_remote_urlFunction · 0.85
hf_bucket_urlFunction · 0.85
cached_pathFunction · 0.85
loadFunction · 0.85
loadMethod · 0.80
keysMethod · 0.80
tie_weightsMethod · 0.80
toMethod · 0.80

Tested by

no test coverage detected