fix non contiguous tensor value error in save_pretrained
Author: congcongke
Pull request: yes

# What does this PR do?
Fixes # [28293](https://github.com/huggingface/transformers/issues/28293)

This issue is disappeared after this fix.
Any way, only classification case is verified. This PR is just a suggestion.

## 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?
- [ ] 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?

 @ArthurZucker @muellerzr and @SunMarc

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

> Look good to me, would just want a small reproducible snippet please!

reproducing keys:

- dataset: https://huggingface.co/datasets/dirtycomputer/simplifyweibo_4_moods/tree/main
- model: https://huggingface.co/hfl/chinese-roberta-wwm-ext/tree/main
- Hardware: Tesla4 * 2
- Framework: PytorchDDP

`

    model = AutoModelForSequenceClassification.from_pretrained(args.model_path, num_labels=4)

    trainingArg = TrainingArguments(
        output_dir=args.output_path,
        learning_rate=2e-5,
        per_device_train_batch_size=args.batch_size,
        per_device_eval_batch_size=args.batch_size,
        num_train_epochs=args.epoch,
        weight_decay=0.01,
        evaluation_strategy="epoch",
        save_strategy="epoch",
        load_best_model_at_end=True,
        disable_tqdm=True,
        ddp_backend="nccl",
        ddp_timeout=args.ddp_timeout,
        save_on_each_node=False,
        seed=random.randint(0, 100000),
        push_to_hub=False)

    trainer = Trainer(
        model=model,
        args=trainingArg,
        train_dataset=tokenized_imdb["train"],
        eval_dataset=tokenized_imdb["train"],
        tokenizer=tokenizer,
        data_collator=data_collator,
        compute_metrics=compute_metrics,
    )

    trainer.train()
`

I encounter this problem today when I fine-tune google-t5/t5-base model and try to save the fine-tuned model.

System Info:
Transformers version: 4.43.4
pytorch version: 2.4.0
Python version: 3.8.19

![image](https://github.com/user-attachments/assets/75cb38f1-3865-4c48-b3d4-7d61180deb99)


> I encounter this problem today when I fine-tune google-t5/t5-base model and try to save the fine-tuned model.
> 
> System Info: Transformers version: 4.43.4 pytorch version: 2.4.0 Python version: 3.8.19
> 
> ![image](https://private-user-images.githubusercontent.com/34939716/355861055-75cb38f1-3865-4c48-b3d4-7d61180deb99.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMxMDUyMTksIm5iZiI6MTcyMzEwNDkxOSwicGF0aCI6Ii8zNDkzOTcxNi8zNTU4NjEwNTUtNzVjYjM4ZjEtMzg2NS00YzQ4LWIzZDQtN2Q2MTE4MGRlYjk5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODA4VDA4MTUxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc3YmQ5ZDk1YzRjOWI4ZjQ0MjViOGZhNWMzZjk2NjVlMWFkZmE1ZGQwYmE2YzhhY2U3NDg5M2QzZWM3NDBiOGEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.PFL-rXozCCpoO8fLNiaI2mMlHFIe5rApBSWIVl8YpVc)

Would you take this PR as a trial please.

@ZhanGHanG9991 If you can confirm this fixes your error I think we're good to merge! 

Let's merge as there's many approvals and could be blocking 

> @ZhanGHanG9991 If you can confirm this fixes your error I think we're good to merge!

Sorry for not replying in time. I just tried it and the bug has been solved after modification. No more errors!

> > I encounter this problem today when I fine-tune google-t5/t5-base model and try to save the fine-tuned model.
> > System Info: Transformers version: 4.43.4 pytorch version: 2.4.0 Python version: 3.8.19
> > ![image](https://private-user-images.githubusercontent.com/34939716/355861055-75cb38f1-3865-4c48-b3d4-7d61180deb99.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMxMDUyMTksIm5iZiI6MTcyMzEwNDkxOSwicGF0aCI6Ii8zNDkzOTcxNi8zNTU4NjEwNTUtNzVjYjM4ZjEtMzg2NS00YzQ4LWIzZDQtN2Q2MTE4MGRlYjk5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODA4VDA4MTUxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc3YmQ5ZDk1YzRjOWI4ZjQ0MjViOGZhNWMzZjk2NjVlMWFkZmE1ZGQwYmE2YzhhY2U3NDg5M2QzZWM3NDBiOGEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.PFL-rXozCCpoO8fLNiaI2mMlHFIe5rApBSWIVl8YpVc)
> 
> Would you take this PR as a trial please.

I've tried it and the bug has been solved after modification! Thank you!