Training and rollout lifecycle
For a single adapter, miles exports the updated LoRA tensors at each configured publish boundary. Colocated jobs load them through the local tensor/IPC path; disaggregated Bridge jobs broadcast them to remote SGLang engines over NCCL. Rollout requests then select the live named adapter withlora_path.
Multi-LoRA currently supports disaggregated rollout only and rejects
--colocate at launch. Each SGLang engine keeps the base checkpoint resident;
adapter weights reach the engines through explicit pushes: each push registers
an immutable version under its own engine-side name, so in-flight sampling
against an older version is never disturbed.
Model support is therefore a three-way contract rather than a hard-coded
allowlist:
- Megatron-Bridge (or a model-specific provider) must build and wrap the training model.
- miles must map and export the selected module names correctly.
- SGLang must be able to allocate and apply the same adapter modules.
LoRA training implementations
The first two implementations use--train-backend megatron and differ in how
LoRA is attached to the Megatron model and converted for serving; the third is
the torchtitan backend’s. All are separate from SGLang’s serving-side
--sglang-lora-backend choice.
The planned maintenance direction is native-first: after the generalized native plugin
lands, new model enablement and ongoing LoRA maintenance will primarily target
the native path. Bridge remains the compatibility path for existing validated
recipes during the transition; this is not an immediate Bridge deprecation.
Native LoRA
Native LoRA attaches adapter modules directly to raw-mode Megatron models instead of relying on Bridge PEFT conversion. An architecture spec declares, once, which HF projections exist on which physical linear and how each is sharded; the same declaration drives attachment, HF export/import, and SGLang serving targets. The spec is selected from the checkpoint’smodel_type.
Adapters cover attention projections (GQA Q/K/V/O, MLA Q-A/Q-B/KV-A/KV-B/O), dense
MLPs, and shared experts. Routed experts carry shared-outer adapters on Inkling, Kimi K3,
Qwen3.5/3.6 MoE and GLM-5.3-Flash; selecting them requires --experts-shared-outer-loras. The output head (lm_head, the
unembed group) is adaptable on every family except Kimi K3, GLM-5.3-Flash and DeepSeek-V4.1; on a
tied-embedding model it gets its own adapter and the input embedding is unchanged, as with official
Tinker’s unembed. A selected head needs --vocab-size, and is refused with --enable-mtp-training and, on a
tied-embedding model, with --save-hf or eval snapshots (a merged tied head would change the input embedding).
Inkling and Kimi K3 accept only their verified adapter layout (Kimi K3 may omit the routed-expert down
projection), so omit --target-modules for them.
Qwen3.5 / Qwen3.6 GDN layers adapt linear_attn.out_proj and the input projections as independent
in_proj_q/in_proj_k/in_proj_v/in_proj_z/in_proj_b/in_proj_a adapters. Official Tinker adapters
train in_proj_q/k/v/z (four distinct A’s), which is what the attn group selects; in_proj_b/in_proj_a
are adapted only when targeted by name. SGLang stacks the components only as complete groups, so in_proj_qkv and
in_proj_z are selected together, and so are in_proj_b and in_proj_a.
Selecting a projection the spec does not implement
(for example routed experts or Qwen3-Next GDN projections) fails at startup; use
--megatron-to-hf-mode bridge for those. A partial fused selection (for example
only q_proj) trains only the selected projection; SGLang serves its fused-buffer
siblings as zero adapters. A shared expert’s up_proj needs gate_proj selected too.
Validated models and recipes
The table distinguishes CI-tested configurations from maintained recipes or full-scale experiment evidence. It is not an exhaustive model whitelist.Quick start
Append the following to a Megatron dense-model recipe:--lora-rank 0 is the default and disables LoRA when no adapter path is
provided. For RL, dropout is normally set to zero. Alpha is recipe-dependent:
maintained recipes use both alpha = rank and alpha = 2 * rank.
Omitting --target-modules or passing all-linear uses the model defaults from
miles/utils/lora/hf_lora_targets.py: attention + MLP, with model-specific exclusions
and output-head defaults. Multi-LoRA without explicit targets selects all three
training groups. Use --target-modules attn,mlp,unembed to select groups explicitly.
Ordinary LoRA also accepts specific HF targets mixed with group names, such as
--target-modules attn,lm_head; Tinker accepts only group names.
Core arguments
A Megatron-Bridge PEFT
iter_N/ (torch_dist, LoRA or CanonicalLoRA matching this run’s rank, type and targets) loads under --megatron-to-hf-mode bridge only. On GPU, a TP2 EP2 save was validated loading under TP2 EP2 and TP1 EP4; PP > 1, virtual pipeline chunks, --optimizer-cpu-offload and the torch_dist base check below have not run on GPU. Other backends need it converted first with --lora-adapter-convert-save under Bridge. Its Adam state loads only into the DistributedOptimizer from a fully reshardable save (else --no-load-optim); its iteration, scheduler and RNG are not resumed.
Its base model must match --hf-checkpoint. A checkpoint.pretrained_checkpoint that is a torch_dist on this machine has its norm weights and the unquantized attention weights of each model chunk’s first layer compared bitwise with the run’s model. Otherwise the local HF files of the base its run_config.yaml records (checkpoint.pretrained_checkpoint, else the first set of checkpoint.hf_source_path, model.hf_model_id, tokenizer.tokenizer_model), from a local dir or the HF cache (nothing is downloaded), are compared by their norm and first-layer attention weights. Not detected: a LoRA merged only into MLP or expert weights, or only into layers past the first; a base fine-tuned in Megatron whose torch_dist is not on this machine; and, against an FP8 or MXFP4 base, anything but the norms, the only weights both sides hold unquantized.
HF target source of truth
miles/utils/lora/hf_lora_targets.py owns HF target groups and defaults for all
backends. It derives attention, MLP, and output-head paths from the model config,
including nested text models, optional MLA projections, expert layouts, and
hybrid attention. Vision towers, routers, norms, and GDN convolutions are excluded.
--target-modules accepts comma-separated attn, mlp, and unembed groups,
explicit HF targets, or a mix of both. Group names expand through the model’s HF
definition, so mlp includes dense, shared, and routed expert projections, including
packed gate_up_proj weights. Only exact group names expand; full paths remain
literal target patterns. Duplicates are removed, then --exclude-modules applies.
Explicit module selections must not overlap exclusions; defaults and group
selections may still be narrowed with exclusions.
A matching pair of gate_proj and up_proj selectors also selects
gate_up_proj when the HF model has packed projections, with a warning.
Scoped pairs retain their path prefix; selecting only gate or only up does not
expand to the packed projection. Split selectors remain where the model has
split modules and are replaced where it has only packed modules.
Without explicit targets, ordinary LoRA uses its model defaults and multi-LoRA
selects all three groups. all-linear selects the ordinary model defaults and
must be used alone. Explicit lists replace the defaults.
Packed expert entries identify HF parameters rather than nn.Linear modules.
Inkling entries follow the native HF model namespace. Its native Megatron LoRA
implementation requires the complete fixed layout. SGLang discovers its adapter
modules with all, and online weight-sync config uses all-linear; adapter
checkpoints derive explicit names from exported tensors. Adapter factors, tensor
packing, and checkpoint names are unchanged. The pinned Transformers version does
not yet include native Inkling, so its HF structure is not covered by the native
meta-model tests. A layout entry is not a backend support claim.
Ordinary LoRA and Tinker share these HF target groups. HF targets retain their
meaning throughout training and serving. miles/utils/hf_utils/weight_mapping.py
uses Transformers conversion rules and a meta model’s parameter names to relate
checkpoint keys to the current HF model namespace, without loading base weights.
This resolves renamed and packed parameter names. Custom models absent from
native Transformers keep their existing checkpoint namespace.
Argument validation checks fused selections against Bridge’s mapping registry and
the HF model’s modules; a model whose HF implementation lists no modules (remote
code) is checked only at model build, where Bridge resolves mappings against
parameters that actually exist across PP/EP ranks. Explicit Megatron selectors retain a
compatibility conversion at startup. Adapter factories receive only Megatron
targets; they do not overwrite the HF selection. Arbitrary layer/expert subsets
within a registry template are not implemented and are rejected.
For Bridge, standard LoRA requires all projections of a fused weight together, and argument validation
refuses a target set that splits one (for example in_proj_qkv without in_proj_b / in_proj_a on
Qwen3.5’s fused GDN in_proj); under --lora-type lora the attn group takes that in_proj whole,
in_proj_b / in_proj_a included;
canonical_lora supports individual Q/K/V and dense gate/up selections, and
Qwen3.5 / 3.6 GDN input projections as in_proj_q/in_proj_k/in_proj_v/in_proj_z/in_proj_b/in_proj_a
adapters, each with its own lora_A, served to SGLang under those names; in_proj_qkv and in_proj_z are
selected together, and so are in_proj_b and in_proj_a.
Grouped-expert FC1 requires both gate and up; in canonical mode each gets its
own adapter. Qwen3-Next GDN input projections remain fused and require all of
their HF projections even in canonical mode.
Tinker uses --target-modules attn,mlp,unembed by default; for example,
--target-modules attn,mlp disables output-head training. Client SDK flags must
match the selected server groups. Tinker rejects explicit module names,
all-linear, and --exclude-modules because the SDK describes only whole groups.
For Bridge, SGLang receives the selected HF paths and normalizes them into buffer types
(for example, Q/K/V become qkv_proj); it does not own the selection policy.
Adapter checkpoints derive their concrete target_modules from exported tensor
keys rather than a separate Megatron-to-HF name table. Online adapter registration
uses the resolved HF selection for Bridge and native LoRA (Qwen3.5 / 3.6 GDN in_proj targets of native and Bridge canonical_lora are
registered as their exported components in_proj_q/k/v/z/b/a), and all-linear for
native Inkling, without an extra
tensor export.
This requires SGLang’s HF-path normalization support,
including GDN split names. FSDP LoRA injection remains
unsupported.
Native LoRA validates the resolved HF selection against the architecture spec
before injection and matches each adapter by its full HF path, so layer-scoped
selections work. Native Inkling uses a fixed adapter schema: defaults select that
complete schema, and partial/custom layouts are rejected. Native LoRA gives every projection its
spec declares its own lora_A (Q/K/V, gate/up; a module HF itself fuses and the spec keeps whole, such
as GLM-4’s gate_up_proj, gets one), which is --lora-type canonical_lora; --lora-type lora is rejected.
Rollout topology
On SGLang attention DP (
--sglang-attn-dp-size N, or the deprecated
--sglang-enable-dp-attention --sglang-dp-size N), SGLang serves LoRA only from
pinned adapters and requires the attention DP size to equal the engine’s TP size
(sgl-project/sglang#36389). miles pins the rollout adapter there and gives the engine
a second LoRA slot, which SGLang keeps for the base model. Multi-LoRA cannot run on
attention DP: pinned adapters are never evicted.
LoRA is not supported by the P2P/RDMA or disk-delta weight-transfer modes. A
hybrid job with both colocated and additional remote rollout engines also cannot
send LoRA weights to the remote engines today.
The legacy --lora-sync-from-tensor flag is still accepted by the parser but is
not consumed by the implementation. The topology selects the synchronization
path automatically; do not rely on this flag.
MoE adapters
This section describes the Bridge path; native Inkling uses its fixed custom expert layout. For grouped MoE experts, the training and serving layouts must agree. A typical Bridge configuration is:triton backend is required by the maintained MoE recipes; the
default backend can skip MoE layers. Per-expert adapters are the default.
--experts-shared-outer-loras selects the shared-outer layout, and miles enables
SGLang virtual-expert serving for expert adapters by default. Use
--no-sglang-lora-use-virtual-experts only when intentionally selecting the
alternative aligned-expert path.
Supported features
- Losses and algorithms. LoRA wraps the actor model independently of the policy loss. The maintained RL recipes use critic-free estimators such as GRPO. The SFT loss path can use the same adapter hooks, although the repository does not yet have a dedicated LoRA-SFT E2E test. Shared actor/critic PPO with Bridge LoRA is untested: the critic is always built as a full model without adapters.
- Checkpoints. Single LoRA (Bridge or native) saves
{save}/iter_N/adapteras an adapter dir: whole fp32 masters, Adam moments and step (resumable under any parallel layout; masters only with--no-save-optim), the iteration and scheduler state, and an HF PEFTadapter_model.safetensorsplusadapter_config.jsonexport. A failed PEFT export fails the save; the committed checkpoint is kept.{save}/iter_N/adapteris a symlink to the hidden dir{save}/iter_N/.adapter.<commit_id>/, so copy it with symlinks followed (e.g.cp -rL,rsync -L). Saving or loading one needs--optimizer adamwith fp32 masters and moments, the distributed optimizer with Gloo process groups, and neither train fault tolerance (--indep-dp/ in-memory checkpoints) nor--stream-optimizer-state-to-disk; other settings are refused at launch.--save-hfexports a merged model and an HF adapter; native LoRA merges each adapter into its host weights before the ordinary base-weight conversion, so the merged model uses the same converters as full-model exports. Both need the family’s HF LoRA target layout inmiles/utils/lora/hf_lora_targets.py. - Weight synchronization. Colocated IPC and remote NCCL broadcast both ship
adapter tensors at each configured update boundary without merging them into
the base.
--check-lora-weight-equalverifies them with SHA-256. - Model structures. Dense attention/MLP, MLA, GDN, multimodal models, models containing DSA, and both per-expert and shared-outer MoE adapters have validated recipes or tests. DSA-indexer adapters themselves are not validated; see the model-specific caveats in the table above.
- Agentic sessions. Session-server requests carry the active single-LoRA name, so multi-turn trajectories are generated by the updated policy rather than the frozen base. See the experimental example below.
Quantized rollout
Precision support is asymmetric: the validated FP8 configuration trains the LoRA actor in BF16 while SGLang serves a separately quantized FP8 base checkpoint. Adapter tensors remain unquantized and are synchronized at each configured weight-update boundary. The GLM-5.2 launcher exposes this as its--fp8-rollout option and writes an SGLang config with update_weights: true.
See Low Precision RL and
INT4 QAT for the underlying precision features.
Historical GLM-5.2 validation measured:
These values are configuration-specific rather than universal FP8 thresholds.
The full-744B row is historical multi-node evidence and cannot be reproduced
directly by the current single-node
main launcher; multi-node launcher work is
tracked in PR #2033.
The same work also produced the following curves from a different, longer
validation run. The exact configuration for these curves was not published, so
their plotted levels should not be mapped to any one of the final point
measurements in the table:


GLM-5.2 744B BF16 validation
Historical full-scale runs validated the GLM-5/5.1/5.2 Bridge LoRA path across MoE and MLA on models containing DSA; the DSA indexer itself was excluded from the adapter targets. The full GLM-5.2 744B run used 64 GPUs and completed more than 50 rollout -> train -> save steps. The validation also compared expert target selections, including a run that excludeddown_proj.
Treat this as historical implementation and scale evidence. The reported
train/rollout log-prob gaps are configuration-specific and are not established
as a portable acceptance threshold, so the corresponding curves are not
reproduced here.
Agentic RL with LoRA (experimental)
Agentic rollout has one extra correctness requirement: every turn sent through the session server must select the newly synchronized adapter. The session server therefore attacheslora_path=miles_lora to its requests; otherwise the
trainer could update LoRA while the agent continues collecting trajectories
from the frozen base policy. The current session integration selects the fixed
single-adapter name; it is not multi-LoRA slot routing, and it should not be
combined with --lora-train-only.
Draft PR #2280 adds the first
LoRA-specific agentic recipe: GLM-5.2 744B-A40B with synchronous GRPO on
Terminal-Bench-2-style tasks, a Harbor agent server, and Daytona sandboxes. Its
reference configuration uses:
- 4 nodes x 8 H200, TP8 / EP32 / PP1 / CP1;
- BF16 training with an FP8 rollout checkpoint;
- rank 16, alpha 32, attention/MLA-only targets;
- 64K sessions, TileLang DSA, full recompute, and disk actor offload; and
- two 16-GPU rollout engines with
--lora-base-cpu-backup.
Multi-LoRA training
For what the service does, how it batches tenants, and the supported models, see the Multi-LoRA Training Service overview. Multi-LoRA training is served through the Tinker protocol:serve_tinker.py
turns a miles deployment into a training service where each client drives its
own adapter slot with explicit forward_backward / optim_step operations (the
server owns no datasets or schedules). The gateway lives in miles/tinker/,
the slot mechanics in miles/backends/megatron_utils/lora/. The dataset-driven
multi-LoRA v1 backend (fully-async driver, adapter controller, per-adapter data
sources) has been removed.
Clients use the official tinker SDK with the gateway URL and a distinct API key
per tenant. The key identifies ownership of models, futures, and checkpoints.
Each adapter accumulates gradients until its client submits an optimizer step;
saving weights for sampling publishes an immutable adapter version.
--experts-shared-outer-loras also works with multi-LoRA on Bridge: routed experts share
the hidden-side factor within each adapter, while tenants remain independent.
The flag applies to the whole server and preserves the single-LoRA export format.
Its save_state / load_state checkpoints have not been verified on GPU yet.
SGLang currently rejects combining this layout with fused shared experts.
save_state saves adapter parameters and optimizer state, including FP32 masters.
It waits for preceding commands but neither steps nor saves pending gradients;
call it after optim_step to save the effect of the accumulated training work.
A save commits a new adapter directory and then points the name at it, so an
overwrite that fails keeps the previous checkpoint; one gateway holds a checkpoint
root at a time, through an flock that the root’s filesystem must enforce across hosts (NFS
mounted nolock and Lustre with localflock do not). load_state adopts the checkpoint’s alpha, and a checkpoint saved
under another adapter layout loads its weights only, where the conversion is exact
(factors become shared only when they are equal).
Sampler saves commit an immutable adapter directory on shared storage, without
contacting inference engines. Engines load the same frozen base at startup and
load adapter snapshots from disk on demand. A failed engine load fails sampling
without invalidating the saved snapshot or model training.
A model holds its adapter slot until its session finishes (ServiceClient.close,
Tinker SDK 0.36 or newer) or the session’s lease expires.
Futures, model leases, and sequence deduplication are in memory and are lost on
gateway restart. Saved checkpoints retain their ownership and adapter metadata
and can be used to create a new training or sampling client.
See the gateway example for the launcher and smoke client.
