the training crashes at logging_steps when running on a single GPU
Author: gouchangjiang
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.57.3
- Platform: Linux-6.6.97+-x86_64-with-glibc2.35
- Python version: 3.11.11
- Huggingface_hub version: 0.36.0
- Safetensors version: 0.7.0
- Accelerate version: 1.12.0
- Accelerate config:    not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.9.1+cu128 (CUDA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: NVIDIA H100 80GB HBM3

### Who can help?

@SunMarc @3outeille  @ArthurZucker  thanks.

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [x] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

With a single GPU, the program crashes silently at [dist.all_gather(output_tensors, tensor)](https://github.com/huggingface/transformers/blob/799103bf9a0046b3a080bf565de5cb6003a24c78/src/transformers/trainer_pt_utils.py#L210), since this line will be called at the logging step, so it crashes at these steps. Here is a minimum script to reproduce the bug.

```python
import numpy as np
from transformers import Trainer, TrainingArguments, AutoModelForSequenceClassification, AutoConfig
from datasets import Dataset
import evaluate

NUM_SAMPLES = 100
SEQ_LEN = 64
MODEL_NAME = "bert-base-uncased"


def generate_fake_data(num_samples):
    config = AutoConfig.from_pretrained(MODEL_NAME)

    return Dataset.from_dict({
        "input_ids": np.random.randint(0, config.vocab_size, (num_samples, SEQ_LEN)),
        "attention_mask": np.ones((num_samples, SEQ_LEN)), # Attend to everything
        "labels": np.random.randint(0, NUM_LABELS, (num_samples,))
    })

full_dataset = generate_fake_data(NUM_SAMPLES)
dataset_dict = full_dataset.train_test_split(test_size=0.2) 

print(f"Generated {NUM_SAMPLES} random samples.")

config = AutoConfig.from_pretrained(MODEL_NAME, num_labels=NUM_LABELS)
model = AutoModelForSequenceClassification.from_config(config)

print("Model initialized with random weights.")

training_args = TrainingArguments(
    output_dir="./results_dummy",
    num_train_epochs=1,
    per_device_train_batch_size=8,
    per_device_eval_batch_size=8,
    logging_steps=10,
    eval_strategy="steps",
    eval_steps=20,
    save_strategy="no",
    report_to="none",
    use_cpu=False,
)

metric = evaluate.load("accuracy")

def compute_metrics(eval_pred):
    logits, labels = eval_pred
    predictions = logits.argmax(axis=-1)
    return metric.compute(predictions=predictions, references=labels)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=dataset_dict["train"],
    eval_dataset=dataset_dict["test"],
    compute_metrics=compute_metrics,
)

trainer.train()
```
Run the training by `torchrun --nproc-per-node 1 --standalone example.py`

### Expected behavior

sliently crash, 

```bash
Generated 100 random samples.
Model initialized with random weights.
 60%|████████████████████████████████████████████████████████████████████████████▏                                                  | 6/10 [00:00<00:00, 15.72it/s]E1209 07:17:37.043000 148062 site-packages/torch/distributed/elastic/multiprocessing/api.py:882] failed (exitcode: 1) local_rank: 0 (pid: 148160) of binary: /opt/conda/envs/py311/bin/python3.11
Traceback (most recent call last):
  File "/opt/conda/envs/py311/bin/torchrun", line 7, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/conda/envs/py311/lib/python3.11/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 357, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/py311/lib/python3.11/site-packages/torch/distributed/run.py", line 936, in main
    run(args)
  File "/opt/conda/envs/py311/lib/python3.11/site-packages/torch/distributed/run.py", line 927, in run
    elastic_launch(
  File "/opt/conda/envs/py311/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 156, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/envs/py311/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 293, in launch_agent
    raise ChildFailedError(
torch.distributed.elastic.multiprocessing.errors.ChildFailedError: 
============================================================
example.py FAILED
------------------------------------------------------------
Failures:
  <NO_OTHER_FAILURES>
------------------------------------------------------------
Root Cause (first observed failure):
[0]:
  time      : 2025-12-09_07:17:37
  host      : finetune-large-0
  rank      : 0 (local_rank: 0)
  exitcode  : 1 (pid: 148160)
  error_file: <N/A>
  traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
============================================================
```

Comments:
cc @SunMarc 

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.