Fix check_training_ready crashing on CPU-only machines - #204
Merged
Conversation
cslht
force-pushed
the
fix/solver-cpu-device-crash
branch
from
August 6, 2026 09:24
e2f575b to
bcc095f
Compare
AnderBiguri
reviewed
Aug 6, 2026
| autofill=autofill, | ||
| verbose=verbose, | ||
| default=torch.device(torch.cuda.current_device()), | ||
| default=torch.device("cuda" if torch.cuda.is_available() else "cpu"), |
Member
There was a problem hiding this comment.
Can't remember not exactly the way this works, but the "current_device" was there explicitly, for machine where you may want to set using cuda:3 and leave the others free. Maybe in this line "cuda" should be torch.cuda.current_device()
check_training_ready passed torch.device(torch.cuda.current_device()) as the default for the device attribute. Python evaluates keyword arguments at call time, so this unconditionally called torch.cuda.current_device(), which raises on systems without CUDA even though self.device is already set in __init__ and the default is never used. Use torch.cuda.is_available() instead, which is safe to call on CPU-only machines and preserves the GPU-default behavior.
cslht
force-pushed
the
fix/solver-cpu-device-crash
branch
from
August 6, 2026 09:37
bcc095f to
4cb8fd8
Compare
Contributor
Author
|
Good point — youre right that the plain
Since |
cslht11
pushed a commit
to cslht11/LION
that referenced
this pull request
Sep 6, 2026
…crash Fix check_training_ready crashing on CPU-only machines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One fix in
LIONsolver.py:check_training_readypassedtorch.device(torch.cuda.current_device())as the default for the device attribute. Python evaluates keyword arguments at call time, so this unconditionally callstorch.cuda.current_device(), which raises on systems without CUDA even thoughself.deviceis already set in__init__and the default is never used. Now usestorch.cuda.is_available(), which is safe on CPU-only machines and preserves the GPU-default behavior.