huggingface config_error ai_generated true

RuntimeError: 在使用 `accelerate` 启动器且多 GPU 时,不能同时设置 `device_map` 和 `device`。

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

其他格式: JSON · Markdown 中文 · English
90%修复率
86%置信度
1证据数
2023-05-10首次发现

版本兼容性

版本状态引入弃用备注
accelerate>=0.20.0 active
transformers>=4.30.0 active

根因分析

在使用 accelerate 启动器且多 GPU 时,设备是自动管理的;同时提供 device_map 和 device 参数会导致设备放置冲突。

English

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.

generic

官方文档

https://huggingface.co/docs/accelerate/en/package_reference/launcher

解决方案

  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.
  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.
  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`).

无效尝试

常见但无效的做法:

  1. 80% 失败

    The error is raised explicitly; both arguments are passed and cause a conflict in the model loading logic.

  2. 50% 失败

    With device=0, the model is placed only on GPU 0, wasting other GPUs and potentially causing OOM on GPU 0.

  3. 40% 失败

    This bypasses accelerate's device management entirely, causing the model to be on a single GPU and not utilizing multi-GPU parallelism.