diff --git a/changelog.d/cluster-qwen-m5-ultra-window-layout.md b/changelog.d/cluster-qwen-m5-ultra-window-layout.md new file mode 100644 index 0000000000..9ded5678e0 --- /dev/null +++ b/changelog.d/cluster-qwen-m5-ultra-window-layout.md @@ -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. diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index ae8c401234..17716e8d40 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -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` @@ -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, diff --git a/libs/darkbloom-cluster/Tests/DarkbloomClusterRuntimeTests/AffineQuantizedVectorsTests.swift b/libs/darkbloom-cluster/Tests/DarkbloomClusterRuntimeTests/AffineQuantizedVectorsTests.swift index c055a119f8..9c23b7eca0 100644 --- a/libs/darkbloom-cluster/Tests/DarkbloomClusterRuntimeTests/AffineQuantizedVectorsTests.swift +++ b/libs/darkbloom-cluster/Tests/DarkbloomClusterRuntimeTests/AffineQuantizedVectorsTests.swift @@ -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) @@ -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) diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index d5bd32b81c..f98ced91b6 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit d5bd32b81c5891b32955a7e69fe11a5e4b3193a1 +Subproject commit f98ced91b6a3b5d60bea087c98b9375a002fadd0