Update no_trainer scripts to include gather_for_metrics
Author: muellerzr
Pull request: no
Labels: name: Examples

name: Good First Issue

### Feature request

🤗 Accelerate has a wrapper to help with distributed metric calculation (a tough problem!), and the `no_trainer` scripts should be updated to include it! 

An example can be seen [here](https://github.com/huggingface/accelerate/blob/main/examples/nlp_example.py#L163-L169), below is an example diff of what the integration would look like:

```diff
-             predictions, references = accelerator.gather((predictions, batch["labels"]))
-             # If we are in a multiprocess environment, the last batch has duplicates
-             if accelerator.num_processes > 1:
-                 if step == len(eval_dataloader) - 1:
-                     predictions = predictions[: len(eval_dataloader.dataset) - samples_seen]
-                     references = references[: len(eval_dataloader.dataset) - samples_seen]
-                 else:
-                     samples_seen += references.shape[0]
+             predictions, references = accelerator.gather_for_metrics((predictions, batch["labels"])) 
```

The list of available scripts to update include:

- [x] examples/pytorch/image-classification/run_image_classification_no_trainer.py
- [x] examples/pytorch/language-modeling/run_clm_no_trainer.py
- [x] examples/pytorch/language-modeling/run_mlm_no_trainer.py
- [x] examples/pytorch/multiple-choice/run_swag_no_trainer.py
- [x] examples/pytorch/question-answering/run_qa_beam_search_no_trainer.py
- [x] examples/pytorch/question_answering/run_qa_no_trainer.py
- [x] examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py
- [x] examples/pytorch/speech-pretraining/run_wav2vec2_pretraining_no_trainer.py
- [x] examples/pytorch/summarization/run_summarization_no_trainer.py

### Motivation

This is a great first issue for someone who wants to learn how to use some of the latest bits in Accelerate and get an easy beginner contribution to the library 🤗 

### Your contribution

If you decide to pick up this issue, feel free to ping myself (@muellerzr), @sgugger, or @pacman100 to review 🤗 

Comments:
Hi @muellerzr opened PR #18443  for first three examples in the list.

Hi @muellerzr I opened this PR https://github.com/huggingface/transformers/pull/18468 for the 4th example and ran it locally.
Please let me know if there is any changes, you would like done on this example, And I'll update it and add the feedback while I work on examples 5 and 6

Hi @muellerzr I opened this PR https://github.com/huggingface/transformers/pull/18474 for examples 5,6 and 7.

@muellerzr In the 7th subtask (semantic segmentation), I think it is already updated if I am not wrong.

I want to work on this issue

Hi @muellerzr  I opened this PR #18877 for example 8. Please let me know if there is any changes

This issue needs to be closed. All the work is already done it seems. 

Seems like [example 9](https://github.com/huggingface/transformers/blob/main/examples/pytorch/summarization/run_summarization_no_trainer.py#L692) was already fixed but not checked off.

@muellerzr Can you close this issue?

Thanks to everyone who worked on this!