Skip to content

M1–M4: simd_qmm.check() crashes load — 1024-thread launch, compiled cap is 704 #91

Closed

Description

@christrade215

Env: M2 Max / macOS 26.6.2 / v0.3.4.1 (bb4b4a3) / MLX 0.32.2

Repro:
tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit
Dies at load, before serving:
ValueError: Thread group size (1024) is greater than the maximum allowed threads per threadgroup (704).

Trace: qwen3_5/init.py load() → install_mlx_lanes → row_forward.install → BACKEND.prepare → simd_qmm.check() → qmm(kind="mma")

Root cause: splits() returns S=32 for ≤64-output linears; _launch mma uses threadgroup = S*32 = 1024, but that kernel compiles to a 704-thread cap here. Any checkpoint with small linears hits it — Qwen3.8-27B has 288 (linear_attn.in_proj_a/b, 48 outputs).

Workaround: TF_ROW_MATMUL=row_qmv loads fine; exactness A/B passed 8/8 (identical token_sha, drafts on vs off). Cost: window scaling goes near-linear (1 row 47.5ms → 8 rows 466ms), so draft gain drops to +8% (12.1 vs 11.2 t/s).

Possible fix: clamp S so S*32 ≤ device limit, or catch the launch error in check() and fall back the way a boolean mismatch already does — a failed exactness check serves without drafts, but a Metal exception inside check() kills the whole load. (Two failure modes, one handled — cf. Christopher Maher's writeup this week: M5/MLX 0.32.2 fails the check gracefully, we just don't get that far.)

Activity

  1. ashhart commented on Sep 29, 2026

    @ashhart
    Owner

    Thank you for the careful trace, you found exactly the cause. It was fixed in 0.3.5.1: every Metal launch now fits its
    pipeline's own thread limit on M1 and M2 (simd_qmm probes 512, 256, ... threads and keeps the largest that fits), so
    the 27B loads with the matmul kernels and drafts at full speed instead of falling back to row_qmv. Your install is
    0.3.4.1; tensorfold update (or 0.3.6.3, out shortly) fixes it. If it still fails on the new version, please send the
    startup log and we'll look straight away.

  2. christrade215 commented on Sep 29, 2026

    @christrade215
    Author

    Confirmed fixed on 0.3.6.3 / M2 Max (32 GB): the 27B loads through simd_qmm with no row_qmv fallback, drafts on. Before/after, same battery:

    probe 0.3.4.1 + row_qmv workaround 0.3.6.3
    decode, drafts on, prose 256 tok 12.1 t/s 25.7 t/s
    decode, drafts on, short code 11.5–12.1 34–50 t/s
    draft gain +8% +104% prose
    acceptance — 51% prose / 77% code
    prefill, 1122 tok 83 tok/s 275 tok/s
    exactness A/B 8/8 12/12 token_sha identical

    One doc note: on 32 GB with the DFlash2 drafter, load failed the new memory guard until TENSORFOLD_MEMORY_LIMIT_GB=25 — may be worth a line in the install docs.

    Cross-version expectation note: the short-prompt sha matched the old build exactly, but the longer run's sha changed (row_qmv → simd_qmm reduction order). Within-build exactness holds 12/12, which is the contract — flagging it so nobody reads it as a regression.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions