code: def test_legacy_dataset_truncation(self, tok):
      tokenizer = AutoTokenizer.from_pretrained(tok)
      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)
      trunc_target = 4
      train_dataset = LegacySeq2SeqDataset(
          tokenizer,
          data_dir=tmp_dir,
          type_path="train",
          max_source_length=20,
          max_target_length=trunc_target,
      )
      dataloader = DataLoader(
          train_dataset,
          batch_size=2,
          collate_fn=train_dataset.collate_fn,
      )
      for batch in dataloader:
          assert (
              batch["attention_mask"].shape == batch["input_ids"].shape
          )
          # show that articles were trimmed.
          assert batch["input_ids"].shape[1] == max_len_source
          assert (
              20 >= batch["input_ids"].shape[1]
          )  # trimmed significantly
          # show that targets were truncated
          assert batch["labels"].shape[1] == trunc_target  # Truncated
          assert max_len_target > trunc_target  # Truncated
          break
  
imports: import os
  from pathlib import Path
  import numpy
  import pytest
  from torch.utils.data import DataLoader
  from pack_dataset import pack_data_dir
  from parameterized import parameterized
  from save_len_file import save_len_file
  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 2 for calling the TestAll obj's underlying member method code with example usage: obj.test_legacy_dataset_truncation(tok) without return types