Repository navigation
fix(rng): drop eager host validation in ManagerRng.choice to unblock sync-free hot paths - #2625
Merged
Merged
Conversation
…sync-free hot paths The per-call torch.isfinite / p < 0 check in ManagerRng.choice forced a device-to-host read on every invocation, breaking sync-free step paths (fixed-shape autoreset with sync-debug mode, CUDA graph capture). The check was redundant: torch.multinomial itself fails fast on invalid probabilities (clean RuntimeError on CPU, device-side assert on CUDA), and the eager per-call pattern contradicted the repository's deferred finite-validation boundary. Existing tests only assert metadata checks (type/device/shape), so no coverage is lost. choice is now sync-free; the method docstring documents the caller contract (finite, non-negative probabilities with a positive sum). Closes #2624
6 tasks done
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.
Summary
torch.isfinite(p).all()/(p < 0).any()wrapped inbool(...)) fromManagerRng.choice(src/unilab/managers/rng.py). The twobool(...)calls were device→host reads, so everychoice(n, p=<cuda tensor>)call forced a synchronization that breaks sync-free hot paths: fixed-shape autoreset undertorch.cuda.set_sync_debug_mode("error")hard-fails every step, and the call cannot be captured into a CUDA graph.torch.multinomialitself fails fast on invalid probabilities — a cleanRuntimeErroron CPU and a device-side assert on CUDA (both reproduced experimentally). The eager per-call pattern also contradicted the repository's deferred finite-validation boundary (poll_finite_validation), and itsp.numel() == 0branch was unreachable dead code.tests/managers/test_rng.pyonly asserts metadata checks (type/device/shape), so no test coverage is lost.choiceis now sync-free. The method docstring documents the caller contract:pmust be finite, non-negative, with a positive sum; invalidpfails insidetorch.multinomial(CPU: cleanRuntimeError; CUDA: device-side assert with a poisoned context).RuntimeErrorfromtorch.multinomialinstead of the previousValueError, and only when the caller actually passes invalid input.Linked Work
mainValidation
make test-allpassed on the final local head before this PR was created or updatedCommands actually run:
Impact
ValueErrorto torch'sRuntimeError)ManagerRng.choice; downstream DR terms using it become eligible for sync-free fixed-shape autoreset and CUDA graph capture)Artifacts
Checklist