From 2318bf77eb4501339e0856b1d43130f217aed1e5 Mon Sep 17 00:00:00 2001 From: Lysandre Debut Date: Fri, 26 Nov 2021 04:35:08 -0500 Subject: [PATCH] Fixes (#14534) --- docs/source/quicktour.rst | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/source/quicktour.rst b/docs/source/quicktour.rst index 111efe395c..0abf9bccad 100644 --- a/docs/source/quicktour.rst +++ b/docs/source/quicktour.rst @@ -346,35 +346,43 @@ Once your model is fine-tuned, you can save it with its tokenizer in the followi .. code-block:: + >>> ## PYTORCH CODE >>> pt_save_directory = './pt_save_pretrained' >>> tokenizer.save_pretrained(pt_save_directory) >>> pt_model.save_pretrained(pt_save_directory) - -.. code-block:: - + >>> ## TENSORFLOW CODE >>> tf_save_directory = './tf_save_pretrained' >>> tokenizer.save_pretrained(tf_save_directory) >>> tf_model.save_pretrained(tf_save_directory) You can then load this model back using the :func:`~transformers.AutoModel.from_pretrained` method by passing the directory name instead of the model name. One cool feature of 🤗 Transformers is that you can easily switch between -PyTorch and TensorFlow: any model saved as before can be loaded back either in PyTorch or TensorFlow. If you are -loading a saved PyTorch model in a TensorFlow model, use :func:`~transformers.TFAutoModel.from_pretrained` like this: +PyTorch and TensorFlow: any model saved as before can be loaded back either in PyTorch or TensorFlow. + + +If you would like to load your saved model in the other framework, first make sure it is installed: + +.. code-block:: bash + + ## PYTORCH CODE + pip install tensorflow + ## TENSORFLOW CODE + pip install torch + +Then, use the corresponding Auto class to load it like this: .. code-block:: + ## PYTORCH CODE >>> from transformers import TFAutoModel >>> tokenizer = AutoTokenizer.from_pretrained(pt_save_directory) >>> tf_model = TFAutoModel.from_pretrained(pt_save_directory, from_pt=True) - -and if you are loading a saved TensorFlow model in a PyTorch model, you should use the following code: - -.. code-block:: - + ## TENSORFLOW CODE >>> from transformers import AutoModel >>> tokenizer = AutoTokenizer.from_pretrained(tf_save_directory) >>> pt_model = AutoModel.from_pretrained(tf_save_directory, from_tf=True) + Lastly, you can also ask the model to return all hidden states and all attention weights if you need them: