Repository navigation
Add Beam BF16 LoRA support on Miles v0.2.0 - #37
Conversation
949b877 to
8e419cc
Compare
69abc2c to
f45c63c
Compare
| ): | ||
| # Even a Q-only canonical selection wraps the whole fused linear. Bridge's | ||
| # split wrapper emits Q/K/V rows, omitting Beam's attention gate rows. | ||
| raise ValueError( |
There was a problem hiding this comment.
i think for now this is ok but (very) soon we want to get off of megatron-bridge completely and do evrything within the miles native lora setup
would it be possible to add native beam model provider on top of the current bridge provider? my agent says that biggest change is going to be adding multi lora support for shared outer expert lora, which it seems miles doesn't have rn
There was a problem hiding this comment.
it's going to be a lot of work to merge this in but modal-labs/spindle#312 is my ultimate goal
There was a problem hiding this comment.
I would prefer to keep the scope small to start with.
|
|
||
| from miles.backends.megatron_utils.model_provider import _apply_bridge_runtime_config | ||
|
|
||
| _apply_bridge_runtime_config(provider, args) |
There was a problem hiding this comment.
Can we drop this and the other three shared LoRA changes in this file (expert TP assert, expert_bias freeze for single LoRA, data_parallel_random_init)? None of them are on upstream main, and they change behaviour for every bridge-mode LoRA model, not just Beam. For example, calculate_per_token_loss now applies, which changes gradient scaling. Beam on Spindle doesn't need them: multi-LoRA already freezes expert_bias and requires expert TP 1, and the Beam provider already sets the router and softmax settings. Dropping them keeps the fork close to radixark#4149. It also fixes the bridge config fixture tests these changes break.
There was a problem hiding this comment.
Dropping them keeps the fork close to radixark#4149.
For what it's worth, these are taken directly from that PR
| if any(".experts." in target for target in adapter_targets): | ||
| assert ( | ||
| provider.expert_tensor_parallel_size or 1 | ||
| ) == 1, "LoRA on MoE experts requires --expert-tensor-parallel-size 1" |
There was a problem hiding this comment.
Same as above: please drop. Multi-LoRA already enforces expert TP 1. For single LoRA, this makes TP>1 runs that never set expert TP fail at build.
| for chunk in transformed: | ||
| for module in chunk.modules(): | ||
| if isinstance(module, TopKRouter): | ||
| module.frozen_expert_bias = True |
There was a problem hiding this comment.
Same as above: please drop. Upstream radixark#4709 freezes expert_bias a different way (freeze_router_expert_bias) and deletes this loop, so we should follow that once it lands rather than diverge here.
There was a problem hiding this comment.
Is there reason to believe that PR is more likely to land or land sooner than radixark#4149 ?
| wrap_with_ddp=True, | ||
| ddp_config=ddp_config, | ||
| data_parallel_random_init=args.backend.data_parallel_random_init, | ||
| ) |
There was a problem hiding this comment.
Same as above: please drop. Spindle never sets data_parallel_random_init, and it defaults to False.
| assert self.num_query_groups % self.tensor_model_parallel_size == 0, "Beam TP must divide num_key_value_heads" | ||
| # Beam is validated with unfused RoPE and SwiGLU. The LoRA path copies the CLI fusion flags, | ||
| # which would change the base model's numerics. | ||
| self.apply_rope_fusion = False |
There was a problem hiding this comment.
Can we set self.moe_router_dtype = "fp32" and self.moe_router_use_torch_mm = True here, next to the fusion overrides? The LoRA path copies the CLI router flags over the provider_bridge defaults, so a launcher that omits them gets a TE router GEMM error or BF16 routing that doesn't match the sampler. scripts/models/beam.py passes only --moe-router-dtype. Forcing both here removes the launcher requirement from the PR body and matches how radixark#4149 already handles fusion.
| raise ValueError( | ||
| "Beam fused QKVG attention does not support canonical_lora: the Bridge wrapper emits only Q/K/V rows. " | ||
| "Use --lora-type lora with all fused attention targets, or select independent projections such as o_proj." | ||
| ) |
There was a problem hiding this comment.
Non-blocking: this check and its tests are fork-only, and Spindle always uses --lora-type lora, so it never fires for us. Consider dropping it here and filing an issue on radixark/miles about radixark#4149 silently mis-resolving canonical_lora on the fused QKVG layer.
|
I'm going to do a new Beam validation run before merging anything. |
Miles moves to d1915e68, the tip of modal-projects/miles#37 after review. It drops the shared Bridge LoRA changes from the upstream port and keeps Beam's FP32 router settings inside its own provider. SGLang moves to 568ab742 on spindle-sglang-v0.5.23, the merge of modal-projects/sglang#95, instead of the personal branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
modal-projects/miles#37 was squash-merged into spindle-miles-v0.2.0 as 3280b7a. Its tree is identical to d1915e68, the commit the validation run trained on, so the Beam image moves to the merged commit under the name miles-v0.2.0-3280b7a. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Adds Beam BF16 training with standard LoRA on Miles v0.2.0. The model, Bridge provider, weight mappings and fused Q/gate/K/V adapter export are ported from radixark/miles#4149, which is still open and is based on v0.1.2.
Scope: trainer only. The bundled SGLang (
fd017154) raisesNotImplementedErrorfor Beam with LoRA, so Miles' own rollout cannot serve Beam adapters. Spindle samples with its own Beam-enabled SGLang.Changes
Ported from radixark#4149:
self_attn.gate_proj) out of the MoE expert checks, unchanged.New in this PR:
canonical_loraon Beam's fused Q/gate/K/V layer now raises an error. Bridge's split wrapper only knows Q/K/V, so the gate would get no adapter. Upstream has no check and would silently mis-resolve this. The check runs when LoRA is applied, after the model is built, not during argument parsing.Not ported, because v0.2.0 already covers it or it's out of scope: DistributedOptimizer state in LoRA checkpoints (v0.2.0 has its own), the SGLang target-module rewrite, the launchers, the reward function, the Docker image and the manual scripts. Beam's provider enforces its required router settings even when a launcher omits those flags.
Base:
spindle-miles-v0.2.0@15afe217(upstream v0.2.08e419cc7plus #39 and #38). SGLang and Bridge (a0c6d6e0) pins are unchanged.Validation
Run at
69abc2c0, before the rebase, on the v0.2.0 image (Torch 2.14.1, Transformers 5.19.0):After the review changes: 71 focused CPU tests passed; the Beam architecture test module (including the new router-override regression) skipped because local SGLang/Megatron dependencies are unavailable. A separate CPU check executed the production Beam provider class with a stubbed model-construction boundary and confirmed that FP32/Torch routing and disabled fusions reach construction after simulated CLI overrides. Pre-commit passed for all changed files. Bridge configuration fixture tests could not collect because SGLang is missing. The earlier H200 results above predate these review changes; no GPU training smoke test was run for this revision. No full-model training, distributed checkpoint restore or learning run has been done on this branch. Earlier Beam results used the v0.1.2 fork.
Spindle integration: modal-labs/spindle#252.