Quantized matmul: opt-in mode where a batched row matches M=1

Aperta
#4,819 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp, machine-learning

Direzione di ricerca

Start in mlx/backend/metal/quantized.cpp at QuantizedMatmul::eval_gpu, use_qmv_wide, and qmm_nax_k_partitions, since they control M-based dispatch and split-K selection. Trace the M=1 and batched quantized-matmul paths, then reproduce the issue by comparing each unequal batched row with the same row run alone. Done means an opt-in flag can force the row-exact route while leaving the default fast path unchanged.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

  • I understand it is strictly prohibited to use AI to write issues.

AI usage disclosure: drafted with AI assistance from measurements we already had. The line numbers below are from current main.

Could quantized matmul grow an opt-in mode where a row inside a batch matches that same row run at M=1?

The Metal dispatch picks the kernel from M.

  • use_qmv_wide (mlx/backend/metal/quantized.cpp, around line 543) runs when M is at least 2. M=1 stays on qmv.
  • QuantizedMatmul::eval_gpu compares M with get_qmv_batch_limit (around line 2183) and sends larger M through qmv_mma, qmm_splitk_nax, or qmm_splitk.
  • qmm_nax_k_partitions (around line 1290) sets the split count from M, because the tile count is ceildiv(M, 64).

A different kernel is a different reduction order, so the result changes with the batch.

What we measured: 16 unequal rows in one forward, against the same rows run alone, flipped 30 to 38 of 256 greedy tokens. That was Qwen3-30B-A3B and a 27B. Grouped short prefill had 12 of 126 rows differ.

oMLX carries a hand patch for the row-exact route: omlx/patches/row_exact_qmv.py. vLLM documents the same property as a feature, docs/features/batch_invariance.md, behind VLLM_BATCH_INVARIANT.

The change we run locally turns qmv_wide and split-K off for every call. That costs throughput, so it has to be a flag. Making it the default would slow the fast path for everyone.

Augustas from Malibu

Lingua principale
C++
Stelle
29.1k
Fork
2.4k
Merge medio
3g 16h
PR unite (30g)
109

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ml-explore/mlx

Tutte le issue di ml-explore/mlx

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.