Change to use relative imports in some files & Add python prompt symbols to example codes (#7202)
* Move 'from transformers' statements to relative imports in some files * Add python prompt symbols in front of the example codes * Reformat the code * Add one missing space Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
This commit is contained in:
@@ -804,17 +804,17 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin):
|
||||
|
||||
Examples::
|
||||
|
||||
from transformers import BertConfig, BertModel
|
||||
# Download model and configuration from S3 and cache.
|
||||
model = BertModel.from_pretrained('bert-base-uncased')
|
||||
# Model was saved using `save_pretrained('./test/saved_model/')` (for example purposes, not runnable).
|
||||
model = BertModel.from_pretrained('./test/saved_model/')
|
||||
# Update configuration during loading.
|
||||
model = BertModel.from_pretrained('bert-base-uncased', output_attentions=True)
|
||||
assert model.config.output_attentions == True
|
||||
# Loading from a TF checkpoint file instead of a PyTorch model (slower, for example purposes, not runnable).
|
||||
config = BertConfig.from_json_file('./tf_model/my_tf_model_config.json')
|
||||
model = BertModel.from_pretrained('./tf_model/my_tf_checkpoint.ckpt.index', from_tf=True, config=config)
|
||||
>>> from transformers import BertConfig, BertModel
|
||||
>>> # Download model and configuration from S3 and cache.
|
||||
>>> model = BertModel.from_pretrained('bert-base-uncased')
|
||||
>>> # Model was saved using `save_pretrained('./test/saved_model/')` (for example purposes, not runnable).
|
||||
>>> model = BertModel.from_pretrained('./test/saved_model/')
|
||||
>>> # Update configuration during loading.
|
||||
>>> model = BertModel.from_pretrained('bert-base-uncased', output_attentions=True)
|
||||
>>> assert model.config.output_attentions == True
|
||||
>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower, for example purposes, not runnable).
|
||||
>>> config = BertConfig.from_json_file('./tf_model/my_tf_model_config.json')
|
||||
>>> model = BertModel.from_pretrained('./tf_model/my_tf_checkpoint.ckpt.index', from_tf=True, config=config)
|
||||
"""
|
||||
config = kwargs.pop("config", None)
|
||||
state_dict = kwargs.pop("state_dict", None)
|
||||
@@ -931,7 +931,7 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin):
|
||||
else:
|
||||
# Load from our TensorFlow 2.0 checkpoints
|
||||
try:
|
||||
from transformers import load_tf2_checkpoint_in_pytorch_model
|
||||
from .modeling_tf_pytorch_utils import load_tf2_checkpoint_in_pytorch_model
|
||||
|
||||
model = load_tf2_checkpoint_in_pytorch_model(model, resolved_archive_file, allow_missing_keys=True)
|
||||
except ImportError:
|
||||
|
||||
Reference in New Issue
Block a user