refactor: make IPEX optional and enable native Intel XPU detection for PyTorch 2.9+#539
refactor: make IPEX optional and enable native Intel XPU detection for PyTorch 2.9+#539Dailaim wants to merge 2 commits intojamiepine:mainfrom
Conversation
Co-authored-by: Copilot <copilot@github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughXPU detection logic was refactored across three backend files: PyTorch's Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
backend/backends/base.py (1)
91-91: Docstring is now slightly stale.
allow_xpuis documented as "Check for Intel XPU (IPEX) support," but after this refactor XPU availability is determined by nativetorch.xpuand IPEX is only an optional performance shim. Consider:Check for Intel XPU support (native PyTorch 2.5+; IPEX optional).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/backends/base.py` at line 91, Update the docstring entry for the parameter named allow_xpu (in the docstring of the relevant backend class/initializer in backend/backends/base.py) to reflect that XPU availability is determined by native torch.xpu and that IPEX is optional; replace the existing line "Check for Intel XPU (IPEX) support." with something like "Check for Intel XPU support (native PyTorch 2.5+; IPEX optional)".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@backend/app.py`:
- Around line 168-171: The intel_extension_for_pytorch import in backend/app.py
currently only catches ImportError and can still crash _get_gpu_status for
RuntimeError/OSError/AttributeError from incompatible IPEX builds; widen the
handler to catch those exception types (e.g. ImportError, RuntimeError, OSError,
AttributeError) and log the exception at debug level instead of silently passing
so failures are visible (update the try/except around the
intel_extension_for_pytorch import and use the module's logger variable—or the
same logger used by _get_gpu_status—to call logger.debug with the exception
details).
In `@backend/backends/base.py`:
- Around line 105-110: The try/except around the optional
intel_extension_for_pytorch import in the torch XPU detection block only catches
ImportError and can miss RuntimeError/OSError from a broken IPEX install; update
the handler in the device-detection code (the branch using hasattr(torch, "xpu")
and torch.xpu.is_available()) to catch Exception instead of ImportError so
get_torch_device (the XPU-returning path) still returns "xpu" even if importing
intel_extension_for_pytorch fails, keeping downstream functions like
empty_device_cache, manual_seed, and the XPU dtype code paths operational.
In `@backend/routes/health.py`:
- Around line 73-76: The import block that attempts to import
intel_extension_for_pytorch in backend/routes/health.py currently only catches
ImportError; broaden the exception handling to also catch RuntimeError and
OSError so a broken/legacy IPEX install won't crash the /health endpoint—update
the try/except around the import of intel_extension_for_pytorch to catch
(ImportError, RuntimeError, OSError) and quietly ignore or log the exception
with context (e.g., mention the import failed) rather than letting it propagate.
---
Nitpick comments:
In `@backend/backends/base.py`:
- Line 91: Update the docstring entry for the parameter named allow_xpu (in the
docstring of the relevant backend class/initializer in backend/backends/base.py)
to reflect that XPU availability is determined by native torch.xpu and that IPEX
is optional; replace the existing line "Check for Intel XPU (IPEX) support."
with something like "Check for Intel XPU support (native PyTorch 2.5+; IPEX
optional)".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f2b2328a-01f0-4ed3-b073-a0c8ef0304a1
📒 Files selected for processing (3)
backend/app.pybackend/backends/base.pybackend/routes/health.py
This pull request refactors how Intel XPU (Arc / Data Center) support is detected and reported across the backend. The main improvement is to make the import of
intel_extension_for_pytorch(IPEX) optional, acknowledging that native XPU support is now integrated into the official PyTorch stack (since v2.5).This change addresses a critical issue where the latest Intel oneAPI drivers (which support PyTorch 2.9+) cause conflicts with older IPEX versions (v2.8 and below). By prioritizing native detection, the logic becomes more robust and future-proof.
Device detection and reporting improvements:
backend/app.pyto check for native PyTorch XPU support first (torch.xpu.is_available()), removing the hard dependency onintel_extension_for_pytorchfor modern environments.get_torch_deviceinbackend/backends/base.pyto make the IPEX import optional. It now only attempts to load IPEX for legacy support (v2.4 - v2.8) or enhanced performance if present, otherwise falling back to native"xpu".backend/routes/health.pyto report XPU status based on native support, ensuring accurate hardware reporting regardless of whether IPEX is installed.References:
Intel has officially announced the retirement of the IPEX extension, recommending the use of native PyTorch XPU support going forward:
Intel® Extension for PyTorch (IPEX) End of Life
Summary by CodeRabbit