add gather_use_object arguments
Author: SangbumChoi
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes https://github.com/huggingface/transformers/issues/30766 (issue)
I have described the problem and the solution at the issue!

## Before submitting
- [X] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [X] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->

@muellerzr and @SunMarc

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_31514). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@SunMarc Thanks for the clean code!

@amyeroberts For the test part where should I add for the extra kwargs or arguments?

https://github.com/huggingface/transformers/blob/main/tests/trainer/test_trainer.py

Maybe here?

@SangbumChoi Yep - test_trainer.py is perfect 👌 It might be hard to verify if the argument is respected, but if we can pass `eval_use_gather_object=True`, have the trainer do a run (small model, dataset etc.) and evaluate I think it's good enough

@amyeroberts @SunMarc Even though the CI says pass the test I'm little bit skeptical about where did the `test_trainer.py` exactly correspends in the CI... I can't see it from the tests_torch.
https://app.circleci.com/pipelines/github/huggingface/transformers/96590/workflows/8552cb16-a227-4ef5-9919-308482684d63/jobs/1275319

Do I need some extra flag or commit for this?

@SangbumChoi The test_trainer.py tests should run in the test_torch run. If you look at the [test artefacts](https://app.circleci.com/pipelines/github/huggingface/transformers/96590/workflows/8552cb16-a227-4ef5-9919-308482684d63/jobs/1275319/artifacts) e.g. the [test_outputs.txt for the parallel run 1](https://circleci-tasks-prod.s3.us-east-1.amazonaws.com/forks/storage/artifacts/d5b57382-7f67-4274-9623-7f238ef4fb6f/726990544/c656982d-b60b-46fb-ad92-34eb6fff507d/3/tests_output.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAQVFQINEONIQ4VSF6%2F20240627%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240627T175141Z&X-Amz-Expires=60&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEEoaCXVzLWVhc3QtMSJGMEQCIGSL%2BFeJUacal2%2FMGkmMuEULRuhe3dFoUTM4a7M35oUTAiAbn97spnyFz3B65MUD%2B6MTaT1keIPuQFMPltBe6f6lECq0Agjz%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F8BEAMaDDA0NTQ2NjgwNjU1NiIM9jhpzLwlGq%2F6PE3LKogClcamdJ1Q%2BOuRe0oxz2mNN5ALzqnzekCPeRlhmd4Rcu38zB%2F2g3Ir6cJ35%2BmSL%2FDCSM4UV4Z1slWYoQm%2BJH1Pxm7AaDS0cMTzZkRBpMG6f%2Bue5eS%2Bqc4W6vNTrd6%2BIarDVfUL%2BQf722kvM9amzGYRZDpH8o5tjt4SEwKOctK0z0QginRdBZCh%2BBvvNv6944LKQIzDB9XmQ4BwqadteM1jCS35XEZsIf2Ddk4PL29mPfLjeNtsqnY%2FoTaZs%2Fr%2F4sJWMX8WZ29API1trcfr0lY0MD0dxsw0tBa5ePxN7pT7oQbX8%2BsYdjvaDt2PGSzO2GWKwK9AOnJFaXhFJvcNWP4NRt7AEav0rc8FMIvH9rMGOp4B5V%2F0uVWqI1sKY%2Bhb2GzEgzk38z2yo%2FMN6uTHLQWCYPoQU8Bb6wlawe7s7ajNGDeJPMHnlpbzBtE1Bt00BgYTRhErqD0bXn97zPUN9JreQzbRBn8O3rvKFaWOYgQ05%2BhezzyR%2Bs8CkLx5Lgzf67RGqvCBOCreJma9MPu10XsPiJ0%2FNPviQlugJXXZRpX%2F%2FDKoO2jg0Yv7zEAdpwqiNFs%3D&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=828aec5ec83a26997ebcda748bfd26991662c5a2f6170b4c8a8127551131f08d), you can find the `test_trainer.py` tests have run

@amyeroberts I think I don't have access to [test_outputs.txt for the parallel run 1](https://circleci-tasks-prod.s3.us-east-1.amazonaws.com/forks/storage/artifacts/d5b57382-7f67-4274-9623-7f238ef4fb6f/726990544/c656982d-b60b-46fb-ad92-34eb6fff507d/3/tests_output.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAQVFQINEONIQ4VSF6%2F20240627%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240627T175141Z&X-Amz-Expires=60&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEEoaCXVzLWVhc3QtMSJGMEQCIGSL%2BFeJUacal2%2FMGkmMuEULRuhe3dFoUTM4a7M35oUTAiAbn97spnyFz3B65MUD%2B6MTaT1keIPuQFMPltBe6f6lECq0Agjz%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F8BEAMaDDA0NTQ2NjgwNjU1NiIM9jhpzLwlGq%2F6PE3LKogClcamdJ1Q%2BOuRe0oxz2mNN5ALzqnzekCPeRlhmd4Rcu38zB%2F2g3Ir6cJ35%2BmSL%2FDCSM4UV4Z1slWYoQm%2BJH1Pxm7AaDS0cMTzZkRBpMG6f%2Bue5eS%2Bqc4W6vNTrd6%2BIarDVfUL%2BQf722kvM9amzGYRZDpH8o5tjt4SEwKOctK0z0QginRdBZCh%2BBvvNv6944LKQIzDB9XmQ4BwqadteM1jCS35XEZsIf2Ddk4PL29mPfLjeNtsqnY%2FoTaZs%2Fr%2F4sJWMX8WZ29API1trcfr0lY0MD0dxsw0tBa5ePxN7pT7oQbX8%2BsYdjvaDt2PGSzO2GWKwK9AOnJFaXhFJvcNWP4NRt7AEav0rc8FMIvH9rMGOp4B5V%2F0uVWqI1sKY%2Bhb2GzEgzk38z2yo%2FMN6uTHLQWCYPoQU8Bb6wlawe7s7ajNGDeJPMHnlpbzBtE1Bt00BgYTRhErqD0bXn97zPUN9JreQzbRBn8O3rvKFaWOYgQ05%2BhezzyR%2Bs8CkLx5Lgzf67RGqvCBOCreJma9MPu10XsPiJ0%2FNPviQlugJXXZRpX%2F%2FDKoO2jg0Yv7zEAdpwqiNFs%3D&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=828aec5ec83a26997ebcda748bfd26991662c5a2f6170b4c8a8127551131f08d), but I confirmed that the CI passed. Thanks again for the detail description!

```
[gw5] [ 83%] PASSED tests/trainer/test_trainer.py::TrainerIntegrationTest::test_eval_use_gather_object 
tests/trainer/test_trainer.py::TrainerIntegrationTest::test_evaluate 
```