Training with Accelerate will crash if using TrainingArguments
Author: tiandeyu-cs
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.47.1
- Platform: Linux-4.18.0-372.9.1.el8.x86_64-x86_64-with-glibc2.35
- Python version: 3.11.10
- Huggingface_hub version: 0.27.0
- Safetensors version: 0.4.5
- Accelerate version: 1.2.1
- Accelerate config:    not found
- PyTorch version (GPU?): 2.5.1+cu124 (True)
- Tensorflow version (GPU?): 2.18.0 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: no
- Using GPU in script?: no
- GPU type: *edited out*

### Who can help?

@muellerzr @SunMarc

### Information

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

### Tasks

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

### Reproduction

The training code `main.py`:

```python
# run with:
# accelerate launch main.py

import torch
from transformers import TrainingArguments, HfArgumentParser
from accelerate import Accelerator
accelerator = Accelerator()

if __name__ == "__main__":
    parser = HfArgumentParser(TrainingArguments)
    
    # it does not matter whether the path exists or not
    d = {"output_dir": "/path/to/output/dir"}
    args = parser.parse_dict(d)

    # it does not matter what the model is
    model = torch.nn.Linear(4, 4)

    # this causes crash
    model = accelerator.prepare(model)
```

Run the following command to reproduce the bug:
```shell
# The configuration of `accelerate` does not affect the bug.
accelerate launch main.py
```

The stack trace:
```
Traceback (most recent call last):
  File "/root/main.py", line 20, in <module>
    model = accelerator.prepare(model)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/accelerate/accelerator.py", line 1294, in prepare
    if self.distributed_type == DistributedType.DEEPSPEED:
       ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/accelerate/accelerator.py", line 568, in distributed_type
    return self.state.distributed_type
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/accelerate/state.py", line 1125, in __getattr__
    raise AttributeError(
AttributeError: `AcceleratorState` object has no attribute `distributed_type`. This happens if `AcceleratorState._reset_state()` was called and an `Accelerator` or `PartialState` was not reinitialized.
Traceback (most recent call last):
  File "/opt/conda/bin/accelerate", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/accelerate/commands/accelerate_cli.py", line 48, in main
    args.func(args)
  File "/opt/conda/lib/python3.11/site-packages/accelerate/commands/launch.py", line 1168, in launch_command
    simple_launcher(args)
  File "/opt/conda/lib/python3.11/site-packages/accelerate/commands/launch.py", line 763, in simple_launcher
    raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)
subprocess.CalledProcessError: Command '['/opt/conda/bin/python3.11', 'main.py']' returned non-zero exit status 1.
```

### Expected behavior

The training should not crash.

Comments:
cc @muellerzr 

If you're using the trainer you should **never** make your own accelerator. I disagree with this "fix" and should raise the error it does

I see. Thanks for your explanation.