{
  "id": "huggingface/device-map-auto-conflict-with-trainer",
  "signature": "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.",
  "signature_zh": "RuntimeError：使用 Trainer 时，模型已通过 device_map='auto' 加载，不支持 device_map='auto'。请设置 device_map=None 或在单个设备上加载模型。",
  "regex": "device_map='auto' is not supported when using Trainer",
  "domain": "huggingface",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Trainer internally manages device placement and conflicts with model parallelism set by `device_map='auto'` from Accelerate, causing a runtime assertion failure.",
  "root_cause_type": "generic",
  "root_cause_zh": "Trainer 内部管理设备分配，与 Accelerate 的 `device_map='auto'` 设置的模型并行冲突，导致运行时断言失败。",
  "versions": [
    {
      "version": "transformers 4.42.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "accelerate 0.28.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "torch 2.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Trainer does not accept `device_map` parameter; it relies on model's existing device map, causing the same conflict.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "DataParallel is incompatible with Trainer's internal gradient accumulation and loss scaling, leading to silent accuracy drop or hang.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Load the model without device_map: `model = AutoModelForCausalLM.from_pretrained('model-name', device_map=None)` and then pass to Trainer.",
      "success_rate": 0.9,
      "how": "Load the model without device_map: `model = AutoModelForCausalLM.from_pretrained('model-name', device_map=None)` and then pass to Trainer.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `accelerate launch` with a config file to manage multi-GPU, and set `device_map=None` in code.",
      "success_rate": 0.85,
      "how": "Use `accelerate launch` with a config file to manage multi-GPU, and set `device_map=None` in code.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Load the model without device_map: `model = AutoModelForCausalLM.from_pretrained('model-name', device_map=None)` and then pass to Trainer.",
    "Use `accelerate launch` with a config file to manage multi-GPU, and set `device_map=None` in code."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/transformers/en/troubleshooting#device-map-issues",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-02-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}