prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  ValueError: could not broadcast input array from shape (2816,384) into shape (2698,384)
  the command to reproduce:
  cd huggingface-transformers/examples/pytorch/question-answering
  python -m torch.distributed.launch --nproc_per_node=8 ./run_qa.py \
  		  --model_name_or_path roberta-large \
  		  --dataset_name squad  \
  		  --do_train --do_eval \
  		  --per_device_train_batch_size 16 \
  		  --per_device_eval_batch_size 256 \
  		  --learning_rate 3e-5 \
  		  --num_train_epochs 2 \
  		  --max_seq_length 384 \
  		  --doc_stride 128 \
  		  --output_dir test_result2/$trials --overwrite_output_dir \
  		  --logging_dir test_result2/$trials/tensorboard --logging_first_step --logging_steps 50 \
                    --fp16
  
  
  
  i tried add "--max_eval_samples 10240", this will fix the error, while the AUC result is quite low(exact_match  = 4.9414, f1 = 8.9784). and when i ran with 1gpu, the above command can succeed(exact_match  = 88.5336, f1 = 94.3266)
  
  
  the full error is "File "./transformers/src/transformers/trainer_pt_utils.py", line 410, in _nested_set_tensors
      i * slice_len : (i + 1) * slice_len
      i * slice_len : (i + 1) * slice_len
  ValueError: could not broadcast input array from shape (2816,384) into shape (2698,384)"
  
  --- 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/pytorch/question-answering/trainer_qa.py`
  Content:
  ```
  1 # coding=utf-8
  2 # Copyright 2020 The HuggingFace Team All rights reserved.
  3 #
  4 # Licensed under the Apache License, Version 2.0 (the "License");
  5 # you may not use this file except in compliance with the License.
  6 # You may obtain a copy of the License at
  7 #
  8 #     http://www.apache.org/licenses/LICENSE-2.0
  9 #
  10 # Unless required by applicable law or agreed to in writing, software
  11 # distributed under the License is distributed on an "AS IS" BASIS,
  12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 # See the License for the specific language governing permissions and
  14 # limitations under the License.
  15 """
  16 A subclass of `Trainer` specific to Question-Answering tasks
  17 """
  18 
  19 from transformers import Trainer, is_torch_tpu_available
  20 from transformers.trainer_utils import PredictionOutput
  21 
  22 
  23 if is_torch_tpu_available():
  24     import torch_xla.core.xla_model as xm
  25     import torch_xla.debug.metrics as met
  26 
  27 
  28 class QuestionAnsweringTrainer(Trainer):
  29     def __init__(self, *args, eval_examples=None, post_process_function=None, **kwargs):
  30         super().__init__(*args, **kwargs)
  31         self.eval_examples = eval_examples
  32         self.post_process_function = post_process_function
  33 
  34     def evaluate(self, eval_dataset=None, eval_examples=None, ignore_keys=None):
  35         eval_dataset = self.eval_dataset if eval_dataset is None else eval_dataset
  36         eval_dataloader = self.get_eval_dataloader(eval_dataset)
  37         eval_examples = self.eval_examples if eval_examples is None else eval_examples
  38 
  39         # Temporarily disable metric computation, we will do it in the loop here.
  40         compute_metrics = self.compute_metrics
  41         self.compute_metrics = None
  42         try:
  43             output = self.prediction_loop(
  44                 eval_dataloader,
  45                 description="Evaluation",
  46                 # No point gathering the predictions if there are no metrics, otherwise we defer to
  47                 # self.args.prediction_loss_only
  48                 prediction_loss_only=True if compute_metrics is None else None,
  49                 ignore_keys=ignore_keys,
  50             )
  51         finally:
  52             self.compute_metrics = compute_metrics
  53 
  54         if self.post_process_function is not None and self.compute_metrics is not None:
  55             eval_preds = self.post_process_function(eval_examples, eval_dataset, output.predictions)
  56             metrics = self.compute_metrics(eval_preds)
  57 
  58             self.log(metrics)
  59         else:
  60             metrics = {}
  61 
  62         if self.args.tpu_metrics_debug or self.args.debug:
  63             # tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.)
  64             xm.master_print(met.metrics_report())
  65 
  66         self.control = self.callback_handler.on_evaluate(self.args, self.state, self.control, metrics)
  67         return metrics
  68 
  69     def predict(self, predict_dataset, predict_examples, ignore_keys=None):
  70         predict_dataloader = self.get_test_dataloader(predict_dataset)
  71 
  72         # Temporarily disable metric computation, we will do it in the loop here.
  73         compute_metrics = self.compute_metrics
  74         self.compute_metrics = None
  75         try:
  76             output = self.prediction_loop(
  77                 predict_dataloader,
  78                 description="Prediction",
  79                 # No point gathering the predictions if there are no metrics, otherwise we defer to
  80                 # self.args.prediction_loss_only
  81                 prediction_loss_only=True if compute_metrics is None else None,
  82                 ignore_keys=ignore_keys,
  83             )
  84         finally:
  85             self.compute_metrics = compute_metrics
  86 
  87         if self.post_process_function is None or self.compute_metrics is None:
  88             return output
  89 
  90         predictions = self.post_process_function(predict_examples, predict_dataset, output.predictions, "predict")
  91         metrics = self.compute_metrics(predictions)
  92 
  93         return PredictionOutput(predictions=predictions.predictions, label_ids=predictions.label_ids, metrics=metrics)
  94
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/examples/pytorch/question-answering/trainer_qa.py b/examples/pytorch/question-answering/trainer_qa.py
  --- a/examples/pytorch/question-answering/trainer_qa.py
  +++ b/examples/pytorch/question-answering/trainer_qa.py
  @@ -39,8 +39,9 @@
           # Temporarily disable metric computation, we will do it in the loop here.
           compute_metrics = self.compute_metrics
           self.compute_metrics = None
  +        eval_loop = self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
           try:
  -            output = self.prediction_loop(
  +            output = eval_loop(
                   eval_dataloader,
                   description="Evaluation",
                   # No point gathering the predictions if there are no metrics, otherwise we defer to
  @@ -72,8 +73,9 @@
           # Temporarily disable metric computation, we will do it in the loop here.
           compute_metrics = self.compute_metrics
           self.compute_metrics = None
  +        eval_loop = self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
           try:
  -            output = self.prediction_loop(
  +            output = eval_loop(
                   predict_dataloader,
                   description="Prediction",
                   # No point gathering the predictions if there are no metrics, otherwise we defer to
  
verification_info: {"golden_diff": "diff --git a/examples/pytorch/question-answering/trainer_qa.py b/examples/pytorch/question-answering/trainer_qa.py\n--- a/examples/pytorch/question-answering/trainer_qa.py\n+++ b/examples/pytorch/question-answering/trainer_qa.py\n@@ -39,8 +39,9 @@\n         # Temporarily disable metric computation, we will do it in the loop here.\n         compute_metrics = self.compute_metrics\n         self.compute_metrics = None\n+        eval_loop = self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop\n         try:\n-            output = self.prediction_loop(\n+            output = eval_loop(\n                 eval_dataloader,\n                 description=\"Evaluation\",\n                 # No point gathering the predictions if there are no metrics, otherwise we defer to\n@@ -72,8 +73,9 @@\n         # Temporarily disable metric computation, we will do it in the loop here.\n         compute_metrics = self.compute_metrics\n         self.compute_metrics = None\n+        eval_loop = self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop\n         try:\n-            output = self.prediction_loop(\n+            output = eval_loop(\n                 predict_dataloader,\n                 description=\"Prediction\",\n                 # No point gathering the predictions if there are no metrics, otherwise we defer to\n", "issue": "ValueError: could not broadcast input array from shape (2816,384) into shape (2698,384)\nthe command to reproduce:\r\ncd huggingface-transformers/examples/pytorch/question-answering\r\npython -m torch.distributed.launch --nproc_per_node=8 ./run_qa.py \\\r\n\t\t  --model_name_or_path roberta-large \\\r\n\t\t  --dataset_name squad  \\\r\n\t\t  --do_train --do_eval \\\r\n\t\t  --per_device_train_batch_size 16 \\\r\n\t\t  --per_device_eval_batch_size 256 \\\r\n\t\t  --learning_rate 3e-5 \\\r\n\t\t  --num_train_epochs 2 \\\r\n\t\t  --max_seq_length 384 \\\r\n\t\t  --doc_stride 128 \\\r\n\t\t  --output_dir test_result2/$trials --overwrite_output_dir \\\r\n\t\t  --logging_dir test_result2/$trials/tensorboard --logging_first_step --logging_steps 50 \\\r\n                  --fp16\r\n\r\n\r\n\r\ni tried add \"--max_eval_samples 10240\", this will fix the error, while the AUC result is quite low(exact_match  = 4.9414, f1 = 8.9784). and when i ran with 1gpu, the above command can succeed(exact_match  = 88.5336, f1 = 94.3266)\r\n\r\n\r\nthe full error is \"File \"./transformers/src/transformers/trainer_pt_utils.py\", line 410, in _nested_set_tensors\r\n    i * slice_len : (i + 1) * slice_len\r\n    i * slice_len : (i + 1) * slice_len\r\nValueError: could not broadcast input array from shape (2816,384) into shape (2698,384)\"\n", "before_files": [{"content": "# coding=utf-8\n# Copyright 2020 The HuggingFace Team All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"\nA subclass of `Trainer` specific to Question-Answering tasks\n\"\"\"\n\nfrom transformers import Trainer, is_torch_tpu_available\nfrom transformers.trainer_utils import PredictionOutput\n\n\nif is_torch_tpu_available():\n    import torch_xla.core.xla_model as xm\n    import torch_xla.debug.metrics as met\n\n\nclass QuestionAnsweringTrainer(Trainer):\n    def __init__(self, *args, eval_examples=None, post_process_function=None, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.eval_examples = eval_examples\n        self.post_process_function = post_process_function\n\n    def evaluate(self, eval_dataset=None, eval_examples=None, ignore_keys=None):\n        eval_dataset = self.eval_dataset if eval_dataset is None else eval_dataset\n        eval_dataloader = self.get_eval_dataloader(eval_dataset)\n        eval_examples = self.eval_examples if eval_examples is None else eval_examples\n\n        # Temporarily disable metric computation, we will do it in the loop here.\n        compute_metrics = self.compute_metrics\n        self.compute_metrics = None\n        try:\n            output = self.prediction_loop(\n                eval_dataloader,\n                description=\"Evaluation\",\n                # No point gathering the predictions if there are no metrics, otherwise we defer to\n                # self.args.prediction_loss_only\n                prediction_loss_only=True if compute_metrics is None else None,\n                ignore_keys=ignore_keys,\n            )\n        finally:\n            self.compute_metrics = compute_metrics\n\n        if self.post_process_function is not None and self.compute_metrics is not None:\n            eval_preds = self.post_process_function(eval_examples, eval_dataset, output.predictions)\n            metrics = self.compute_metrics(eval_preds)\n\n            self.log(metrics)\n        else:\n            metrics = {}\n\n        if self.args.tpu_metrics_debug or self.args.debug:\n            # tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.)\n            xm.master_print(met.metrics_report())\n\n        self.control = self.callback_handler.on_evaluate(self.args, self.state, self.control, metrics)\n        return metrics\n\n    def predict(self, predict_dataset, predict_examples, ignore_keys=None):\n        predict_dataloader = self.get_test_dataloader(predict_dataset)\n\n        # Temporarily disable metric computation, we will do it in the loop here.\n        compute_metrics = self.compute_metrics\n        self.compute_metrics = None\n        try:\n            output = self.prediction_loop(\n                predict_dataloader,\n                description=\"Prediction\",\n                # No point gathering the predictions if there are no metrics, otherwise we defer to\n                # self.args.prediction_loss_only\n                prediction_loss_only=True if compute_metrics is None else None,\n                ignore_keys=ignore_keys,\n            )\n        finally:\n            self.compute_metrics = compute_metrics\n\n        if self.post_process_function is None or self.compute_metrics is None:\n            return output\n\n        predictions = self.post_process_function(predict_examples, predict_dataset, output.predictions, \"predict\")\n        metrics = self.compute_metrics(predictions)\n\n        return PredictionOutput(predictions=predictions.predictions, label_ids=predictions.label_ids, metrics=metrics)\n", "path": "examples/pytorch/question-answering/trainer_qa.py"}], "after_files": [{"content": "# coding=utf-8\n# Copyright 2020 The HuggingFace Team All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"\nA subclass of `Trainer` specific to Question-Answering tasks\n\"\"\"\n\nfrom transformers import Trainer, is_torch_tpu_available\nfrom transformers.trainer_utils import PredictionOutput\n\n\nif is_torch_tpu_available():\n    import torch_xla.core.xla_model as xm\n    import torch_xla.debug.metrics as met\n\n\nclass QuestionAnsweringTrainer(Trainer):\n    def __init__(self, *args, eval_examples=None, post_process_function=None, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.eval_examples = eval_examples\n        self.post_process_function = post_process_function\n\n    def evaluate(self, eval_dataset=None, eval_examples=None, ignore_keys=None):\n        eval_dataset = self.eval_dataset if eval_dataset is None else eval_dataset\n        eval_dataloader = self.get_eval_dataloader(eval_dataset)\n        eval_examples = self.eval_examples if eval_examples is None else eval_examples\n\n        # Temporarily disable metric computation, we will do it in the loop here.\n        compute_metrics = self.compute_metrics\n        self.compute_metrics = None\n        eval_loop = self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop\n        try:\n            output = eval_loop(\n                eval_dataloader,\n                description=\"Evaluation\",\n                # No point gathering the predictions if there are no metrics, otherwise we defer to\n                # self.args.prediction_loss_only\n                prediction_loss_only=True if compute_metrics is None else None,\n                ignore_keys=ignore_keys,\n            )\n        finally:\n            self.compute_metrics = compute_metrics\n\n        if self.post_process_function is not None and self.compute_metrics is not None:\n            eval_preds = self.post_process_function(eval_examples, eval_dataset, output.predictions)\n            metrics = self.compute_metrics(eval_preds)\n\n            self.log(metrics)\n        else:\n            metrics = {}\n\n        if self.args.tpu_metrics_debug or self.args.debug:\n            # tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.)\n            xm.master_print(met.metrics_report())\n\n        self.control = self.callback_handler.on_evaluate(self.args, self.state, self.control, metrics)\n        return metrics\n\n    def predict(self, predict_dataset, predict_examples, ignore_keys=None):\n        predict_dataloader = self.get_test_dataloader(predict_dataset)\n\n        # Temporarily disable metric computation, we will do it in the loop here.\n        compute_metrics = self.compute_metrics\n        self.compute_metrics = None\n        eval_loop = self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop\n        try:\n            output = eval_loop(\n                predict_dataloader,\n                description=\"Prediction\",\n                # No point gathering the predictions if there are no metrics, otherwise we defer to\n                # self.args.prediction_loss_only\n                prediction_loss_only=True if compute_metrics is None else None,\n                ignore_keys=ignore_keys,\n            )\n        finally:\n            self.compute_metrics = compute_metrics\n\n        if self.post_process_function is None or self.compute_metrics is None:\n            return output\n\n        predictions = self.post_process_function(predict_examples, predict_dataset, output.predictions, \"predict\")\n        metrics = self.compute_metrics(predictions)\n\n        return PredictionOutput(predictions=predictions.predictions, label_ids=predictions.label_ids, metrics=metrics)\n", "path": "examples/pytorch/question-answering/trainer_qa.py"}]}