Repository navigation
MiMo V2.6: tensor-parallel shard, hooks and FP32 partials - #380
Merged
Merged
Conversation
Add what one rank of a two-rank MiMo V2.6 tensor-parallel text model needs, behind state that a single Mac never sets: - MiMoV26TensorShard. A rank keeps half the query heads with the KV heads they read on full and sliding layers (head dims 192/128 kept as stored), the sliding layers' sink bias for those heads, and half of the dense and expert channels. splitAxis names the cut axis of every text parameter, including axis 1 and 2 of the 3-D expert banks; slice, localShape and byteRuns (GLM5NextByteRuns over an n-D tensor) cut a stored tensor; localConfiguration halves the six head and width fields and drops MTP. - MiMoV26TextModel.installTensorParallel(reduce:vocabularyRows:). Each layer sums its o_proj partial (stored BF16, summed in FP32, rounded once) before the post-attention norm. A routed layer combines its experts' rows from the stock MXFP4 banks and decode kernels locally in FP32 with the replicated router weights, then sums that one row; the dense layer sums its down projection like o_proj. lm_head becomes a shell of this rank's vocabulary rows, loaded before the weights. - The fused decode tail takes the summed feed-forward through addRMS. - hasLoadedReadoutPrecision still means the whole vocabulary, so the paged, CBv2 and MTP owners refuse a tensor-parallel rank. Without installTensorParallel every forward is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tensor-parallel rank's lm_head holds only its own vocabulary rows, so the independent-history readout check now asks for the rows the head projects (headVocabularyRange). A whole model asks for the whole vocabulary, as before. The scalar forwardIndependentHistory path already runs the backbone, which sums each layer's partials when tensor parallel is installed. The batched decodeIndependentHistories layer loop does not take those sums, so a rank refuses more than one row there. CBv2 and MTP still refuse a rank. Without installTensorParallel every forward is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MiMoV26TextModel.observeRoutes(_:) hands each routed layer's selected expert indices (not evaluated) and its layer index to an observer, in forward order. Every path that routes goes through MiMoV26Router: the generic and row-local selections, the fused decode tail and tensor-parallel ranks. Observation only: with no observer, a router returns the same arrays as before. The d-inference route-set oracle uses this to find where a tensor-parallel run first routes a token to other experts than the whole model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in the Gemma 4 tensor-parallel branch head a4f67fa (CBv2 decoder-layer submission and the shortened doc comments) under the MiMo V2.6 tensor-parallel stack. No file overlaps; no conflicts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Trims the new doc comments in MiMoV26TensorParallel.swift and MiMoV26MoE.swift to two or three lines, as the fork asks. tensorParallelPartial now says why a rank sums one combined FP32 row instead of TensorParallelSwitchLinear's per-expert rows (the stock MXFP4 kernels run) and what it costs (each expert's half-width row is rounded to BF16 first). Comment lines only; swift format 6.4.4 makes no change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tensor-parallel rank's expert rows, o_proj and dense down_proj partials were stored in BF16 before the FP32 cross-rank sum, so each half was rounded once and the sum again. One Mac rounds each full-width product once. Each row-parallel product now takes an exact FP32 widening of its BF16 input, so the partial is FP32 and is rounded only after the sum: - SwitchGLU.float32ExpertRows: the down projection's input is widened; the decode-expert kernel gets an FP32-output twin of its down kernel (MiMoV26DecodeExperts float32Rows). The product's kernel source is unchanged. - MiMoV26Attention.attend splits out the rows o_proj projects; MiMoV26DecoderLayer.attentionOutput widens them on a rank. - MiMoV26DenseMLP.tensorParallelPartial widens the activation product; verification rows run it one row at a time. - MiMoV26TensorParallelContext.sum takes only an FP32 partial and rounds once to the activation dtype. A model without tensor parallel runs the same graph as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308
marked this pull request as ready for review
November 2, 2026 19:18
…-parallel Brings in SDK main (2311af6) through the Gemma 4 branch. Conflict: Libraries/MLXLMCommon/SwitchLayers.swift. SwitchGLU.projectExperts takes both new parameters: this branch's float32Rows (exact FP32 widening of the down projection's input) and main's hintsSorted (#384: sort only for weight locality, keep the unsorted M=1 gathers). The final down projection uses downInput(activated) with sortedIndices: hint. The file is byte-identical to the resolution in integration/0.10.7-rehearsal (cb2fc27). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai
approved these changes
Nov 3, 2026
davidtai
left a comment
There was a problem hiding this comment.
Approved on David's order, 2026-11-03.
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
Adds what one rank of a two-rank MiMo V2.6 tensor-parallel text model needs, behind state a single Mac never sets. Stacked on
feat/gemma4-tensor-parallel. Pinned by Layr-Labs/d-inference#1707 and #1715.MiMoV26TensorShard: a rank keeps half the query heads with the KV heads they read, the sliding layers' sink bias for those heads, and half the dense and expert channels.localConfigurationhalves the six head and width fields and drops MTP.MiMoV26TextModel.installTensorParallel(reduce:vocabularyRows:): each layer sums itso_projpartial before the post-attention norm, and a routed layer combines its experts' rows locally, then sums that one row.lm_headbecomes a shell of this rank's vocabulary rows.headVocabularyRange). A rank refuses more than one row in the batcheddecodeIndependentHistoriesloop, and CBv2 and MTP still refuse a rank.MiMoV26TextModel.observeRoutes(_:): hands each routed layer's selected expert indices to an observer. With no observer a router returns the same arrays as before.SwitchGLU.float32ExpertRows).A model without tensor parallel runs the same graph as before.
Conflict to expect:
Libraries/MLXLMCommon/SwitchLayers.swiftconflicts withfeat/gemma4-batched-prompt-experts. That PR lands after this one and takes the resolution incb2fc27f.Tests: none in this branch. The tests live in d-inference's cluster packages (#1707).
Not validated here: the real pair and speed. See #1707.
Merge with a merge commit, not a squash. The d-inference PRs pin these exact commits, and a merge commit keeps them on
main. Replaying the stack with squashes conflicts; with merge commits it is clean.The order for all six is in the 0.10.7 list:
feat/gemma4-tensor-parallel,feat/mimo-v26-tensor-parallel,feat/mimo-v26-tp-speculative,perf/qwen27-tp-row-exact,perf/qwen27-tp-prompt-wavefront, thenfeat/gemma4-batched-prompt-experts.Together with the other five branches, this one is in
integration/0.10.7-rehearsal(cb2fc27f), the SDK side of Layr-Labs/d-inference#1726.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesAI usage
accurately describes the code changes.
open PRs on this fork for d-inference work, so this was opened from a branch that was already pushed; no code changed
in opening it. It has had no human review.
🤖 Generated with Claude Code