text: 
  
  TITLE
  [s2s examples] convert existing scripts to run_seq2seq.py from finetune_trainer.py
  
  COMMENTS
  2
  
  REACTIONS
  +1: 0
  -1: 0
  laugh: 0
  hooray: 0
  heart: 0
  rocket: 0
  eyes: 0
  
  BODY
  As `transformers` examples are evolving it seems that the good old `finetune_trainer.py` is going to be moved into unmaintained `examples/legacy/` area, and `run_seq2seq.py` is to be the new king, so let's automate this process
  
  Assuming your cmd script is `process.txt` (and replace with the file names that you have (one or many), let's auto-adjust it:
  
  1. Renames
  ```
  # main name and args rename
  perl -pi -e 's|finetune_trainer|run_seq2seq|g; s#--n_(train|val)#--max_$1_samples#g; \
  s|--src_lang|--source_lang|g; s|--tgt_lang|--target_lang|g; s|--eval_beams|--num_beams|'  process.txt
  
  # drop no longer supported args
  perl -pi -e 's|--freeze_embeds||; s|--test_max_target_length[ =]+\d+||;' process.txt
  
  ```
  
  2. t5 auto-adding prefix has been dropped, so you need to add it manually, e.g.:
  ```
  --source_prefix "translate English to Romanian: "
  ```
  otherwise the results would be terrible.
  
  3. Datasets are different
  
  a. need to convert the normal dataset into jsonlines (unless the data is already on datasets hub)
  instructions are: https://huggingface.co/docs/datasets/loading_datasets.html#json-files
  
  b. new arguments:
  
  instead of 
  ```
              --data_dir {data_dir}
  ```
  now you need:
  ``` 
              --train_file {data_dir}/train.json
              --validation_file {data_dir}/val.json
  ```
  
  Here's is an example conversion script for the `wmt_en_ro` dataset:
  
  ```
  # convert.py
  import io
  import json
  import re
  
  src_lang, tgt_lang = ["en", "ro"]
  
  for split in ["train", "val", "test"]:
      recs = []
      fout = f"{split}.json"
      with io.open(fout, "w", encoding="utf-8") as f:
          for type in ["source", "target"]:
              fin = f"{split}.{type}"
              recs.append([line.strip() for line in open(fin)])
          for src, tgt in zip(*recs):
              out = {"translation": { src_lang: src, tgt_lang: tgt } }
              x = json.dumps(out, indent=0, ensure_ascii=False)
              x = re.sub(r'\n', ' ', x, 0, re.M)
              f.write(x + "\n")
  ```
  
  Or if you find an existing dataset in `datasets`, you can supply it instead of the `--data_dir` arg as following:
  
  ```
  --dataset_name wmt16 --dataset_config_name ro-en 
  ```
  
  Here is the full conversion table from the previously recommended 4 datasets in the `examples/seq2seq` folder:
  * [x] `--data_dir wmt_en_de` => `--dataset_name wmt14 --dataset_config "de-en"` or if you want the highest score use: `--dataset_name wmt14-en-de-pre-processed`
  * [x] `--data_dir wmt_en_ro` => --dataset_name wmt16 --dataset_config "ro-en"` 
  * [x] `--data_dir cnn_dm` => `--dataset_name cnn_dailymail --dataset_config "3.0.0"`
  * [x] `--data_dir xsum` => `--dataset_name xsum`
  
  You will find more details [here](https://github.com/huggingface/transformers/issues/10044#issuecomment-779555741)
  
  ----
  
  t5-specific changes: from https://github.com/huggingface/transformers/pull/10133#issuecomment-778071812
  
      1. Use the same dataset
      2. if using T5 manually pass the `prefix` argument,
      3. manually copy the `task_specific_parms` to `config`
  
  
  