43125: Ensure correct checkpoint saving behavior by simplifying Trainer.save_model parallelism logic
Author: vaibhav-research
Pull request: yes

# What does this PR do?

This PR improves the correctness and robustness of model checkpoint saving by removing a redundant parallelism_config branch from Trainer.save_model().

The removed logic attempted to special-case checkpoint saving whenever accelerator.parallelism_config was present. In practice, this routing was unnecessary and error-prone, as checkpointing behavior for supported parallelism strategies (FSDP, DeepSpeed, tensor parallelism) is already handled by their respective, dedicated code paths.

As discussed in the linked issue, the presence of this branch could intercept the save flow prematurely, leading to incorrect save semantics—particularly in configurations involving FSDP—by invoking a generic _save() path instead of the required backend-specific logic.

<!--
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.
-->

Fixes #43125 


## 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.
- [ ] 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?

@SunMarc 

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 @Cyrilvallez
- vision models: @yonigozlan @molbap
- audio models: @eustlb @ebezzam @vasqu
- multimodal models: @zucchini-nlp
- graph models: @clefourrier

Library:

- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- continuous batching: @remi-or @ArthurZucker @McPatate
- pipelines: @Rocketknight1
- tokenizers: @ArthurZucker and @itazap
- trainer: @SunMarc
- attention: @vasqu @ArthurZucker @CyrilVallez
- model loading (from pretrained, etc): @CyrilVallez
- distributed: @3outeille @ArthurZucker
- CIs: @ydshieh

Integrations:

- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization: @SunMarc @MekkCyber
- kernels: @MekkCyber @drbh
- peft: @BenjaminBossan @githubnemo

Devices/Backends:

- AMD ROCm: @ivarflakstad
- Intel XPU: @IlyasMoutawwakil
- Ascend NPU: @ivarflakstad 

Documentation: @stevhliu

Research projects are not maintained and should be taken as is.

 -->


Comments:
> Thanks, just a nit

thanks for the review @SunMarc, updated the PR

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

the CI is failing on following test which seems unrelated to this change

```#!/bin/bash -eo pipefail
( python3 -m pytest -m 'not generate' -n 8  -p no:warning -o junit_family=xunit1 --junitxml=test-results/junit.xml --reruns 5 --reruns-delay 2 --only-rerun '(OSError|Timeout|ConnectionError|FileNotFoundError|PIL.UnidentifiedImageError|HTTPError|AssertionError: Tensor-likes are not close!|TypeError: expected str, bytes or os.PathLike object, not NoneType|TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType|Converting from Tiktoken failed|KeyError: <class |TypeError: not a string)' --max-worker-restart=0 -vvv -rsfE --make-reports=tests_torch $(cat splitted_tests.txt) | tee tests_output.txt)

SKIPPED [1] tests/generation/test_utils.py:2063: Model is an encoder-decoder
SKIPPED [1] tests/models/t5gemma2/test_modeling_t5gemma2.py:1003: SiglipVisionModel (vision backbone) does not support standalone training
SKIPPED [1] tests/models/vitdet/test_modeling_vitdet.py:175: Does not work on the tiny model as we keep hitting edge cases.
SKIPPED [1] tests/models/vitdet/test_modeling_vitdet.py:180: Does not work on the tiny model as we keep hitting edge cases.
SKIPPED [1] tests/models/vitdet/test_modeling_vitdet.py:184: Does not work on the tiny model as we keep hitting edge cases.
SKIPPED [3] tests/test_modeling_common.py:3437: VitDetModel does not support grouped_mm
FAILED tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_batched_and_grouped_inference_1_fp32 - RuntimeError: expected data_ptr to be aligned to 16 bytes
FAILED tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_sdpa_inference_08_fp32_pad_left_sdpa_kernels - RuntimeError: expected data_ptr to be aligned to 16 bytes
FAILED tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_sdpa_inference_09_fp32_pad_left - RuntimeError: expected data_ptr to be aligned to 16 bytes
FAILED tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_sdpa_inference_10_fp32_pad_left_no_attn_mask_sdpa_kernels - RuntimeError: expected data_ptr to be aligned to 16 bytes
FAILED tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_sdpa_inference_11_fp32_pad_left_no_attn_mask - RuntimeError: expected data_ptr to be aligned to 16 bytes
FAILED tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_sdpa_inference_12_fp32_pad_right_sdpa_kernels - RuntimeError: expected data_ptr to be aligned to 16 bytes
FAILED tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_sdpa_inference_13_fp32_pad_right - RuntimeError: expected data_ptr to be aligned to 16 bytes
FAILED tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_sdpa_inference_14_fp32_pad_right_no_attn_mask_sdpa_kernels - RuntimeError: expected data_ptr to be aligned to 16 bytes
FAILED tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_sdpa_inference_15_fp32_pad_right_no_attn_mask - RuntimeError: expected data_ptr to be aligned to 16 bytes
= 9 failed, 2647 passed, 3963 skipped, 6 xfailed, 26 warnings in 178.34s (0:02:58) =

Exited with code exit status 1

#!/bin/bash -eo pipefail
python3 .circleci/parse_test_outputs.py --file tests_output.txt --fail

   9 failed because RuntimeError -> expected data_ptr to be aligned to 16 bytes
Number of failed tests: 9

Exited with code exit status 1
```


I just verified a few things on my local

```
(transformer) vaibhavpandey@Vaibhavs-MacBook-Pro transformers % python - <<'PY'
import torch
print("torch:", torch.__version__)
print("mps available:", torch.backends.mps.is_available())
print("cuda available:", torch.cuda.is_available())
PY
torch: 2.9.1
mps available: True
cuda available: False
(transformer) vaibhavpandey@Vaibhavs-MacBook-Pro transformers % CUDA_VISIBLE_DEVICES="" python -m pytest -q \
  tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_batched_and_grouped_inference_1_fp32

tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py::Qwen3OmniMoeThinkerForConditionalGenerationModelTest::test_eager_matches_batched_and_grouped_inference_1_fp32 PASSED [100%]

=================================================== 1 passed in 2.71s ===================================================

```

@SunMarc 
sorry to bother you again, checking in if this is good ? as the tests failing are unrelated to the changes. looking for your inputs.
thanks

all the tests are passing now. looking forward  for your feedback @SunMarc