Skip to content

feat: make native LoRA refit the vLLM default - #3964

Merged
yuki-97 merged 14 commits into
mainfrom
jia/native-lora-default
Oct 27, 2026
Merged

yuki-97 merged 14 commits into
mainfrom
jia/native-lora-default

Conversation

@fujial-code

@fujial-code fujial-code commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes vLLM native LoRA adapter refit the correctness-first default for supported Automodel LoRA policies, while preserving the previous merged full-state refit implementation as an explicit opt-in.

Native refit (default)

The native path:

  • synchronizes only factorized LoRA A/B tensors over the topology-default CUDA-IPC or collective transport;
  • exports custom Automodel layouts through the model's existing state-dict adapter, including grouped-MoE factors converted to conventional per-expert HF/PEFT A/B tensors;
  • stages received tensors in CPU memory, installs a stable in-memory vLLM adapter, and passes its LoRARequest on every synchronous generation call;
  • leaves the frozen vLLM base model and model-owned non-LoRA state unchanged across policy updates;
  • validates complete A/B pairs, trainable state, runtime-module mapping, skipped modules, rank/cache capacity, and supported execution modes.

Native refit works with both HF-native and custom Automodel model implementations. It does not require automodel_kwargs.force_hf: true; an individual recipe may still select force_hf for unrelated model-loading or parallelization compatibility.

Merged refit (explicit opt-in)

The existing merged behavior remains available without changing its implementation:

policy:
  generation:
    lora_refit_mode: merged

This path continues to materialize the full policy state, including W + scale * B @ A, and sends it through the previous full-weight refit flow. Megatron LoRA recipes explicitly select this compatibility path.

Issues

Closes #3696

Usage

Native refit is selected by the shared exemplar configuration for supported Automodel + synchronous vLLM LoRA jobs:

policy:
  automodel_cfg:
    lora_cfg:
      enabled: true
  generation:
    lora_refit_mode: native

Unsupported native combinations fail during setup with guidance to use merged. Current exclusions include Megatron LoRA, asynchronous or HTTP-served vLLM, speculative decoding, quantized rollout models, custom refit transports, DoRA, MoE rank scaling, and policies with dynamically updated MoE router bias.

Validation

Strict matched 50-step Nemotron Nano V3 A/B

Both arms used:

  • the same NeMo-RL native-LoRA implementation;
  • the current pinned Automodel revision (1814c6c9) with force_hf: false;
  • the same seed, prompts, batch and sampling configuration;
  • trainer EP4 and vLLM TP4;
  • two nodes with four GB200 GPUs per node;
  • the same checkpoint and logging configuration.

The only intentional variable was policy.generation.lora_refit_mode.

Refit mode Mean train/gen_kl_error Min Max Final Steps > 0.02
Native 0.002030 0.0014 0.0028 0.0023 0 / 50
Merged 0.051178 0.0017 0.4469 0.0537 14 / 50

Both runs completed 50/50 steps and wrote step_50 checkpoints without OOM, NaN/Inf, traceback, or refit failure. The native run stayed in the expected approximately 0.002 KL band, while the unchanged merged path showed the previously observed step-dependent mismatch.

Additional checks on the current rebased head:

  • targeted coverage for native/merged selection, activation-checkpoint parameter names, vLLM adapter installation, and pre-build configuration materialization;
  • repository-pinned Ruff 0.9.9 formatting and lint checks;
  • Python syntax compilation, shell syntax checks, and git diff --check;
  • exact-head CI triggered on this PR.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the full unit and functional test suites locally? Exact-head coverage is delegated to CI.
  • Did you add or update any necessary documentation?

@copy-pr-bot

copy-pr-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Sep 2, 2026
@fujial-code fujial-code added the CI:L2 Run doctests, unit tests, functional tests, and convergence tests label Sep 2, 2026
@fujial-code
fujial-code force-pushed the jia/native-lora-default branch from 2690e01 to cf14810 Compare September 2, 2026 10:04

@fujial-code fujial-code left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No action needed — the own-PR self-review found no blocking or actionable issues at the final head.

Self-review completed for commit cf148103094f6449dd9a838d9550d22c0694c47c using the repository’s /review-pr-team workflow.

The config-convention issue identified during the first pass has been resolved: lora_refit_mode is now required, accessed directly, documented, and tested to fail loudly when missing.

The review covered configuration and algorithm wiring, DTensor A/B export, CUDA-IPC and collective receive paths, vLLM adapter installation and replacement, request propagation, test coverage, configuration parity, and design boundaries. No blocking correctness, security, API, test, documentation, or design findings remain.

Before moving the PR out of Draft, CI:L2 and a matched Nemotron Nano native-vs-merged GPU regression should still be completed, including multi-step gen_kl and basic refit latency/memory checks.

Generated by Codex using the repository’s /review-pr-team workflow.

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test cf14810

@fujial-code
fujial-code force-pushed the jia/native-lora-default branch from cf14810 to dfb8fa7 Compare September 9, 2026 08:44
@fujial-code
fujial-code requested a review from yuki-97 September 9, 2026 10:18
@fujial-code
fujial-code marked this pull request as ready for review September 9, 2026 15:53
@fujial-code
fujial-code requested review from a team as code owners September 9, 2026 15:53

@fujial-code fujial-code left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actionability: no additional code changes are requested by this self-review.

Self-review completed for commit 5f42cb8b using the repository's /review-pr-team workflow, including independent RL correctness, bug, test, configuration, design, comment, and devil's-advocate passes.

The review covered configuration materialization across GRPO/PPO/distillation/SingleController, DTensor A/B selection, producer dispatch, CUDA-IPC and collective buffer ownership, vLLM adapter creation/replacement and module mapping, LoRARequest propagation through both synchronous generation entry points, unsupported-mode rejection, merged opt-in behavior, documentation, and regression coverage.

The initial review's configuration finding is resolved: lora_refit_mode is explicit for LoRA configurations, validated centrally, documented, and tested to fail loudly when missing. The final devil's-advocate pass also found a stale unit-test call that omitted the newly required collective-refit argument; commit 5f42cb8b fixes that call and a repository-wide search found no equivalent omission. No additional high-confidence correctness, race, API, security, documentation, or test-design blockers remain in the NeMo-RL patch itself.

Static validation passed on the latest-main head: Ruff format/lint for all changed Python files, Python compilation, and git diff --check. The strict matched 50-step A/B completed without OOM, NaN, traceback, or refit failure: native mean/max/final gen_kl_error was 0.002468 / 0.0056 / 0.0021, while merged was 0.019636 / 0.1766 / 0.0157.

The native-LoRA implementation does not depend on Automodel #3845. The matched Nano validation used a Nemotron-specific FP32 load contract; #3845 tracks that model-loading correctness issue independently and is not a merge prerequisite for this PR. Repository CI and the normal maintainer review remain the release gates.

Generated by Codex using the repository's /review-pr-team workflow.

@yuki-97 yuki-97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this — native A/B refit is a really nice feature. It LGTM.

Scope: full pass at 5f42cb8 — config/schema wiring, the DTensor A/B export, the vLLM adapter install path, docs, and test coverage.

Checked:

  • Support matrix — every shipped YAML that reaches lora_cfg.enabled / megatron_cfg.peft.enabled, resolved through defaults: inheritance, plus which line rejects each unsupported cell and how late.
  • Upstream — the vLLM calls against the pinned v0.25.1 source (LoRARequest, LoRAModel.from_lora_tensors, PEFTHelper.from_dict, add/remove/activate sequencing), and the LoRA scaling contract against the pinned Automodel.
  • Reachability — dead and redundant branches, and the reverse direction: which new guards can never fire.
  • Coverage — the nightly and functional LoRA recipes, and which refit mode each one actually resolves to.
  • Docs — every surface describing the mechanism this PR changes, including files the diff does not touch.

The comments below fall into three themes:

  • Default config — flipping the exemplar default to native changes what the shipped recipes, the functional drivers and the non-vLLM backends resolve to; several of them need an explicit mode or force_hf to keep working.
  • Config validation — where the checks belong, which of them are backend-independent, and the required-key regression on lora_refit_mode.
  • Docs — the LoRA guide describes native's supported set more narrowly than the code enforces it, never says which rollout backend it needs or that Megatron LoRA has to opt out, and the GRPO guide still carries the old merge-weight description.

The remainder are one no-op context manager and a duplicated staging copy.

Comment thread examples/configs/grpo_math_1B.yaml Resolved
Comment thread docs/guides/lora.md Resolved
Comment thread docs/guides/lora.md Resolved
@fujial-code
fujial-code force-pushed the jia/native-lora-default branch 2 times, most recently from e42c0ac to f627798 Compare September 17, 2026 07:10
@fujial-code
fujial-code force-pushed the jia/native-lora-default branch from f627798 to 1cd104b Compare October 9, 2026 20:23
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 1cd104b

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 9d986d9

@fujial-code
fujial-code force-pushed the jia/native-lora-default branch from 9d986d9 to 85789b3 Compare October 15, 2026 05:22
@copy-pr-bot

copy-pr-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

/ok to test 85789b38f4e1ce1225e3ee403942f16ef036c28e

@fujial-code, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 85789b3

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 08ad010

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 38cc7d3

@fujial-code
fujial-code force-pushed the jia/native-lora-default branch from 38cc7d3 to 32153e1 Compare October 18, 2026 17:48
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 32153e1

@copy-pr-bot

copy-pr-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

/ok to test 7468117c6f9a37e3b67d3c58accc789f06fb93a0

@fujial-code, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 7468117

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 3408543

@yuki-97 yuki-97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Merge blockers — please rebase on main and resolve conflicts.

Thanks for resolving the comments from the previous review.

Scope: fix commits 69689df through 3408543, checked against the open threads from the previous review, plus a scan of the changed files for new issues.

Checked:

  • Activation checkpointing — native refit canonicalizes trainable names, and L1 AutoModel runs grpo_automodel_lora.sh on native with AC on.
  • vLLM 0.29 — get_rename_mapper is on the native path that L1 run exercised; no get_unstacked_mapper call remains.
  • Refit-mode tests — the new dispatch and setup-ordering tests run the production code and fail if the branch or the order changes.
  • Draft model after the rebase — the merged path still forwards draft_model, and native with speculative decoding is rejected at setup.

Remaining comments are on:

  • The merged nightly's gen_kl_error gates, which predate #4810, and a run of the native Qwen3-8B nightly.
  • Native refit silently dropping lm_head from the trained modules for every model.

@fujial-code
fujial-code force-pushed the jia/native-lora-default branch from 3408543 to 342a2f8 Compare October 26, 2026 11:35
@fujial-code fujial-code added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L2 Run doctests, unit tests, functional tests, and convergence tests labels Oct 26, 2026
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 342a2f8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC] Make native LoRA adapter sync the default for RL refit and keep merged full-weight sync opt-in

2 participants