Repository navigation
Studio ROCm layer split: apply the common SDPA guard only once the split fits - #17347
Merged
Merged
Conversation
…lit fits The guard flips process-wide SDPA switches, but it ran while candidate cards were still being filtered. A split later declined on memory fell back to the one-card plan with the primary's flash SDPA still off. Defer the guard until the split is placed and run it on the cards the split actually uses.
Codex Review Summary: ✅ CompletedThis 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. |
[skip ci]
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
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
On ROCm, the layer split's common SDPA kernel guard now runs only after the split has been placed, and only on the cards the split actually uses. If the split is declined on memory and the load falls back to the one-card plan, the primary's process-wide flash / memory-efficient SDPA switches stay as they were.
Root cause
#14655 added a guard to
_rocm_drop_math_onlythat keeps only the fused SDPA kernels shared by the primary and the kept secondaries. It does this by turning off the other kernels through the process-widetorch.backends.cudaswitches. The guard ran whilerefine_plan_for_layer_splitwas still filtering candidate cards, beforeplan_layer_splitchecked memory. When the split did not fit, the function returned the original one-card plan, but the switches stayed changed. A primary that runs flash SDPA then lost flash for its single-card load because of a secondary that ended up with no work. With the same cached kernel answers, the PR's parent left both switches on.Fix
_backend_cards,_rocm_backend_cardsand_rocm_drop_math_onlytake a keywordguard(defaultTrue, so other callers such as_secondary_runs_denoiserbehave as before).refine_plan_for_layer_splitfilters withguard = False. Onceplan_layer_splitreturns a split, it applies the guard tosplit.cards, under the same conditions as before: ROCm, native SDPA, and a primary that is not math-only.Flip test
tests/test_diffusion_layer_split_plan.py::test_rocm_split_declined_on_memory_keeps_the_primarys_fused_sdpauses the real probe, guard and torch switches (only ROCm detection and the child probe answers are faked). The primary has flash and memory-efficient SDPA, the secondary has only memory-efficient SDPA.Results:
At index 0 diff: False != True(flash is turned off although the split was declined)1 passedTests run
(flash, mem_efficient) = (True, True), main(False, True), both on the same declined one-card plan.pytest -o addopts= -m "not server and not native_mxc"over the layer split, multi-GPU, diffusion attention and diffusion ROCm test files: 815 passed, 27 skipped. There are 3 failures, and the same 3 test IDs fail on clean main:test_diffusion_attention_install.py::test_an_imported_old_kernels_is_not_papered_over,test_diffusion_multigpu.py::test_execution_device_reports_the_primary_of_a_split_pipelineandtest_diffusion_rocm_fused.py::test_teardown_survives_a_later_eager_layer.prepush_gate.py: PASS.Not proven
apply_layer_split_plan(falling back tofallback_plan) still keeps the guard applied. This change does not touch that path._secondary_runs_denoiser) still guards while it evaluates, unchanged here.