Skip to content

feat: Support PEFT weight mapping and merge LoRA adapters when export to hf#1310

Merged
cuichenx merged 4 commits intoNVIDIA-NeMo:mainfrom
HollowMan6:lora_merge
Nov 14, 2025
Merged

feat: Support PEFT weight mapping and merge LoRA adapters when export to hf#1310
cuichenx merged 4 commits intoNVIDIA-NeMo:mainfrom
HollowMan6:lora_merge

Conversation

@HollowMan6
Copy link
Contributor

@HollowMan6 HollowMan6 commented Nov 12, 2025

What does this PR do ?

Now we support PEFT weight mapping (to_warp), and ignore those adapters export for now, but merge LoRA adapters to the base weights when export to hf. The linear_in tensors for LoRA adapters needs to be gathered before we merge lora using the transformation.

Changelog

  • Support PEFT weight mapping
  • Merge LoRA adapters when export to hf

GitHub Actions CI

See the CI sectionin the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.

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 add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

If you haven't finished some of the above items you can still open "Draft" PR.

Additional Information

✨ Presented to you with Mind Lab - A Lab for Experiential Intelligence.

@copy-pr-bot
Copy link

copy-pr-bot bot commented Nov 12, 2025

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.

@yaoyu-33
Copy link
Contributor

@HollowMan6 : we have a plan to do this in 2 steps. We are going to provide a merging script, then you can use regular export to export the merged weights.
Mixing together will reduce the readability of the code. Is there a strong reason you need to do it in single step?

@HollowMan6
Copy link
Contributor Author

Is there a strong reason you need to do it in single step?

@yaoyu-33 Yes, in RL training, it’s better to do it in a single step so that merged model weights can be updated to rollout engines in a streaming manner without any hassle. Please check verl-project/verl#4063 (comment)

@yaoyu-33
Copy link
Contributor

@HollowMan6 : we understand the need now, can help you merge this.
Please check our comments, see if it makes sense to you.

Copy link
Contributor

@cuichenx cuichenx 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 your contribution! The overall logic and structure look good to me. Some comments below. Could you also add a unit test that covers the newly added code in model bridge?

@ananthsub ananthsub linked an issue Nov 13, 2025 that may be closed by this pull request
… to hf

Signed-off-by: Hollow Man <hollowman@opensuse.org>
@HollowMan6
Copy link
Contributor Author

Thank you for reviewing @cuichenx and @yaoyu-33 ! I have just addressed all your change requests and added straightforward unit tests for this feature. Please let me know if you still have any other concerns or suggestions, thanks!

@HollowMan6 HollowMan6 requested a review from cuichenx November 13, 2025 22:42
cuichenx
cuichenx previously approved these changes Nov 14, 2025
Copy link
Contributor

@cuichenx cuichenx left a comment

Choose a reason for hiding this comment

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

LGTM

@cuichenx
Copy link
Contributor

/ok to test 01599fc

@ananthsub ananthsub added the r0.2.0 Cherry-pick label for r0.2.0 release branch label Nov 14, 2025
Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Chen Cui <chcui@nvidia.com>
@cuichenx
Copy link
Contributor

/ok to test 33eeac6

@cuichenx cuichenx merged commit 42d856c into NVIDIA-NeMo:main Nov 14, 2025
42 checks passed
chtruong814 pushed a commit that referenced this pull request Nov 14, 2025
… to hf (#1310)

Signed-off-by: Hollow Man <hollowman@opensuse.org>
Signed-off-by: Chen Cui <chcui@nvidia.com>
Co-authored-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: NeMo Bot <nemo-bot@nvidia.com>
@HollowMan6 HollowMan6 deleted the lora_merge branch November 14, 2025 18:56
sudostock pushed a commit to sudostock/Megatron-Bridge that referenced this pull request Nov 21, 2025
… to hf (NVIDIA-NeMo#1310)

Signed-off-by: Hollow Man <hollowman@opensuse.org>
Signed-off-by: Chen Cui <chcui@nvidia.com>
Co-authored-by: Chen Cui <chcui@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request r0.2.0 Cherry-pick label for r0.2.0 release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support load_hf_weights and export_hf_weights for PEFT/LoRA enabled models Add hf-peft-exporting for GPT OSS model recipes

5 participants