Repository navigation
Description
Describe the bug
With the DTensor (automodel) policy worker, LoRA, and policy.dtensor_cfg.activation_checkpointing: true, the LoRA delta is never merged into the weights pushed to vLLM at refit. vLLM keeps generating from the base model for the whole run. Nothing raises an error.
The cause is in dtensor_params_generator (nemo_rl/models/policy/workers/dtensor_policy_worker_v2.py):
module_map = dict(model.named_modules())
for name, tensor in model.state_dict().items():
...
merged_tensor = _maybe_merge_lora_weight(module_map, name, full_tensor) # module_map[name[:-7]]CheckpointWrapper strips _checkpoint_wrapped_module. from state_dict() keys, but named_modules() keeps it:
state_dict() : layers.0.q_proj.weight
named_modules() : layers.0._checkpoint_wrapped_module.q_proj
The lookup misses, so _maybe_merge_lora_weight returns the base tensor unchanged. The lora_A/lora_B entries are then skipped by name.
The code path is unchanged on main as of 486c345.
Steps/Code to reproduce bug
End to end. Run colocated GRPO with DTensor LoRA and activation_checkpointing: true.
gen_kl_errorgrows as the adapter moves away from the base. In our run it went 0.005 → 0.019 over 30 steps at lr 5e-5.- In-training validation stays at base-model quality, while the saved adapter checkpoints, served separately, do change.
Tensor-level. Fingerprint the tensors received in VllmInternalWorkerExtension._load_hf_weights at the refit after step 1. Every LoRA-targeted tensor equals the base weight bit-for-bit. base + scale · B @ A computed from the saved step-1 adapter differs.
Minimal CPU repro (plain PyTorch; mirrors the lookup in dtensor_params_generator):
import torch
from torch import nn
from torch.distributed.algorithms._checkpoint.checkpoint_wrapper import (
_CHECKPOINT_PREFIX, checkpoint_wrapper,
)
class LinearLoRA(nn.Linear): # stand-in for nemo_automodel LinearLoRA
def __init__(self, i, o, r=4, scale=2.0):
super().__init__(i, o, bias=False)
self.lora_A = nn.Linear(i, r, bias=False)
self.lora_B = nn.Linear(r, o, bias=False)
nn.init.normal_(self.lora_B.weight)
self.scale = scale
class Block(nn.Module):
def __init__(self):
super().__init__()
self.q_proj = LinearLoRA(8, 8)
model = nn.Module()
model.layers = nn.ModuleList([checkpoint_wrapper(Block())])
def lookup(module_map, fqn):
return module_map.get(fqn[: -len(".weight")])
print(isinstance(lookup(dict(model.named_modules()), "layers.0.q_proj.weight"), LinearLoRA))
# False -> merge skipped, base weight sent to vLLM
fixed = {n.replace(_CHECKPOINT_PREFIX, ""): m for n, m in model.named_modules()}
print(isinstance(lookup(fixed, "layers.0.q_proj.weight"), LinearLoRA))
# TrueOutput with torch 2.14.1: False, then True.
Expected behavior
The weights sent to vLLM at refit equal W + scale · B @ A for every LoRA-targeted module, whether or not activation checkpointing is enabled.
With the module map keyed by state-dict names, we verified the following:
- Every LoRA-targeted tensor received at the post-step-1 refit equals
base + scale · B @ Aof the saved step-1 adapter. gen_kl_errorstays flat at about 0.005 (0.0044 / 0.0051), compared with 0.019 without the fix.
Environment overview
- NeMo RL
main@ fb8396a (nvcr.io/nvidia/nemo-rl:v0.7.0container), vLLM 0.29.0 - Model:
nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16, LoRA GRPO, DTensor policy worker v2 - 8x L40S, colocated vLLM (TP4), IPC refit
Additional context
- Two open PRs already fix this: fix: merge LoRA into refit weights under activation checkpointing #3953 and fix(dtensor): merge LoRA into refit weights under checkpoint wrappers #4259. Neither is linked to an issue or reviewed yet, so this issue gives them something to close. Either fix resolves the case above, and both merge cleanly into current
main. - Automodel already exports
nemo_automodel.shared.parameter_names.canonical_parameter_fqn, which strips_CHECKPOINT_PREFIXfor exactly this mismatch, and its checkpointing and optimizer code already use it. Reusing it here would keep NeMo RL aligned with any future wrapper prefixes Automodel adds. - Impact: every colocated DTensor LoRA run with activation checkpointing trains off-policy on base-model samples, bounded only by the importance-sampling clamp. Full-parameter runs are unaffected because nothing is merged.
- A cheap guard would turn this silent failure into a loud one: after
lora_Bis non-zero, assert that at least one LoRA module resolved during refit. fix: merge LoRA into refit weights under activation checkpointing #3953 adds a similar check.
Activity
petrojm commentedon Oct 20, 2026
A partner also hit this on Nemotron 3.5 Super VL (GRPO + LoRA, activation_checkpointing: true). The LoRA adapters were never merged into the weights refit to vLLM, so vLLM generated rollouts from the base model at every step while the adapters kept training. Train reward stayed flat. Could a maintainer please pick this up?
yuekaizhang commentedon Oct 20, 2026
A partner hit this on Nemotron 3.5 Super VL as well (GRPO + LoRA with activation checkpointing: train reward flat at ~0.45 for the whole run, ~0.83 once the adapters actually reached vLLM). I opened #4810 against current
main(the two earlier fixes target the olddtensor_policy_worker_v2.pyand no longer apply): it keys the refit module map by Automodel'scanonical_parameter_fqn()as suggested here, raises if aLinearLoRAhas no matching state_dict weight, merges in fp32, and tightens thegrpo-qwen3-8B-base-1n8g-automodel-loranightly so it catches a broken refit (before/after runs in the PR). Credits to #3953, #4259 and the Salesforce patch, which it consolidates.lonexreb commentedon Nov 24, 2026
This looks fixed on main by #4810 (merged 2026-10-22). The refit generator in
automodel_policy_worker.pynow keys its module map by Automodel'scanonical_parameter_fqn, soLinearLoRAmodules insideCheckpointWrapperare found and merged. It also raises if a LoRA base weight has no matching state_dict entry.test_merges_lora_inside_activation_checkpoint_wrapperintests/unit/models/policy/test_automodel_worker.pycovers it. Can this be closed?