Skip to content

[peft] Define PEFT base class and LoRA transform#71

Merged
ananthsub merged 5 commits intoNVIDIA-NeMo:mainfrom
ananthsub:peft-base
Jun 13, 2025
Merged

[peft] Define PEFT base class and LoRA transform#71
ananthsub merged 5 commits intoNVIDIA-NeMo:mainfrom
ananthsub:peft-base

Conversation

@ananthsub
Copy link
Copy Markdown
Contributor

@ananthsub ananthsub commented Jun 12, 2025

Base class implementation leans heavily on implementations from PeFT in NeMo: https://github.com/NVIDIA/NeMo/blob/ec9c486557f1b5fb211a903e299d4cb5be1fd3b9/nemo/lightning/pytorch/callbacks/peft.py#L44

PEFT base class differences:

  1. PEFT is an abstract dataclass so that implementations neatly plug into the ConfigContainer (params_to_save is now set in the post init, which subclasses need to explicitly initialize)
  2. We explicitly pass a training flag to __call__ and freeze_model as we cannot rely on the presence of a lightning trainer object to indicate what stage is being requested
  3. The base class does not yet concern itself with checkpointing outside of setting the params to save and the adapter key filter. This save/restore paths will be sent out in follow up PRs as part of integrating peft into the main training loop flow

LoRA is otherwise nearly identical to what's in NeMo minus the following:

LoRAMerge is identical to what's in NeMo

This PR includes fixes to walk_utils found from new unit tests

See #68 for the ModuleMatcher, which should get merged first as it's independently testable

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Jun 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.

@ananthsub ananthsub mentioned this pull request Jun 12, 2025
@ananthsub
Copy link
Copy Markdown
Contributor Author

/ok to test 46f3623

@ananthsub ananthsub requested a review from marcromeyn June 12, 2025 02:36
@ananthsub ananthsub changed the title Define PEFT base class and LoRA transform [peft] Define PEFT base class and LoRA transform Jun 12, 2025
@marcromeyn
Copy link
Copy Markdown
Contributor

What's the timeline for adding PEFT to the hub? In the work I was previously doing I have re-implemented PEFT and was thinking to contribute that. But I first need to finish the bridge, so I can likely start with that in a few weeks. The new implementation would also leverage the bridge to support 2-way binding with HF.

The new implementation I worked on doesn't really change the external API, it's mostly internal. So could make sense to first merge a nemo-inspired PEFT and them iterate on it.

@ananthsub
Copy link
Copy Markdown
Contributor Author

@marcromeyn I'd like to have some basic PEFT support in for 25.07, so as soon as possible. for now I am following the existing nemo pattern as closely as possible to simplify the migration

@ananthsub
Copy link
Copy Markdown
Contributor Author

/ok to test 09c7d73

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
@ananthsub
Copy link
Copy Markdown
Contributor Author

/ok to test 4256a0b

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
@ananthsub
Copy link
Copy Markdown
Contributor Author

/ok to test c9c5b74

@ananthsub ananthsub merged commit 9a83e5e into NVIDIA-NeMo:main Jun 13, 2025
10 checks passed
yaoyu-33 pushed a commit that referenced this pull request Jul 10, 2025
Signed-off-by: ashors1 <ashors@nvidia.com>
Signed-off-by: Anna Shors <ashors@nvidia.com>
Co-authored-by: Terry Kong <terrycurtiskong@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants