Repository navigation
[CUDA] Add locality-domain green context support - #190656
MatthiasKohl wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/190656
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 11 Unrelated Failures, 11 Unclassified FailuresAs of commit de02341 with merge base 9b6e452 ( NEW FAILURES - The following jobs have failed:
UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
6ecbe75 to
0175ab3
Compare
|
I take it from @ptrblck there are no public cuda-python 13.4 wheels yet? |
0175ab3 to
6bbb65c
Compare
Small PR building on top of #190639 / #192256 to use the cuda-bindings 13.4 beta for the CUDA 13.4 image specifically. This unblocks testing of PRs requiring CUDA 13.4 + cuda-bindings (e.g. #190656) CC: @tinglvv @nWEIdia @atalman @malfet @eqy @ptrblck Pull Request resolved: #192769 Approved by: https://github.com/tinglvv, https://github.com/atalman
|
@ngimel tests should now be possible in the 13.4 CI image. I'll rebase and fix linting, then we can hopefully run all tests here |
6bbb65c to
5fe69c0
Compare
|
Still no 13.4 cuda-python on pypi, so how does docker get it? |
|
There should be a preview release on pypi which we added to CI here #192769 |
) Small PR building on top of pytorch#190639 / pytorch#192256 to use the cuda-bindings 13.4 beta for the CUDA 13.4 image specifically. This unblocks testing of PRs requiring CUDA 13.4 + cuda-bindings (e.g. pytorch#190656) CC: @tinglvv @nWEIdia @atalman @malfet @eqy @ptrblck Pull Request resolved: pytorch#192769 Approved by: https://github.com/tinglvv, https://github.com/atalman
|
@claude the failure in CI seems to be networking related. How can I restart just this one job? |
|
@claude I assume CI failures are unrelated, so this should be safe to land? |
|
Claude finished @eqy's task in 3m 18s —— View job CI check: failures are unrelated — safe to land, with two caveats
Short answer: yes, the one failure is infra/network, not this PR. But CI green here does not validate the new locality-domain code paths, and the PR still needs a release-notes label. DetailsThe failureAt head
curl status 56 is a transport-level read failure against This PR touches Caveat 1: green CI is not evidence the new code works
So the load-bearing validation is your own Blackwell/Rubin runs, not this CI signal. Worth confirming in the PR description which of the 310 new test lines actually executed there (the mocked ones — Caveat 2: label blockerpytorch-bot flagged that this PR needs a On landing mechanicsSince the red job is a genuine infra flake, One non-blocking noteThe three new mocked tests reach fairly deep into module privates ( |
|
@pytorchmergebot merge -i |
|
This PR needs to be approved by an authorized maintainer before merge. |
|
@pytorchmergebot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
d80d25e to
c631b67
Compare
|
There are 0 13.4 CI jobs |
|
@pytorchbot review this PR, pay special attention to correctness and concurrency issues |
|
❌ 🤖 pytorchbot command failed: Try |
|
|
||
| def execute_in_green_contexts( | ||
| green_ctx_streams: list[torch.cuda.Stream], | ||
| fn: Callable[[int, GreenContext | None], None], |
There was a problem hiding this comment.
why does the function need GreenContext argument? None of the tests show the need for it
There was a problem hiding this comment.
that's a good point, it was necessary previously when using the green context as a context manager to activate execution in it. Since we now just use the stream, it's only a convenience thing, but the user can simply extract the green context from the stream through get_green_context_from_stream as it's done in the implementation right now.
I'll update this to remove the GreenContext argument and I'll just add a short comment mentioning that you can get the context through get_green_context_from_stream if necessary
9014212 to
1d3e64c
Compare
|
|
|
@ngimel we now have 13.4 CI jobs here through the periodic workflow. This job shows the new green context tests passing on 13.4: https://github.com/pytorch/pytorch/actions/runs/35190939624/job/105110156370?pr=190656 Right now, there are 10 running/pending CPU-only checks, but they are unrelated to this PR. The 9 failures are classified as follows:
All of the above are unrelated to this PR, so I believe this PR is OK to merge, as soon as CI has run through. |
|
@claude any outstanding TODOs before landing? |
|
Claude finished @eqy's task in 11m 44s —— View job Nothing blocking from the review threads — both are addressed. Two small correctness nits and a label check remain.
DetailsOutstanding review comments: both done
CI11 workflow runs at head The 13.4 job does now exercise the real code: periodic / linux-jammy-cuda13.4 test — that resolves the "green CI proves nothing" caveat from my earlier comment. 1.
|
|
Let's revisit requests in #195378 - it asks for disjoint partitioning of SMs that's totally unrelated to locality domains, and, in fact, can and should be used on devices that don't support locality domains. That's how we should have structured the rollout:
“Building on top” should mean supplying locality constraints during SM selection, rather than splitting arbitrarily and assigning domain labels afterward. |
| # any device with SM < 10.0 or SM == 12.X has 1 locality domain, so | ||
| # we can safely provide the result without initializing the CUDA context | ||
| # and poisoning the fork. In the future, this might need to be updated. | ||
| capability = torch.cuda._raw_device_capability_nvml(device_id) |
There was a problem hiding this comment.
does this correctly work on heterogenous systems where device are renumbered via CUDA_VISIBLE_DEVICE? Even without renumbering, I think this implicitly relies on cuda runtime and pcie device order being the same, which is not guaranteed
There was a problem hiding this comment.
yeah e.g., GB300 stations explicitly have RTX as index 0, GB300 as index 1 in nvidia-smi while the runtime orders by "speed" putting GB300 first
There was a problem hiding this comment.
thanks for raising it ! I now check against all visible devices, and extended the test to support a few other corner cases.
Ideally, we should remove this logic here entirely and just rely on the CUDA driver, but this logic was requested by the vLLM team, so I kept it in for now.
1d3e64c to
6f93160
Compare
| # any device with SM < 10.0 or SM == 12.X has 1 locality domain, so | ||
| # we can safely provide the result without initializing the CUDA context | ||
| # and poisoning the fork. In the future, this might need to be updated. | ||
| capability = torch.cuda._raw_device_capability_nvml(device_id) |
There was a problem hiding this comment.
thanks for raising it ! I now check against all visible devices, and extended the test to support a few other corner cases.
Ideally, we should remove this logic here entirely and just rely on the CUDA driver, but this logic was requested by the vLLM team, so I kept it in for now.
ngimel
left a comment
There was a problem hiding this comment.
Let's first nail down the splitting public API and implementation (one PR) and then move on to adding locality domain on top. Current design mixes resource spliltting and creating green context from split resources.
| num_sms: int | None = None, | ||
| workqueue_scope: str | None = None, | ||
| workqueue_concurrency_limit: int | None = None, | ||
| disjoint_split: tuple[GreenContextSplit, int] | None = None, |
There was a problem hiding this comment.
Concurrent initialization can invalidate disjointness. The global cache (/tmp/190656.diff:1101) allows simultaneous misses to execute separate CUDA
splits. Each constructor independently selects a group, so sibling contexts can come from different splits and overlap. This was reproduced with a mock driver
returning different valid partitions. Materialize the split once and pass its resources to the constructors. The factory should own that operation;
configuration equality plus a cache should not establish the guarantee.
This is not a problem for existing invocation from split but it is a problem for publicly exposed GreenContext constructor.
In general, this way of construction mixes two separate concerns - creating a green context from resources, and splitting resources. We should separate them
- Validate the complete request.
- Perform one CUDA split.
- Construct each context from its returned resource.
e.g.
resources, remainder = split_resources(input_resource, specifications)
contexts = tuple(
GreenContext._from_sm_resource(resource, ...)
for resource in resources
)
This also gives the factory a straightforward way to accept workqueue configuration.
There should be no disjoint_split constructor argument.
For recursively partitioning the remainder, expose a small object representing an actual SM resource, with its device and actual SM count. It could support:
subpartitions = partition.split(...)
ctx = GreenContext(sm_partition=subpartitions[0], ...)
There was a problem hiding this comment.
I don't fully understand this concern. The driver's implementation of splits is fully deterministic and this is quite important for how green contexts work internally. If the driver would return different partitions for the same input arguments, that would be a driver bug.
If you still prefer using an upfront split, I can implement that, but it will simply complicate the code further as we need to have two more or less separate code paths, one for non-disjoint green contexts and one for disjoint ones.
I think we should also think about what the goal is here:
"recursively partitioning the remainder" simply doesn't make much sense in the general case as the remainder will have almost 0 guarantees w.r.t. the given constraints of the original split. For example, the remainder of a split by locality domain 0 is not simply "locality domain 1", it has no guarantee on locality domain. Similar things hold for the coscheduled SM count, or even the SM count without backfill. With backfill, there are even less constraints on the remainder, as more or less anything can land in there, and a further split without backfill might not even be possible. It's hard to see how one would want to recursively split that and get something useful out of it.
If you are sure that we want this functionality, I can implement it, but I'd like to verify upfront first.
There was a problem hiding this comment.
concerning separate PRs, I can create a new one of course, but it would be good to have the full code reviewed first as the addition of locality domains changes some of the arguments for the public API that make sense to me
|
@MatthiasKohl here's what I had in mind https://github.com/pytorch/pytorch/compare/ngimel/green-context-sm-partitions?expand=1, please take a look at whether it supports the requirements fomr nvidia perspective, it is otherwise more flexible wrt setting workqueue limits and recursive splitting |
Add reusable SMPartition resources and disjoint green-context SM allocation through cuDevSmResourceSplit. Start review with SMPartition.split and its broadcasting, discovery, co-scheduling, and backfill options, then follow GreenContext construction and recursive subdivision through sm_partition. Retain the shared stream execution and lookup helpers, non-owning context wrappers, cached SM counts, and CUDA bindings version checks. Include their documentation and test coverage; locality-domain functionality and its NVML helpers are added separately on top of this commit. Test Plan Ran lint with autofixes through spin using the base_env environment: ```bash PATH=/home/mjoux/base_env/bin:$PATH spin lint -a docs/source/cuda.md test/test_cuda.py torch/cuda/__init__.py torch/cuda/_utils.py torch/cuda/green_contexts.py torch/testing/_internal/common_utils.py git diff --check ``` Tests were not run, as requested; live-system testing is left to the author. Authored with an AI assistant.
CUDA 13.4 adds support for locality domains on NVIDIA Blackwell compute capability 10.x devices. Add locality-domain support to CUDA green contexts using cuda-python, building on the SM partitioning API in the preceding commit. Review the per-group locality constraints and context metadata first, then the locality-count and support queries. Before driver initialization, these queries use NVML where possible, warning and falling back to driver queries when inference fails. Include locality-specific version checks, lazy test skipping, behavioral tests, and documentation. Test Plan Ran lint with autofixes through spin using the base_env environment: ```bash PATH=/home/mjoux/base_env/bin:$PATH spin lint -a docs/source/cuda.md test/test_cuda.py torch/cuda/__init__.py torch/cuda/_utils.py torch/cuda/green_contexts.py torch/testing/_internal/common_utils.py git diff --check git diff --exit-code b5a0445 ``` Tests were not run, as requested; live-system testing is left to the author. Authored with an AI assistant.
cf51a33 to
de02341
Compare
|
@ngimel Thank you very much for taking the time to create this suggestion. I did the following:
There are a few differences I wanted to point out with the current state compared to your proposal:
|
|
I've left a few comments in #198178 but main thing, it still pulls in lots of things that it shouldn't. What do you think of me landing my stack first (adding broadcasting, caching and nvml-based checks), and then you can add execute_in_green_context on top |
|
SGTM. Please go ahead and further simplify #198178 , land that first, then I'll add the remainder on top. |
CUDA 13.4 adds support for locality domains for NVIDIA Blackwell+ Architectures (compute capabilities 10.X).
This PR adds support for locality domains in
torch.cuda.GreenContext, using cuda-python.It also adds a few other features:
GreenContextinstances: this allows converting a (potentially external) green context stream into aGreenContextinstance, allowing to query resources and attributes from the green context associated with a streamgreen_contexts.pyNote: subsequent PRs will allow easy allocation of localized memory. These PRs are only dependent on this one due to the additional utilities (cuda bindings version checking,
get_num_locality_domainsand similar utilities).Test Plan (run on both Blackwell and Rubin systems using CUDA 13.4)
Authored with an AI assistant.
CC @ptrblck @eqy @msaroufim @ngimel @jerryzh168 @ezyang @Aidyn-A