Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/cluster-qwen-m5-ultra-window-layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Faster Qwen tensor-parallel decode on two M5 Ultra

- Qwen3.8 27B tensor parallel on two M5 Ultra decodes about 6% faster for one request (75.8 to 80.5 tok/s at 256 tokens, 62.7 to 66.8 at 1,024). The exact decode projections take a layout measured on the M5 Ultra for a verify window's vectors (rows in registers). Outputs are unchanged byte for byte, and other chips keep their layouts.
13 changes: 10 additions & 3 deletions docs/architecture/inference.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Provider inference engine

> Last updated: 2026-10-29
> Last updated: 2026-10-30

How a chat-completion request is served inside the `darkbloom` provider
process: one in-process engine (`mlx-swift-lm`
Expand Down Expand Up @@ -3725,10 +3725,17 @@ multiply-add per weight and vector) and the words a lane takes per step (capped
to the weight's quantization group). The M3 Ultra (family 15) and the M5 Max
(17) take the dequantized weights at one word per lane, with layouts `a:4:4:1`
for one vector, `a:2:4:4` for two to four and `a:2:4:5` for five, and tiles of
four (`a:2:4:4`) past five. The kernel also serves whole-cohort tiles (one tile
four (`a:2:4:4`) past five. The M5 Ultra (`applegpu_g17d`, family 17) has its
own table in `architectureLayouts`, read before the family's: rows in registers
for two to five vectors (`b:2:2:4`, `b:2:2:5`) and family 17's for the rest.
On two M5 Ultra 256 GB serving the 27B pair the table cut the one-request round
from 35.3 ms (family 17's layout, same build) to 33.2 ms. Against the
`0.10.4-dev.branch.9` release (34.5 ms) it raised decode from 75.8 to 80.5 tok/s
at 256 tokens (62.7 to 66.8 at 1,024), with identical outputs.
The kernel also serves whole-cohort tiles (one tile
of eight, `b:4:4:8`, or tiles of sixteen, `b:2:4:16`, reading the weights once
for up to 32 vectors; a tile that runs past the call's end skips its missing
vectors), but no family selects them: on two M5 Ultra 256 GB serving the 27B
vectors), but no table selects them: on two M5 Ultra 256 GB serving the 27B
pair they lowered the four-request aggregate by 19 % (73.1 against 90.1 tok/s,
identical outputs). Other families take the scaled inputs and the generic
layouts. A layout (rows per SIMD group, SIMD groups, vectors per weight read,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct AffineQuantizedVectorsTests {
}

@Test func layoutsAreValidForEveryVectorCountAndFamily() {
for architecture in ["applegpu_g15d", "applegpu_g17s", "applegpu_g16s", ""] {
for architecture in ["applegpu_g15d", "applegpu_g17s", "applegpu_g17d", "applegpu_g16s", ""] {
for vectors in 1...64 {
let layout = AffineQuantizedVectors.layout(vectors: vectors, inputs: 5120, outputs: 6144, bits: 4,
architecture: architecture)
Expand All @@ -45,15 +45,22 @@ struct AffineQuantizedVectorsTests {
&& layout.schedule != .sharedInputs, "\(architecture) M=\(vectors) \(layout)")
}
}
// The measured families read the weights once for a whole cohort's vectors (up to sixteen a
// tile past five), instead of once per four.
for architecture in ["applegpu_g15d", "applegpu_g17s"] {
// Past five vectors the measured tables keep tiles of four: whole-cohort tiles measured slower on a pair.
for architecture in ["applegpu_g15d", "applegpu_g17s", "applegpu_g17d"] {
for vectors in 6...48 {
let layout = AffineQuantizedVectors.layout(vectors: vectors, inputs: 5120, outputs: 6144, bits: 4,
architecture: architecture)
#expect(layout.vectorsPerTile >= min(vectors, 8), "\(architecture) M=\(vectors) \(layout)")
#expect(layout.vectorsPerTile == 4, "\(architecture) M=\(vectors) \(layout)")
}
}
// Two M5 Ultra measured rows in registers fastest for a verify window's four and five vectors; the M5 Max
// keeps its family's table.
func window(_ architecture: String, _ vectors: Int) -> String {
AffineQuantizedVectors.layout(vectors: vectors, inputs: 5120, outputs: 6144, bits: 4,
architecture: architecture).description
}
#expect(window("applegpu_g17d", 4) == "br2s2v4" && window("applegpu_g17d", 5) == "br2s2v5")
#expect(window("applegpu_g17s", 4) == "ar2s4v4" && window("applegpu_g15d", 4) == "ar2s4v4")
#expect(AffineQuantizedVectors.parseLayout("b:2:4:32") != nil && AffineQuantizedVectors.parseLayout("b:2:4:33") == nil)
#expect(AffineQuantizedVectors.family("applegpu_g15d") == 15)
#expect(AffineQuantizedVectors.family("applegpu_g17s") == 17)
Expand Down
2 changes: 1 addition & 1 deletion libs/mlx-swift-lm
Loading