save_vocabulary() got an unexpected keyword argument 'filename_prefix'
Author: szarki9
Pull request: no

### System Info

hi,

Im trying to fine-tune T5ForConditionalGeneration model using trainer.train(). Im getting the following error:

```
Saving model checkpoint to models/simple-finetuned-T5CHEM-to-SSRT/checkpoint-500
Configuration saved in models/simple-finetuned-T5CHEM-to-SSRT/checkpoint-500/config.json
Model weights saved in models/simple-finetuned-T5CHEM-to-SSRT/checkpoint-500/pytorch_model.bin
tokenizer config file saved in models/simple-finetuned-T5CHEM-to-SSRT/checkpoint-500/tokenizer_config.json
Special tokens file saved in models/simple-finetuned-T5CHEM-to-SSRT/checkpoint-500/special_tokens_map.json
added tokens file saved in models/simple-finetuned-T5CHEM-to-SSRT/checkpoint-500/added_tokens.json
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [27], in <module>
----> 1 trainer.train()

File /opt/conda/lib/python3.8/site-packages/transformers/trainer.py:1521, in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
   1516     self.model_wrapped = self.model
   1518 inner_training_loop = find_executable_batch_size(
   1519     self._inner_training_loop, self._train_batch_size, args.auto_find_batch_size
   1520 )
-> 1521 return inner_training_loop(
   1522     args=args,
   1523     resume_from_checkpoint=resume_from_checkpoint,
   1524     trial=trial,
   1525     ignore_keys_for_eval=ignore_keys_for_eval,
   1526 )

File /opt/conda/lib/python3.8/site-packages/transformers/trainer.py:1840, in Trainer._inner_training_loop(self, batch_size, args, resume_from_checkpoint, trial, ignore_keys_for_eval)
   1837     self.state.epoch = epoch + (step + 1) / steps_in_epoch
   1838     self.control = self.callback_handler.on_step_end(args, self.state, self.control)
-> 1840     self._maybe_log_save_evaluate(tr_loss, model, trial, epoch, ignore_keys_for_eval)
   1841 else:
   1842     self.control = self.callback_handler.on_substep_end(args, self.state, self.control)

File /opt/conda/lib/python3.8/site-packages/transformers/trainer.py:2069, in Trainer._maybe_log_save_evaluate(self, tr_loss, model, trial, epoch, ignore_keys_for_eval)
   2066     self._report_to_hp_search(trial, self.state.global_step, metrics)
   2068 if self.control.should_save:
-> 2069     self._save_checkpoint(model, trial, metrics=metrics)
   2070     self.control = self.callback_handler.on_save(self.args, self.state, self.control)

File /opt/conda/lib/python3.8/site-packages/transformers/trainer.py:2141, in Trainer._save_checkpoint(self, model, trial, metrics)
   2138     self.store_flos()
   2140 output_dir = os.path.join(run_dir, checkpoint_folder)
-> 2141 self.save_model(output_dir, _internal_call=True)
   2142 if self.deepspeed:
   2143     # under zero3 model file itself doesn't get saved since it's bogus! Unless deepspeed
   2144     # config `stage3_gather_16bit_weights_on_model_save` is True
   2145     self.deepspeed.save_checkpoint(output_dir)

File /opt/conda/lib/python3.8/site-packages/transformers/trainer.py:2631, in Trainer.save_model(self, output_dir, _internal_call)
   2628             self.deepspeed.save_checkpoint(output_dir)
   2630 elif self.args.should_save:
-> 2631     self._save(output_dir)
   2633 # Push to the Hub when `save_model` is called by the user.
   2634 if self.args.push_to_hub and not _internal_call:

File /opt/conda/lib/python3.8/site-packages/transformers/trainer.py:2685, in Trainer._save(self, output_dir, state_dict)
   2683     self.model.save_pretrained(output_dir, state_dict=state_dict)
   2684 if self.tokenizer is not None:
-> 2685     self.tokenizer.save_pretrained(output_dir)
   2687 # Good practice: save your training arguments together with the trained model
   2688 torch.save(self.args, os.path.join(output_dir, TRAINING_ARGS_NAME))

File /opt/conda/lib/python3.8/site-packages/transformers/tokenization_utils_base.py:2132, in PreTrainedTokenizerBase.save_pretrained(self, save_directory, legacy_format, filename_prefix, push_to_hub, **kwargs)
   2128 logger.info(f"Special tokens file saved in {special_tokens_map_file}")
   2130 file_names = (tokenizer_config_file, special_tokens_map_file)
-> 2132 save_files = self._save_pretrained(
   2133     save_directory=save_directory,
   2134     file_names=file_names,
   2135     legacy_format=legacy_format,
   2136     filename_prefix=filename_prefix,
   2137 )
   2139 if push_to_hub:
   2140     self._upload_modified_files(
   2141         save_directory, repo_id, files_timestamps, commit_message=commit_message, token=token
   2142     )

File /opt/conda/lib/python3.8/site-packages/transformers/tokenization_utils_base.py:2176, in PreTrainedTokenizerBase._save_pretrained(self, save_directory, file_names, legacy_format, filename_prefix)
   2173         f.write(out_str)
   2174         logger.info(f"added tokens file saved in {added_tokens_file}")
-> 2176 vocab_files = self.save_vocabulary(save_directory, filename_prefix=filename_prefix)
   2178 return file_names + vocab_files + (added_tokens_file,)

TypeError: save_vocabulary() got an unexpected keyword argument 'filename_prefix'
```


So Im not sure what's happening exactly, especially that this argument is Optional.

Im using tokenizers==0.12.1 & transformers==4.22.0

I would appreciate any help!

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

Im using the model published here: https://github.com/HelloJocelynLu/t5chem


```
from transformers import AutoModelForSeq2SeqLM, DataCollatorForSeq2Seq, Seq2SeqTrainingArguments, Seq2SeqTrainer
batch_size = 16
model_name = model_checkpoint.split("/")[-1]

model_path = "/home/jovyan/workbench-shared-folder/retro-syn/models/pretrain/simple/"
model     = T5ForConditionalGeneration.from_pretrained(model_path)
tokenizer = SimpleTokenizer(vocab_file=model_path + 'vocab.pt')

args = Seq2SeqTrainingArguments(
        f"models/{model_name}-finetuned-T5CHEM-to-SSRT",
        evaluation_strategy = "epoch",
        learning_rate=2e-5,
        per_device_train_batch_size=batch_size,
        per_device_eval_batch_size=batch_size,
        weight_decay=0.01,
        save_total_limit=3,
        num_train_epochs=1,
        predict_with_generate=True,
        fp16=True,
        push_to_hub=False,
)

train_path_source = 'data/USPTO_50k/train.source'
train_path_target = 'data/USPTO_50k/train.target'

valid_path_source = 'data/USPTO_50k/val.source'
valid_path_target = 'data/USPTO_50k/val.target'

train_data = pd.read_csv(train_path_source, header = None)
train_data = train_data.rename(columns = {0:'product'})

train_data_reactant = pd.read_csv(train_path_target, header = None)
train_data_reactant = train_data_reactant.rename(columns = {0:'reactant'})

train_dataset = pd.concat([train_data, train_data_reactant], axis = 1)
train_dataset.head(3)

data_collator = DataCollatorForSeq2Seq(tokenizer, model=model)

max_input_length = 128
max_target_length = 128

task_type2 = "Reactants:"

def preprocess_function(train_dataset):
    inputs = [task_type2 + ex for ex in train_dataset["product"]]
    targets = [ex for ex in train_dataset["reactant"]]
    model_inputs = tokenizer(inputs, max_length=max_input_length, truncation=True, padding=True, return_tensors='pt')#.squeeze(0)
    print(model_inputs)
    # Setup the tokenizer for targets
    with tokenizer.as_target_tokenizer():
        labels = tokenizer(targets, max_length=max_target_length, truncation=True, padding=True, return_tensors='pt')
    #print(labels.shape)
    model_inputs["labels"] = labels["input_ids"]
    return model_inputs


import datasets
raw_datasets = datasets.DatasetDict({'train': datasets.Dataset.from_dict(train_dataset), 'val': datasets.Dataset.from_dict(valid_dataset)})

tokenized_datasets = raw_datasets.map(preprocess_function, batched=True)

from transformers.trainer_utils import PredictionOutput
from typing import Dict, List, NamedTuple

def AccuracyMetrics(model_output: PredictionOutput) -> Dict[str, float]:
    label_ids: np.ndarray = model_output.label_ids # type: ignore
    predictions: np.ndarray = model_output.predictions.reshape(-1, label_ids.shape[1]) # type: ignore
    correct: int = np.all(predictions==label_ids, 1).sum()
    return {'accuracy': correct/len(predictions)}


tokenized_datasets = tokenized_datasets.remove_columns(['product', 'reactant', 'token_type_ids'])


trainer = Seq2SeqTrainer(
    model,
    args,
    train_dataset=tokenized_datasets['train'],
    eval_dataset=tokenized_datasets['val'],
    data_collator=data_collator,
    tokenizer=tokenizer,
    compute_metrics=AccuracyMetrics,
)

trainer.train() 
```

### Expected behavior

I would expect the model to be trained without errors.

Comments:
The tokenizer you are passing to the `Trainer` does not look like it comes from the Transformers library and the reason you are getting the error is that its `save_pretrained` method doesn't look like it works. Just remove the line `tokenizer=tokenizer` in the creation of the `Seq2SeqTrainer` and you should be able to train.

Thanks so much for a prompt response, indeed that was the issue :) 

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.