Skip to content

Fix check_training_ready crashing on CPU-only machines - #204

Merged
AnderBiguri merged 1 commit into
CambridgeCIA:mainfrom
cslht:fix/solver-cpu-device-crash
Aug 6, 2026
Merged

Fix check_training_ready crashing on CPU-only machines#204
AnderBiguri merged 1 commit into
CambridgeCIA:mainfrom
cslht:fix/solver-cpu-device-crash

Conversation

@cslht

@cslht cslht commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

One fix in LIONsolver.py:

  • 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 calls 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. Now uses torch.cuda.is_available(), which is safe on CPU-only machines and preserves the GPU-default behavior.

@cslht
cslht force-pushed the fix/solver-cpu-device-crash branch from e2f575b to bcc095f Compare August 6, 2026 09:24
Comment thread LION/optimizers/LIONsolver.py Outdated
autofill=autofill,
verbose=verbose,
default=torch.device(torch.cuda.current_device()),
default=torch.device("cuda" if torch.cuda.is_available() else "cpu"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
cslht force-pushed the fix/solver-cpu-device-crash branch from bcc095f to 4cb8fd8 Compare August 6, 2026 09:37
@cslht

cslht commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Good point — youre right that the plain "cuda" would ignore current_device(). Ive updated it to keep the original semantics while staying safe on CPU-only machines:

torch.cuda.current_device() if torch.cuda.is_available() else "cpu"

Since torch.cuda.is_available() short-circuits, current_device() is only evaluated when CUDA is present, so the original multi-GPU behavior (e.g. cuda:3) is preserved and CPU-only machines no longer crash.

@AnderBiguri
AnderBiguri merged commit c9d760e into CambridgeCIA:main Aug 6, 2026
1 check passed
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants