(model, save_directory)
Save a model and its configuration file to a directory, so that it
        can be re-loaded using the `:func:`~transformers.PreTrainedModel.from_pretrained`` class method.
Save a model and its configuration file to a directory, so that it
        can be re-loaded using the `:func:`~transformers.PreTrainedModel.from_pretrained`` class method.
Save a model and its configuration file to a directory so that it can be re - loaded using the : func : ~transformers . PreTrainedModel . from_pretrained class method .
def save_pretrained(model, save_directory):
    """ Save a model and its configuration file to a directory, so that it
        can be re-loaded using the `:func:`~transformers.PreTrainedModel.from_pretrained`` class method.
    """
    assert os.path.isdir(save_directory), "Saving path should be a directory where the model and configuration can be saved"

    # Only save the model it-self if we are using distributed training
    model_to_save = model.module if hasattr(model, 'module') else model

    # Save configuration file
    model_to_save.config.save_pretrained(save_directory)

    # If we save using the predefined names, we can load using `from_pretrained`
    output_model_file = os.path.join(save_directory, WEIGHTS_NAME)

    xm.save(model_to_save.state_dict(), output_model_file)
    log_info(f"Model weights saved in {output_model_file}")
def save_pretrained ( model , save_directory ) : assert os . path . isdir ( save_directory ) , "Saving path should be a directory where the model and configuration can be saved" # Only save the model it-self if we are using distributed training model_to_save = model . module if hasattr ( model , 'module' ) else model # Save configuration file model_to_save . config . save_pretrained ( save_directory ) # If we save using the predefined names, we can load using `from_pretrained` output_model_file = os . path . join ( save_directory , WEIGHTS_NAME ) xm . save ( model_to_save . state_dict ( ) , output_model_file ) log_info ( f"Model weights saved in {output_model_file}" )