code: def test_seq2seq_dataset_truncation(self, tok_name):
      tokenizer = AutoTokenizer.from_pretrained(tok_name)
      tmp_dir = make_test_data_dir(
          tmp_dir=self.get_auto_remove_tmp_dir()
      )
      max_len_source = max(len(tokenizer.encode(a)) for a in ARTICLES)
      max_len_target = max(len(tokenizer.encode(a)) for a in SUMMARIES)
      max_src_len = 4
      max_tgt_len = 8
      assert max_len_target > max_src_len  # Will be truncated
      assert max_len_source > max_src_len  # Will be truncated
      src_lang, tgt_lang = (
          "ro_RO",
          "de_DE",
      )  # ignored for all but mbart, but never causes error.
      train_dataset = Seq2SeqDataset(
          tokenizer,
          data_dir=tmp_dir,
          type_path="train",
          max_source_length=max_src_len,
          max_target_length=max_tgt_len,  # ignored
          src_lang=src_lang,
          tgt_lang=tgt_lang,
      )
      dataloader = DataLoader(
          train_dataset,
          batch_size=2,
          collate_fn=train_dataset.collate_fn,
      )
      for batch in dataloader:
          assert isinstance(batch, dict)
          assert (
              batch["attention_mask"].shape == batch["input_ids"].shape
          )
          # show that articles were trimmed.
          assert batch["input_ids"].shape[1] == max_src_len
          # show that targets are the same len
          assert batch["labels"].shape[1] == max_tgt_len
          if tok_name != MBART_TINY:
              continue
          # check language codes in correct place
          batch["decoder_input_ids"] = shift_tokens_right(
              batch["labels"], tokenizer.pad_token_id
          )
          assert (
              batch["decoder_input_ids"][0, 0].item()
              == tokenizer.lang_code_to_id[tgt_lang]
          )
          assert (
              batch["decoder_input_ids"][0, -1].item()
              == tokenizer.eos_token_id
          )
          assert (
              batch["input_ids"][0, -2].item() == tokenizer.eos_token_id
          )
          assert (
              batch["input_ids"][0, -1].item()
              == tokenizer.lang_code_to_id[src_lang]
          )
  
          break
  
imports: import os
  from pathlib import Path
  import numpy
  import pytest
  from pack_dataset import pack_data_dir
  from parameterized import parameterized
  from save_len_file import save_len_file
  from torch.utils.data import DataLoader
  from transformers import AutoTokenizer
  from transformers.models.mbart.modeling_mbart import shift_tokens_right
  from transformers.testing_utils import TestCasePlus, slow
  from utils import FAIRSEQ_AVAILABLE, DistributedSortishSampler, LegacySeq2SeqDataset, Seq2SeqDataset
label_desc: Use image node_id 1 for calling the TestAll obj's underlying member method code with example usage: obj.test_seq2seq_dataset_truncation(tok_name) without return types