Repository navigation
Studio diffusion: store chunked int8 W8A8 results straight into the output rows - #15533
Conversation
…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.
|
@codex review |
Codex Review SummaryThis 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. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
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]
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
#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_allocatedabove the pre-call baseline.Outputs are bitwise identical to main, and the peak is equal or lower in every case.
Compile behaviour
_w8a8_rows_intois compiled withdynamic=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 realtorch.compilegives 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).