Repository navigation
Conversation
…ad of refusing it (ashhart#142) oMLX's oQ checkpoints of Qwen3.8 Flash Next store each n-gram table's rows scaled up with one factor in `ngram_embedding.weight_scale` (e.g. Jundot/Qwen3.8-Flash-Next-oQ4e-mtp: 0.000199). 0.5.0 refused any scale other than 1, so those checkpoints did not load (ashhart#142). - sanitize() collects each table's scale by embedding path (still refuses a scale other than 1 when called without the dict, as before). - NGramEmbedding.table_scale and PleTables.scale carry it; embed.ple_lookup and NGramEmbedding's host and resident paths multiply the looked-up bf16 rows by it once (fp32 multiply, one bf16 rounding). The same function of each row on every path and at every row count, so drafted == undrafted and prompt chunking are unaffected; scale 1 is the identity. - tests/test_qwen4_exp_table_scale.py. Jundot/Qwen3.8-Flash-Next-oQ4e-mtp (MTP drafts) on an M5 Ultra: loads (101.1 GiB resident); 437, runnable code and a structured tool call; 122-186 tok/s single stream, N=4 223-249, 3,049 tok/s prefill at 6.9K; MTP accepted 53-64%; concurrent replies equal to serial ones.
… matrix units before M5 On M1-M4, Flash Next's dense projections that are not 4-bit/32 (oQ4e and other mixed checkpoints: 5/6/8-bit in groups of 64 or 128) run rows.qmv_rows, one row at a time at any window width. The Qwen dense family already has a matrix backend for these widths (row_matmul.simd_qmm_backend: simd_qmm for 4-bit, simd_qmm_bits for 5/6/8-bit in groups of 64, affine_rows for the rest, each shape checked once). TF_FLASH_DENSE=matrix sends every quantized dense linear through that backend at every row count; groups of 128 are read as two groups of 64 with the group's scale and bias (the same weights, as the M5 lane path does). Opt-in: the default stays "rows". tests/test_qwen4_exp_matrix_widths.py: 5/6/8-bit at groups of 64 and 128, 4-bit at 32 and 64 - a 16-row window equals 16 one-row steps bit for bit, and stays within 2% of MLX's quantized matmul. Jundot/Qwen3.8-Flash-Next-oQ4e-mtp (with the n-gram scale change) on an M3 Ultra, MTP drafts: 1 stream 89-130 tok/s (rows: 83-111), N=4 140-168 (rows: 121-126), prefill 1,175 (1,148); replies drafted and concurrent equal serial ones. Flash Next / n-gram / PLE / simd tests: 286 passed, 42 skipped, with and without TF_FLASH_DENSE=matrix.
|
Thanks, @gilby. Mixed checkpoints like oQ4e keep many dense layers at 5, 6 and 8 bits, and your M3 Ultra numbers show what the matrix units buy there: one stream 83-111 to 89-130 tok/s, four streams 121-126 to 140-168. Part of this landed in 0.6.0, out tonight, from our side: before M5, Flash Next's 5-, 6- and 8-bit projections of four or more rows now run on the matrix units with the per-row bits. Your numbers are against 0.5.0, so could you re-measure oQ4e on 0.6.0? What remains, most likely the one- to three-row windows and groups of 128, is what we'd take in 0.6.1. One change from the PR: when a faster path gives the same bits, we make it the default for the shapes it wins on rather than adding a switch, so we'd measure per width against the row kernels. |
|
Re-measured on 0.6.0, as asked: M3 Ultra, End to end
0.6.0's This PR's commit (8d55431 here) cherry-picks cleanly onto 0.6.0. Its tests pass:
Per width against the row kernels Each cell is
What the table shows:
A question before I rework this into a default "Same bits" can mean two things here:
Which do you prefer? 🤖 Generated with Claude Code |
|
Thanks for re-measuring, @gilby, and for the per-width table: it answers the question better than we asked it. (1) is enough. Our contract is that a row's bits never depend on the window or the other rows, so drafted == serial and concurrent == solo. A different accumulation order at the same precision is fine, as with the Qwen dense change in 0.4.0, on two conditions:
So yes to the per-shape default with no switch. If you'd like to do that rework on 0.6.0, go ahead. Otherwise we'll rebase it ourselves in 0.6.1, keeping your commit, and post our M3 Ultra numbers here. |
|
Thanks again for the per-width table. Both PRs are ported onto 0.6.1 and pass their tests on an M3 Ultra, still behind the switches for now. Your table shows where the matrix path wins: two to sixteen rows, the verify and multi-stream widths. At one row it's level or slower, and slower at groups of 128. So the plan is the per-shape default we discussed, with no switch: the matrix path where it's faster, rows elsewhere, and a native g128 scale load. Before it becomes the default, we'll run the fp32-referenced quality check and served tok/s at one, two and four streams. If you've started that rework, push it to the PR and we'll take yours; otherwise we'll build it on top of your commits. We'll post the numbers here. |
|
This is in TensorFold 0.6.3, with your commit under your name in the release history: https://github.com/ashhart/TensorFold/releases/tag/v0.6.3
Thank you, @gilby! |
Stacked on #148. The test checkpoint needs its n-gram scale support to load; the only new commit here is the last one.
Problem
On M1–M4, Flash Next's dense projections that aren't 4-bit/32 run through
rows.qmv_rows, one row at a time at every window width (decode.py:project). Mixed checkpoints such as oMLX's oQ4e keep many dense layers at 5/6/8-bit in groups of 64 or 128, so they miss the matrix units.The Qwen dense family already has a backend for exactly these widths,
row_matmul.simd_qmm_backend():simd_qmmfor 4-bit;simd_qmm_bitsfor 5/6/8-bit in groups of 64;affine_rowsfor anything else;Change
TF_FLASH_DENSE=matrixsends every quantized dense linear through that backend, at every row count. It's opt-in; the default staysrows._lane_project.tests/test_qwen4_exp_matrix_widths.pycovers 5/6/8-bit at groups 64 and 128, and 4-bit at 32 and 64. A 16-row window equals 16 one-row steps bit for bit, and stays within 2% of MLX's quantized matmul.Checks (M3 Ultra)
Jundot/Qwen3.8-Flash-Next-oQ4e-mtp, MTP draftsrows)TF_FLASH_DENSE=matrixTF_FLASH_DENSE=matrix. The new test: 7 passed.qa_expert_*for non-4/32 formats; that's a separate change.rowsso you can decide whethermatrixshould become the default on M1–M4 after your own measurements.🤖 Generated with Claude Code