Skip to content

MiMo V2.6: tensor-parallel shard, hooks and FP32 partials - #380

Merged
davidtai merged 7 commits into
mainfrom
feat/mimo-v26-tensor-parallel
Nov 3, 2026
Merged

davidtai merged 7 commits into
mainfrom
feat/mimo-v26-tensor-parallel

Conversation

@jonathan308

Copy link
Copy Markdown

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. localConfiguration halves the six head and width fields and drops MTP.
  • MiMoV26TextModel.installTensorParallel(reduce:vocabularyRows:): each layer sums its o_proj partial before the post-attention norm, and a routed layer combines its experts' rows locally, then sums that one row. lm_head becomes a shell of this rank's vocabulary rows.
  • Independent-history pages: the readout check asks for the rows the head projects (headVocabularyRange). A rank refuses more than one row in the batched decodeIndependentHistories loop, 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.
  • FP32 partials: each row-parallel product takes an exact FP32 widening of its BF16 input, so a partial is rounded only once, after the cross-rank sum (SwitchGLU.float32ExpertRows).

A model without tensor parallel runs the same graph as before.

Conflict to expect: Libraries/MLXLMCommon/SwitchLayers.swift conflicts with feat/gemma4-batched-prompt-experts. That PR lands after this one and takes the resolution in cb2fc27f.

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, then feat/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

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure: the commits and this description were written by Claude Code. The owner has allowed agents to
    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

jonathan308 and others added 6 commits October 31, 2026 23:42
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
jonathan308 marked this pull request as ready for review November 2, 2026 19:18
@jonathan308
jonathan308 requested a review from davidtai 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
davidtai changed the base branch from feat/gemma4-tensor-parallel to main November 3, 2026 17:19

@davidtai davidtai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on David's order, 2026-11-03.

@davidtai
davidtai merged commit 36047dd into main Nov 3, 2026
20 of 27 checks passed
@davidtai
davidtai deleted the feat/mimo-v26-tensor-parallel branch November 3, 2026 18:43
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