# RuntimeError: You cannot set both `device_map` and `device` when using the `accelerate` launcher with multiple GPUs.

- **ID:** `huggingface/accelerate-multi-gpu-device-map-conflict`
- **Domain:** huggingface
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

When using accelerate launcher with multiple GPUs, the device is automatically managed; providing both device_map and device arguments causes a conflict in device placement.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| accelerate>=0.20.0 | active | — | — |
| transformers>=4.30.0 | active | — | — |

## Workarounds

1. **Remove the `device` argument and only use `device_map='auto'` (or a custom dict) when loading the model. Example: `model = AutoModelForCausalLM.from_pretrained('model-name', device_map='auto')`. The accelerate launcher will handle multi-GPU placement automatically.** (95% success)
   ```
   Remove the `device` argument and only use `device_map='auto'` (or a custom dict) when loading the model. Example: `model = AutoModelForCausalLM.from_pretrained('model-name', device_map='auto')`. The accelerate launcher will handle multi-GPU placement automatically.
   ```
2. **If you must set a specific device, do not use the accelerate launcher; instead, use `with torch.device('cuda:0'): model = ...` and manually wrap with DataParallel or DistributedDataParallel.** (80% success)
   ```
   If you must set a specific device, do not use the accelerate launcher; instead, use `with torch.device('cuda:0'): model = ...` and manually wrap with DataParallel or DistributedDataParallel.
   ```
3. **Use `accelerate launch` without any device_map or device argument in the script; let accelerate handle device placement via its config file (e.g., `--num_processes=4`).** (90% success)
   ```
   Use `accelerate launch` without any device_map or device argument in the script; let accelerate handle device placement via its config file (e.g., `--num_processes=4`).
   ```

## Dead Ends

- **** — The error is raised explicitly; both arguments are passed and cause a conflict in the model loading logic. (80% fail)
- **** — With device=0, the model is placed only on GPU 0, wasting other GPUs and potentially causing OOM on GPU 0. (50% fail)
- **** — This bypasses accelerate's device management entirely, causing the model to be on a single GPU and not utilizing multi-GPU parallelism. (40% fail)
