Skip to content
Merged
Show file tree
Hide file tree
Changes from 89 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
12e4e88
lora: map DSA indexer modules across sglang↔megatron-bridge names
yushengsu-thu Jun 18, 2026
7e5de94
lora: include MLA + DSA indexer modules in all-linear expansion
yushengsu-thu Jun 18, 2026
cb84455
lora: register dsa experimental-attention-variant spec for bridge LoR…
yushengsu-thu Jun 18, 2026
655608d
examples,scripts: add GLM-5.1 LoRA launcher, example, and 6-layer reg…
yushengsu-thu Jun 19, 2026
37a7cf1
lora: move dsa spec registration to Megatron-Bridge (drop caller-side…
yushengsu-thu Jun 19, 2026
9f08173
scripts: add GLM-5.2 LoRA registries + extend run_glm5_lora.py
yushengsu-thu Jun 20, 2026
96064c3
examples,tests: add GLM-5.1/5.2 LoRA e2e CI tests; drop ad-hoc example
yushengsu-thu Jun 20, 2026
a3f6efc
scripts,tests: rename GLM-5.1-specific files to glm5.1/glm5_1 for ver…
yushengsu-thu Jun 20, 2026
06b6416
utils: add --dsa-attention-backend arg (GLM DSA fused/unfused selection)
yushengsu-thu Jun 22, 2026
86edaea
backends: wire --dsa-attention-backend onto the GLM bridge provider
yushengsu-thu Jun 22, 2026
ab23877
scripts: surface --dsa-attention-backend in run_glm5_lora + document …
yushengsu-thu Jun 22, 2026
899d6cb
scripts,tests: align GLM-5.2 LoRA example + CI to the canonical GLM-5…
yushengsu-thu Jun 23, 2026
5e1cd0d
scripts,utils: default --dsa-attention-backend=slime + enable R3 in r…
yushengsu-thu Jun 23, 2026
2689e6b
backends,scripts: honor --dsa-attention-backend on the bridge LoRA bu…
yushengsu-thu Jun 23, 2026
f10c293
utils: add MILES_RAY_SUBMIT_NO_WAIT to detach ray job submit from the…
yushengsu-thu Jun 23, 2026
a868606
utils: add MILES_R3_DIAG replay-check diagnostic + cap mismatch warnings
yushengsu-thu Jun 23, 2026
03720b4
scripts: add run_glm5_lora_multinode.sh for multi-node GLM-5 LoRA RL
yushengsu-thu Jun 23, 2026
761558a
scripts: add dapo-math example task to run_glm5_lora.py
yushengsu-thu Jun 23, 2026
eb089cf
scripts: support --task (gsm8k/dapo-math) in run_glm5_lora_multinode.sh
yushengsu-thu Jun 23, 2026
7c018f7
GLM-5.2 LoRA rollout: fix DSA-indexer gibberish + dense-gate_up sglan…
yushengsu-thu Jun 24, 2026
99ef33a
GLM-5.2 744B LoRA-RL: full-scale slime e2e launcher + host-OOM knobs
yushengsu-thu Jun 24, 2026
ff5f2d2
GLM-5.2 LoRA-RL: default dapo-math seq-length to 4096 (validated swee…
yushengsu-thu Jun 24, 2026
42fb843
GLM-5.2 LoRA-RL full preset: default DAPO_DYNAMIC_SAMPLING=off
yushengsu-thu Jun 25, 2026
14bc26f
GLM-5.2 LoRA-RL: R3 = routing replay ONLY (drop DSA indexer replay)
yushengsu-thu Jun 25, 2026
ccc944b
run_glm5_lora.py: fix stale use_r3 docstring (R3 = routing replay only)
yushengsu-thu Jun 25, 2026
683a57d
R3: default use_rollout_routing_replay ON (BooleanOptionalAction)
yushengsu-thu Jun 25, 2026
da74f00
full preset: --lora-base-cpu-backup ON (required for correct colocate…
yushengsu-thu Jun 25, 2026
f07d114
colocate LoRA: stop dropping q_b_proj/kv_b_proj from the sglang rollo…
yushengsu-thu Jun 25, 2026
1631adc
GLM-5.2 multinode LoRA: add 5layer-like-full 2-node wrapper, full-mod…
yushengsu-thu Jun 25, 2026
96ce6c5
gsm8k: default SEQ/RESP_LEN to 256 (short-answer task)
yushengsu-thu Jun 25, 2026
83959d2
lora rl: drop SEQ default (auto-derive window), response-len dapo=409…
yushengsu-thu Jun 25, 2026
144b0ec
lora rl: dapo seq window = 8192 (hard-bound prompt+response); gsm8k s…
yushengsu-thu Jun 25, 2026
38777bf
lora rl: gsm8k response-len default 256 -> 512
yushengsu-thu Jun 25, 2026
c5051fe
lora rl: add periodic held-out eval (interval default 5)
yushengsu-thu Jun 26, 2026
c378269
fix: window eval submission to avoid dp-attention colocate hang
yushengsu-thu Jun 26, 2026
d4f0431
Revert "fix: window eval submission to avoid dp-attention colocate hang"
yushengsu-thu Jun 26, 2026
ff8b4fe
add NVSHMEM_DISABLE_NCCL to avoid cuda graph hang
yueming-yuan Jun 19, 2026
d79e27c
lora rl: enable MoE/MLP LoRA by default + select per-expert vs shared…
yushengsu-thu Jun 26, 2026
0e5851e
glm5 lora: default MoE-expert LoRA on + always-paired shared-outer/vi…
yushengsu-thu Jun 27, 2026
eb636e9
glm5 lora: add MOE_LORA_LAYERS knob to restrict MoE-expert LoRA to a …
yushengsu-thu Jun 27, 2026
2061379
glm5 lora: default MOE_LORA_LAYERS to ALL MoE layers (toy + full GLM-…
yushengsu-thu Jun 28, 2026
67bd92c
glm5 lora: default-on CPU-Adam (optimizer-cpu-offload) + disable MOE_…
yushengsu-thu Jun 28, 2026
fed3f1c
glm5 lora: default sglang LoRA kernel backend to triton
yushengsu-thu Jun 28, 2026
f402c4d
Revert "lora rl: add periodic held-out eval (interval default 5)"
yushengsu-thu Jun 29, 2026
d888950
glm5 lora: add launch_glm_rl.sh (full GLM-5.2 attention-only LoRA-RL …
yushengsu-thu Jun 29, 2026
7d75076
glm5 lora: one-command launch_glm_rl.sh + pre-run cleanup + 4x16 batch
yushengsu-thu Jun 29, 2026
b14acdc
glm5 lora: enable MoE-expert LoRA (gate/up/down) + lora-rank 4
yushengsu-thu Jun 29, 2026
1d93245
glm5 lora: lora-rank 8 (rank 4 invalid under TP=8 / moe_router_topk=8)
yushengsu-thu Jun 29, 2026
60b746f
glm5 lora: fix step-0 OOM — MoE LoRA last-N layers + NVSHMEM_DISABLE_…
yushengsu-thu Jun 29, 2026
1ce9f53
glm5 lora: bump --num-rollout to 10000 for a long MoE-LoRA RL run
yushengsu-thu Jun 29, 2026
f0562bd
[LoRA] add --check-lora-weight-update-equal (default ON when LoRA): L…
yushengsu-thu Jun 30, 2026
81e9df3
Revert "[LoRA] add --check-lora-weight-update-equal (default ON when …
yushengsu-thu Jun 30, 2026
f3888fe
[launch] bump rollout-batch-size 4->8; fix miles_dev->miles_lora paths
yushengsu-thu Jun 30, 2026
815b691
[launch] split launcher: rename to att_fused_moe; add att_unfused_moe…
yushengsu-thu Jul 1, 2026
61b555f
Merge remote-tracking branch 'radixark/main' into miles-dev-2026-06-1…
yushengsu-thu Jul 1, 2026
49c9158
[lora] fix review regressions: R3 default-off, all-linear scope, expe…
yushengsu-thu Jul 2, 2026
c4d9d49
[lora] fix: tag refactor-rollout generate requests with lora_path
yushengsu-thu Jul 2, 2026
986c2a9
[lora] chore: move ad-hoc GLM dev launchers out of the repo
yushengsu-thu Jul 2, 2026
38473dc
[lora] refactor: split run_glm5_lora.py into per-model PR-style run s…
yushengsu-thu Jul 2, 2026
9c1d2fd
[lora] fix: default --lora-base-cpu-backup ON in the GLM-5.x LoRA run…
yushengsu-thu Jul 2, 2026
44293db
tiny fix
yushengsu-thu Jul 2, 2026
697cd8a
[lora] refactor: rename DSA backend values to megatron-bridge-native …
yushengsu-thu Jul 2, 2026
7327504
Merge remote-tracking branch 'radixark/main' into miles-dev-2026-06-1…
yushengsu-thu Jul 2, 2026
90c3372
nit fix
yushengsu-thu Jul 2, 2026
ac48ea7
fix lora ci: arch-gate all-linear MLA targets; make weight-update che…
yushengsu-thu Jul 2, 2026
e1c4ad5
fix: update stale SlimeMLASelfAttention references after DSA backend …
yushengsu-thu Jul 2, 2026
2eb0ed0
docs: trim redundant comments in GLM-5.1/5.2 LoRA runners, registries…
yushengsu-thu Jul 3, 2026
2427faa
docs: second-pass comment cleanup across the GLM-5 LoRA PR
yushengsu-thu Jul 3, 2026
46092b2
revert --use-rollout-routing-replay to action=store_true
yushengsu-thu Jul 3, 2026
c1d163c
[lora] refactor: rename --dsa-attention-backend choices to megatron /…
yushengsu-thu Jul 5, 2026
1dc86b4
[lora] refactor: move the LoRA weight-check skip-list out of argument…
yushengsu-thu Jul 5, 2026
7834d72
docs: drop the dsa_attention_backend override comments
yushengsu-thu Jul 6, 2026
33cd2df
[lora] refactor: drop the post-build dsa_attention_backend force loop
yushengsu-thu Jul 6, 2026
96df315
[lora] refactor: centralize the MoE-expert LoRA layout handling in ar…
yushengsu-thu Jul 6, 2026
fb218e5
Merge branch 'main' into miles-dev-2026-06-16-merging
yueming-yuan Jul 6, 2026
aeb1a85
[lora] feat: auto-enable sglang virtual-experts serving for MoE-exper…
yushengsu-thu Jul 6, 2026
cf9ca2f
Merge remote-tracking branch 'origin/miles-dev-2026-06-16-merging' in…
yushengsu-thu Jul 6, 2026
22ef339
[lora] refactor: pass only experts_shared_outer_loras to Megatron-Bridge
yushengsu-thu Jul 6, 2026
fbe1e1a
[lora] refactor: default --sglang-lora-use-virtual-experts ON
yushengsu-thu Jul 6, 2026
6aedd89
revert: drop the MILES_RAY_SUBMIT_NO_WAIT ray-submit option from comm…
yushengsu-thu Jul 7, 2026
18538c0
[lora] refactor: resolve all-linear MLA gating via load_hf_config
yushengsu-thu Jul 7, 2026
ee8d650
[lora] test: run the MoE-expert LoRA combination matrix in the GLM-5 …
yushengsu-thu Jul 7, 2026
2299d88
docs: drop the resolved-target-modules info log
yushengsu-thu Jul 7, 2026
5941746
[lora] refactor: drop the MILES_R3_DIAG block; cap R3 mismatch dumps …
yushengsu-thu Jul 7, 2026
3504271
docs: align PR-added comments with the core codebase style
yushengsu-thu Jul 7, 2026
4c665ee
Merge remote-tracking branch 'radixark/main' into miles-dev-2026-06-1…
yushengsu-thu Jul 7, 2026
6f9877c
Replace weight-checker comment with TODO
yueming-yuan Jul 7, 2026
4d940be
Remove obsolete comments
yueming-yuan Jul 7, 2026
2c4e33a
Move backend-neutral LoRA helpers out of megatron_utils
yueming-yuan Jul 7, 2026
aeff684
Remove comment in generate_endpoint_utils
yueming-yuan Jul 7, 2026
e079735
Repoint LORA_ADAPTER_NAME imports to miles.utils.lora; fix pre-commit
yueming-yuan Jul 7, 2026
cfac946
Fix test imports of LORA_ADAPTER_NAME after move to miles.utils.lora
yueming-yuan Jul 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions miles/backends/megatron_utils/bridge_lora_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def _setup_lora_model_via_bridge(args: Namespace) -> list:
provider.num_layers_in_first_pipeline_stage = args.decoder_first_pipeline_num_layers
if getattr(args, "decoder_last_pipeline_num_layers", None) is not None:
provider.num_layers_in_last_pipeline_stage = args.decoder_last_pipeline_num_layers
if hasattr(provider, "dsa_attention_backend"):
provider.dsa_attention_backend = getattr(args, "dsa_attention_backend", "megatron")
provider.finalize()

lora = create_lora_instance(args)
Expand Down
25 changes: 11 additions & 14 deletions miles/backends/megatron_utils/lora_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import torch.distributed as dist

from miles.backends.training_utils.parallel import get_parallel_state
from miles.utils.lora import LORA_ADAPTER_NAME, is_lora_enabled

logger = logging.getLogger(__name__)

LORA_ADAPTER_NAME = "miles_lora"

# ---------------------------------------------------------------------------
# Unified HF <-> Megatron module name mappings
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -78,24 +77,22 @@
"kv_a_proj_with_mqa": "linear_kv_down_proj",
"q_b_proj": "linear_q_up_proj",
"kv_b_proj": "linear_kv_up_proj",
# DSA indexer (GLM-5 / DeepSeek-V3.2): HF/SGLang leaf names vs Megatron-Bridge linear_* names.
"wq_b": "linear_wq_b",
"wk": "linear_wk",
"weights_proj": "linear_weights_proj",
Comment thread
yushengsu-thu marked this conversation as resolved.
Resolved
}
_MEGATRON_MLA_TO_HF = {v: k for k, v in _MLA_HF_TO_MEGATRON.items()}

# SGLang default get_hidden_dim (lora/utils.py) handles fused_qkv_a_proj_with_mqa via q_a / kv_a mapping,
# but not separate q_b_proj / kv_b_proj yet — omit from rollout adapter config to avoid init crashes.
_SGLANG_UNSUPPORTED_HF_TARGETS = frozenset({"q_b_proj", "kv_b_proj"})
# Empty: dropping a module here makes sglang silently skip its shipped adapter tensors.
_SGLANG_UNSUPPORTED_HF_TARGETS = frozenset()


# ---------------------------------------------------------------------------
# Core helpers
# ---------------------------------------------------------------------------


def is_lora_enabled(args: Namespace) -> bool:
"""Check if LoRA is enabled based on arguments."""
return getattr(args, "lora_rank", 0) > 0 or getattr(args, "lora_adapter_path", None) is not None


def lora_base_cpu_backup_enabled(args: Namespace) -> bool:
"""LoRA + --colocate + --lora-base-cpu-backup all set."""
return is_lora_enabled(args) and getattr(args, "colocate", False) and getattr(args, "lora_base_cpu_backup", False)
Expand Down Expand Up @@ -255,7 +252,7 @@ def convert_target_modules_to_hf(megatron_modules: list[str]) -> list[str]:


def target_modules_hf_for_sglang_rollout(args: Namespace) -> list[str]:
"""HF target_modules for SGLang LoRA init/sync, with MLA q_b/kv_b dropped (unsupported)."""
"""HF target_modules for SGLang LoRA init/sync (minus _SGLANG_UNSUPPORTED_HF_TARGETS, currently empty)."""
raw = list(args.target_modules) if args.target_modules else []
hf = convert_target_modules_to_hf(raw)
out = [m for m in hf if m not in _SGLANG_UNSUPPORTED_HF_TARGETS]
Expand Down Expand Up @@ -315,9 +312,9 @@ def create_lora_instance(args: Namespace):
lora_A_init_method=getattr(args, "lora_A_init_method", "xavier"),
lora_B_init_method=getattr(args, "lora_B_init_method", "zero"),
)
# Opt-in to SGLang PR #21466's shared-outer grouped-expert LoRA. Only the
# standard ``LoRA`` class supports the flag today.
if lora_cls is LoRA and getattr(args, "experts_shared_outer_loras", False):
# shared-outer grouped-expert LoRA (SGLang PR #21466); per-expert is the default
if getattr(args, "experts_shared_outer_loras", False):
assert lora_cls is LoRA, "--experts-shared-outer-loras requires the standard LoRA adapter type"
lora_kwargs["experts_shared_outer_loras"] = True

lora = lora_cls(**lora_kwargs)
Expand Down
3 changes: 3 additions & 0 deletions miles/backends/megatron_utils/model_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def _apply_bridge_runtime_config(provider, args: argparse.Namespace) -> None:
if getattr(args, "moe_aux_loss_coeff", None) is not None:
provider.moe_aux_loss_coeff = args.moe_aux_loss_coeff

if hasattr(provider, "dsa_attention_backend"):
provider.dsa_attention_backend = getattr(args, "dsa_attention_backend", "megatron")


# Adapt from https://github.com/volcengine/verl/blob/c3b20575d2bc815fcccd84bddb4c0401fc4b632b/verl/models/llama/megatron/layers/parallel_linear.py#L82
class LinearForLastLayer(torch.nn.Linear):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,12 @@ def update_weights(self) -> None:
# a host mirror across pause/resume), we can skip the base sync entirely
# and the surrounding restore_weights_before_load / post_process_quantization
# calls that would otherwise prep / re-quantize fresh base bytes.
skip_base_sync = self.is_lora and (self.use_distribute or lora_base_cpu_backup_enabled(self.args))
# TODO: implement lora weight checker
skip_base_sync = (
self.is_lora
and (self.use_distribute or lora_base_cpu_backup_enabled(self.args))
and not getattr(self.args, "check_weight_update_equal", False)
)

if rank == 0:
mode = self.args.pause_generation_mode
Expand Down
4 changes: 3 additions & 1 deletion miles/ray/placement_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def create_rollout_manager(args, pg):

if args.check_weight_update_equal:
ray.get(rollout_manager.check_weights.remote(action="snapshot"))
ray.get(rollout_manager.check_weights.remote(action="reset_tensors"))
ray.get(
rollout_manager.check_weights.remote(action="reset_tensors", skip_list=args.check_weight_update_skip_list)
)

if args.offload_rollout:
ray.get(rollout_manager.offload.remote())
Expand Down
5 changes: 5 additions & 0 deletions miles/rollout/generate_utils/generate_endpoint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import numpy as np
import pybase64

from miles.utils.lora import LORA_ADAPTER_NAME, is_lora_enabled
from miles.utils.processing_utils import encode_image_for_rollout_engine
from miles.utils.types import Sample

Expand Down Expand Up @@ -55,6 +56,10 @@ def compute_request_payload(
"return_routed_experts": args.use_rollout_routing_replay,
"return_indexer_topk": args.use_rollout_indexer_replay,
}
# Untagged requests are served by the BASE model; tag them so sglang applies the
# trained adapter (mirrors the legacy sglang_rollout.generate path).
if is_lora_enabled(args):
payload["lora_path"] = LORA_ADAPTER_NAME
if image_data := (multimodal_inputs or {}).get("images"):
payload["image_data"] = [encode_image_for_rollout_engine(image) for image in image_data]

Expand Down
2 changes: 1 addition & 1 deletion miles/rollout/generate_utils/prefill_logprobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections.abc import Mapping
from typing import Any

from miles.backends.megatron_utils.lora_utils import LORA_ADAPTER_NAME, is_lora_enabled
from miles.utils.lora import LORA_ADAPTER_NAME, is_lora_enabled
from miles.utils.http_utils import post
from miles.utils.processing_utils import encode_image_for_rollout_engine
from miles.utils.types import Sample
Expand Down
2 changes: 1 addition & 1 deletion miles/rollout/sglang_rollout.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from packaging.version import parse
from tqdm import tqdm

from miles.backends.megatron_utils.lora_utils import LORA_ADAPTER_NAME, is_lora_enabled
from miles.utils.lora import LORA_ADAPTER_NAME, is_lora_enabled
from miles.rollout.base_types import GenerateFnInput, RolloutFnEvalOutput, RolloutFnTrainOutput
from miles.rollout.filter_hub.base_types import MetricGatherer, call_dynamic_filter
from miles.rollout.inference_rollout.compatibility import load_generate_function
Expand Down
42 changes: 41 additions & 1 deletion miles/utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@ def add_train_arguments(parser):
default="raw",
help="The method to convert megatron weights to hugging face weights for SGLang.",
)
parser.add_argument(
"--dsa-attention-backend",
choices=["megatron", "tilelang"],
default="tilelang",
help=(
"DSA sparse-MLA kernel backend for GLM (glm_moe_dsa) under --megatron-to-hf-mode bridge. "
"'tilelang' (default) uses the fused TileLang kernels (SparseMLA + lighting_indexer, vendored from slime) for "
"rollout<->train numerical parity; 'megatron' uses the portable unfused megatron-core "
"kernels. 'tilelang' requires --qkv-format thd and the optional tilelang dep, and is "
"training/forward-only (no KV cache, cannot serve inference). Both support GLM-5.1 and "
"GLM-5.2, full or LoRA. No effect on non-DSA models or the 'raw' path."
),
)
Comment thread
yushengsu-thu marked this conversation as resolved.
Resolved
parser.add_argument(
"--extra-high-precision-layers-hf",
type=str,
Expand Down Expand Up @@ -1085,7 +1098,9 @@ def add_algo_arguments(parser):
"--use-rollout-routing-replay",
action="store_true",
default=False,
help="The rollout routing replay technique from https://arxiv.org/abs/2510.11370",
help="The rollout routing replay technique from https://arxiv.org/abs/2510.11370 (R3): "
"replay the rollout's MoE routing in training. MoE-only; the GLM-5 launchers pass it "
"explicitly.",
)
parser.add_argument(
"--use-indexer-replay",
Expand Down Expand Up @@ -1882,6 +1897,16 @@ def add_user_provided_function_arguments(parser):
parser = add_router_arguments(parser)
parser = add_debug_arguments(parser)
parser = add_sglang_arguments(parser)
# required whenever expert projections are LoRA targets, inert otherwise
# (sglang's own default is False)
parser.set_defaults(sglang_lora_use_virtual_experts=True)
parser.add_argument(
"--no-sglang-lora-use-virtual-experts",
dest="sglang_lora_use_virtual_experts",
action="store_false",
help="Serve MoE-expert LoRA through sglang's fused_moe_lora alignment path instead "
"of the virtual-experts path.",
)
parser = add_session_arguments(parser)
parser = add_network_arguments(parser)
parser = add_reward_model_arguments(parser)
Expand Down Expand Up @@ -2196,7 +2221,14 @@ def miles_validate_args(args):
assert args.target_modules is not None, "'--target-modules' is required when LoRA is enabled."

if args.target_modules == "all-linear":
# MLA projections are HF-config-gated (SGLang sizes LoRA buffers per module name;
# listing them on a dense model crashes the engine). The DSA indexer stays excluded.
modules = ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
hf_config = load_hf_config(args.hf_checkpoint)
if getattr(hf_config, "kv_lora_rank", None):
modules += ["kv_a_proj_with_mqa", "kv_b_proj"]
if getattr(hf_config, "q_lora_rank", None):
modules += ["q_a_proj", "q_b_proj"]
elif "," in args.target_modules:
modules = [m.strip() for m in args.target_modules.split(",")]
else:
Expand All @@ -2220,6 +2252,14 @@ def miles_validate_args(args):
args.sglang_experts_shared_outer_loras
), "experts_shared_outer_loras and sglang_experts_shared_outer_loras must agree"

# the two MoE-expert adapter layouts are not checkpoint-compatible; say which one runs
_expert_leaves = ("linear_fc1", "linear_fc2", "gate_proj", "up_proj", "down_proj")
if any(leaf in str(tm) for tm in modules for leaf in _expert_leaves):
logger.warning(
"MoE-expert LoRA layout: %s (--experts-shared-outer-loras).",
"shared-outer" if args.experts_shared_outer_loras else "per-expert",
)

assert not (args.kl_coef != 0 and args.kl_loss_coef != 0), "Only one of kl_coef and kl_loss_coef can be set"

if args.advantage_estimator in ["reinforce_plus_plus", "reinforce_plus_plus_baseline"]:
Expand Down
8 changes: 8 additions & 0 deletions miles/utils/lora.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from argparse import Namespace

LORA_ADAPTER_NAME = "miles_lora"


def is_lora_enabled(args: Namespace) -> bool:
"""Check if LoRA is enabled based on arguments."""
return getattr(args, "lora_rank", 0) > 0 or getattr(args, "lora_adapter_path", None) is not None
2 changes: 1 addition & 1 deletion miles/utils/replay_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def check_replay_result(self, old_topk_fn, scores, topk, top_indices, *args, **k
threshold = float(os.environ.get("MILES_TEST_R3_THRESHOLD", self.replay_check_max_mismatch_fraction))
mismatch_threshold = threshold * orig_flat.shape[0]
mismatch_indices = is_mismatch.nonzero(as_tuple=False).squeeze(1)
for idx in mismatch_indices:
for idx in mismatch_indices[:10]:

@yushengsu-thu yushengsu-thu Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I still modify here.
Because if r3 fail, it will stay here too longer to show the mismatch_indices. So, i just let it extract final 10 to quickly move forward and the users can also get the error msg.

i = idx.item()
lines = []
for j in range(max(0, i - 3), min(len(orig_flat), i + 4)):
Expand Down
14 changes: 14 additions & 0 deletions scripts/models/glm5.1-744B-A40B_6layer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" &>/dev/null && pwd)"
source "${SCRIPT_DIR}/glm5-744B-A40B.sh"

# Override for the 6-layer pruned GLM-5.1 toy (jybsuper/GLM-5.1-6layer):
# first 6 layers = 3 dense + 3 MoE.
N_MOE_LAYERS=3

for ((i=0; i<${#MODEL_ARGS[@]}; i++)); do
case "${MODEL_ARGS[$i]}" in
--num-layers) MODEL_ARGS[$((i+1))]=$((N_DENSE_LAYERS + N_MOE_LAYERS)) ;;
--moe-layer-freq) MODEL_ARGS[$((i+1))]="[0]*${N_DENSE_LAYERS}+[1]*${N_MOE_LAYERS}" ;;
esac
done

13 changes: 13 additions & 0 deletions scripts/models/glm5.1-744B-A40B_6layer_lora.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" &>/dev/null && pwd)"
source "${SCRIPT_DIR}/glm5.1-744B-A40B_lora.sh"

# Override for the 6-layer pruned GLM-5.1 toy (jybsuper/GLM-5.1-6layer):
# first 6 layers = 3 dense + 3 MoE.
N_MOE_LAYERS=3

for ((i=0; i<${#MODEL_ARGS[@]}; i++)); do
case "${MODEL_ARGS[$i]}" in
--num-layers) MODEL_ARGS[$((i+1))]=$((N_DENSE_LAYERS + N_MOE_LAYERS)) ;;
--moe-layer-freq) MODEL_ARGS[$((i+1))]="[0]*${N_DENSE_LAYERS}+[1]*${N_MOE_LAYERS}" ;;
esac
done
58 changes: 58 additions & 0 deletions scripts/models/glm5.1-744B-A40B_lora.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
MOE_ROUTED_EXPERTS=256
MOE_ACTIVE_ROUTED_EXPERTS=8
MOE_SHARED_EXPERTS=1

NHIDDEN=6144
MOE_FFN_HIDDEN=2048
MOE_SHARED_EXPERT_INTERMEDIATE_SIZE=$(($MOE_FFN_HIDDEN * $MOE_SHARED_EXPERTS))
FFN_HIDDEN=12288
N_DENSE_LAYERS=3
N_MOE_LAYERS=75
NHEADS=64

# GLM-5.1 744B-A40B (zai-org/GLM-5.1, glm_moe_dsa). Identical to glm5-744B-A40B.sh; the only
# architecture difference vs the glm5.2-744B-A40B* registries is --rotary-base (5.2 uses 8e6).
MODEL_ARGS=(
--spec "miles_plugins.models.glm5.glm5" "get_glm5_spec"
--moe-layer-freq "[0]*${N_DENSE_LAYERS}+[1]*${N_MOE_LAYERS}"
--num-experts $MOE_ROUTED_EXPERTS
--moe-shared-expert-intermediate-size $MOE_SHARED_EXPERT_INTERMEDIATE_SIZE
--moe-router-topk $MOE_ACTIVE_ROUTED_EXPERTS
--moe-grouped-gemm
--moe-permute-fusion
--moe-ffn-hidden-size $MOE_FFN_HIDDEN
--moe-router-score-function sigmoid
--moe-router-pre-softmax
--moe-router-enable-expert-bias
--moe-router-bias-update-rate 0
--moe-router-load-balancing-type seq_aux_loss
--moe-router-topk-scaling-factor 2.5
--moe-aux-loss-coeff 0
--moe-router-dtype fp32
--make-vocab-size-divisible-by 16
--num-layers $((N_DENSE_LAYERS + N_MOE_LAYERS))
--hidden-size $NHIDDEN
--ffn-hidden-size $FFN_HIDDEN
--num-attention-heads $NHEADS
--disable-bias-linear
--swiglu
--untie-embeddings-and-output-weights
--position-embedding-type rope
--no-position-embedding
--normalization RMSNorm
--qk-layernorm
--multi-latent-attention
--q-lora-rank 2048
--kv-lora-rank 512
--qk-head-dim 192
--v-head-dim 256
--kv-channels 192
--qk-pos-emb-head-dim 64
--vocab-size 154880
--rotary-base 1000000
--enable-experimental
)

# LoRA registry for scripts/run_glm5_1_744b_a40b_lora.py: MODEL_ARGS carries the architecture only
# (identical to glm5-744B-A40B.sh); every LoRA / run-mode flag lives in the runner, which
# always wins (argparse last-occurrence). --spec above is inert under bridge LoRA.
13 changes: 13 additions & 0 deletions scripts/models/glm5.2-744B-A40B_5layer_lora.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" &>/dev/null && pwd)"
source "${SCRIPT_DIR}/glm5.2-744B-A40B_lora.sh"

# Override for the 5-layer pruned model (first 5 layers: 3 dense + 2 MoE). Keeps at least
# one computing + one skip layer so the DSA cross-layer index sharing path is exercised.
N_MOE_LAYERS=2

for ((i=0; i<${#MODEL_ARGS[@]}; i++)); do
case "${MODEL_ARGS[$i]}" in
--num-layers) MODEL_ARGS[$((i+1))]=$((N_DENSE_LAYERS + N_MOE_LAYERS)) ;;
--moe-layer-freq) MODEL_ARGS[$((i+1))]="[0]*${N_DENSE_LAYERS}+[1]*${N_MOE_LAYERS}" ;;
esac
done
Loading
Loading