Repository navigation
perf(xla): raise the K tile for long-K vecmats on ROCm - #2874
Merged
Merged
Conversation
The pinned IREE gives every single-row contraction `reduction = [0, 4]`. That tile is fine for short-K shapes but leaves the down projection (K = intermediate, 8192 on llama-3.2-1b) at about 50 GB/s, while the same shape reaches about 110 GB/s at `reduction = [0, 32]`. On a standalone trace of `x[8192] x W[8192, 2048] f16 -> f32` the tile moves the kernel from 667 to 304 us; in the model the 16 down projections fall from 13.4 to 4.8 ms per decode step. A user tuning spec now raises that tile for exactly those contractions and leaves everything else on the compiler default. It matches rank-1 by rank-2 `f16`/`f16` -> `f32` contractions with no batch dims and a reduction axis of at least 4096 elements (`transform.iree.match.dim_bounds`), so the K=2048 shapes keep the default: the same wider tile measured 1.75x slower on qkv/o (N=2048, K=2048), 1.43x slower on N=512, and neutral on the head, while split-K (`partial_reduction`) was 5-9x slower and is not used. The spec is a plain MLIR asset (`assets/rocm/bigk_vecmat_tuning.mlir`). `tuning.rs` writes it to the compile cache under a content-hashed name and returns `--iree-codegen-tuning-spec-path`, so changing the spec changes the vmfb cache key instead of reusing a stale build. `compile_bundle` adds the flag for hip targets on dense configs only; Gemma3n keeps the compiler defaults, and CPU, CUDA and Metal are untouched. Validation on gfx1151 (hip, llama-3.2-1b-instruct-4bit, release build): the decode step drops from 39.6 to 27.45 ms, the down projection from 13.4 to 4.8 ms, and dispatches stay at 317. B=1 CLI at capacity 256: n=64 23.1-27.5 tok/s and n=128 27.8-28.0 tok/s (32.96 in a standalone profiled run), against 21.6-25.1 and 21.3-27.8 before. Greedy output is token-identical on llama-3.2-1b and qwen3-1.7b (tied) and mistral-7b-instruct-v0.3 (untied). Batch B=4 N=8 66.4-67.5 and B=8 N=16 70.1-75.3 tok/s, both REFERENCE-EXACT, and the ragged vmfb byte size is unchanged by the spec. `cargo test -p mlxcel-xla --lib` 388 passed with unchanged goldens; clippy clean at default and `iree` features. The argmax (3.87 ms per step, single workgroup of one lane) is the next item in #2873 and is not addressed here. Refs #2873
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
The pinned IREE gives every single-row contraction
reduction = [0, 4]. That tile is fine for short-K shapes but leaves the down projection (K = intermediate, 8192 on llama-3.2-1b) at about 50 GB/s, while the same shape reaches about 110 GB/s atreduction = [0, 32]. This PR adds a user tuning spec that raises the tile for exactly those contractions.First part of #2873; the argmax (3.87 ms per step, single workgroup of one lane) is the next item and is not addressed here.
Changes
assets/rocm/bigk_vecmat_tuning.mlir: a transform-dialect tuning spec that matches rank-1 by rank-2f16/f16->f32contractions with no batch dims and a reduction axis of at least 4096 elements, and annotates them withreduction = [0, 32]at the compiler's default workgroup and thread tiles.tuning.rs: writes the spec into the compile cache under a content-hashed name and returns--iree-codegen-tuning-spec-path. The hash is in both the file name and the flag, so the vmfb cache key changes with the spec. Kept outside theireefeature gate so its test runs in the default lib suite.compile_bundle: adds the flag for hip targets on dense configs only. Gemma3n keeps the compiler defaults, and CPU, CUDA and Metal are untouched.Why the match is K-bounded
A standalone sweep on the pinned compiler (same runtime path, one dispatch per run):
[0, 4][0, 32]partial_reduction)Workgroup-size changes did nothing on the down-projection shape (all about 650 us), and split-K was 5-9x slower, so the reduction tile is the lever and the K bound is what keeps it from regressing the short-K shapes.
Validation (gfx1151, hip, llama-3.2-1b-instruct-4bit, release build)
cargo test -p mlxcel-xla --lib388 passed (new: the content-addressed spec flag), committed goldens unchanged.cargo clippy -p mlxcel-xla --all-targets --features iree -- -D warningsand at default features clean;cargo fmt --checkclean.Refs #2873