Skip to content

Studio ROCm layer split: apply the common SDPA guard only once the split fits - #17347

Merged
danielhanchen merged 2 commits into
mainfrom
studio-rocm-split-sdpa-guard-after-fit
Nov 10, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-rocm-split-sdpa-guard-after-fit

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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_only that 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-wide torch.backends.cuda switches. The guard ran while refine_plan_for_layer_split was still filtering candidate cards, before plan_layer_split checked 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_cards and _rocm_drop_math_only take a keyword guard (default True, so other callers such as _secondary_runs_denoiser behave as before).
  • refine_plan_for_layer_split filters with guard = False. Once plan_layer_split returns a split, it applies the guard to split.cards, under the same conditions as before: ROCm, native SDPA, and a primary that is not math-only.
  • If the split is declined, the switches are left alone.

Flip test

tests/test_diffusion_layer_split_plan.py::test_rocm_split_declined_on_memory_keeps_the_primarys_fused_sdpa uses 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.

  • With 4000 MiB cards the split is declined, and flash must stay on.
  • With 20000 MiB cards the split is placed on cards (0, 1), and flash must go off.

Results:

  • origin/main: At index 0 diff: False != True (flash is turned off although the split was declined)
  • this branch: 1 passed

Tests run

  • Standalone repro with the PR parent's modules and with origin/main: parent (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_pipeline and test_diffusion_rocm_fused.py::test_teardown_survives_a_later_eager_layer.
  • prepush_gate.py: PASS.

Not proven

  • Not run on a mixed ROCm host. The switch state is proven with the real torch switches on CPU, and the throughput effect is not measured.
  • A split that is placed but later fails in apply_layer_split_plan (falling back to fallback_plan) still keeps the guard applied. This change does not touch that path.
  • The companion-split path (_secondary_runs_denoiser) still guards while it evaluates, unchanged here.

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T04:20:26.485049Z a5d85ea Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: a5d85eac27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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
danielhanchen merged commit 2d0774e into main Nov 10, 2026
@danielhanchen
danielhanchen deleted the studio-rocm-split-sdpa-guard-after-fit branch November 10, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant