Fix FSDP2 defaulting to version 1 in TrainingArguments; add dynamic plugin param passthrough
Author: amanzoni1
Pull request: yes

# What does this PR do?

Fixes the bug where `TrainingArguments(fsdp=True, fsdp_config={"fsdp_version": 2, ...})` defaults to FSDP version 1, ignoring the version (unless the Accelerator was initialized manually), and most params were lost.
Adds dynamic passthrough of all FSDP plugin params (FullyShardedDataParallelPlugin) from fsdp_config to the plugin args (future-proof, no hardcoding).

### Changes
- Extract `fsdp_version` pre-stripping to preserve it.
- Skip stripping for "fsdp_version" to avoid mangling.
- Dynamic copy from `FullyShardedDataParallelPlugin` dataclass for all fields.
- Add `test_fsdp_version_2_config` for regression.

### Repro
```python
from transformers import TrainingArguments

args = TrainingArguments(
    output_dir="/tmp/test",
    fsdp=True,
    fsdp_config={
        "fsdp_version": 2,
        "reshard_after_forward": True,
    },
)

# Call the internal method to test argument parsing
plugin_args = args._process_fsdp_args()

# Expected output after this PR:
print(f"fsdp_version: {plugin_args['fsdp_version']}")                      # Before: 1, After: 2
print(f"reshard_after_forward: {plugin_args['reshard_after_forward']}")    # Before: None, After: True
```

## Before submitting
- [ ] 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?
- [ X ] 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.
     https://discuss.huggingface.co/t/how-to-start-fsdp2-when-using-trainer/151885
- [ ] 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).
- [ X ] Did you write any new necessary tests?


## Who can review?

@SunMarc @3outeille

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.


Comments:
Thanks for the feedback @SunMarc!!
implemented the hardcoded defaults + dynamic copy at end, and needed to add a conditional skip for forward_prefetch in v2 (Accelerate raises ValueError otherwise: "ValueError: forward_prefetch is not yet implemented in FSDP2, set to None or use `fsdp_version=1`").
Let me know if that can works

I've merged this PR that seems to fix a bit more things ! Feel free to rebase and add your updates, especially the test is nice ! 

https://github.com/huggingface/transformers/pull/42566

@SunMarc Thanks for the feedback! Rebased onto the latest main, and ready for review

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

Hey @SunMarc, not sure if there's anything more I should do here. The failed CI doesn't seem code related. Thanks!

cc @ArthurZucker can you merge ? 

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=42521&sha=661f54

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=42521&sha=dd3f32