We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
❓ Summarization example : Why no shuffling ?
# ❓ Questions & Help

Usually, when loading using Dataloader, data is shuffled for the training set. But in the case of the summarization example, data is not shuffled for training set :

https://github.com/huggingface/transformers/blob/1dc9b3c7847269961458c059ad8ad443b26bf60d/examples/summarization/bart/finetune.py#L105-L108

---

**Why data is not shuffled ?**

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `examples/summarization/bart/finetune.py`
Content:
```
1 import argparse
2 import glob
3 import logging
4 import os
5 import time
6 
7 import torch
8 from torch.utils.data import DataLoader
9 
10 from transformer_base import BaseTransformer, add_generic_args, generic_train, get_linear_schedule_with_warmup
11 
12 
13 try:
14     from .utils import SummarizationDataset
15 except ImportError:
16     from utils import SummarizationDataset
17 
18 
19 logger = logging.getLogger(__name__)
20 
21 
22 class SummarizationTrainer(BaseTransformer):
23 
24     mode = "language-modeling"
25 
26     def __init__(self, hparams):
27         super().__init__(hparams, num_labels=None, mode=self.mode)
28         self.dataset_kwargs: dict = dict(
29             data_dir=self.hparams.data_dir,
30             max_source_length=self.hparams.max_source_length,
31             max_target_length=self.hparams.max_target_length,
32         )
33 
34     def forward(self, input_ids, attention_mask=None, decoder_input_ids=None, lm_labels=None):
35         return self.model(
36             input_ids, attention_mask=attention_mask, decoder_input_ids=decoder_input_ids, lm_labels=lm_labels,
37         )
38 
39     def _step(self, batch):
40         pad_token_id = self.tokenizer.pad_token_id
41         source_ids, source_mask, y = batch["source_ids"], batch["source_mask"], batch["target_ids"]
42         y_ids = y[:, :-1].contiguous()
43         lm_labels = y[:, 1:].clone()
44         lm_labels[y[:, 1:] == pad_token_id] = -100
45         outputs = self(source_ids, attention_mask=source_mask, decoder_input_ids=y_ids, lm_labels=lm_labels,)
46 
47         loss = outputs[0]
48 
49         return loss
50 
51     def training_step(self, batch, batch_idx):
52         loss = self._step(batch)
53 
54         tensorboard_logs = {"train_loss": loss}
55         return {"loss": loss, "log": tensorboard_logs}
56 
57     def validation_step(self, batch, batch_idx):
58         loss = self._step(batch)
59         return {"val_loss": loss}
60 
61     def validation_end(self, outputs):
62         avg_loss = torch.stack([x["val_loss"] for x in outputs]).mean()
63         tensorboard_logs = {"val_loss": avg_loss}
64         return {"avg_val_loss": avg_loss, "log": tensorboard_logs}
65 
66     def test_step(self, batch, batch_idx):
67         pad_token_id = self.tokenizer.pad_token_id
68         source_ids, source_mask, y = SummarizationDataset.trim_seq2seq_batch(batch, pad_token_id)
69         # NOTE: the following kwargs get more speed and lower quality summaries than those in evaluate_cnn.py
70         generated_ids = self.model.generate(
71             input_ids=source_ids,
72             attention_mask=source_mask,
73             num_beams=1,
74             max_length=80,
75             repetition_penalty=2.5,
76             length_penalty=1.0,
77             early_stopping=True,
78             use_cache=True,
79         )
80         preds = [
81             self.tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True)
82             for g in generated_ids
83         ]
84         target = [self.tokenizer.decode(t, skip_special_tokens=True, clean_up_tokenization_spaces=True) for t in y]
85         loss = self._step(batch)
86 
87         return {"val_loss": loss, "preds": preds, "target": target}
88 
89     def test_end(self, outputs):
90         return self.validation_end(outputs)
91 
92     def test_epoch_end(self, outputs):
93         output_test_predictions_file = os.path.join(self.hparams.output_dir, "test_predictions.txt")
94         output_test_targets_file = os.path.join(self.hparams.output_dir, "test_targets.txt")
95         # write predictions and targets for later rouge evaluation.
96         with open(output_test_predictions_file, "w+") as p_writer, open(output_test_targets_file, "w+") as t_writer:
97             for output_batch in outputs:
98                 p_writer.writelines(s + "\n" for s in output_batch["preds"])
99                 t_writer.writelines(s + "\n" for s in output_batch["target"])
100             p_writer.close()
101             t_writer.close()
102 
103         return self.test_end(outputs)
104 
105     def get_dataloader(self, type_path: str, batch_size: int) -> DataLoader:
106         dataset = SummarizationDataset(self.tokenizer, type_path=type_path, **self.dataset_kwargs)
107         dataloader = DataLoader(dataset, batch_size=batch_size, collate_fn=dataset.collate_fn)
108         return dataloader
109 
110     def train_dataloader(self) -> DataLoader:
111         dataloader = self.get_dataloader("train", batch_size=self.hparams.train_batch_size)
112         t_total = (
113             (len(dataloader.dataset) // (self.hparams.train_batch_size * max(1, self.hparams.n_gpu)))
114             // self.hparams.gradient_accumulation_steps
115             * float(self.hparams.num_train_epochs)
116         )
117         scheduler = get_linear_schedule_with_warmup(
118             self.opt, num_warmup_steps=self.hparams.warmup_steps, num_training_steps=t_total
119         )
120         self.lr_scheduler = scheduler
121         return dataloader
122 
123     def val_dataloader(self) -> DataLoader:
124         return self.get_dataloader("val", batch_size=self.hparams.eval_batch_size)
125 
126     def test_dataloader(self) -> DataLoader:
127         return self.get_dataloader("test", batch_size=self.hparams.eval_batch_size)
128 
129     @staticmethod
130     def add_model_specific_args(parser, root_dir):
131         BaseTransformer.add_model_specific_args(parser, root_dir)
132         # Add BART specific options
133         parser.add_argument(
134             "--max_source_length",
135             default=1024,
136             type=int,
137             help="The maximum total input sequence length after tokenization. Sequences longer "
138             "than this will be truncated, sequences shorter will be padded.",
139         )
140         parser.add_argument(
141             "--max_target_length",
142             default=56,
143             type=int,
144             help="The maximum total input sequence length after tokenization. Sequences longer "
145             "than this will be truncated, sequences shorter will be padded.",
146         )
147 
148         parser.add_argument(
149             "--data_dir",
150             default=None,
151             type=str,
152             required=True,
153             help="The input data dir. Should contain the dataset files for the CNN/DM summarization task.",
154         )
155         return parser
156 
157 
158 def main(args):
159 
160     # If output_dir not provided, a folder will be generated in pwd
161     if not args.output_dir:
162         args.output_dir = os.path.join("./results", f"{args.task}_{time.strftime('%Y%m%d_%H%M%S')}",)
163         os.makedirs(args.output_dir)
164     model = SummarizationTrainer(args)
165     trainer = generic_train(model, args)
166 
167     # Optionally, predict on dev set and write to output_dir
168     if args.do_predict:
169         # See https://github.com/huggingface/transformers/issues/3159
170         # pl use this format to create a checkpoint:
171         # https://github.com/PyTorchLightning/pytorch-lightning/blob/master\
172         # /pytorch_lightning/callbacks/model_checkpoint.py#L169
173         checkpoints = list(sorted(glob.glob(os.path.join(args.output_dir, "checkpointepoch=*.ckpt"), recursive=True)))
174         model = model.load_from_checkpoint(checkpoints[-1])
175         trainer.test(model)
176 
177 
178 if __name__ == "__main__":
179     parser = argparse.ArgumentParser()
180     add_generic_args(parser, os.getcwd())
181     parser = SummarizationTrainer.add_model_specific_args(parser, os.getcwd())
182     args = parser.parse_args()
183 
184     main(args)
185
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/examples/summarization/bart/finetune.py b/examples/summarization/bart/finetune.py
--- a/examples/summarization/bart/finetune.py
+++ b/examples/summarization/bart/finetune.py
@@ -102,13 +102,13 @@
 
         return self.test_end(outputs)
 
-    def get_dataloader(self, type_path: str, batch_size: int) -> DataLoader:
+    def get_dataloader(self, type_path: str, batch_size: int, shuffle: bool = False) -> DataLoader:
         dataset = SummarizationDataset(self.tokenizer, type_path=type_path, **self.dataset_kwargs)
-        dataloader = DataLoader(dataset, batch_size=batch_size, collate_fn=dataset.collate_fn)
+        dataloader = DataLoader(dataset, batch_size=batch_size, collate_fn=dataset.collate_fn, shuffle=shuffle)
         return dataloader
 
     def train_dataloader(self) -> DataLoader:
-        dataloader = self.get_dataloader("train", batch_size=self.hparams.train_batch_size)
+        dataloader = self.get_dataloader("train", batch_size=self.hparams.train_batch_size, shuffle=True)
         t_total = (
             (len(dataloader.dataset) // (self.hparams.train_batch_size * max(1, self.hparams.n_gpu)))
             // self.hparams.gradient_accumulation_steps

{"golden_diff": "diff --git a/examples/summarization/bart/finetune.py b/examples/summarization/bart/finetune.py\n--- a/examples/summarization/bart/finetune.py\n+++ b/examples/summarization/bart/finetune.py\n@@ -102,13 +102,13 @@\n \n         return self.test_end(outputs)\n \n-    def get_dataloader(self, type_path: str, batch_size: int) -> DataLoader:\n+    def get_dataloader(self, type_path: str, batch_size: int, shuffle: bool = False) -> DataLoader:\n         dataset = SummarizationDataset(self.tokenizer, type_path=type_path, **self.dataset_kwargs)\n-        dataloader = DataLoader(dataset, batch_size=batch_size, collate_fn=dataset.collate_fn)\n+        dataloader = DataLoader(dataset, batch_size=batch_size, collate_fn=dataset.collate_fn, shuffle=shuffle)\n         return dataloader\n \n     def train_dataloader(self) -> DataLoader:\n-        dataloader = self.get_dataloader(\"train\", batch_size=self.hparams.train_batch_size)\n+        dataloader = self.get_dataloader(\"train\", batch_size=self.hparams.train_batch_size, shuffle=True)\n         t_total = (\n             (len(dataloader.dataset) // (self.hparams.train_batch_size * max(1, self.hparams.n_gpu)))\n             // self.hparams.gradient_accumulation_steps\n", "issue": "\u2753 Summarization example : Why no shuffling ?\n# \u2753 Questions & Help\r\n\r\nUsually, when loading using Dataloader, data is shuffled for the training set. But in the case of the summarization example, data is not shuffled for training set :\r\n\r\nhttps://github.com/huggingface/transformers/blob/1dc9b3c7847269961458c059ad8ad443b26bf60d/examples/summarization/bart/finetune.py#L105-L108\r\n\r\n---\r\n\r\n**Why data is not shuffled ?**\n", "before_files": [{"content": "import argparse\nimport glob\nimport logging\nimport os\nimport time\n\nimport torch\nfrom torch.utils.data import DataLoader\n\nfrom transformer_base import BaseTransformer, add_generic_args, generic_train, get_linear_schedule_with_warmup\n\n\ntry:\n    from .utils import SummarizationDataset\nexcept ImportError:\n    from utils import SummarizationDataset\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass SummarizationTrainer(BaseTransformer):\n\n    mode = \"language-modeling\"\n\n    def __init__(self, hparams):\n        super().__init__(hparams, num_labels=None, mode=self.mode)\n        self.dataset_kwargs: dict = dict(\n            data_dir=self.hparams.data_dir,\n            max_source_length=self.hparams.max_source_length,\n            max_target_length=self.hparams.max_target_length,\n        )\n\n    def forward(self, input_ids, attention_mask=None, decoder_input_ids=None, lm_labels=None):\n        return self.model(\n            input_ids, attention_mask=attention_mask, decoder_input_ids=decoder_input_ids, lm_labels=lm_labels,\n        )\n\n    def _step(self, batch):\n        pad_token_id = self.tokenizer.pad_token_id\n        source_ids, source_mask, y = batch[\"source_ids\"], batch[\"source_mask\"], batch[\"target_ids\"]\n        y_ids = y[:, :-1].contiguous()\n        lm_labels = y[:, 1:].clone()\n        lm_labels[y[:, 1:] == pad_token_id] = -100\n        outputs = self(source_ids, attention_mask=source_mask, decoder_input_ids=y_ids, lm_labels=lm_labels,)\n\n        loss = outputs[0]\n\n        return loss\n\n    def training_step(self, batch, batch_idx):\n        loss = self._step(batch)\n\n        tensorboard_logs = {\"train_loss\": loss}\n        return {\"loss\": loss, \"log\": tensorboard_logs}\n\n    def validation_step(self, batch, batch_idx):\n        loss = self._step(batch)\n        return {\"val_loss\": loss}\n\n    def validation_end(self, outputs):\n        avg_loss = torch.stack([x[\"val_loss\"] for x in outputs]).mean()\n        tensorboard_logs = {\"val_loss\": avg_loss}\n        return {\"avg_val_loss\": avg_loss, \"log\": tensorboard_logs}\n\n    def test_step(self, batch, batch_idx):\n        pad_token_id = self.tokenizer.pad_token_id\n        source_ids, source_mask, y = SummarizationDataset.trim_seq2seq_batch(batch, pad_token_id)\n        # NOTE: the following kwargs get more speed and lower quality summaries than those in evaluate_cnn.py\n        generated_ids = self.model.generate(\n            input_ids=source_ids,\n            attention_mask=source_mask,\n            num_beams=1,\n            max_length=80,\n            repetition_penalty=2.5,\n            length_penalty=1.0,\n            early_stopping=True,\n            use_cache=True,\n        )\n        preds = [\n            self.tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True)\n            for g in generated_ids\n        ]\n        target = [self.tokenizer.decode(t, skip_special_tokens=True, clean_up_tokenization_spaces=True) for t in y]\n        loss = self._step(batch)\n\n        return {\"val_loss\": loss, \"preds\": preds, \"target\": target}\n\n    def test_end(self, outputs):\n        return self.validation_end(outputs)\n\n    def test_epoch_end(self, outputs):\n        output_test_predictions_file = os.path.join(self.hparams.output_dir, \"test_predictions.txt\")\n        output_test_targets_file = os.path.join(self.hparams.output_dir, \"test_targets.txt\")\n        # write predictions and targets for later rouge evaluation.\n        with open(output_test_predictions_file, \"w+\") as p_writer, open(output_test_targets_file, \"w+\") as t_writer:\n            for output_batch in outputs:\n                p_writer.writelines(s + \"\\n\" for s in output_batch[\"preds\"])\n                t_writer.writelines(s + \"\\n\" for s in output_batch[\"target\"])\n            p_writer.close()\n            t_writer.close()\n\n        return self.test_end(outputs)\n\n    def get_dataloader(self, type_path: str, batch_size: int) -> DataLoader:\n        dataset = SummarizationDataset(self.tokenizer, type_path=type_path, **self.dataset_kwargs)\n        dataloader = DataLoader(dataset, batch_size=batch_size, collate_fn=dataset.collate_fn)\n        return dataloader\n\n    def train_dataloader(self) -> DataLoader:\n        dataloader = self.get_dataloader(\"train\", batch_size=self.hparams.train_batch_size)\n        t_total = (\n            (len(dataloader.dataset) // (self.hparams.train_batch_size * max(1, self.hparams.n_gpu)))\n            // self.hparams.gradient_accumulation_steps\n            * float(self.hparams.num_train_epochs)\n        )\n        scheduler = get_linear_schedule_with_warmup(\n            self.opt, num_warmup_steps=self.hparams.warmup_steps, num_training_steps=t_total\n        )\n        self.lr_scheduler = scheduler\n        return dataloader\n\n    def val_dataloader(self) -> DataLoader:\n        return self.get_dataloader(\"val\", batch_size=self.hparams.eval_batch_size)\n\n    def test_dataloader(self) -> DataLoader:\n        return self.get_dataloader(\"test\", batch_size=self.hparams.eval_batch_size)\n\n    @staticmethod\n    def add_model_specific_args(parser, root_dir):\n        BaseTransformer.add_model_specific_args(parser, root_dir)\n        # Add BART specific options\n        parser.add_argument(\n            \"--max_source_length\",\n            default=1024,\n            type=int,\n            help=\"The maximum total input sequence length after tokenization. Sequences longer \"\n            \"than this will be truncated, sequences shorter will be padded.\",\n        )\n        parser.add_argument(\n            \"--max_target_length\",\n            default=56,\n            type=int,\n            help=\"The maximum total input sequence length after tokenization. Sequences longer \"\n            \"than this will be truncated, sequences shorter will be padded.\",\n        )\n\n        parser.add_argument(\n            \"--data_dir\",\n            default=None,\n            type=str,\n            required=True,\n            help=\"The input data dir. Should contain the dataset files for the CNN/DM summarization task.\",\n        )\n        return parser\n\n\ndef main(args):\n\n    # If output_dir not provided, a folder will be generated in pwd\n    if not args.output_dir:\n        args.output_dir = os.path.join(\"./results\", f\"{args.task}_{time.strftime('%Y%m%d_%H%M%S')}\",)\n        os.makedirs(args.output_dir)\n    model = SummarizationTrainer(args)\n    trainer = generic_train(model, args)\n\n    # Optionally, predict on dev set and write to output_dir\n    if args.do_predict:\n        # See https://github.com/huggingface/transformers/issues/3159\n        # pl use this format to create a checkpoint:\n        # https://github.com/PyTorchLightning/pytorch-lightning/blob/master\\\n        # /pytorch_lightning/callbacks/model_checkpoint.py#L169\n        checkpoints = list(sorted(glob.glob(os.path.join(args.output_dir, \"checkpointepoch=*.ckpt\"), recursive=True)))\n        model = model.load_from_checkpoint(checkpoints[-1])\n        trainer.test(model)\n\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser()\n    add_generic_args(parser, os.getcwd())\n    parser = SummarizationTrainer.add_model_specific_args(parser, os.getcwd())\n    args = parser.parse_args()\n\n    main(args)\n", "path": "examples/summarization/bart/finetune.py"}], "after_files": [{"content": "import argparse\nimport glob\nimport logging\nimport os\nimport time\n\nimport torch\nfrom torch.utils.data import DataLoader\n\nfrom transformer_base import BaseTransformer, add_generic_args, generic_train, get_linear_schedule_with_warmup\n\n\ntry:\n    from .utils import SummarizationDataset\nexcept ImportError:\n    from utils import SummarizationDataset\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass SummarizationTrainer(BaseTransformer):\n\n    mode = \"language-modeling\"\n\n    def __init__(self, hparams):\n        super().__init__(hparams, num_labels=None, mode=self.mode)\n        self.dataset_kwargs: dict = dict(\n            data_dir=self.hparams.data_dir,\n            max_source_length=self.hparams.max_source_length,\n            max_target_length=self.hparams.max_target_length,\n        )\n\n    def forward(self, input_ids, attention_mask=None, decoder_input_ids=None, lm_labels=None):\n        return self.model(\n            input_ids, attention_mask=attention_mask, decoder_input_ids=decoder_input_ids, lm_labels=lm_labels,\n        )\n\n    def _step(self, batch):\n        pad_token_id = self.tokenizer.pad_token_id\n        source_ids, source_mask, y = batch[\"source_ids\"], batch[\"source_mask\"], batch[\"target_ids\"]\n        y_ids = y[:, :-1].contiguous()\n        lm_labels = y[:, 1:].clone()\n        lm_labels[y[:, 1:] == pad_token_id] = -100\n        outputs = self(source_ids, attention_mask=source_mask, decoder_input_ids=y_ids, lm_labels=lm_labels,)\n\n        loss = outputs[0]\n\n        return loss\n\n    def training_step(self, batch, batch_idx):\n        loss = self._step(batch)\n\n        tensorboard_logs = {\"train_loss\": loss}\n        return {\"loss\": loss, \"log\": tensorboard_logs}\n\n    def validation_step(self, batch, batch_idx):\n        loss = self._step(batch)\n        return {\"val_loss\": loss}\n\n    def validation_end(self, outputs):\n        avg_loss = torch.stack([x[\"val_loss\"] for x in outputs]).mean()\n        tensorboard_logs = {\"val_loss\": avg_loss}\n        return {\"avg_val_loss\": avg_loss, \"log\": tensorboard_logs}\n\n    def test_step(self, batch, batch_idx):\n        pad_token_id = self.tokenizer.pad_token_id\n        source_ids, source_mask, y = SummarizationDataset.trim_seq2seq_batch(batch, pad_token_id)\n        # NOTE: the following kwargs get more speed and lower quality summaries than those in evaluate_cnn.py\n        generated_ids = self.model.generate(\n            input_ids=source_ids,\n            attention_mask=source_mask,\n            num_beams=1,\n            max_length=80,\n            repetition_penalty=2.5,\n            length_penalty=1.0,\n            early_stopping=True,\n            use_cache=True,\n        )\n        preds = [\n            self.tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True)\n            for g in generated_ids\n        ]\n        target = [self.tokenizer.decode(t, skip_special_tokens=True, clean_up_tokenization_spaces=True) for t in y]\n        loss = self._step(batch)\n\n        return {\"val_loss\": loss, \"preds\": preds, \"target\": target}\n\n    def test_end(self, outputs):\n        return self.validation_end(outputs)\n\n    def test_epoch_end(self, outputs):\n        output_test_predictions_file = os.path.join(self.hparams.output_dir, \"test_predictions.txt\")\n        output_test_targets_file = os.path.join(self.hparams.output_dir, \"test_targets.txt\")\n        # write predictions and targets for later rouge evaluation.\n        with open(output_test_predictions_file, \"w+\") as p_writer, open(output_test_targets_file, \"w+\") as t_writer:\n            for output_batch in outputs:\n                p_writer.writelines(s + \"\\n\" for s in output_batch[\"preds\"])\n                t_writer.writelines(s + \"\\n\" for s in output_batch[\"target\"])\n            p_writer.close()\n            t_writer.close()\n\n        return self.test_end(outputs)\n\n    def get_dataloader(self, type_path: str, batch_size: int, shuffle: bool = False) -> DataLoader:\n        dataset = SummarizationDataset(self.tokenizer, type_path=type_path, **self.dataset_kwargs)\n        dataloader = DataLoader(dataset, batch_size=batch_size, collate_fn=dataset.collate_fn, shuffle=shuffle)\n        return dataloader\n\n    def train_dataloader(self) -> DataLoader:\n        dataloader = self.get_dataloader(\"train\", batch_size=self.hparams.train_batch_size, shuffle=True)\n        t_total = (\n            (len(dataloader.dataset) // (self.hparams.train_batch_size * max(1, self.hparams.n_gpu)))\n            // self.hparams.gradient_accumulation_steps\n            * float(self.hparams.num_train_epochs)\n        )\n        scheduler = get_linear_schedule_with_warmup(\n            self.opt, num_warmup_steps=self.hparams.warmup_steps, num_training_steps=t_total\n        )\n        self.lr_scheduler = scheduler\n        return dataloader\n\n    def val_dataloader(self) -> DataLoader:\n        return self.get_dataloader(\"val\", batch_size=self.hparams.eval_batch_size)\n\n    def test_dataloader(self) -> DataLoader:\n        return self.get_dataloader(\"test\", batch_size=self.hparams.eval_batch_size)\n\n    @staticmethod\n    def add_model_specific_args(parser, root_dir):\n        BaseTransformer.add_model_specific_args(parser, root_dir)\n        # Add BART specific options\n        parser.add_argument(\n            \"--max_source_length\",\n            default=1024,\n            type=int,\n            help=\"The maximum total input sequence length after tokenization. Sequences longer \"\n            \"than this will be truncated, sequences shorter will be padded.\",\n        )\n        parser.add_argument(\n            \"--max_target_length\",\n            default=56,\n            type=int,\n            help=\"The maximum total input sequence length after tokenization. Sequences longer \"\n            \"than this will be truncated, sequences shorter will be padded.\",\n        )\n\n        parser.add_argument(\n            \"--data_dir\",\n            default=None,\n            type=str,\n            required=True,\n            help=\"The input data dir. Should contain the dataset files for the CNN/DM summarization task.\",\n        )\n        return parser\n\n\ndef main(args):\n\n    # If output_dir not provided, a folder will be generated in pwd\n    if not args.output_dir:\n        args.output_dir = os.path.join(\"./results\", f\"{args.task}_{time.strftime('%Y%m%d_%H%M%S')}\",)\n        os.makedirs(args.output_dir)\n    model = SummarizationTrainer(args)\n    trainer = generic_train(model, args)\n\n    # Optionally, predict on dev set and write to output_dir\n    if args.do_predict:\n        # See https://github.com/huggingface/transformers/issues/3159\n        # pl use this format to create a checkpoint:\n        # https://github.com/PyTorchLightning/pytorch-lightning/blob/master\\\n        # /pytorch_lightning/callbacks/model_checkpoint.py#L169\n        checkpoints = list(sorted(glob.glob(os.path.join(args.output_dir, \"checkpointepoch=*.ckpt\"), recursive=True)))\n        model = model.load_from_checkpoint(checkpoints[-1])\n        trainer.test(model)\n\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser()\n    add_generic_args(parser, os.getcwd())\n    parser = SummarizationTrainer.add_model_specific_args(parser, os.getcwd())\n    args = parser.parse_args()\n\n    main(args)\n", "path": "examples/summarization/bart/finetune.py"}]}