Skip to content

DTensor LoRA refit sends unmerged base weights to vLLM when activation_checkpointing is on #4470

Open

Description

@yoavf

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_error grows 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))
# True

Output 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 @ A of the saved step-1 adapter.
  • gen_kl_error stays 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.0 container), 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_PREFIX for 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_B is 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

  1. added
    bug
    on Oct 4, 2026
  2. added
    waiting-on-maintainers
    on Oct 6, 2026
  3. petrojm commented on Oct 20, 2026

    @petrojm

    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?

  4. removed
    waiting-on-maintainers
    on Oct 20, 2026
  5. yuekaizhang commented on Oct 20, 2026

    @yuekaizhang
    Contributor

    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 old dtensor_policy_worker_v2.py and no longer apply): it keys the refit module map by Automodel's canonical_parameter_fqn() as suggested here, raises if a LinearLoRA has no matching state_dict weight, merges in fp32, and tightens the grpo-qwen3-8B-base-1n8g-automodel-lora nightly so it catches a broken refit (before/after runs in the PR). Credits to #3953, #4259 and the Salesforce patch, which it consolidates.

  6. added
    waiting-on-maintainers
    on Oct 22, 2026
  7. lonexreb commented on Nov 24, 2026

    @lonexreb
    Contributor

    This looks fixed on main by #4810 (merged 2026-10-22). The refit generator in automodel_policy_worker.py now keys its module map by Automodel's canonical_parameter_fqn, so LinearLoRA modules inside CheckpointWrapper are found and merged. It also raises if a LoRA base weight has no matching state_dict entry. test_merges_lora_inside_activation_checkpoint_wrapper in tests/unit/models/policy/test_automodel_worker.py covers it. Can this be closed?

  8. added
    waiting-on-maintainers
    and removed
    waiting-on-maintainers
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    accuracybugcommunity-requestwaiting-on-maintainers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions