Skip to content

feat: support convert_lora_to_hf without merge #2234

Merged
yuki-97 merged 7 commits intomainfrom
ruit/convert_lora_ckpt
Apr 21, 2026
Merged

feat: support convert_lora_to_hf without merge #2234
yuki-97 merged 7 commits intomainfrom
ruit/convert_lora_ckpt

Conversation

@RayenTian
Copy link
Copy Markdown
Contributor

@RayenTian RayenTian commented Apr 8, 2026

Summary

  • New --adapter-only flag: exports only the LoRA adapter weights in HuggingFace PEFT format (no base model required at export time), enabling workflows like vLLM's split base+adapter serving
  • Bug fix in merge_lora_to_hf: adapter weights are now loaded via dist_checkpointing.load with a filtered sharded state dict (via apply_peft_adapter_filter_to_state_dict), fixing a KeyError that occurred when using the previous _load_model_weights_from_checkpoint path which silently drops adapter
    parameters
  • Functional test: test_converter_roundtrip.py now covers the adapter-only export path and verifies that re-merging the exported PEFT adapter via merge_lora_to_hf produces weights identical to the direct merge path
  • Docs: updated checkpointing.md and sft.md with both export modes (Option A: merged, Option B: adapter-only)

What does this PR do ?

Add a one line overview of what this PR aims to accomplish.

Issues

closes #2190

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this

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 unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • ...

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Apr 8, 2026

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.

@RayenTian RayenTian force-pushed the ruit/convert_lora_ckpt branch from 43f4642 to 0642c7a Compare April 9, 2026 09:12
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Apr 9, 2026
@RayenTian RayenTian added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Apr 9, 2026
@RayenTian
Copy link
Copy Markdown
Contributor Author

/ok to test eeef66c

@RayenTian RayenTian marked this pull request as ready for review April 9, 2026 09:21
@RayenTian RayenTian requested review from a team as code owners April 9, 2026 09:21
@RayenTian RayenTian changed the title feat: enhance convert_lora_to_hf script to support exporting LoRA ada… feat: support convert_lora_to_hf without merge Apr 9, 2026
@RayenTian
Copy link
Copy Markdown
Contributor Author

/ok to test 9de1880

@RayenTian
Copy link
Copy Markdown
Contributor Author

/ok to test 64a8679

@RayenTian
Copy link
Copy Markdown
Contributor Author

/ok to test ed1bbdd

@RayenTian
Copy link
Copy Markdown
Contributor Author

/ok to test f24be7a

yuki-97
yuki-97 previously approved these changes Apr 13, 2026
Copy link
Copy Markdown
Contributor

@yuki-97 yuki-97 left a comment

Choose a reason for hiding this comment

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

thanks for fixing and adding the support! lgtm

@yuki-97
Copy link
Copy Markdown
Contributor

yuki-97 commented Apr 13, 2026

@terrykong could you take a review as well?

@RayenTian
Copy link
Copy Markdown
Contributor Author

/ok to test 5396d85

Copy link
Copy Markdown
Collaborator

@terrykong terrykong left a comment

Choose a reason for hiding this comment

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

Nice work on this PR! The refactoring to extract _build_megatron_model_with_lora as a shared context manager is clean, the bug fix for adapter loading (using dist_checkpointing.load with a filtered state dict via apply_peft_adapter_filter_to_state_dict) correctly addresses the KeyError from the old _load_model_weights_from_checkpoint path, and the docs clearly present both export modes with examples. Nice work addressing the community request (#2190).

Two minor suggestions below — neither is a blocker.

Generated by Claude Code

Comment thread examples/converters/convert_lora_to_hf.py Outdated
terrykong
terrykong previously approved these changes Apr 21, 2026
Copy link
Copy Markdown
Collaborator

@terrykong terrykong left a comment

Choose a reason for hiding this comment

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

lgtm docstring was just a nit, btw looks like sphinx build failure

…pters in HuggingFace PEFT format

Signed-off-by: ruit <ruit@nvidia.com>
Signed-off-by: ruit <ruit@nvidia.com>
Signed-off-by: ruit <ruit@nvidia.com>
Signed-off-by: ruit <ruit@nvidia.com>
…options

Signed-off-by: ruit <ruit@nvidia.com>
Signed-off-by: ruit <ruit@nvidia.com>
@RayenTian RayenTian dismissed stale reviews from terrykong and yuki-97 via 2db3e7d April 21, 2026 07:09
@RayenTian RayenTian force-pushed the ruit/convert_lora_ckpt branch from 5396d85 to 2db3e7d Compare April 21, 2026 07:09
@RayenTian
Copy link
Copy Markdown
Contributor Author

/ok to test 2db3e7d

@yuki-97 yuki-97 merged commit f1835bb into main Apr 21, 2026
29 checks passed
@yuki-97 yuki-97 deleted the ruit/convert_lora_ckpt branch April 21, 2026 08:28
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.

How save Lora Weight into normal format

3 participants