Repository navigation
Support Nemotron 3.5 (Lightning, Bolt, Super) text models - #712
Merged
davidkoski merged 2 commits intoOct 28, 2026
Merged
Conversation
Nemotron 3.5 configs describe the layer stack with layers_block_type (or block_configs) instead of hybrid_override_pattern, so they failed to load. Read the stack from any of these, and omit num_hidden_layers when the config does. - Add moe_latent_size: routed experts run in a latent space between fc1_latent_proj and fc2_latent_proj, as in mlx-lm nemotron_h.py. - Add per-layer block_configs overrides (expert count, expert size, experts per token) and register nemotron_h_puzzle (Bolt). - Skip MTP head weights (mtp.*) at load. Tested: mlx-community/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-4bit and rapid-mlx/NVIDIA-Nemotron-3.5-Bolt-74B-A9B-MLX-3bit load and generate. AI-assisted (Claude Code); changes reviewed against mlx-lm.
Nemotron 3 and 3.5 chat templates open <think> in the generation prompt unless enable_thinking is false. NemotronHModel declared no reasoningConfig, so callers could not turn thinking off and the reasoning span the template opened was not recognized. Declare <think>/</think> with the enable_thinking template flag (default on). The tokenizers do not mark <think> as special. Tested: through LocalLM Lab's helper, Lightning 30B with thinking off now answers directly; before this change the flag was ignored. AI-assisted (Claude Code).
davidkoski
approved these changes
Oct 28, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Change looks good, thank you!
wballard
added a commit
to swissarmyhammer/mlx-swift-lm-old
that referenced
this pull request
Nov 5, 2026
Apply the upstream commits efcedcd..c8dabc6 (the 25 after 991266a) as cherry-picks. CLAUDE.md is untouched. Where a conflict was only a fork refactor, upstream's code is taken; the fork's MTP speed and prompt-cache behavior is kept. - efcedcd Gemma 4 VLM: expose hidden states for a prepared input (ml-explore#730) - 3d066d3 mlx-swift 0.33.0 (ml-explore#720) - 39b92df Read Gemma 3 RoPE scaling from rope_parameters (ml-explore#723) - c358cea Throw when Bert id2label keys share an integer id (ml-explore#736) - c3d3afe FastVLM: Keep image sentinels out of the repetition-penalty history (ml-explore#735) - 72a4673 Fix attention masks sized from the absolute cache offset (ml-explore#728) - cf9b7e9 Prefill over a quantized KV cache through the fused SDPA kernel (ml-explore#703) - ef36109 Add reasoning streaming events and support Gemma 4 channels (ml-explore#563) - 691a19a Support Nemotron 3.5 (Lightning, Bolt, Super) text models (ml-explore#712) - f5b0677 Expose Qwen 3.5 text geometry read-only (ml-explore#737) - c2f1073 Add GrammarConstraint.freshMatcher() (ml-explore#732) - 411d8e7 Feed the sampled token before its fast-forward tokens (ml-explore#731) - 71cc028 MLXFoundationModels: let MLXLanguageModel set the prefill step size (ml-explore#745) - 52e6001 Report model tensor buffer memory (ml-explore#746) - 128f49f Use the MLXFast gated delta kernel where mlx core supports it (ml-explore#740) - 35bd2c9 Add MiniCPM5 Tool Call Parser (ml-explore#637) - c611a3f integration tests to run using xcode 27 (now that it is released) (ml-explore#743) - bb36fc3 EmbeddingGemma 2: soft tokens for every row of a batch (ml-explore#729) - b8d4935 Show the response schema to the model during guided generation (ml-explore#715) - 2775ddd RotatingKVCache: keep the pinned prefix visible in multi-token masks (ml-explore#747) - eccf774 Fix EmbeddingGemma 2 image orientation and batch text embeddings (ml-explore#692) - ffe7647 Add resumable Qwen MTP speculative decoding to ChatSession (ml-explore#581) - 327d92d Put images before text in GLM-OCR prompts (ml-explore#765) - 2fdad9e Keep Nemotron-H Mamba activations in the input dtype (ml-explore#754) - c8dabc6 Fix the x86_64 build of the EmbeddingGemma 2 image processor (ml-explore#763) mlx-swift 0.33.0 (MLX core 0.32.4 line): - MultiRowQuantizedMatvec: widen each input before the 4-bit pack sum, as qmv_fast now does, so verify rows keep the bits of a decode step. - GatedDeltaDecodeKernel and the DeepSeek-V4 Sinkhorn kernel: the sigmoid reads metal::precise::exp, as MLX Sigmoid now does (mlx#4461). Conflicts and choices: - ml-explore#563: Generation.reasoning carries thinking apart from .chunk on every path (textToolHandler takes reasoningPrimedInside, read before the prefill). ChatSession records the content with the finished reasoning beside it, and prefilledReasoningStartDelimiter, as upstream does; ReasoningHistory keeps one fork rule: a protocol that replays reasoning also replays a turn cut off inside it, so the next render extends the cache. Upstream's Qwen3VL generator replaces separatingImportedReasoning; the fork's whole-text helpers (separating, staysInsidePrimedReasoning, the duplicate prompt probe) are gone. FM ports the thinking gate fix, routed reasoning on allowed-tool turns, and ReasoningTokenCollector. Benchmark transcripts count .reasoning. - ml-explore#581: the fork already holds the port of the PR and the MTP work on it. The later transcript rebuild after a target-only turn is not taken: the fork cold-starts the drafter at the cached position and keeps the target cache. Recorded as an empty pick. - ml-explore#740: MLXFast gated delta for prefill and fallbacks; decode and MTP verify keep the fork kernels. - ml-explore#745: same public API; the executor reads the step size from a task-local, as drainCoordinator, and makeParameters defaults to it. - ml-explore#715: the schema prompt is built after the fork's history replay. A session that changes schema between turns changes its system prompt. - ml-explore#703: quantizedCacheAttention carries the fork's attention sinks. - ml-explore#728, ml-explore#747, ml-explore#731, ml-explore#735: applied to the split files; ml-explore#747 and ml-explore#731 were already fixed in the fork. - ml-explore#732: the fork's xgrammar v0.1.34 keeps Fork(); the clone tests stay on. Tests: MLXLMTests 964 XCTest and 2278 Swift Testing tests pass. MLXGuidedGenerationTests 76, MLXFoundationModelsTests 493, CXGrammarTests 7, MLXHuggingFaceMacrosTests 7 pass. HybridRecurrentCacheOffsetTests pass; nemotron_h_puzzle reuses NemotronHModel. Release, M5 Ultra: Qwen35SessionPromptCacheTests, Qwen35AgenticPromptCacheAssessmentTests, PromptCacheSpoolCostAssessmentTests, qwen38FourBitMTPGeneration and qwen38FourBitMTPSystemPromptCache pass (each run alone). Default MTP math/code ~94-100 / 85 tok/s against plain ~57; edit turn reuses 2169 and prefills 123. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
Nemotron 3.5 checkpoints fail to load:
Their configs describe the layer stack with
layers_block_type(Lightning, Super) or per-layerblock_configs(Bolt,model_typenemotron_h_puzzle) instead of ahybrid_override_patternstring. They also use latent MoE (moe_latent_size) and ship MTP head weights.Commit 1: Support Nemotron 3.5 (Lightning, Bolt) text models
hybrid_override_pattern,layers_block_typeorblock_configs, and derivesnum_hidden_layerswhen the config leaves it out.moe_latent_size: routed experts run in a latent space betweenfc1_latent_projandfc2_latent_proj, matching mlx-lm'snemotron_h.py.block_configsoverrides (expert count, expert size, experts per token) and registersnemotron_h_puzzle.mtp.*) at load.Commit 2: Declare Nemotron-H reasoning config (enable_thinking)
<think>in the generation prompt unlessenable_thinkingis false.NemotronHModeldeclared noreasoningConfig, so callers couldn't turn thinking off.<think>/</think>with theenable_thinkingtemplate flag, on by default. The tokenizers don't mark<think>as special.Existing Nemotron-H checkpoints keep loading:
hybrid_override_patternis still read first, and dense checkpoints without MoE keys (#635) are unchanged.Changes are limited to
Libraries/MLXLLM/Models/NemotronH.swift, one registration line inLLMModelFactory.swift, andTests/MLXLMTests/NemotronHTests.swift.Tests
NemotronHTestscases: decodinglayers_block_type(and rejecting an unknown block type),block_configswith latent MoE, dropping MTP weights, and the reasoning config. All 39NemotronHTestspass.xcodebuild test -scheme mlx-swift-lm-Package -destination 'platform=macOS' -skipPackagePluginValidationlocally.NemotronHTestspass. Three numeric-tolerance suites fail on my machine (Gemma3nSharedKVTests,EmbeddingGemma2Tests, "VLM text-only continuation"), with the same 28 issues as on an unmodifiedmain(48114ee).MellumTests.testIncrementalDecodeMatchesFullForwardalso fails, and fails the same way on unmodifiedmain. This PR doesn't touch Mellum, Gemma or the VLM code.mlx-community/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-4bitandrapid-mlx/NVIDIA-Nemotron-3.5-Bolt-74B-A9B-MLX-3bit: correct answers with thinking on and off, and a single tool call dispatched.rapid-mlx/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-MLX-3bit(text-only conversion): loads and generates. Before this change it failed with the error above.nemotron_h_omni, RADIO encoder). They still don't load.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesAI usage
nemotron_h.py; I reviewed and understand every line. PR description drafted with Claude and reviewed by me. Resulting host app manually tested by me.