paddlenlp/experimental/model_utils.py
def save_pretrained(self, save_dir):
        """
        Saves model configuration and related resources (model state) as files
        under `save_dir`. The model configuration would be saved into a file named
        "model_config.json", and model state would be saved into a file
        named "model_state.pdparams".

        The `save_dir` can be used in `from_pretrained` as argument value
        of `pretrained_model_name_or_path` to re-load the trained model.

        Args:
            save_dir (str): Directory to save files into.

        Example:
            .. code-block::

                from paddlenlp.transformers import BertForSequenceClassification

                model = BertForSequenceClassification.from_pretrained('bert-base-uncased')
                model.save_pretrained('./trained_model/')
                # reload from save_directory
                model = BertForSequenceClassification.from_pretrained('./trained_model/')
        """
        assert not os.path.isfile(
            save_dir
        ), "Saving directory ({}) should be a directory, not a file".format(
            save_dir)
        os.makedirs(save_dir, exist_ok=True)
        # Save model config
        self.save_model_config(save_dir)
        # Save model
        if paddle.in_dynamic_mode():
            file_name = os.path.join(
                save_dir, list(self.resource_files_names.values())[0])
            paddle.save(self.state_dict(), file_name)
        else:
            logger.warning(
                "Save pretrained model only supported dygraph mode for now!")
        # Save resources file
        self.save_resources(save_dir)

        Saves model configuration and related resources (model state) as files
        under `save_dir`. The model configuration would be saved into a file named
        "model_config.json", and model state would be saved into a file
        named "model_state.pdparams".

        The `save_dir` can be used in `from_pretrained` as argument value
        of `pretrained_model_name_or_path` to re-load the trained model.

        Args:
            save_dir (str): Directory to save files into.

        Example:
            .. code-block::

                from paddlenlp.transformers import BertForSequenceClassification

                model = BertForSequenceClassification.from_pretrained('bert-base-uncased')
                model.save_pretrained('./trained_model/')
                # reload from save_directory
                model = BertForSequenceClassification.from_pretrained('./trained_model/')
        
Saves model configuration and related resources (model state) as files
under `save_dir`. The model configuration would be saved into a file named
"model_config.json", and model state would be saved into a file
named "model_state.pdparams".


Saves model configuration and related resources ( model state ) as files under ` save_dir ` . The model configuration would be saved into a file named " model_config . json " and model state would be saved into a file named " model_state . pdparams " .
def save_pretrained(self, save_dir):
        assert not os.path.isfile(
            save_dir
        ), "Saving directory ({}) should be a directory, not a file".format(
            save_dir)
        os.makedirs(save_dir, exist_ok=True)
        self.save_model_config(save_dir)
        if paddle.in_dynamic_mode():
            file_name = os.path.join(
                save_dir, list(self.resource_files_names.values())[0])
            paddle.save(self.state_dict(), file_name)
        else:
            logger.warning(
                "Save pretrained model only supported dygraph mode for now!")
        self.save_resources(save_dir)
def save_pretrained ( self , save_dir ) : assert not os . path . isfile ( save_dir ) , "Saving directory ({}) should be a directory, not a file" . format ( save_dir ) os . makedirs ( save_dir , exist_ok = True ) self . save_model_config ( save_dir ) if paddle . in_dynamic_mode ( ) : file_name = os . path . join ( save_dir , list ( self . resource_files_names . values ( ) ) [ 0 ] ) paddle . save ( self . state_dict ( ) , file_name ) else : logger . warning ( "Save pretrained model only supported dygraph mode for now!" ) self . save_resources ( save_dir )
Saves model configuration and related resources (model state) as files
under `save_dir`.
Saves model configuration and related resources ( model state ) as files under ` save_dir ` .
"""
        Saves model configuration and related resources (model state) as files
        under `save_dir`. The model configuration would be saved into a file named
        "model_config.json", and model state would be saved into a file
        named "model_state.pdparams".

        The `save_dir` can be used in `from_pretrained` as argument value
        of `pretrained_model_name_or_path` to re-load the trained model.

        Args:
            save_dir (str): Directory to save files into.

        Example:
            .. code-block::

                from paddlenlp.transformers import BertForSequenceClassification

                model = BertForSequenceClassification.from_pretrained('bert-base-uncased')
                model.save_pretrained('./trained_model/')
                # reload from save_directory
                model = BertForSequenceClassification.from_pretrained('./trained_model/')
        """ # Save model config # Save model # Save resources file
self
save_dir
Directory to save files into.
Directory to save files into .
examples
code-block:.

from paddlenlp.transformers import BertForSequenceClassification

model = BertForSequenceClassification.from_pretrained('bert-base-uncased')
model.save_pretrained('./trained_model/')
reload from save_directory
model = BertForSequenceClassification.from_pretrained('./trained_model/')
code - block : . from paddlenlp . transformers import BertForSequenceClassification model = BertForSequenceClassification . from_pretrained ( ' bert - base - uncased ' ) model . save_pretrained ( ' . / trained_model / ' ) reload from save_directory model = BertForSequenceClassification . from_pretrained ( ' . / trained_model / ' )