Repository navigation
Resolve "cuda" to the caller's current GPU - #4
Merged
Merged
Conversation
torch.cuda.set_device is per thread, and ManyPred's prefetch and saving threads start on GPU 0. With set_device(1) and device="cuda", inputs already on cuda:1 were stacked on cuda:0 by the prefetch thread, then copied back, with record_stream given a stream from the other GPU. resolve_device now turns an unindexed "cuda" into cuda:<current device> on the calling thread, so every thread gets an explicit index. Tests: unit tests with a mocked current device, and a two-GPU test (skips with fewer). Codex reviewed the fix: no issues. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes a multi-GPU issue found in the pre-release sweep.
Bug.
torch.cuda.set_deviceis per thread, and ManyPred's prefetch and saving threads start on GPU 0. Aftertorch.cuda.set_device(1)withdevice="cuda"(or no device), the prefetch thread read"cuda"as GPU 0. Inputs already oncuda:1were stacked on GPU 0, copied back, andrecord_streamwas given a stream from the other GPU. Results were never wrong, but it used memory on GPU 0 (possibly another job's) and could crash. Inputs from numpy or files weren't affected.Fix.
resolve_deviceturns an unindexed"cuda"intocuda:<current device>on the calling thread, before any worker thread starts. Every device path (inference,mosaic_device, program.device, ensembles) already goes through it. Explicit"cuda:N", CPU, MPS and machines without CUDA behave as before.Tests.
predict_batchoncuda:1withdevice="cuda"and checks that GPU 0's peak memory doesn't move. It skips with fewer than two GPUs, so it hasn't run yet.Review. Codex reviewed the fix and found no issues. It checked that every device path into worker threads goes through
resolve_device, and thatsame_device,device_lock, ensembles, ROCm andtorch.compileare unaffected.Also adds an
[Unreleased]section to the changelog.🤖 Generated with Claude Code