huggingface
config_error
ai_generated
true
ValueError: Cannot use device_map='auto' with pipeline when device is explicitly set to 0. Please set device_map=None or remove device argument.
ID: huggingface/pipeline-device-map-conflict
92%Fix Rate
90%Confidence
1Evidence
2024-03-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| transformers>=4.30.0 | active | — | — | — |
| accelerate>=0.20.0 | active | — | — | — |
Root Cause
The pipeline API conflicts when both `device` and `device_map` are specified; `device_map='auto'` requires the model to be loaded with Accelerate's device mapping, which is incompatible with a fixed device index.
generic中文
当同时指定 `device` 和 `device_map` 时,pipeline API 发生冲突;`device_map='auto'` 要求模型使用 Accelerate 的设备映射加载,这与固定的设备索引不兼容。
Official Documentation
https://huggingface.co/docs/transformers/v4.30.0/en/main_classes/pipelines#pipeline-device-mapWorkarounds
-
95% success Remove the `device` argument and use only `device_map='auto'`: pipe = pipeline('text-generation', model='model-name', device_map='auto'). This lets Accelerate handle device placement.
Remove the `device` argument and use only `device_map='auto'`: pipe = pipeline('text-generation', model='model-name', device_map='auto'). This lets Accelerate handle device placement. -
90% success Remove `device_map` and use `device=0` explicitly: pipe = pipeline('text-generation', model='model-name', device=0). This forces the model onto GPU 0.
Remove `device_map` and use `device=0` explicitly: pipe = pipeline('text-generation', model='model-name', device=0). This forces the model onto GPU 0.
中文步骤
移除 `device` 参数,仅使用 `device_map='auto'`:pipe = pipeline('text-generation', model='model-name', device_map='auto')。这使 Accelerate 处理设备放置。移除 `device_map` 并显式使用 `device=0`:pipe = pipeline('text-generation', model='model-name', device=0)。这强制模型使用 GPU 0。
Dead Ends
Common approaches that don't work:
-
Set both `device=0` and `device_map='auto'` and expect the pipeline to resolve the conflict
100% fail
The pipeline raises a ValueError immediately because the two arguments are mutually exclusive.
-
Use `device_map='sequential'` instead of 'auto'
90% fail
The same conflict applies; any non-None device_map with an explicit device argument will raise an error.
-
Set `device=-1` to use CPU and keep device_map='auto'
80% fail
device_map='auto' requires at least one GPU to be available; setting device=-1 will cause a separate error about no GPU found.