From 037e4709d05bea388f1448c6e40b0ee0490b219c Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:34:15 -0700 Subject: [PATCH 1/3] perf(glm): pin the SDK's long-context paged reads and decode command buffers Re-pins libs/mlx-swift-lm to ed573083 (perf/glm-long-context-decode on efd38585): - paged GLM history and selection reads bind up to 17 KV segments per launch and copy only each segment's pages, with no zero fill (exact copies); - plain GLM decode steps take op-count-only command buffers (100 ops, no input bound), as Nemotron Super and Flint do. Docs: the GLM paged-read and command-buffer behaviour in docs/architecture/inference.md. Changelog fragment glm-long-context-decode. --- changelog.d/glm-long-context-decode.md | 7 +++++++ docs/architecture/inference.md | 8 +++++++- libs/mlx-swift-lm | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 changelog.d/glm-long-context-decode.md diff --git a/changelog.d/glm-long-context-decode.md b/changelog.d/glm-long-context-decode.md new file mode 100644 index 0000000000..d8378053e9 --- /dev/null +++ b/changelog.d/glm-long-context-decode.md @@ -0,0 +1,7 @@ +### GLM-5.3-Flash decodes faster at long context + +GLM's paged attention reads (index metadata, latent history and each query's selected latents) now bind up to 17 +memory segments per GPU launch and copy only the pages each segment holds, instead of one full-history launch per +segment after a zero fill. A long conversation's decode step therefore issues a handful of these launches instead of +hundreds. Plain decode steps (three or more concurrent requests) also submit GPU work in larger command buffers, as +Nemotron Super already does. Outputs are unchanged: every read copies the same bytes. diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 55526cf3fb..8e8ab7f7ff 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -800,7 +800,13 @@ engine prices one worst-case step at setup and stays inactive when it exceeds the post-load envelope (about 56.8 GB of admission on a 256 GiB host, shared with KV). Decode and MTP verification rows (at most 8 sparse queries) read one selection row per query, retained until the step fence (about 46 MB per query -across 11 DSA layers). A longer row whose selection rows would read at least +across 11 DSA layers). Every paged read launches once per 64 MiB segment that +holds the row's pages: index metadata and latent-history reads cover only that +segment's pages, one threadgroup per page, with no zero fill, and a selection +read copies each row with one SIMD-group (`GLM5NextPagedTransfers`). Plain +decode steps (every row one token, no MTP round) commit a Metal command buffer +every 100 operations with no input-size bound, as Nemotron Super and Flint do +(`GLM5NextDecodeCommandBuffers`). A longer row whose selection rows would read at least its history instead reads its whole latent plane once per layer through the page table and runs the contiguous arithmetic over it (`GLM5NextPagedPayload.latentHistory`, `GLM5NextPagedModelBinding.readsLatentHistory`), diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index efd3858532..ed5730830b 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit efd38585321a9d401bb0ce8af965b2fbb6f91922 +Subproject commit ed5730830b6cbc980c1a80b19a9a5b4557a83b8c From b7c3badc57f1c665a50b1dda99dd98705a6e7746 Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Sat, 24 Oct 2026 12:11:20 -0700 Subject: [PATCH 2/3] perf(glm): pin the SDK's command-buffer scope for MTP verification rounds Re-pins libs/mlx-swift-lm to 5fba64c0 (perf/glm-long-context-decode): GLM MTP rounds whose rows are all decode or verification rows take the same op-count-only command buffers as plain decode; rounds that carry a prompt chunk keep MLX's defaults. Docs and the changelog fragment state the scope and the measured M5 Ultra speeds. --- changelog.d/glm-long-context-decode.md | 7 ++++--- docs/architecture/inference.md | 7 ++++--- libs/mlx-swift-lm | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/changelog.d/glm-long-context-decode.md b/changelog.d/glm-long-context-decode.md index d8378053e9..19b7c9efd5 100644 --- a/changelog.d/glm-long-context-decode.md +++ b/changelog.d/glm-long-context-decode.md @@ -2,6 +2,7 @@ GLM's paged attention reads (index metadata, latent history and each query's selected latents) now bind up to 17 memory segments per GPU launch and copy only the pages each segment holds, instead of one full-history launch per -segment after a zero fill. A long conversation's decode step therefore issues a handful of these launches instead of -hundreds. Plain decode steps (three or more concurrent requests) also submit GPU work in larger command buffers, as -Nemotron Super already does. Outputs are unchanged: every read copies the same bytes. +segment after a zero fill. Decode steps and MTP verification rounds also submit GPU work in larger command buffers, +as Nemotron Super already does for plain decode. On an M5 Ultra, one request now decodes at about 73, 62 and 48 +tokens per second after 8K-, 32K- and 64K-token prompts, up from about 63, 36 and 19. Outputs are unchanged: every +read copies the same bytes. diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 8e8ab7f7ff..83cb72317a 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -804,9 +804,10 @@ across 11 DSA layers). Every paged read launches once per 64 MiB segment that holds the row's pages: index metadata and latent-history reads cover only that segment's pages, one threadgroup per page, with no zero fill, and a selection read copies each row with one SIMD-group (`GLM5NextPagedTransfers`). Plain -decode steps (every row one token, no MTP round) commit a Metal command buffer -every 100 operations with no input-size bound, as Nemotron Super and Flint do -(`GLM5NextDecodeCommandBuffers`). A longer row whose selection rows would read at least +decode steps (every row one token) and MTP rounds whose rows are all decode or +verification rows (at most 8 tokens) commit a Metal command buffer every 100 +operations with no input-size bound, as Nemotron Super and Flint do for plain +decode (`GLM5NextDecodeCommandBuffers`); prefill chunks keep MLX's defaults. A longer row whose selection rows would read at least its history instead reads its whole latent plane once per layer through the page table and runs the contiguous arithmetic over it (`GLM5NextPagedPayload.latentHistory`, `GLM5NextPagedModelBinding.readsLatentHistory`), diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index ed5730830b..5fba64c00a 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit ed5730830b6cbc980c1a80b19a9a5b4557a83b8c +Subproject commit 5fba64c00ae6e584308b75d701fda1087eb956b7 From 8bd2d66f7cd9e7a3fb55beebca436ae92ff3a271 Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Sat, 24 Oct 2026 12:29:59 -0700 Subject: [PATCH 3/3] docs(glm): say each paged read launch binds up to 17 segments Refactor pass. The pinned SDK (ed573083 onward) binds up to PagedSegmentDispatchPlan.maximumBindings (17) segments per paged read launch; inference.md still said one launch per 64 MiB segment. Also rewraps the paragraph. Docs only. --- docs/architecture/inference.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 83cb72317a..5be9c12738 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -800,14 +800,16 @@ engine prices one worst-case step at setup and stays inactive when it exceeds the post-load envelope (about 56.8 GB of admission on a 256 GiB host, shared with KV). Decode and MTP verification rows (at most 8 sparse queries) read one selection row per query, retained until the step fence (about 46 MB per query -across 11 DSA layers). Every paged read launches once per 64 MiB segment that -holds the row's pages: index metadata and latent-history reads cover only that -segment's pages, one threadgroup per page, with no zero fill, and a selection -read copies each row with one SIMD-group (`GLM5NextPagedTransfers`). Plain -decode steps (every row one token) and MTP rounds whose rows are all decode or -verification rows (at most 8 tokens) commit a Metal command buffer every 100 -operations with no input-size bound, as Nemotron Super and Flint do for plain -decode (`GLM5NextDecodeCommandBuffers`); prefill chunks keep MLX's defaults. A longer row whose selection rows would read at least +across 11 DSA layers). Each paged read launch binds up to 17 of the 64 MiB +segments that hold the row's pages (`PagedSegmentDispatchPlan.maximumBindings`): +index metadata and latent-history reads cover only those segments' pages, one +threadgroup per page, with no zero fill, and a selection read copies each row +with one SIMD-group (`GLM5NextPagedTransfers`). Plain decode steps (every row +one token) and MTP rounds whose rows are all decode or verification rows (at +most 8 tokens) commit a Metal command buffer every 100 operations with no +input-size bound, as Nemotron Super and Flint do for plain decode +(`GLM5NextDecodeCommandBuffers`); prefill chunks keep MLX's defaults. A longer +row whose selection rows would read at least its history instead reads its whole latent plane once per layer through the page table and runs the contiguous arithmetic over it (`GLM5NextPagedPayload.latentHistory`, `GLM5NextPagedModelBinding.readsLatentHistory`),