Repository navigation
Conversation
Add support for using the existing 4-row interleaved CQ4 layout with full-width orthogonal output heads. The LM-head path now dispatches to an optimized interleaved decode kernel while preserving the scalar fallback for unsupported shapes. Teach CQ weight export, QDQ, and runtime loading about explicit INTERLEAVED_4ROW storage for orthogonal CQ4 tensors. The loader validates malformed interleaved tensors strictly, including metadata byte counts, embedding lookup can read tied interleaved weights, and the converter policy selects this layout for large output heads and tied token embeddings. Add a temporary artifact patching tool for rewriting existing full-width orthogonal CQ4 weight files to the interleaved layout without running a full reconversion. This keeps current artifacts testable while the converter pipeline is updated. Validation: pytest python/cactus/convert/tests/test_cq.py python/cactus/convert/tests/test_policy.py python/tests/test_transpile_weight_compat.py -q; cactus-graph/build/test_ops; cactus-graph/build/test_io; cactus-kernels/build/test_matmul; cactus build --android; local e2e generation checks for Gemma, LFM, and Qwen temp interleaved bundles; Pixel Gemma shared-KV generation and token benchmark with interleaved and row-major tied weights. Signed-off-by: Noah Cylich <noahcylich@gmail.com>
ncylich
force-pushed
the
feature/cq4-interleaved-lmhead
branch
from
May 26, 2026 00:33
61b7bc2 to
4b0ccb3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds first-class support for full-width orthogonal CQ4 LM heads stored in the existing 4-row interleaved layout.
Key changes:
INTERLEAVED_4ROWLM-head matmul path for decode.Validation
Ran:
PYTHONPATH=/Users/noahcylich/Documents/Desert/cactus-v2/python pytest python/cactus/convert/tests/test_cq.py python/cactus/convert/tests/test_policy.py python/tests/test_transpile_weight_compat.py -qcactus-graph/build/test_opscactus-graph/build/test_iocactus-kernels/build/test_matmulcactus build --androidExplain shrodingers cat.cactus-graph/build/test_opsandpython -m py_compile python/cactus/convert/interleave_orthogonal_cq4.py.Generation checks produced coherent outputs. On the Pixel run, interleaved was slightly faster than row-major in the same slow device/build path (
decode_tps: 2.67 vs 2.15;prefill_tps: 9.57 vs 9.24).