Skip to content

Studio diffusion: store chunked int8 W8A8 results straight into the output rows - #15533

Merged
danielhanchen merged 4 commits into
mainfrom
dh/int8-fused-into-slice
Oct 27, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
dh/int8-fused-into-slice

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

#15456 capped the compiled int8 W8A8 linear's peak by running large inputs in row chunks. Each chunk's result was a fresh tensor that was then copied into the preallocated output. That cost an extra full write per chunk and a chunk-sized temporary, so common Flux / Wan linears became slower than before #15456 even when memory was ample.

This change compiles a second function, _w8a8_rows_into, that stores each chunk's result straight into its row slice of the output. There is no temporary and no second copy. The returning path from #15456 is kept unchanged for the one case where the output dtype is not known up front: a rotated layer under autocast, where the output is still allocated from the first chunk's dtype.

Results

Colab L4 (sm_89), torch 2.11, bf16. Times are the median of 7 repeats of 20 iterations, with half-range spread. A/A was run first and is inside 0.05 ms for every shape. Arms were interleaved ABBA. Peak is max_memory_allocated above the pre-call baseline.

linear main ms this PR ms change main peak MiB this PR peak MiB output
8192x3072 -> 14336, rot256, bias 11.776 +-0.098 10.033 +-0.058 -14.8% 392.0 342.0 bitwise equal
8192x14336 -> 3072, rot256, bias 11.082 +-0.125 10.866 +-0.106 -1.9% 132.0 132.0 bitwise equal
20000x3072 -> 14336, rot256, no bias 29.840 +-0.187 25.793 +-0.226 -13.6% 729.7 675.4 bitwise equal
4608x3072 -> 12288, no rotation, bias 5.726 +-0.175 4.943 +-0.166 -13.7% 270.0 222.8 bitwise equal

Outputs are bitwise identical to main, and the peak is equal or lower in every case.

Compile behaviour

_w8a8_rows_into is compiled with dynamic=True, fullgraph=True, like _w8a8_rows. Chunk heights and slice offsets all reuse one graph: one frame, no graph breaks. The new CPU test checks this with a compile counter. Inductor's generated kernel stores directly into the slice argument and the graph returns nothing, so no output-sized buffer is allocated. It is a separate code object, so it does not use up _w8a8_rows's recompile budget. A compile failure in either function still falls back to the eager kernels, exactly as before.

Tests

Added to studio/backend/tests/test_diffusion_native_quant_fused.py:

  • test_chunks_are_stored_once_into_their_output_rows: each chunk is written once, into the returned output at its row offset, without calling the returning function. Fails on main.
  • test_compiled_into_slice_is_one_graph_and_bit_identical: the real torch.compile gives one frame and no graph breaks over several heights and offsets, and the result is bit-equal to the unchunked function. Fails on main.
  • test_rotation_under_autocast_keeps_the_returning_path: a rotated layer under autocast keeps the dtype fix from Studio diffusion: keep the compiled int8 W8A8 linear at or below the eager peak, honor force-eager #15456.

On CPU: 26 passed, 4 skipped (CUDA-only).

…utput rows

The chunked compiled linear from #15456 built each chunk result and then
copied it into the preallocated output, costing about 20-25% per large
linear against the unchunked path. A second compiled function now writes
each chunk in place into its slice of the output (one graph for every
offset and chunk height), so there is no chunk-sized temporary and no
extra copy. Output bits are unchanged. Rotated layers under autocast keep
the returning path so the output dtype still comes from the compiled
result.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T11:41:25.895547Z 6e66be9 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. Nice work!

Reviewed commit: bb070c265c

ℹ️ 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 self-assigned this Oct 27, 2026
Older dynamo guards on len(_FUSED_STATE), so adding the calls key after the first
call recompiled each compiled function once on torch 2.6.

[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. Delightful!

Reviewed commit: 6e66be9f72

ℹ️ 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 5541b47 into main Oct 27, 2026
@danielhanchen
danielhanchen deleted the dh/int8-fused-into-slice branch October 27, 2026 14:25
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