fix(cpu): return "cpu" from get_device_type() instead of raising when no GPU found#604
fix(cpu): return "cpu" from get_device_type() instead of raising when no GPU found#604LeoBorcherding wants to merge 10 commits into
Conversation
…fs #5008 Fixes CPU-only installs (issue #5008 path 1): get_device_type() now returns "cpu" when no CUDA/XPU/HIP accelerator is available, instead of raising NotImplementedError.
|
Marking PR's as draft, need to test again after latest improvements. Will retest both paths tomorrow against the latest commits before merging. |
There was a problem hiding this comment.
Code Review
This pull request enhances the library's robustness in environments where PyTorch is not installed by introducing a _HAS_TORCH flag and providing fallback values or mocks for torch-dependent variables and functions. It also updates device detection to return "cpu" instead of raising an error when no GPU is found. The review feedback suggests refactoring repetitive _HAS_TORCH checks into a single block for better readability and removing redundant checks where dependent boolean flags already account for the absence of torch.
|
This PR is ready and working with unsloth#5119. Tested end-to-end on Windows CPU-only:
Ready for review with #5119. |
6a63dd7 to
7b3c412
Compare
|
Linux validation done - 3/3 pass on Ubuntu 24.04 (WSL2, Python 3.12, Both PRs are fully validated across platforms. Ready to merge whenever #5119 is reviewed. |
|
check comment on Companion PR: unslothai/unsloth#5119 |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
LeoBorcherding
left a comment
There was a problem hiding this comment.
addressed Datta's concerns, and applied some of Gemini's suggestions
Companion branch: https://github.com/LeoBorcherding/unsloth/tree/fix/cpu-no-torch-import
Companion issue: unslothai/unsloth#5008
Changes
device_type.py: return"cpu"instead of raisingNotImplementedErrorwhen no GPU accelerator found__init__.py: gate all torch-dependent imports and allocator config behind_HAS_TORCH, add CPU stubs for device type functionstemporary_patches/gpt_oss.py: guard CUDA memory query behind device type check to avoid crash on CPUValidation
Validated in LeoBorcherding/unsloth@fix/cpu-no-torch-import. Full validation log posted in unsloth/pull/5119.