{
  "id": "huggingface/torch-compile-incompatible-with-peft",
  "signature": "RuntimeError: torch.compile is not supported for PEFT models with dynamic adapters",
  "signature_zh": "运行时错误：PEFT模型与动态适配器不兼容torch.compile",
  "regex": "RuntimeError: torch\\.compile is not supported for PEFT models with dynamic adapters",
  "domain": "huggingface",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "torch.compile fails on PEFT models when adapters are dynamically loaded or switched because the computation graph changes during runtime.",
  "root_cause_type": "generic",
  "root_cause_zh": "当适配器被动态加载或切换时，torch.compile在PEFT模型上失败，因为计算图在运行时发生变化。",
  "versions": [
    {
      "version": "transformers>=4.38.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "peft>=0.9.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": "The issue is not about optimization mode; dynamic adapter switching breaks torch.compile's graph tracing regardless of mode.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The incompatibility is fundamental to PEFT's dynamic nature, not a torch bug; nightly versions have the same limitation.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "torch.compile captures the graph at compile time; gradient disabling does not prevent graph changes from dynamic adapters.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use `torch.compile` only after loading all adapters and disable dynamic switching: `model = torch.compile(model, dynamic=False)`",
      "success_rate": 0.85,
      "how": "Use `torch.compile` only after loading all adapters and disable dynamic switching: `model = torch.compile(model, dynamic=False)`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Avoid torch.compile for PEFT models with dynamic adapters; use eager mode with `model.eval()` and manual fusion instead.",
      "success_rate": 0.9,
      "how": "Avoid torch.compile for PEFT models with dynamic adapters; use eager mode with `model.eval()` and manual fusion instead.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Set environment variable `TORCH_COMPILE_DISABLE=1` and rely on `torch.inference_mode()` for inference.",
      "success_rate": 0.95,
      "how": "Set environment variable `TORCH_COMPILE_DISABLE=1` and rely on `torch.inference_mode()` for inference.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use `torch.compile` only after loading all adapters and disable dynamic switching: `model = torch.compile(model, dynamic=False)`",
    "Avoid torch.compile for PEFT models with dynamic adapters; use eager mode with `model.eval()` and manual fusion instead.",
    "Set environment variable `TORCH_COMPILE_DISABLE=1` and rely on `torch.inference_mode()` for inference."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/peft/main/en/developer_guides/torch_compile",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2024-03-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}