# RuntimeError: device_map='auto' is not supported when using Trainer with a model that has been loaded with device_map='auto'. Please set device_map=None or load the model on a single device.

- **ID:** `huggingface/device-map-auto-conflict-with-trainer`
- **Domain:** huggingface
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Trainer internally manages device placement and conflicts with model parallelism set by `device_map='auto'` from Accelerate, causing a runtime assertion failure.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| transformers 4.42.0 | active | — | — |
| accelerate 0.28.0 | active | — | — |
| torch 2.2.0 | active | — | — |

## Workarounds

1. **Load the model without device_map: `model = AutoModelForCausalLM.from_pretrained('model-name', device_map=None)` and then pass to Trainer.** (90% success)
   ```
   Load the model without device_map: `model = AutoModelForCausalLM.from_pretrained('model-name', device_map=None)` and then pass to Trainer.
   ```
2. **Use `accelerate launch` with a config file to manage multi-GPU, and set `device_map=None` in code.** (85% success)
   ```
   Use `accelerate launch` with a config file to manage multi-GPU, and set `device_map=None` in code.
   ```

## Dead Ends

- **** — Trainer does not accept `device_map` parameter; it relies on model's existing device map, causing the same conflict. (100% fail)
- **** — DataParallel is incompatible with Trainer's internal gradient accumulation and loss scaling, leading to silent accuracy drop or hang. (80% fail)
