Skip to content

fix(nemotron-super): free prefill temporaries per layer; read checkpoints around the file cache - #318

Merged
Gajesh2007 merged 1 commit into
mainfrom
fix/nemotron-super-prefill-memory
Oct 21, 2026
Merged

Gajesh2007 merged 1 commit into
mainfrom
fix/nemotron-super-prefill-memory

Conversation

@jonathan308

Copy link
Copy Markdown

Summary

  • Prefill memory growth (2–4× too large): each Mamba layer's staged recurrent states (next conv state, final SSM state) fed nothing on the residual stream, so MLX evaluated them only after the whole trunk, and every layer's padded conv input and SSD contributions stayed alive until the chunk ended (3.2 GB at 2,048 tokens). NemotronHMamba2Mixer.cbv2Forward now makes them dependencies of the layer output (depends(input:dependencies:)), so they are computed, and their inputs freed, within the layer. Values and arithmetic order are unchanged.
  • Checkpoint reads around the file cache: ModelOptTensorFile reads each shard with F_NOCACHE and no read-ahead. The shard is hashed and then staged into model-owned memory; through the file cache, a second copy of the checkpoint stayed resident until memory pressure compressed the loaded weights.

Measured (M5 Ultra, full Nemotron 3.5 Super NVFP4 checkpoint)

before after
24K-token prompt: MLX active growth +5.63 GiB +2.62 GiB
24K-token prompt: process footprint growth +4.87 GiB +1.84 GiB
4 parallel 12K prompts: MLX growth +9.18 GiB +5.31 GiB
Greedy outputs (26 A/B prompts) — identical 26/26

prefillActivationBoundBytes keeps its measured value until it is re-measured; the doc comment now explains where the peak came from.

Used by Layr-Labs/d-inference#1528 (pinned at a3dbc56d).

Testing

  • d-inference provider harness at #1528 + this pin, debug build: 204 tests in 29 suites. One failure, advertisedTokenBudgetFitsTheLedgerBesideTheOwnerReservations (307 MB over under full parallel load), passes when run alone and passes in #1528's CI. It's a provider ledger test, unrelated to this change.
  • swift-format format makes no changes.

…ints around the file cache

Each Mamba layer's staged recurrent states (the next convolution state and
the final SSM state) feed nothing on the residual stream, so MLX evaluated
them after the whole trunk and every layer's padded convolution input and
SSD contributions stayed alive until the chunk ended (3.2 GB at 2,048
tokens). cbv2Forward now makes them dependencies of the layer's output, so
they are computed and their inputs released within the layer. Values and
order of arithmetic are unchanged.

M5 Ultra, full checkpoint: a 24K-token prompt grows MLX active memory by
2.62 GiB instead of 5.63 GiB (process footprint 1.84 instead of 4.87), four
parallel 12K prompts by 5.31 instead of 9.18 GiB; greedy outputs identical.

ModelOptTensorFile reads each shard with F_NOCACHE and no read-ahead: the
shard is hashed and then staged into memory the model owns, and through the
file cache a second copy of the checkpoint stayed resident until memory
pressure compressed the loaded weights.
@jonathan308

Copy link
Copy Markdown
Author

Stack status: latest performance state (2026-10-21)

PR Head Contents
#318 a3dbc56d prefill memory fix (bit-identical)
#319 (on #318) c6aa5665 M5 decode + prefill speedups
Layr-Labs/d-inference#1528 d30062fc Super provider + memory-fix pin
Layr-Labs/d-inference#1531 (on #1528) 9a94cbcd pins #319, changelog, docs

Measured on the M5 Ultra, full checkpoint, production flags, at the #1531 pin with no overrides:

shipped this morning latest
Prefill, 12K prompt 1,567 tok/s 2,985 tok/s (1.9x)
Prefill, 1.5K prompt 1,660 tok/s 3,063 tok/s
Realistic decode, median of 14 prompts 70.5 tok/s ~79 tok/s
Counting benchmark decode 87.7 tok/s 103 tok/s
24K prompt, MLX memory growth +5.63 GiB +2.62 GiB
Teacher-forced top-1 / perplexity (46,070 positions) 78.12% / 2.7294 78.09% / 2.7275

The decode changes, the NAX expert kernels, the fused expert route and the dense NAX projections are bit-identical to the MLX NAX path. The chunked NAX Mamba SSD is not, and passes the accuracy-vs-truth gate (top-1 within 0.05 pts of shipped, perplexity within +0.1% of shipped). Measured and not shipped: grouped-GEMM M5 retune, multi-row decode expert gather, Phase C expert tilings, and keeping Mamba in_proj on MLX (no gain).

@Gajesh2007
Gajesh2007 merged commit 66f556b into main Oct 21, 2026
6 checks passed
jonathan308 added a commit to Layr-Labs/d-inference that referenced this pull request Oct 21, 2026
Gajesh2007 added a commit that referenced this pull request Oct 21, 2026
Refresh before review: picks up #318 and #314 (GLM-5.3-Flash), which
d-inference master now pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
javiech1 pushed a commit to javiech1/mlx-swift-lm that referenced this pull request Oct 24, 2026
Adds a basic Swift model conversion API for quantizing safetensors-backed LLMs through MLXLMCommon and LLMModelFactory. Fix Layr-Labs#266 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants