Repository navigation
Add native Nemotron Nano and multi-slot routed expert LoRA - #46
Closed
kailash109 wants to merge 10 commits into
Closed
kailash109 wants to merge 10 commits into
kailash109 wants to merge 10 commits into
Conversation
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.
kailash109
commented
Nov 17, 2026
| |---|---|---|---| | ||
| | **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. | |
kailash109
commented
Nov 17, 2026
|
|
||
|
|
||
| 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. |
Author
There was a problem hiding this comment.
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
kailash109
commented
Nov 17, 2026
| return mlp.linear_fc1.weight.shape[0] // 2 | ||
|
|
||
|
|
||
| class UngatedMLPSpec(LayoutSpec): |
Author
There was a problem hiding this comment.
split into separate PR, one for multi lora routed expert and one for native nemotron nano
This was referenced Nov 17, 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.
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
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.88ca1d1over the pinned base image.88ca1d1completed 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.0bd70b3.88ca1d1(0.2752 after four successful RL updates), so freezing router bias alone does not resolve it. This draft is not ready to merge.CI timing:
tests/fast-gpu/test_lora_native_experts.pyusesstage-b-2-gpu-h200,num_gpus=2, andest_time=180as 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.