Repository navigation
Keep the plain capability cache on single-GPU hosts - #13962
Merged
Merged
Conversation
With one visible device every device spelling names it, so caching the call is exact. The per-device wrapper added Python work to every eager get_device_capability(Q.device) hit in attention dispatch; it now only applies when more than one device is visible.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
danielhanchen
added a commit
that referenced
this pull request
Oct 16, 2026
…ice (#13982) ## Summary `Repo tests (CPU, studio)` fails on every PR based on main since #13882 (for example #13960 and #13962): ``` tests/python/test_accelerator_skip_guards.py::test_no_skip_guard_reads_a_spoofable_accelerator_probe E AssertionError: these skip guards read a probe tests/_zoo_aggressive_cuda_spoof.py patches to True process-wide, ... E assert not ['test_optimizer_state_offload.py:139: torch.cuda.is_available()', ...] ``` #13882 added `tests/test_optimizer_state_offload.py` with seven `@pytest.mark.skipif(not torch.cuda.is_available(), ...)` guards. The CUDA spoof the zoo tests install patches `torch.cuda.is_available` to True for the whole process. When this file shares a session with them on a CPU runner, its CUDA cases un-skip and fail. The repo-wide guard caught this before it could flake. The product change is fine; the guards are what is wrong. ## Change Gate those seven cases on `has_real_cuda()` from `tests/_shared/real_accelerator.py`, the same probe the other CUDA-only tests use (#13936, #13937). It checks for a real device rather than the patchable `is_available`. The CPU cases in the file are unchanged. ## Testing - `tests/python/test_accelerator_skip_guards.py` + `tests/test_optimizer_state_offload.py` on CPU: 40 passed, 15 skipped. - With the original file restored, the guard test fails again (1 failed, 23 passed), naming the same seven lines.
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.
Problem
#13923 replaced
functools.cache(torch.cuda.get_device_capability)with a per-device wrapper, so a no-argument call followstorch.cuda.set_device. On a host with one visible GPU that correctness gain cannot apply, but every cache hit now runs Python code (resolve the device, then a dict lookup) instead of the C-levelfunctools.cachehit. The attention helpers callget_device_capability(Q.device)on every eager forward, so single-GPU runs pay a small cost for nothing.Measured on the cache itself (CPU, 300k calls, best of 7):
get_device_capability(Q.device)The last column is the same
functools.cacheobject as before #13923; the residual difference is timer noise.Fix
_cache_device_capabilityreturns the plainfunctools.cachewrapper whentorch.cuda.device_count() <= 1, exactly what main had before #13923. With one visible device every spelling (no argument,0,"cuda:0",torch.device("cuda"),x.device) names the same card, so caching the call is exact. The per-device wrapper is kept for hosts with two or more visible devices, where it is needed.Tests
test_capability_cache_single_device_keeps_the_plain_cache: a one-device host gets afunctools.cacheobject, probed once per distinct argument, and re-wrapping does not stack.tests/test_mixed_nvidia_capabilities.py: 36 passed (the multi-device cases still use the per-device wrapper).test_capability_cache_traces_in_fullgraph(no argument,0,"cuda:0",torch.device("cuda"),x.deviceunderfullgraph=True): 5 passed.