Repository navigation
perf(qwen35): upload only the live columns of the causal mask - #765
Conversation
The Qwen3.5/3.6/3.8 target graph sizes its attention mask to max_ctx so the graph allocator never has to grow. The host then built and copied the whole max_ctx-wide mask on every prefill chunk and every verify step: at --max-ctx 131072 that is about 128 MiB per 512-token prefill chunk and a few MiB per verify step, whatever the real context length. Flash attention reads mask columns only inside the KV view (the window rounded up to at most 256 keys). Build and copy just those columns plus one 256 stride with a strided 2-D write into the same tensor. The graph shape is unchanged and every value the kernels read is unchanged. R9700, Qwen3.8-27B UD-IQ4_XS + DFlash2 block 16, published profile: output byte-identical on 11 prompts; decode steps 2.8% faster; 26.7K-token prefill 34.7 s -> 31.9 s (host build+upload 67 -> 21 ms per chunk). LUCE_QWEN35_MASK_FULL_WIDTH=1 restores the full-width upload. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
The layer-split forward rebuilt and copied the full max_ctx-wide causal mask for every attention layer of every step (16 per step on Qwen3.8). Use the same live-width upload as the single-device path. R9700 + Strix Halo layer split 0.75/0.25, Qwen3.8-27B UD-IQ4_XS + DFlash2 block 16, --max-ctx 131072: outputs byte-identical on 7 prompts; code decode 24.8 -> 35.0 and 33.1 -> 46.5 tok/s; 7.6K-token prefill 20.6 -> 12.5 s, its decode 17.1 -> 22.4 tok/s. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Upload into a max_ctx-wide CPU tensor filled with a sentinel and check that every row's live columns match the full-width mask and the columns past them are left untouched. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Addressed both review points: the layer-split forward now goes through the same live-width upload (5d1b281, measured +40% decode / -39% prefill on the R9700 + Strix layer split, outputs identical), so the ENVIRONMENT.md row is accurate; and d7ffd15 adds a CPU-backend test that calls |
|
@cubic-dev-ai review the current head |
@davide221 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.
Re-trigger cubic
A second ctest runs the mask upload cases with LUCE_QWEN35_MASK_FULL_WIDTH=1 and checks that every column is written. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
The remaining point, kill-switch coverage for @cubic-dev-ai review the current head |
@davide221 I have started the AI code review. It will take a few minutes to complete. |
Summary
The Qwen3.5/3.6/3.8 target graph sizes its attention mask to
max_ctx, so the graph allocator never has to grow. The host then built and uploaded the wholemax_ctx-wide mask on every prefill chunk and every verify step. At--max-ctx 131072that is about 128 MiB per 512-token prefill chunk and a few MiB per verify step, regardless of the real context length.Flash attention reads mask columns only inside the KV view: the window rounded up to at most 256 keys. This change builds and copies only those columns plus one 256 stride, using a strided 2-D write into the same tensor. The graph shape is unchanged, and every mask value a kernel reads is unchanged.
qwen35_causal_mask_live_width()+upload_qwen35_causal_mask_window()inqwen35/prefill_helpers.hqwen35_dflash_target.cpp, and the layer-split forward inlayer_split_forward.cpp, which uploaded the mask once per attention layer (tree and kvflash-pool masks unchanged)LUCE_QWEN35_MASK_FULL_WIDTH=1, documented indocs/ENVIRONMENT.mdtest_qwen35_mask_upload.cpp: the width covers the attention view, and every uploaded row equals the matching prefix of the full-width maskResults
R9700 (gfx1201), Qwen3.8-27B UD-IQ4_XS + DFlash2 q8_0 drafter, published profile (
--draft-block-size 16 --max-ctx 131072 --cache-type-k q8_0 --cache-type-v q8_0), maina5050c703vs this branch, same server settings:Layer split across R9700 + Strix Halo (
--target-split-mode layer --target-layer-split 0.75,0.25), same model and flags, 7 prompts byte-identical:The ~2.3 ms H2D copy on 479 of 504 verify steps in a rocprofv3 trace is the mask; it drops to a few KB at short context.
Test plan
test_server_unit: 600/600 pass on gfx1201 (includes the 2 new cases)LUCE_PREFILL_TIMING=1🤖 Generated with Claude Code