Skip to content

track(upstream-iree): fused dequant->matmul for the packed int8 bandwidth win #574

Open

Description

@inureyes

Part of #570. Status: BLOCKED for fused-kernel implementation; a bounded latest-pin revalidation can start now. This remains a tracking issue, not active fused-kernel implementation work. The in-tree representation is already shipped and correctness-verified; the throughput win it exists for still requires IREE target support on CUDA or metal-spirv. The 2026-07-22 upstream audit found no advertised data-tiling support for either target in the latest IREE candidate.

What is already in-tree (the representation is ready)

The blocker (measured)

The #573 spike ran real graphs through iree-compile + the runtime and concluded the fusion is upstream IREE work:

  • CUDA (GB10): the packed decode is token-exact but about 4.3x slower than f16 (~1.6 vs ~6.7 tok/s, Llama-3.2-1B 4-bit, greedy). IREE's CUDA codegen does not fuse the in-graph unpack+dequant into the matmul: the decode step is ~678 dispatches and the reconstructed f32 weight is materialized to DRAM every step, so the graph pays MORE bandwidth and compute, not less. The aggressive-fusion / generalize-matmul / early-trunc-fusion flags leave the dispatch count unchanged (678 -> 677).
  • Metal (M1 Ultra): the packed prefill compiles for metal-spirv but the invoke faults at runtime in the metal HAL driver (metal_device.m: Metal command buffer failed (status 5) at hal.fence.await, surfaced as IREE INTERNAL). Found in feat: extend the fused low-precision path to the Metal target #575, guarded off in bug(xla): packed int8 (MLXCEL_XLA_QUANT=packed) prefill invoke faults on metal-spirv #613.

So the memory-bandwidth payoff is not realized by authoring the dequant in the portable graph alone; it needs the TARGET to fuse dequant into the matmul (a quantized-matmul op, or an int8 dot_general lowering to the hardware int8 path). ADR 0004 already scopes per-backend fused kernel codegen as upstream IREE's responsibility.

Upstream status refresh (2026-07-22)

The three previously linked IREE issues do not all represent active blockers:

  • iree-org/iree#18513 — OPEN / PARTIAL / related foundation. DispatchCreation data-tiling and grouped quantized-matmul fusion have advanced, including a regression showing dequant and contraction in one dispatch. However, IREE's documentation for iree-3.12.0rc20260721 lists data-tiling support only for x86/AArch64/RISC-V CPU, ROCm GPU, and VMVX — not CUDA or metal-spirv. Keep this as background tracking, but its closure alone would not satisfy this issue.
  • iree-org/iree#8330 — DONE / historical reference. The lowering from linalg.quantized_matmul to linalg.matmul plus zero-point arithmetic landed in iree-org/iree#8409 on 2022-02-27 and remains covered by IREE tests. It does not provide a fused packed-dequant GPU kernel, so it is not an active dependency.
  • iree-org/iree#16937 — OPEN / context only. iree-org/iree#16927 added a shared-memory-aware cooperative-matrix schedule, but the reporter reproduced the SPIR-V failure afterward and a default Distribute-path follow-up was left unverified. More importantly, that Vulkan compile-time shared-memory failure is not the same failure class as mlxcel's Metal HAL runtime command-buffer fault. Keep it as diagnostic context, not as the Metal unblock tracker.

The direct upstream unblock remains target support that fuses dequant/unpack into the matmul (or lowers a grouped/quantized dot to a native int8 kernel) on CUDA and metal-spirv, so the packed graph does not materialize reconstructed f32 weights to DRAM each step.

The latest stable IREE release is still v3.11.0; the next validation target is the official candidate iree-3.12.0rc20260721 at dc9601f88654749456c7cee4ae87e13de2654e1e. The candidate compiler/runtime must be version-matched on both CUDA and Metal.

We do not open an issue on the IREE repository (project policy: issues live on lablup/mlxcel). Re-check the target support and measured behavior on each MLX/IREE pin bump rather than using upstream issue closure alone.

Next actionable step: latest-pin revalidation

This bounded work can start without treating the fused-kernel implementation as unblocked:

  • CUDA / GB10: build the version-matched iree-3.12.0rc20260721 compiler/runtime, rerun scripts/xla/fusion_spike.sh, and record packed/f16 dispatch counts, token exactness, tok/s, and whether generated code contains native int8 instructions (dp4a / integer MMA) instead of scalar widening.
  • Metal / M1 Ultra: compile and invoke the minimal packed repro on the matching candidate, capture the faulting encoder/dispatch with Metal command-buffer diagnostics, and determine whether the failure is a bad kernel or a HAL command-buffer limit.
  • Record both results here. If CUDA still has no fused/native-int8 path and Metal still faults, keep this issue blocked and update only the last-checked pin/date.

Unblock criteria (what mlxcel does when upstream lands)

Payoff caveat

Even once fused, the bandwidth win only matters on an int-native / NPU target. On the compute-bound Metal decode it is un-demonstrable regardless (the #575 f16 result shows the Metal decode tracks compute, not bandwidth; ADR 0004). So this unblocks the CUDA/NPU path first; Metal gets correctness, not throughput.

References

#570 (epic), #573 (spike: in-tree vs upstream split), #568 / #569 (packed representation + bf16 dequant-at-load), #612 / #613 (Metal fail-fast guards), #575 / #611 (Metal transfer validation), ADR docs/adr/0004-compute-backend-session-seam-and-stablehlo-family.md.


Refresh log

  • 2026-07-22 — Audited the linked IREE issues and latest official release state.
    • Reclassified iree-org/iree#18513 as partial/background because CUDA and metal-spirv are still outside the documented data-tiling target set.
    • Reclassified completed iree-org/iree#8330 as historical context, not an active dependency.
    • Reclassified iree-org/iree#16937 as diagnostic context, not a direct tracker for the Metal runtime fault.
    • Added a concrete iree-3.12.0rc20260721 CUDA/Metal revalidation checklist; the fused-kernel implementation remains blocked.

Activity

  1. added
    status:ready
    type:performance
    priority:medium
    area:inference
    on Jul 1, 2026
  2. inureyes commented on Jul 2, 2026

    @inureyes
    MemberAuthor

    Spike outcome: the fusion is upstream IREE work

    The #573 spike (merged in #578; findings in src/lib/mlxcel-xla/README.md, reproducible via scripts/xla/fusion_spike.sh) measured that IREE's CUDA codegen does not fuse the packed dequant into the matmul, and that no in-tree lever changes it:

    • 11-config iree-compile flag sweep: 677-678 decode flow.dispatch (no fusion).
    • dequant then matmul microtest: always 2 dispatches under every flag (the reconstructed weight is materialized to DRAM).
    • linalg.quantized_matmul / ukernels / data-tiling encodings: gated to hip / rocm / llvm-cpu, not the cuda target.
    • int8 dot_general: lowers to a single CUDA kernel but upcasts i8 -> i32 (17 sext, zero dp4a / mma.*.s8), so int8 would not beat f16.

    So this issue takes its documented fallback: track the upstream IREE work, with the minimal in-tree representation kept prepared.

    Keeping this open as the upstream tracker for the fused quantized-matmul.

  3. added a commit that references this issue on Jul 2, 2026
  4. inureyes commented on Jul 2, 2026

    @inureyes
    MemberAuthor

    Metal data point, from the #575 validation (#611): the packed path (MLXCEL_XLA_QUANT=packed) compiles for metal-spirv but the prefill invoke faults at runtime with IREE status 13 (IREE_STATUS_INTERNAL) on an M1 Ultra. It has only ever executed on the GB10 CUDA runtime. This is separate from the dequant-to-matmul fusion gate this issue tracks; noting it so the eventual fused-matmul work also covers the Metal runtime path (and because its bandwidth win is un-demonstrable on the compute-bound Metal decode anyway).

  5. added
    status:blocked
    and removed
    status:ready
    priority:medium
    on Jul 2, 2026
  6. changed the title [-]feat: fused quantized-matmul realizing the int8 bandwidth win[/-] [+]track(upstream-iree): fused dequant->matmul for the packed int8 bandwidth win[/+] on Jul 2, 2026
  7. inureyes commented on Jul 2, 2026

    @inureyes
    MemberAuthor

    Reorganized this as an upstream-IREE tracker (was a to-implement issue). The in-tree packed representation is already shipped and token-exact on CUDA (#568/#569), with Metal/bf16 fail-fast guards (#612/#613); the remaining work is IREE fusing dequant into the matmul on the GPU targets, which #573 established is upstream. Relabeled status:ready to status:blocked and priority to low. Primary upstream item to watch: iree-org/iree#18513 (data-tiling fusion for grouped quantized matmul). Per project policy no issue is filed on the IREE repo; we re-check the linked upstream items on each MLX/IREE pin bump. Full unblock criteria in the body.

  8. inureyes commented on Jul 2, 2026

    @inureyes
    MemberAuthor

    Can we patch IREE ourselves (like the in-tree MLX Metal kernels)?

    The surface splits in two, because setup-{macos,cuda}.sh builds only half of IREE from source:

    • Runtime = source-built (iree_runtime_unified, IREE_HAL_DRIVER_METAL=ON), so the metal HAL driver is our build. The Metal command-buffer fault (bug(xla): packed int8 (MLXCEL_XLA_QUANT=packed) prefill invoke faults on metal-spirv #613) is patchable here, the same shape as src/lib/mlx-cpp/turbo/*. Concrete first step: runtime/src/iree/hal/drivers/metal/direct_command_buffer.m creates the buffer with MTLCommandBufferErrorOptionNone; switching to MTLCommandBufferErrorOptionEncoderExecutionStatus would name the faulting encoder/dispatch and tell us whether it is an in-tree-fixable HAL limit (e.g. oversized dispatch, split the command buffer) or a bad kernel from the compiler. Payoff is correctness only: the packed bandwidth win is un-demonstrable on the compute-bound Metal decode regardless.
    • Compiler = a prebuilt wheel (iree_base_compiler, IREE_BUILD_COMPILER=OFF). Patching the fusion codegen (the 4.3x lever) means either source-building and forking the data-tiling / fusion passes, which is reimplementing iree-org/iree#18513 (heavy, general compiler work, belongs upstream), OR the MLX-kernel analogue: a custom-dispatch fused dequant->matmul kernel that links a hand-written kernel through the stock compiler (samples/custom_dispatch/...). That custom-dispatch route ships for CUDA / HIP / Vulkan / CPU but not Metal.

    Assessment. The only self-patch with a real, demonstrable payoff is a custom-dispatch fused kernel on CUDA / GB10 (reverses the 4.3x, and CUDA has no MLX so IREE is the backend there). It needs a GB10 host to build and validate, plus emitter integration to emit the custom-dispatch call, and re-pin / rebase maintenance. The Metal HAL fault is cheaply patchable but low value. Forking the compiler is not worth it against upstream #18513. Parked here until a GB10 host is available or the payoff is warranted.

  9. self-assigned this
    on Jul 2, 2026
  10. inureyes commented on Oct 14, 2026

    @inureyes
    MemberAuthor

    ROCm (hip / gfx1151) Update from #851 Qualification

    On IREE 3.12.0rc20260721 (dc9601f88654749456c7cee4ae87e13de2654e1e) targeting AMD Radeon 8060S Graphics (gfx1151, ROCm 7.2.2):

    • Baseline hip lowering (--iree-hal-target-device=hip --iree-rocm-target=gfx1151): compiles cleanly (1,209 flow.dispatch ops across the 16-layer Llama-3.2-1B-Instruct-4bit decode graph) and passes the 64-token greedy trajectory gate (64/64 TOKEN-EXACT PASS, max step layer-15 logit max_abs = 6.953e-2), cutting host-to-device weight upload bytes by ~3.5x (0.93 GiB vs 3.21 GiB for host-dequantized f16). However, iree-compile still lowers each dequant -> matmul pair into 2 separate dispatches (1 elementwise i8 -> f16 dequant dispatch + 1 materialized f16 GEMM dispatch), resulting in 4.33 tok/s decode vs 14.22 tok/s for host-dequantized f16.
    • --iree-global-opt-data-tiling (pad and data-tiling encoding layout resolvers): fails on hip during iree-ROCMSelectLoweringStrategyPass with error: 'tensor.expand_shape' op expected collapsed rank (2) to equal the number of reassociation maps (3) followed by error: failed to materializeConstant of type 'tensor<16x128xf32>'.

    Full reproduction commands and compiler dump excerpts are recorded in docs/benchmark_results/xla_iree_rocm_qualification.md and scripts/xla/fusion_spike.sh (generalized for MLXCEL_XLA_DEVICE=hip).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferencepriority:lowstatus:blockedtype:performance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions