-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
add UNSLOTH_ALLOW_CPU=1 path for CPU-only CI / source-inspection tests #5429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,10 @@ def get_device_type(): | |
| # Check torch.accelerator | ||
| if hasattr(torch, "accelerator"): | ||
| if not torch.accelerator.is_available(): | ||
| # Test-only CPU fallback. The env var is read exactly once per | ||
| # process because get_device_type is @functools.cache'd. | ||
| if os.environ.get("UNSLOTH_ALLOW_CPU", "0") == "1": | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The environment variable |
||
| return "cuda" | ||
| raise NotImplementedError( | ||
| "Unsloth cannot find any torch accelerator? You need a GPU." | ||
| ) | ||
|
|
@@ -73,6 +77,8 @@ def get_device_type(): | |
| f"But `torch.accelerator.current_accelerator()` works with it being = `{accelerator}`\n" | ||
| f"Please reinstall torch - it's most likely broken :(" | ||
| ) | ||
| if os.environ.get("UNSLOTH_ALLOW_CPU", "0") == "1": | ||
| return "cuda" | ||
| raise NotImplementedError( | ||
| "Unsloth currently only works on NVIDIA, AMD and Intel GPUs." | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1193,7 +1193,7 @@ def _is_openai_available(): | |
| HAS_FLASH_ATTENTION = False | ||
| HAS_FLASH_ATTENTION_SOFTCAPPING = False | ||
|
|
||
| if DEVICE_TYPE == "cuda": | ||
| if DEVICE_TYPE == "cuda" and torch.cuda.is_available(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this guard correctly prevents hardware probes on CPU hosts, a similar call to |
||
| major_version, minor_version = torch.cuda.get_device_capability() | ||
| torch.cuda.get_device_capability = functools.cache(torch.cuda.get_device_capability) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On CPU-only CI with
UNSLOTH_ALLOW_CPU=1, this guard is reached only after_gpu_inithas already importedDEVICE_TYPEfromunsloth_zoo.device_type(lines 125-130). With any installedunsloth_zooversion that satisfies the current dependency but does not yet include the companion fallback, that import still raisesNotImplementedErrorbefore the new localunsloth/device_type.pyfallback or thistorch.cuda.is_available()guard can run, so the advertisedimport unsloth.trainerpath remains broken unless users happen to upgrade zoo out-of-band.Useful? React with 👍 / 👎.