Skip to content

Add native Nemotron Nano and multi-slot routed expert LoRA - #46

Closed
kailash109 wants to merge 10 commits into
spindle-miles-v0.2.0from
codex/native-nemotron-experts
Closed

kailash109 wants to merge 10 commits into
spindle-miles-v0.2.0from
codex/native-nemotron-experts

Conversation

@kailash109

@kailash109 kailash109 commented Nov 17, 2026 •

Copy link
Copy Markdown

Superseded by the requested split: #47 routed expert LoRA and #48 Nemotron Nano. Merge #47 first; #48 is stacked on it. The validation history below belongs to the combined implementation.

Summary

Native multi-LoRA previously rejected routed experts because its slots assumed contiguous token ranges. Carry adapter slot IDs through Megatron's all-to-all dispatcher and apply each slot's factors to its expert-major rows. Reuse the native slot lifecycle, checkpoint export and independent Q/K/V adapters. Support independent factors per expert as well as the existing shared-outer layout, and mask ranks along the correct axes of 3-D expert tensors. Freeze the shared router expert bias for native slots using the same helper as Bridge so tenant updates cannot alter base routing.

Add raw-mode Nemotron-3 Nano support: Megatron-Core hybrid provider, mbridge HF checkpoint conversion, Mamba tensor-parallel component packing, and ungated up/down adapters on routed and shared experts. Mamba projections remain frozen. Larger latent-expert Nemotron variants and GPT-OSS are outside this change.

Reuse the Qwen3.5/3.6 expert naming work from upstream #4824, with generic expert specs for the registered Qwen, DeepSeek, Kimi and GLM MoE layouts. Model-specific GPU validation is still in progress; this draft is not ready to merge.

Testing

  • All 243 native adapter tests pass in the pinned Miles v0.2.0 runtime (pytest --noconftest -o addopts= -q tests/fast/backends/megatron_utils/lora/native). This includes adapter math, target contracts, expert slot isolation, empty slots, rank padding, Nemotron checkpoint packing and Transformers' packed expert namespace.
  • Repository pre-commit checks pass on changed files.
  • The real TP2/EP2/ETP1 regression passes on two H200 GPUs: gated and ungated experts, independent and shared-outer factors, recomputation, tenant isolation, collective export, checkpoint row probing and rank slicing. It also verifies that the shared router bias stays fixed with a nonzero configured update rate. The latest torchrun subprocess took 51.9 seconds, and the 243 adapter tests passed again. These checks mounted source corresponding to 88ca1d1 over the pinned base image.
  • Full-model Nemotron Nano at current revision 88ca1d1 completed four successful RL optimizer updates (two steps each for concurrent rank-8 and rank-16 clients) through Spindle's Miles command backend, including generation and adapter publication. In a diagnostic continuation, both clients also published trained adapters and returned finite sampler scores after restore.
  • Checkpoint tensors round-trip exactly for both clients: streamed comparisons found zero mismatches across 651,988,992 (rank 8) and 1,303,977,984 (rank 16) weight and Adam-moment elements. These measurements use runtime 0bd70b3.
  • Unresolved full-model check: the strict probe-score restore assertion failed (up to 0.2555). Repeated forwards without loading also differed, by 0.1249 and 0.2299 on the two diagnostic clients. Tensor equality above separates this from checkpoint corruption, but score repeatability and exact optimizer replay remain unvalidated. The original end-to-end check also fails on 88ca1d1 (0.2752 after four successful RL updates), so freezing router bias alone does not resolve it. This draft is not ready to merge.
  • Earlier validation exposed the packed HF expert target namespace fixed here, and a Ray logical CPU reservation deadlock fixed in Spindle PR Super tiny update link radixark/miles#312.

CI timing: tests/fast-gpu/test_lora_native_experts.py uses stage-b-2-gpu-h200, num_gpus=2, and est_time=180 as an upper bound. The development run above was measured on Modal; timing on the registered CI runner remains unmeasured. No shared CI rerun has been requested.

Generated run outputs stay outside Git.

nanjiangwill and others added 7 commits November 17, 2026 20:26
Native LoRA adapted Qwen3.5/3.6 MoE's attention, Gated DeltaNet and shared
expert, but not its routed experts. The shared-outer grouped-expert spec Inkling
and Kimi K3 use attaches to Megatron's grouped experts of any model; only how
targets name the experts was theirs. GroupedExpertsSpec now names the expert
leaves the converter gives (w1/w3/w2) and whether targets name one expert, and
the adapters export under those leaves. PackedGroupedExpertsSpec covers HF
models that pack their experts in experts.gate_up_proj and experts.down_proj,
with gate_proj/up_proj/down_proj leaves, as Qwen3.5/3.6 MoE does. A spec without
a fixed target layout gives the pattern its expert targets sit under, so the
target check accepts them.

--experts-shared-outer-loras and --expert-tensor-parallel-size 1 are required
only once the targets reach the routed experts (a fixed layout always does), so
attention-only Qwen3.5/3.6 MoE runs work as before.
Comment thread docs/advanced/lora.md
|---|---|---|---|
| **Megatron-Bridge PEFT** | `AutoBridge` builds the provider, applies Bridge LoRA before DDP, and exports HF-named adapter tensors. Select it with `--megatron-to-hf-mode bridge`. | Qwen2.5, Qwen3, GPT-OSS, Kimi K2.5, GLM-5/5.1/5.2/5.3, and Qwen3.5/3.6, subject to the evidence and module caveats below. | General production path, single LoRA and multi-LoRA. |
| **Native / raw-mode LoRA** | Under `--megatron-to-hf-mode raw`, miles builds the model with its own Megatron provider and the `miles.backends.megatron_utils.lora.native` plugin attaches adapter modules directly before DDP. | Architectures registered in `miles/backends/megatron_utils/lora/native/registry.py`: fused-QKV GQA (Llama, Qwen2/3, GLM-4), Qwen3.5/3.6 hybrids (GQA and GDN layers), Qwen3-Next (GQA layers), MLA (DeepSeek-V3/V3.2, Kimi K2/K2.5, GLM-4.7-Flash, GLM-5.x), Inkling, and Kimi K3. | Single LoRA, and multi-LoRA on dense projections and lm_head (see [multi-LoRA supported models](/advanced/multi-lora#supported-models)). Unregistered models fail at startup. |
| **Native / raw-mode LoRA** | Under `--megatron-to-hf-mode raw`, miles builds the model with its own Megatron provider and the `miles.backends.megatron_utils.lora.native` plugin attaches adapter modules directly before DDP. | Architectures registered in `miles/backends/megatron_utils/lora/native/registry.py`: fused-QKV GQA (Llama, Qwen2/3, GLM-4), Qwen3.5/3.6 hybrids (GQA and GDN layers), Qwen3-Next (GQA layers), MLA (DeepSeek-V3/V3.2, Kimi K2/K2.5, GLM-4.7-Flash, GLM-5.x), Inkling, Kimi K3, and Nemotron-3 Nano. | Single LoRA, and multi-LoRA on dense projections, grouped routed experts (all-to-all, expert TP=1, no capacity padding), and lm_head (see [multi-LoRA supported models](/advanced/multi-lora#supported-models)). Unregistered models fail at startup. |

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

delete docs change



def _co_permute_slot_ids(dispatcher, slot_ids: torch.Tensor, num_experts: int) -> torch.Tensor:
# Megatron is optional on CPU hosts that import the native adapter definitions.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

is this true? i'm pretty sure i've seen some files that have top level imports for megatron/megatron.bridge

if not then can keep here but otherwise move to top of file

return mlp.linear_fc1.weight.shape[0] // 2


class UngatedMLPSpec(LayoutSpec):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

split into separate PR, one for multi lora routed expert and one for native nemotron nano

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