Skip to content

Studio diffusion: allow the multi-GPU layer split on discrete ROCm cards - #14479

Merged
danielhanchen merged 8 commits into
mainfrom
studio-diffusion-layer-split-rocm
Oct 21, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
studio-diffusion-layer-split-rocm

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Enables the diffusion multi-GPU layer split (#14412) on ROCm. Until now the planner declined every ROCm host with ROCm (layer split is CUDA only). With this change a denoiser that does not fit one card is cut across discrete ROCm GPUs, on Linux and on Windows, the same way it already is on CUDA. Integrated GPUs and APUs (unified memory) decline with a clear reason, and every ROCm-specific gate is scoped to ROCm only, so nothing changes on CUDA. UNSLOTH_DIFFUSION_LAYER_SPLIT=0 still turns the split off (as does UNSLOTH_DIFFUSION_MULTIGPU=0).

What changed

studio/backend/core/inference/diffusion_layer_split_plan.py

  • The blanket ROCm decline is gone. On ROCm, _rocm_discrete_secondaries runs Studio's existing APU classifier on each card (utils.hardware._rocm_props_unified_status: the driver's integrated flag, then the gfx target). A unified primary declines with unified memory: cuda:N is an integrated GPU (APU) sharing system memory, so cutting the denoiser across cards frees no memory. A unified secondary is dropped, and if that leaves no secondary the split declines with the same reason.
  • New note_unified_primary: when refine_plan_for_multigpu stops on a unified-memory plan, ROCm now records the unified reason in status()["multi_gpu"]["layer_split"], so a two-APU selection is no longer silent. On CUDA this stays a silent no-op, same as before.
  • Attention backends: on ROCm, native SDPA keeps every card. ROCm flash (flash_attn, Studio: pick ROCm flash attention by a whole-block timing probe instead of a model table #13792) and aiter only keep secondaries with the primary's exact gfx target. flash must also pass its own probe on each secondary (_rocm_flash_attn_runs for that card and the denoiser's dtype), the same probe the primary passes at load. The CUDA branch (_PRIMARY_ARCH_BACKENDS compared by compute capability) is unchanged.
  • _is_rocm now also detects AMD SDK / Radeon wheels, which leave torch.version.hip unset.

studio/backend/core/inference/diffusion_multigpu.py

  • make_selection on ROCm no longer orders gfx targets as if they were CUDA capabilities. Before, a 7900 XTX (11, 0) primary dropped an MI300 (9, 4) secondary. Now a secondary is kept when it can run the primary's load dtype: if the primary has native bf16, a card that only emulates bf16 (RDNA1/2, GCN, Vega per rocm_bf16) is dropped. The CUDA path is untouched.
  • refine_plan_for_multigpu calls note_unified_primary on its existing unified-memory early return. It still returns the plan unchanged.

Review follow-ups

  • utils/hardware: the APU arch set now names every target LLVM's AMDGPUUsage table types as APU (gfx1153 Krackan Point 2, gfx1033, gfx1035, gfx1036, gfx1013, gfx90c, gfx902, gfx909, gfx801, gfx810), so an APU whose runtime leaves is_integrated unset no longer reads as discrete. The device-name fallback (no arch attributes, no flag) also matches 820M, 8040S, 780M / 760M / 740M, 680M / 660M and 610M as whole tokens, so discrete mobile names such as RX 7600M stay discrete.
  • Native SDPA on ROCm: each secondary runs the existing per-device SDPA probe at the model dtype. A math-only card beside a fused primary gets no blocks (math SDPA builds the full score matrix the plan never priced on that card).
  • Component split: a second denoiser (for example Wan's transformer_2) moves to a ROCm secondary only if that card passes the same per-card backend gate; otherwise both denoisers stay on the primary and only the text encoder / VAE move.

Already ROCm-safe on main, audited and left alone:

  • Per-card CUDA graphs and block graphs: backend != "cuda" is off on ROCm.
  • int8 GEMM and fused int8 / QKV records: _split_cards and resident_cuda_cards return nothing on HIP.
  • Cross-card copies: the boundary does plain tensor.to(device). There are no custom streams or events in the split path.
  • Memory probes: trusted_mem_get_info(ordinal) already caps the free figure on Windows ROCm, per card.
  • Compile: per-block regional compile on each card. The ROCm compile probe is keyed per device.

Tests

  • tests/test_diffusion_layer_split_plan.py: 8 new tests. They run Studio's real classifiers (_rocm_props_unified_status, rocm_bf16) over faked device properties:
    • two discrete ROCm cards plan exactly the split CUDA plans;
    • two APUs decline with the unified reason;
    • a unified-memory plan records the reason on ROCm and stays silent on CUDA;
    • a discrete primary skips an APU secondary;
    • the kill switch on ROCm;
    • mixed arch selection (7900 XTX + MI300 both kept, RDNA2 dropped under a bf16 primary);
    • mixed arch native SDPA splits, while flash / aiter stay on the primary's gfx target and flash probes the secondary;
    • the Windows ROCm WDDM free cap on secondary budgets.
  • The ROCm decline test is now test_rocm_discrete_splits_and_explicit_modes_and_legacy_cpu_offload_keep_the_plan.
  • The fixtures in the plan, order and multigpu suites pin _rocm_torch, so the CUDA-shaped tests behave the same on a ROCm host.
  • CPU sweep over every diffusion / video / multigpu / layer split / rocm test file, base vs head: 18780 vs 18788 passed. The 340 failing / erroring test IDs are the same on both sides (local environment issues, present on base).

AMD CI evidence (gfx1151, Linux, device multiplier)

One batched GPU job on the Strix Halo runner, torch ROCm (HIP 7.13), --spoof-devices 2 (3 HIP devices, 2 of them phantom), base = main a74da3f321, head = main + this change, same runner and seeds.

cell base (main) head
tiny FLUX.1 pipeline, forced split, discrete spoof declines ROCm (layer split is CUDA only) split on cuda:0 + cuda:1, 2 calls / 10 hand-offs, bit-identical to one card
tiny Qwen-Image pipeline declines split, 2 / 6, bit-identical
tiny Wan transformer declines split, 1 / 8, bit-identical
tiny Wan, three cards selected declines split on [0, 1], bit-identical
same models, this host as it is (gfx1151 APU) declines (CUDA only) declines unified memory: cuda:0 is an integrated GPU (APU) ...
FLUX.2-klein-4B, 512 px, 4 steps, forced split vs one card declines blocks 0-11 on cuda:0, 12-24 on cuda:1, 4 calls / 156 hand-offs, bit-identical; 0.585-0.590 vs 0.580-0.585 s/step (phantom card, wiring only)
compiled split (compile_repeated_blocks(fullgraph=True)), tiny FLUX.1 / Qwen-Image / Wan, prompts 2-4 n/a bit-identical to one card, 0 new graphs, 0 graph breaks
compiled split, FLUX.2-klein-4B n/a not proven: Triton's HIP launcher raised invalid device ordinal (101) for the phantom ordinal while precompiling. The multiplier only wraps the HIP calls torch makes, so this is the spoof, not the split; it needs a real second card
kill switch UNSLOTH_DIFFUSION_LAYER_SPLIT=0 no split no split, nothing recorded
head's layer split / multi-GPU test files 38 passed, 176 errors (the head's tests need the head's API) 212 passed, 1 skipped, 1 failed

The one head failure, test_execution_device_reports_the_primary_of_a_split_pipeline, is the runner's diffusers failing to import in the test process (Failed to import diffusers.pipelines.pipeline_utils), and the skip is the same import. Both pass on the CPU sweep above.

What the spoof cannot prove

The device multiplier shows extra HIP ordinals that are the same physical gfx1151. So this run proves wiring: selection, planning, placement, the boundary hand-offs, bit identity, and compile with zero recompiles. It does not prove:

  • real multi-GPU memory relief (the "cards" share one pool);
  • cross-card copy bandwidth or stream behaviour over a real PCIe / xGMI link;
  • any s/step figure (recorded, but phantom);
  • the compiled split of a real model (blocked by the spoof above);
  • mixed gfx targets on one host;
  • ROCm flash_attn or AITER on a secondary;
  • the Windows ROCm path on real hardware.

gfx1151 is an APU, so reaching the discrete branch at all required a Studio-layer spoof in the harness: the memory kind reported as discrete, and the per-card unified classifier answering discrete. The unmodified host takes the unified decline, which is the intended behaviour on this hardware.

For a tester with two or more discrete AMD GPUs

# 1. CPU and two-card unit tests from the PR checkout
cd studio/backend
python -m pytest -q tests/test_diffusion_layer_split_plan.py tests/test_diffusion_layer_split_order.py \
  tests/test_diffusion_multigpu.py tests/test_diffusion_layer_split_cuda.py tests/test_diffusion_multigpu_cuda.py
# 2. Forced split on a model one card holds: Studio, select both GPUs, load FLUX.2-klein-4B with
UNSLOTH_DIFFUSION_LAYER_SPLIT=force unsloth studio
#    then check the log for "diffusion.layer_split: ... split cuda:0: N blocks ..., cuda:1: M blocks ..." and the
#    model status multi_gpu.layer_split (cards [0, 1], live.calls > 0), and that the image matches a run with
#    UNSLOTH_DIFFUSION_LAYER_SPLIT=0 (same seed)
# 3. Real need: a model larger than one card (FLUX.2-dev bf16 on 2x 24 GB), default settings:
#    status shows layer_split engaged instead of an offload policy, and s/step beats the one-card offload run
# 4. Mixed cards (for example 7900 XTX + MI300 or RDNA3 + RDNA4): the status shows which cards were used, and
#    with flash_attn installed the split stays on cards of the primary's gfx target
rocm-smi --showproductname; python -c "import torch; print([torch.cuda.get_device_properties(i).gcnArchName for i in range(torch.cuda.device_count())])"

Replace the blanket ROCm decline with ROCm-specific gates: an APU / unified
memory primary or secondary declines with a unified memory reason, the
selection compares native bf16 support instead of the gfx target as a CUDA
capability, and ROCm flash_attn / AITER keep blocks on cards of the
primary's gfx target (flash also probed on each secondary). CUDA paths are
unchanged; UNSLOTH_DIFFUSION_LAYER_SPLIT=0 still turns it off.
@danielhanchen danielhanchen self-assigned this Oct 21, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
🔒 Security Review 🔄 Running since 2026-10-21T09:32:07.002500Z d137b0a PR opened
ℹ️ 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T10:43:55.705793Z 52649e6 Manual request
🔒 Security Review ⚠️ Failed 2026-10-21T09:32:09.929790Z
We couldn’t complete this review. Comment @codex security review to try again.
d137b0a PR opened
ℹ️ 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5b82639ae

ℹ️ 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".

Comment on lines +562 to +563
from utils.hardware.hardware import _rocm_props_unified_status
return _rocm_props_unified_status(torch.cuda.get_device_properties(int(ordinal)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat gfx1153 as unified before enabling the split

When a Windows ROCm gfx1153/Krackan Point 2 device exposes a missing or zero is_integrated field, this classifier returns False: the underlying hardcoded APU set ends at gfx1152, and its name fallback is skipped whenever gcnArchName is present. Because Studio explicitly supports gfx1153 on Windows, such an APU can now pass _rocm_discrete_secondaries and receive denoiser blocks even though this change intends to exclude shared-memory GPUs; extend the unified classifier for gfx1153 (and cover the unset-integrated case) before using its negative result as proof that a card is discrete.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. gfx1153 is listed as an APU in the LLVM AMDGPUUsage processor table, and so are gfx1033, gfx1035, gfx1036, gfx90c and the older APU targets, but only gfx1103 and gfx1150-1152 were named, so any of them read as discrete when the runtime leaves is_integrated unset. The shared APU arch set in utils.hardware now names every APU-only target (5f54056); its callers all ask "known APU" and none of those targets shipped as a discrete board. Tests cover the classifier and the split skipping such a secondary.

Comment on lines +754 to +755
if backend is None:
return cards, None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Verify fused SDPA on each native-backend secondary

When a mixed-gfx ROCm secondary has no working fused SDPA kernel at the model dtype, this unconditional native-backend path still assigns it denoiser blocks. Studio's own SDPA diagnostics note that the resulting math backend materializes a quadratic attention matrix and can exceed VRAM by many times, while the layer planner reserves only its ordinary block working set; large image or video renders can therefore OOM on the secondary even though the split was selected to avoid offload. Probe each secondary with the existing per-device SDPA capability check and exclude cards that are math-only (or account for that peak) rather than assuming native SDPA has the same memory behavior everywhere.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The primary is probed and priced as math-only at load, but on the native path a mixed-gfx secondary was never probed, so math SDPA could build the full score matrix on a card budgeted for a fused kernel. The ROCm native path now runs the per-device SDPA probe from diffusion_attention on each secondary at the model dtype and drops math-only cards when the primary has a fused kernel, recording a math-only decline if none are left (33a90aedd8). CUDA is unchanged, and a test covers both cases.

gfx1153 Krackan Point 2 and the other targets LLVM types APU only were
read as discrete when the runtime leaves is_integrated unset, which let
the diffusion layer split hand such a part denoiser blocks.
Under native SDPA a mixed-gfx secondary with no fused kernel at the model
dtype would run its blocks on math SDPA, whose score matrix the plan never
priced for that card. Probe each secondary with diffusion_attention's
per-device SDPA check and drop it when the primary has a fused kernel,
recording the reason when no secondary is left.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 813b3489d8

ℹ️ 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".

Comment on lines +128 to +135
if _rocm_torch():
# ROCm's capability is the gfx target (gfx942 (9, 4)), which does not order; match the primary's load dtype
# instead (arch-pinned attention kernels are gated per card in diffusion_layer_split_plan).
others = tuple(o for o in others if _rocm_dtype_parity(int(primary), o))
return (
MultiGpuSelection(primary = int(primary), secondaries = others, automatic = automatic)
if others
else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Gate mixed-gfx cards before moving a second denoiser

When a gfx1100 primary is paired with a gfx942 secondary, this new ROCm branch admits the secondary because both support bf16, whereas the previous capability ordering rejected it. That selection is also consumed by refine_plan_for_multigpu, whose component-assignment path can move transformer_2 wholesale before the new _backend_cards checks run. For a two-expert pipeline using the primary's flash or aiter backend, the second expert can therefore execute an architecture-pinned kernel on an unverified gfx target and fail during generation. Apply the per-gfx backend filtering to secondary denoisers in the component split as well, or limit this relaxed admission to the layer-split path.

Useful? React with 👍 / 👎.

@danielhanchen danielhanchen Oct 21, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed: the component assignment could move transformer_2 to a mixed-gfx secondary before the layer split per-card gate ever ran. The second denoiser now moves only to a card that passes the same gate (flash / AITER on the primary exact gfx target with the flash probe, native SDPA not math-only beside a fused primary); otherwise both denoisers stay on the primary and only the companions move (688c899). CUDA is unchanged, and a test covers flash, AITER and the math-only case.

Comment on lines +2816 to +2817
"gfx1103",
"gfx1153",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle gfx1153 when architecture properties are absent

Adding gfx1153 to this arch-only set still misclassifies Krackan Point 2 on the AMD SDK/Radeon-wheel case where the architecture attributes and integrated flag are both unavailable: _rocm_classify_unified_memory then falls back to the device name, but its marker list does not include the 820M name used by this change's own gfx1153 test data. The classification therefore returns ("", False), this set cannot match it, and the APU remains eligible for denoiser blocks even though it shares system memory. Extend the name fallback for gfx1153 as well as the architecture set.

Useful? React with 👍 / 👎.

@danielhanchen danielhanchen Oct 21, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed: with no arch attributes and no integrated flag the name fallback only knew the Strix and Krackan Point names, so a Radeon 820M (Krackan Point 2, gfx1153) read as discrete. It now also matches 820M, 8040S, 780M / 760M / 740M, 680M / 660M and 610M as whole tokens, all integrated-only parts, so discrete mobile names such as RX 7600M or 6800M stay discrete (52649e6). Tests cover the new names and those negatives.

pre-commit-ci Bot and others added 3 commits October 21, 2026 10:32
make_selection admits mixed gfx targets on ROCm, and the component
assignment could move transformer_2 wholesale to a card the primary's
flash_attn / AITER kernel was never verified on, or whose native SDPA is
math-only. Apply the layer split's per-card attention gate before
offering the second denoiser to the secondary.
With every arch attribute and is_integrated unset (AMD SDK / Radeon
wheels), the classifier only knew the Strix and Krackan Point names, so
a Radeon 820M Krackan Point 2 and the Phoenix, Rembrandt and Raphael
iGPUs read as discrete. Match their integrated-only names as whole
tokens so discrete mobile parts such as the RX 7600M stay discrete.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 52649e68d5

ℹ️ 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 deleted the studio-diffusion-layer-split-rocm branch October 21, 2026 11:26
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 9, 2026
…ntion dtype (unslothai#14655)

## Studio ROCm layer split: probe secondary cards without changing the
primary's SDPA switches

Follow-up to unslothai#14479. Two issues in how the ROCm layer split checks a
candidate secondary card's attention kernels.

### 1. A secondary card's probe turned off fused SDPA for the whole
process

`_rocm_drop_math_only` checks each candidate card with
`diffusion_attention.sdpa_math_only`. The first time a card's ROCm probe
finishes, `_probe_rocm_sdpa_kernels` passes its answer to
`_apply_rocm_guard`, which flips `torch.backends.cuda.enable_flash_sdp`
/ `enable_mem_efficient_sdp`. Those switches apply to the whole process,
so they also control the primary card the model is already running on.

On a host where cuda:0 has fused kernels and cuda:1 is math-only (only
the ROCm build check and the child-process answers are faked; the probe,
guard and torch switches are real):

| | flash | mem_efficient | secondary kept |
|---|---|---|---|
| before | True | True | |
| first `_rocm_drop_math_only` | False | False | no |
| identical second call | False | False | yes |

The card we reject still moves the primary onto math attention for the
rest of the session. The plan was priced assuming the primary's fused
kernel. Then, because of the switches the first call flipped, the next
identical preview sees the primary as math-only and keeps the card it
just rejected.

Fix: `diffusion_attention.read_only_sdpa_probe()` (a context variable)
stops a completed probe from applying the guard. The planner wraps only
the secondary checks in it. The primary check still applies its own
answer, as before. The secondary's answer is still cached, so
`guard_rocm_fused_sdpa` applies it if a model is later loaded onto that
card.

Because the switches are process-wide, the cards that are kept and run
blocks also need a guard that holds for all of them:

- A secondary that shares no fused kernel with the primary and the cards
kept before it is dropped like a math-only one. For example, if cuda:1
runs only flash and cuda:2 runs only mem_efficient, keeping both would
leave math as the only common kernel under a plan priced for fused
attention.
- Once the kept cards are known, `guard_rocm_fused_sdpa_cards` applies
the guard with the kernels that ran on every one of them (primary plus
kept secondaries).

### 2. The probe dtype came from the first registered parameter

`_rocm_attention_dtype` used `next(module.parameters()).dtype`.
MiniMax-H3 keeps `proj_in` and the other `_keep_in_fp32_modules` in fp32
while its blocks and their attention run in bf16. So the probe ran at
fp32 instead of the dtype attention actually runs at. Kernel
availability depends on the dtype: on gfx1151, SDPA flash and the
flash_attn package run at bf16 but not at fp32 (mem_efficient runs at
both, see the results below). A probe at the wrong dtype can therefore
reach the wrong keep / drop decision. The flash branch of
`_rocm_backend_cards` had the same problem: at fp32 the flash_attn check
fails, so a flash-backed MiniMax-H3 split dropped secondaries that run
flash at bf16.

Fix: `_attention_dtype` reads the compute dtype of the first attention
projection (`to_q`, or the fused `to_qkv` that resident INT8 H3 leaves).
It uses, in order, a diffusers layerwise-casting hook's compute dtype,
the projection's `compute_dtype` (GGUF / packed linears), then its
weight or bias dtype. If no projection has a readable fp16 / bf16 / fp32
dtype, it uses the first parameter outside `_keep_in_fp32_modules`
(diffusers' own `ModelMixin.dtype` rule), then the pipeline dtype, then
the first parameter as before. The flash branch of `_rocm_backend_cards`
uses the same dtype.

### Tests

- `test_rocm_secondary_probe_leaves_the_primary_sdpa_switches_alone`:
runs the real probe and guard against the real torch switches, with only
the ROCm build check and the child answers faked. Fails on main
(`(False, False) != (True, True)`), passes here.
- `test_rocm_kept_secondaries_share_a_fused_sdpa_kernel`: a flash-only
and a mem_efficient-only secondary are not both kept. Fails on main,
passes here.
- `test_rocm_kept_secondary_still_gets_the_fused_sdpa_guard` (guard,
passes on main too): a kept secondary whose flash launch failed still
turns flash off once it runs blocks.
- `test_rocm_probe_runs_at_the_attention_dtype_not_an_fp32_stem`: uses a
module with an fp32 stem registered before bf16 attention. Fails on main
(`float32 != bfloat16`), passes here.
- `test_rocm_probe_dtype_packed_projection_with_fp32_norm_synthetic` and
`test_rocm_probe_dtype_skips_fp32_pinned_modules_when_projections_carry_no_dtype`:
packed bias-free projections beside an fp32 `norm_q`, with and without a
`compute_dtype`. Fail on main, pass here.
`test_rocm_probe_reads_a_quantized_projection_not_its_fp32_qk_norm`
covers the same with a real Krea-2 denoiser.
- `test_studio_regional_fullgraph_compile_keeps_the_pdd_hook_eager`
(guard, passes on main too): Studio compiles DiTs only through
`compile_repeated_blocks` or per-block forwards below offload hooks.
This test checks that `fullgraph=True` on a PDD MiniMax-H3 denoiser
leaves the root `__call__`, and with it the PDD pre-hook, eager. Every
step's sigmas still reach the banks.

On the latest main merged in: `test_diffusion_layer_split_plan.py` and
`test_video_minimax_h3_pdd.py` give 5 failed / 88 passed on main and 93
passed here. The related attention, ROCm fused and multi-GPU suites give
the same 560 passed on both sides, plus one failure on both sides that
comes from the test environment.

### Results on hardware

AMD Strix Halo (gfx1151), torch 2.11.0+rocm7.13.0, main vs this branch
in the same job. The probe, the guard and the torch switches are real.
This host has one GPU, so cuda:1 is either the same card renumbered or,
for the mixed case, a child answer replaced with math-only.

Real SDPA kernels on gfx1151: fp16 and bf16 run math, flash and
mem_efficient; fp32 runs math and mem_efficient. The flash_attn package
runs at bf16 but not at fp32.

| | main | this PR |
|---|---|---|
| flash / mem_efficient after rejecting a math-only cuda:1 | False /
False | True / True |
| cards kept, first / second identical check | none / cuda:1 | none /
none |
| SDPA op the primary then runs at bf16 | math | flash |
| same-arch pair (all real): switches, cards kept | unchanged, cuda:1 |
unchanged, cuda:1 |
| tiny MiniMax-H3 (fp32 proj_in, bf16 attention): probe dtype | float32
| bfloat16 |
| same model, flash branch: dtype / flash_attn runs there | float32 / no
| bfloat16 / yes |

Studio regression run on this head (`aacd677133`) vs main
(`ed3eec632c`): no functional regression across auth, settings, crawl,
inference settings, image and video generation, the tiny diffusion bench
suites (HTTP, in-process, matrix), the upstream CI suites and the
diffusion import check. The two settings screenshots that differ show
only the per-run state directory path in the AGENTS.md hint; no frontend
file changes here.

Not covered: no real mixed ROCm pair and no Windows ROCm host were
available, so the effect on speed and activation memory of the old
global flip was not measured on hardware.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant