Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ def select_device(device="", batch_size=0, newline=True):
device = str(device).strip().lower().replace("cuda:", "").replace("none", "") # to string, 'cuda:0' to '0'
cpu = device == "cpu"
mps = device == "mps" # Apple Metal Performance Shaders (MPS)
if cpu or mps:
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # force torch.cuda.is_available() = False
Comment on lines -118 to -119

Choose a reason for hiding this comment

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

💡 MEDIUM: Removing the CUDA_VISIBLE_DEVICES='-1' assignment for cpu/mps makes select_device('cpu') and select_device('mps') no longer guarantee that CUDA is effectively disabled for the current process. Any existing callers that relied on select_device('cpu') to force torch.cuda.is_available() to be False (or to prevent accidental CUDA usage by downstream libs) will now see different behavior. It would be good to double‑check call sites, update any docstrings/comments that describe this behavior, and consider adding a small test to lock in the new contract so this change is intentional and well‑documented.

elif device: # non-cpu device requested
if device and not cpu and not mps: # non-cpu device requested
os.environ["CUDA_VISIBLE_DEVICES"] = device # set environment variable - must be before assert is_available()
assert torch.cuda.is_available() and torch.cuda.device_count() >= len(device.replace(",", "")), (
f"Invalid CUDA '--device {device}' requested, use '--device cpu' or pass valid CUDA device(s)"
Expand Down