Skip to content

Studio FLUX.3: pass cuDNN attention the projections' strided Q/K/V instead of contiguous copies - #17180

Merged
danielhanchen merged 3 commits into
mainfrom
perf/flux3-cudnn-strides
Nov 9, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
perf/flux3-cudnn-strides

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Problem

On NVIDIA cards where Studio pins cuDNN attention (Auto on sm80 to sm90, including L4 and A100), every FLUX.3 attention call goes through diffusers' _native_cudnn backend. That wrapper (attention_dispatch.py, diffusers 0.42.1) does

query, key, value = (x.permute(0, 2, 1, 3).contiguous() for x in (query, key, value))

so each call writes full contiguous [B, H, S, D] copies of Q, K and V, and its [B, H, S, D] output then needs another copy when the processor flattens it back to [B, S, H * D]. cuDNN reads the projections' own [B, S, H, D] strides directly (that is its native interleaved layout), so all four copies are avoidable. At klein's 1024x1024 shape (24 heads, head dim 128, 4,352 joint tokens) that is 76.5 MiB of Q/K/V copies per call, plus the output copy.

Fix

New core/inference/diffusion_flux3_attn.py:

  • A Flux3AttnProcessor subclass whose cuDNN path is the stock processor op for op, except that SDPA gets q.permute(0, 2, 1, 3) views (no .contiguous()), with the same sdpa_kernel(CUDNN_ATTENTION) pin, no mask, no dropout, default scale. Masks, context parallelism and every other backend call the stock __call__.
  • apply_attention_backend installs it right after it engages _native_cudnn on NVIDIA CUDA, before compile, only on a Flux3Transformer2DModel, and only when diffusers' processor source matches the one it mirrors (d42ebf9c and 0.42.1).
  • Load-time probe: one small cuDNN call per (card, dtype, heads, head dim), strided vs contiguous inputs. The swap happens only when the two outputs are bitwise equal; otherwise diffusers' contiguous call stays.
  • The swapped processors keep their _attention_backend / _parallel_config; the RoPE call still goes through the module attribute the fused RoPE install patches.
  • Kill switch: UNSLOTH_DIFFUSION_FLUX3_STRIDED_ATTN=0.

ROCm, MPS, XPU, CPU, T4 (no cuDNN attention below sm80) and Blackwell cards where Auto keeps native SDPA are unchanged.

Tests

studio/backend/tests/test_diffusion_flux3_strided_attn.py (CPU; the cuDNN pin is replaced by a no-op so the math runs on CPU SDPA):

  • The subclass matches diffusers' _native_cudnn processor call bitwise (fp32 and bf16, batch 1 and 2, odd lengths).
  • Masks and other backends take the stock call; the strided path never calls it.
  • Install swaps every FLUX.3 processor, keeps the backend, is idempotent, and declines on other backends, other transformers, non-CUDA targets, a failed probe, a changed diffusers source and the kill switch.
  • A tiny random FLUX.3 transformer is bitwise unchanged, and its per-block torch.compile(fullgraph=True, dynamic=True) traces once per block over three steps (no graph break, no recompile).

Measurements

Colab L4 (sm89, 22 GiB), torch 2.13.0+cu130, diffusers 0.42.1, transformers 5.5.0, one VM. Base = main bdebdc8, head = base plus #17180, #17181 and #17182 together (one patch). FLUX.3 klein, 1024x1024, 16 steps, Studio default speed; each cell is a fresh process with 3 timed renders (median), order base, head, baseline, head, base, baseline per configuration. 6 GiB = a ballast process leaving 6 GiB free for both stacks. The baseline runs its own INT8 / FP8 files of the same checkpoint on the same VM.

Raw attention at klein shapes (24 heads, head dim 128, bf16, inputs as [B, S, 3072] projection outputs unflattened), cuDNN pinned in both arms, diffusers' _native_cudnn call vs the strided call including the final flatten, 9 interleaved x 20 calls:

mode B, S output extra peak MiB, stock -> strided ms per call, stock -> strided speedup
eager 1, 4352 bitwise equal 104.0 -> 26.0 4.659 -> 3.951 1.18x
eager 2, 4352 bitwise equal 208.0 -> 52.0 9.392 -> 7.825 1.20x
eager 1, 8448 bitwise equal 198.0 -> 49.5 15.842 -> 14.464 1.10x
compiled 1, 4352 bitwise equal 104.0 -> 26.0 4.653 -> 3.987 1.17x
compiled 2, 4352 bitwise equal 208.0 -> 52.0 9.390 -> 7.896 1.19x
compiled 1, 8448 bitwise equal 198.0 -> 49.5 15.785 -> 14.551 1.08x

The load-time probe passed on the L4 and every head render logged 43 FLUX.3 attention calls pass cuDNN their strided views.

Full renders:

config base s/img (r1, r2) head s/img (r1, r2) baseline s/img baseline / Studio, base -> head
INT8 resident 8.876, 8.848 8.811, 8.823 8.594, 8.601 0.970 -> 0.975
INT8 6 GiB 11.685, 11.435 11.578, 11.735 9.455, 9.411 0.816 -> 0.809
FP8 resident 9.906, 9.919 9.877, 9.901 10.655, 10.674 1.076 -> 1.078
FP8 6 GiB 12.755, 12.722 12.674, 12.781 11.370, 11.394 0.894 -> 0.894
  • Resident INT8: head is 0.5% faster than base (base A/A spread 0.3%). Resident FP8: 0.2% faster, inside its spread. At 6 GiB the change is inside the run-to-run spread (offload dominates there).
  • In a whole compiled step most of the Q/K copy was already fused into the RoPE / cast kernels by Inductor, so the render gain is much smaller than the raw-attention gain; what is left is the V copy and the output copy.
  • Pixels: Studio's speed renders are not bit-stable across processes on this card (base r1 vs base r2 LPIPS 0.025 INT8 resident, 0.019 FP8 resident, 0.035 INT8 6 GiB). Head vs base is inside that floor: LPIPS 0.014 / 0.022 / 0.035 / 0.011 (INT8 resident, FP8 resident, INT8 6 GiB, FP8 6 GiB). The raw attention output is bitwise equal at every shape above.

Not proven here

  • Only sm89 (L4) was measured. A100 / H100 / sm120 take the same path behind the same probe but were not run; T4 (no cuDNN attention), ROCm, MPS, XPU and CPU are untouched by construction.
  • Windows was not run.
  • This does not close the 6 GiB INT8 gap to the baseline (0.81x at this budget on this VM); that cell is offload-bound.

@danielhanchen danielhanchen self-assigned this Nov 9, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 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-09T02:05:13.775890Z 8930249 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.

@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 them coming!

Reviewed commit: 89302495f8

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

[skip ci]
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 9, 2026
…tates they read (unslothai#17182)

## Problem

Both prompt encoders request `output_hidden_states=True` and keep every
decoder layer's output alive for the whole encoder call, although each
reads only a few:

- FLUX.3 (diffusers `Flux3TextEncoderStep._get_qwen3_vl_prompt_embeds`)
stacks hidden states `(4, 8, ..., 32)` of its Qwen3-VL encoder. Studio's
dead-tail truncation already drops the unread layers 33 to 36, but the
25 unread states before layer 32 stay alive: about 0.98 GiB at an
8,192-token window (bf16, width 2560).
- Qwen-Image-2.1 (`QwenImage21Pipeline._get_qwen_prompt_embeds`) reads
only `hidden_states[-1]`, but all 37 states of its 36-layer Qwen3-VL
stay alive: about 2.25 GiB at 8,192 tokens (width 4096).

## Fix

One shared helper, `core/inference/diffusion_te_select.py`:

- `run_selected(encoder, indices, call)` runs `call()` with forward
hooks that turn the encoder's `output_hidden_states=True` into `False`
for that one forward and record only the requested entries: entry `k` (1
<= k < n) is decoder layer `k - 1`'s output, read from that layer's own
output; the final entry only when the caller guarantees its stock
reading is the final norm's input (Qwen-Image-2.1's pipeline neutralizes
the norm for exactly that), recorded from the norm's input.
- The output's `hidden_states` answers exactly those indices with the
same tensors. Any other read, a recorder that did not fire, or a forward
that still built the tuple raises inside the call, and the call is
re-run stock.
- Engages only when the language stack length equals the config's
`num_hidden_layers` (passthrough tail slots from the truncation are
fine), never on a compiled encoder. Hooks are removed when the call
returns.
- FLUX.3: `Flux3Pipeline.encode_prompt` wraps its helper call.
- Qwen-Image-2.1: `select_final_hidden_state` wraps
`_get_qwen_prompt_embeds` next to the K/V-cache skip from unslothai#17118, only
when the pipeline source still has its norm-neutralizing hook.
- Kill switch: `UNSLOTH_DIFFUSION_TE_SELECT_HIDDEN=0`.

Tokenization, padding, `use_cache`, the truncation and the prompt cache
are unchanged; the embeddings are bitwise identical.

## Tests

`studio/backend/tests/test_diffusion_te_select.py` and
`test_diffusion_qwenimage21_te_no_kv.py` (CPU, random tiny Qwen3-VL), on
transformers 4.57.6 (torch 2.12) and 5.17.0 (torch 2.10, diffusers
0.42.1):

- FLUX.3 layers and the Qwen-Image-2.1 final pre-norm state are bitwise
the stock tensors, through diffusers' own FLUX.3 helper and the real
Qwen-Image-2.1 pipeline method (with the K/V skip).
- During the forward only the requested layer outputs survive (weakrefs
on every layer's output).
- An unrequested read falls back to the stock call; embeddings, final
entry without the pre-norm contract, non-encoders and the kill switch
run stock; dead-tail passthrough slots keep it exact; hooks are removed
afterwards.

## Measurements

Colab L4 (sm89, 22 GiB), torch 2.13.0+cu130, diffusers 0.42.1,
transformers 5.5.0, one VM. Base = main bdebdc8, head = base plus
unslothai#17180, unslothai#17181 and unslothai#17182 together (one patch). FLUX.3 klein, 1024x1024,
16 steps, Studio default speed; each cell is a fresh process with 3
timed renders (median), order base, head, baseline, head, base, baseline
per configuration. 6 GiB = a ballast process leaving 6 GiB free for both
stacks. The baseline runs its own INT8 / FP8 files of the same
checkpoint on the same VM.

Same L4, random Qwen3-VL text stack (36 layers, width 2560, bf16;
FLUX.3's 8 layers and Qwen-Image-2.1's final pre-norm state), peak
allocated over the encode start, stock vs selective:

| encoder read | tokens | output | extra peak MiB, stock -> selective |
encode s, stock -> selective |
|---|---|---|---|---|
| FLUX.3, 8 layers | 1,024 | bitwise equal | 267.0 -> 122.0 | 0.276 ->
0.062 (first call includes warm-up) |
| FLUX.3, 8 layers | 8,192 | bitwise equal | 2136.1 -> 976.1 | 0.414 ->
0.416 |
| Qwen-Image-2.1, final state | 1,024 | bitwise equal | 205.5 -> 35.5 |
0.059 -> 0.053 |
| Qwen-Image-2.1, final state | 8,192 | bitwise equal | 1644.2 -> 284.2
| 0.400 -> 0.410 |

(The Qwen-Image-2.1 row uses width 2560 here; its real encoder is width
4096, so its real saving is about 1.6x these numbers.)

End to end on FLUX.3 klein (same VM, base vs head with all three PRs):
the speed-off bf16 renders are pixel-identical (LPIPS 0, 3 of 3 images),
and prompt encode time is unchanged (0.12 s resident, 0.46 s at 6 GiB in
both arms). The benchmark prompts are short (an 80-token window), so the
render-level peak does not move; the saving grows with prompt length as
above.

## Not proven here

- No real Qwen-Image-2.1 render was run; the pipeline-level check is the
real pipeline method on a tiny random encoder (CPU) plus the width-2560
CUDA stack above.
- No long-prompt end-to-end render was timed; the memory saving was
measured on the encoder alone.
- Multimodal Qwen-Image-2.1 encodes (reference images through the vision
tower) were not run; the final-state read does not depend on them, but
they were not tested.
- ROCm, MPS, XPU and Windows were not run.
danielhanchen added a commit to Etherll/unsloth that referenced this pull request Nov 9, 2026
… the joint blocks (unslothai#17181)

## Problem

With reference images, FLUX.3's joint blocks get one modulation tensor
for the content sequence (image tokens, then reference tokens). The
image and reference spans carry different timesteps, so
`_flux3_cached_forward` expands the compact per-sample rows from unslothai#17059
back to one row per token and concatenates them:

```python
content_mod = torch.cat([_rows(image_single_mod, ...), _rows(cond_single_mod, ...)], dim = 1)
```

That is `[B, image_tokens + reference_tokens, 3 * 3072]`, alive for
every joint block of every step: 144 MiB in bf16 for a 1024x1024 image
with one 1024x1024 reference, 648 MiB with eight. Each span holds a
single repeated row.

## Fix

In `core/inference/diffusion_cond_blocks.py`:

- At load (`prepare`, before compile or offload hooks bind it)
`Flux3SingleTransformerBlock.forward` is replaced by a forward that
mirrors the stock one op for op, gated on the stock source hash
(d42ebf9c and 0.42.1). Called without the new keyword it is the stock
forward.
- With references, `_flux3_cached_forward` passes the image row as
`temb_mod` (`[B, 1, 3D]`), the reference row as `unsloth_cond_mod` (`[B,
1, 3D]`) and an empty `[reference_tokens, 0]` tensor as
`unsloth_cond_span`, which only carries the span length (no storage, so
a per-block CUDA graph can still copy every input). The block splits the
normed sequence and the residual at the span boundary, modulates and
gates each span by its own row, and concatenates. Element for element it
is what the per-token rows compute, so outputs are bitwise identical.
- Text-only renders, a kill-switched compact path and per-token rows
(`UNSLOTH_DIFFUSION_FLUX3_COMPACT_MOD=0`) are unchanged.
- Kill switch: `UNSLOTH_DIFFUSION_FLUX3_SPAN_MOD=0`.

## Tests

`studio/backend/tests/test_diffusion_cond_blocks.py`, tiny random
`Flux3Transformer2DModel` on CPU:

- Span rows vs per-token rows bitwise equal for fp32 and bf16, batch 1
and 2, 0 / 1 / 8 references with odd span lengths; every joint block
sees `[B, 1, 3D]` rows, and each of its inputs copies into a block-graph
static buffer of the same strides.
- The kill switch restores the per-token rows; the patched block without
the keyword is the stock forward.
- Per-block `torch.compile(fullgraph=True, dynamic=True)`: no graph
break, one frame per block across two reference counts (no recompile),
compiled output bitwise equal to the compiled per-token rows.
- The existing cond-block suite (cache, compact, offload,
whole-transformer compile) passes unchanged.

## Measurements

Colab L4 (sm89, 22 GiB), torch 2.13.0+cu130, diffusers 0.42.1,
transformers 5.5.0, one VM. Base = main bdebdc8, head = base plus
unslothai#17180, unslothai#17181 and unslothai#17182 together (one patch). FLUX.3 klein, 1024x1024,
16 steps, Studio default speed; each cell is a fresh process with 3
timed renders (median), order base, head, baseline, head, base, baseline
per configuration. 6 GiB = a ballast process leaving 6 GiB free for both
stacks. The baseline runs its own INT8 / FP8 files of the same
checkpoint on the same VM.

CUDA check on the same L4 (tiny random FLUX.3 transformer in bf16, 1024
image tokens, 1 and 3 references of 1024 tokens plus 3): span rows vs
per-token rows are bitwise equal eager and with per-block
`torch.compile(fullgraph=True, dynamic=True)`; peak allocated 66.5 ->
63.2 MiB eager, 86.2 -> 76.0 MiB compiled. That GPU check ran the first
version of this branch (a stride-0 view for the reference row); the
current marker-tensor version is the same arithmetic and was checked on
CPU (tests above).

The full renders on that VM (text-to-image, no references, so this
change does not engage there) are in unslothai#17180.

## Not proven here

- No full render with reference images was timed or compared, on any
GPU.
- The CUDA check above predates the marker-tensor change; the current
version is CPU-verified (bitwise, eager and compiled) only.
- Offloaded and block-graph runs with references were not exercised on a
GPU; the test copies every joint-block input into a block-graph static
buffer on CPU.
@danielhanchen
danielhanchen merged commit dac1edb into main Nov 9, 2026
@danielhanchen
danielhanchen deleted the perf/flux3-cudnn-strides branch November 9, 2026 12:52
dayanruben pushed a commit to dayanruben/unsloth that referenced this pull request Nov 10, 2026
unslothai#17341)

## Summary

FLUX.3 strided cuDNN attention is now verified on every card a layer
split places blocks on, not just the primary. If any secondary card
fails the probe, Studio keeps the stock processors on every FLUX.3
attention module.

## Root cause

unslothai#17180 added `diffusion_flux3_attn.install`, which swaps FLUX.3
attention processors only when a load-time probe shows the strided cuDNN
call is bitwise equal to the contiguous call. That probe runs on
`target`'s device, which is the primary GPU. It runs from
`apply_attention_backend`, and that happens before placement. The layer
split planner (`_backend_cards`) restricts secondaries to identical
cards only for flash / Sage backends, not `_native_cudnn`. So in a
mixed-card layer split, the strided processor can run on a secondary
card where it was never probed. cuDNN admission depends on the hardware
and the tensor parameters, so a pass on one card says nothing about
another. unslothai#17290 narrowed Auto's use of cuDNN, but an explicit cuDNN
selection still reaches this path.

## Fix

- `diffusion_flux3_attn.install` records the probe dtype on each swapped
processor.
- New `diffusion_flux3_attn.verify_cards(pipe, cards)` runs the existing
per-card cached probe (`strided_matches`) on every secondary card for
each swapped module's (dtype, heads, head_dim). If any card fails, it
restores the stock `Flux3AttnProcessor` and keeps the backend and
parallel config. It never raises.
- `apply_layer_split_plan` calls it with the split's non-primary cards
before `place_layer_split`, so the swap happens before the first
forward. The probes run outside any compiled forward.
- Single-card loads and splits onto cards that pass the probe are
unchanged.

## Flip test


`studio/backend/tests/test_diffusion_flux3_strided_attn.py::test_layer_split_probes_every_secondary_card[True|False]`
installs the strided processors with a mocked probe that passes on
cuda:0. It then applies a mocked two-card layer split (0, 1) and checks
two things: cuda:1 was probed, and the processors stay strided when
cuda:1 passes but revert to stock when it fails.

- origin/main: `2 failed` (`assert 1 in [0, 0, 0, 0, 0]`: only the
primary is ever probed)
- this branch: `2 passed`

## Tests run

- `tests/test_diffusion_flux3_strided_attn.py`: 11 passed (diffusers
0.42.1, CPU).
- Neighbouring files with `-o addopts= -m "not server and not
native_mxc"`: `test_diffusion_flux3_strided_attn.py`,
`test_diffusion_layer_split_plan.py`, `test_diffusion_layer_split.py`,
`test_diffusion_layer_split_order.py`,
`test_diffusion_layer_split_lifecycle.py`, `test_diffusion_flux3.py`.
Result: 230 passed, 6 failed. The same 6 failures happen on origin/main
without this change (5 in `test_diffusion_flux3.py` auto-switch / status
tests, 1 in `test_diffusion_layer_split_lifecycle.py` workflow pipeline
guard), so they are not caused by this change.
- Pre-push gate (stray files, AGPL headers, pre-commit ruff): pass.

## Not proven

- No GPU run. The probe and placement are mocked on CPU. I have not
shown that a real secondary card produces different output or fails with
the strided call.
- On a failing secondary, the processors revert on every card, including
the primary, so the primary loses the strided speedup in that case.
Per-block retention was not attempted.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 17, 2026
…ded cuDNN admits only the probed dtype, fused int8 takes plain SYMMETRIC only, `_int_mm` fallback stays on the operand's card (unslothai#18140)

Fixes from a re-check of recent Studio INT8 kernel PRs.

1. **CFG replicas lose the INT8 sink mode (unslothai#18004, route from unslothai#17758).**
`Int8Route.__reduce__`
(`studio/backend/core/inference/diffusion_int8_attention_dispatch.py`)
rebuilt the route from its constructor arguments only, so
`copy.deepcopy` (Studio's CFG-parallel replica builder), `copy.copy` and
pickle reset the sink kernel mode chosen at install to 0. With CFG split
across two cards, the replica ran the plain INT8 path while the primary
ran the sink path, so the guided output depended on the card count. The
reduce tuple now carries the mode as state.
2. **Qwen-Image-2.1 strided cuDNN (unslothai#18083).** The `StridedCudnn` marker
kept only the probed card ids, so a bf16 probe also sent fp16 calls (an
autocast, or a later cast of the pipe) down the strided path. The marker
now carries the probed dtype, `plain_qkv` declines other dtypes, and a
re-install at a new dtype probes that dtype. The INT8 dispatch race
named the strided incumbent `dispatch:_native_cudnn`, the same key as
the contiguous cuDNN call, so cached verdicts crossed over; it now races
as `dispatch:_native_cudnn:strided`. The GPU no-copy check asserted
`flatten(2, 3).is_contiguous()`, which also holds when flatten copies;
it now checks the flatten shares storage.
3. **Fused act quant and exact ConvRot take plain SYMMETRIC weights only
(unslothai#17114, unslothai#17617).** `_plain_int8_weight` accepted any mapping containing
SYMMETRIC, so a torchao weight with `SYMMETRIC_NO_CLIPPING_ERR`
activation quant reached kernels that always divide amax by 127.5.
Studio's own loaders build plain SYMMETRIC only, so this narrows a path
no Studio load takes.
4. **`_int_mm` off-grid fallback returns on the operand's card (unslothai#17613,
inherited from torchao).** For K or N not a multiple of 8 the safe
`_int_mm` wrapper (Studio `diffusion_torchao_patches.py` and the copy in
`unsloth/import_fixes.py`) ran the matmul on the CPU and moved the
result with `.to(input.device.type)`, which is the current card. With
the operands on cuda:1 and cuda:0 current, the int32 result landed on
cuda:0. It now moves back to `input.device`.
5. **FLUX.3 strided attention: a test for the no-copy claim (unslothai#17180).**
No test checked it: restoring diffusers' `.contiguous()` copies passed
every test. The new test spies on `scaled_dot_product_attention` and
asserts Q / K / V arrive as the permuted views. Test only.

### GPU results, base (main 62d66cb) vs this branch

CFG sink mode, Kaggle 2x T4 (sm75), torch 2.11.0+cu130, diffusers
0.42.1. Tiny FLUX.1 transformer with random weights at the real head dim
(128), fp16, one attention-sink key; Studio's `CfgParallelRouter` with
the replica built by `build_replica` on cuda:1; INT8 attention installed
with the sink kernels (mode 2, NVRTC CUDA kernel) on both cards; guided
3-step render, cond on cuda:0 and uncond on the replica.

| | base | this branch |
|---|---|---|
| sink mode, primary (cuda:0) | 2, 2 | 2, 2 |
| sink mode, replica (cuda:1) | **0, 0** | **2, 2** |
| kernel path on cuda:1 | plain x4 | sink x4 |
| final latent, CFG split vs single card | rel L2 4.82e-4, max abs
3.9e-3 | bitwise equal |
| uncond step 2, CFG split vs native attention | rel L2 6.43e-4 (single
card 6.11e-4) | 6.11e-4, same as single card |

`_int_mm` fallback, same Kaggle 2x T4: int8 operands on cuda:1, cuda:0
current, both copies of `_make_safe_int_mm` with the real `out_dtype`.

| case (Studio and core copies alike) | base | this branch |
|---|---|---|
| K=65 (off grid) | result on cuda:0 (values exact); the next op with a
cuda:1 tensor raises "Expected all tensors to be on the same device" |
result on cuda:1, exact |
| N=36 (off grid) | result on cuda:0, same error | result on cuda:1,
exact |
| K=64, N=32 (cuBLAS, control) | cuda:1 | cuda:1 |

L4 (sm89), Colab, torch 2.12.1+cu130, cuDNN 9.20.0, torchao 0.17.0:

| fix | check | base | this branch |
|---|---|---|---|
| strided cuDNN | tiny QwenImage21, bf16 probe at install, then the pipe
cast to fp16 | fp16 call takes the strided path (marker has no dtype) |
fp16 call goes to diffusers; marker records bf16 |
| strided cuDNN | fp16 output vs diffusers cuDNN | equal (on L4 the fp16
strided call happens to be correct; the defect is the admission) | equal
|
| plain SYMMETRIC | Int8Tensor FeedForward 256 to 1024,
`SYMMETRIC_NO_CLIPPING_ERR` weights | fused, identical to the SYMMETRIC
result, differs from torchao in 106941 of 153600 elements (max abs
0.086) | stays on torchao, bitwise equal |
| plain SYMMETRIC | plain SYMMETRIC weights | fused, bitwise equal to
torchao | same, same hash as base |
| no-copy test | real cuDNN, bf16, head dim 128 | SDPA gets the views |
SDPA gets the views; with the copies restored it gets contiguous tensors
and the new test fails |

### Tests

-
`studio/backend/tests/test_diffusion_int8_attention_dispatch.py::test_route_copies_keep_the_sink_mode[1|2]`:
fails on main.
- On the T4 pair: `test_diffusion_int8_attention_dispatch.py` base 2
failed (`test_route_copies_keep_the_sink_mode[1|2]`) / 46 passed, this
branch 48 passed with the two-card tests included.
-
`studio/backend/tests/test_torchao_int_mm_transposed.py::test_off_grid_fallback_returns_on_the_operand_card`:
fails on main; on the T4 pair base 1 failed / 9 passed, this branch 10
passed (including the CUDA transposed `_int_mm` exactness cases).
- `studio/backend/tests/test_diffusion_qwenimage21_strided_attn.py`:
`test_marker_admits_only_its_probed_dtype`,
`test_reinstall_at_a_new_dtype_probes_it`,
`test_strided_incumbent_races_under_its_own_name` fail on main; on the
L4 base 3 failed / 14 passed, this branch 17 passed, and the GPU bitwise
test ran in both arms.
-
`studio/backend/tests/test_diffusion_int8_fused.py::test_only_plain_symmetric_activation_quant_is_eligible[SYMMETRIC_NO_CLIPPING_ERR-False]`:
fails on main; on the L4 this branch 101 passed / 1 skipped (a torchao
>= 0.18 case).
-
`studio/backend/tests/test_diffusion_flux3_strided_attn.py::test_strided_processor_hands_sdpa_the_projection_views`:
passes on main, fails with the copies restored.
- CPU (torch 2.14.1) on this branch: the five files pass (100 passed, 78
skipped, running the Qwen-Image-2.1 file in its own process). Running
the Qwen-Image-2.1 file in one pytest process with the others,
`test_real_processor_decode_call_takes_the_strided_path` hits a
RecursionError on main and on this branch alike (test-order interaction,
not touched here).

### Not covered

- No real checkpoint or decoded image: the CFG check compares DiT
latents of a tiny random model, and the auto (raced) route was not
exercised (the dropped field is the same for any non-zero mode).
- sm80 and sm120 cards; the strided cuDNN and SYMMETRIC fixes ran on L4
only, the CFG and `_int_mm` checks on T4 only.
- torchao 0.18 for the SYMMETRIC narrowing.
- The GPU runs used main 62d66cb; the branch was then rebased onto
main 142c398 and only the CPU tests were rerun there.
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