Skip to content

fix: subclass Lora config from upstream peft.LoraConfig#609

Merged
dushyantbehl merged 9 commits into
foundation-model-stack:mainfrom
romitjain:fix/lora-config
Sep 26, 2025
Merged

fix: subclass Lora config from upstream peft.LoraConfig#609
dushyantbehl merged 9 commits into
foundation-model-stack:mainfrom
romitjain:fix/lora-config

Conversation

@romitjain
Copy link
Copy Markdown
Collaborator

@romitjain romitjain commented Sep 16, 2025

Description of the change

  1. The LoraConfig in tuning/config/peft_config.py subclasses from peft.LoraConfig which will now support all the LoraConfig arguments. I have decided to subclass because of 2 reasons
    1. We have different defaults for (lora_alpha and lora_dropout)
    2. Some of the fields from LoraConfig are ported to the custom LoraConfig with restricted field types. This is due to this issue: HfArgumentParser does not support peft.LoraConfig huggingface/transformers#40915.
  2. Updated the documentation to point to the peft library documentation for arguments.

Related issue number

There is no specific issue number for this yet. However, the issue was that the launch only accepted 5 arguments for LoraConfig, and if any standard parameter (like modules_to_save) was provided, it was ignored.

How to verify the PR

Any run that passes modules_to_save will now be respected (instead of being ignored earlier).

Was the PR tested

  • I have added >=1 unit test(s) for every new method I have added.
  • I have ensured all unit tests pass

All the config-related tests are passing

@github-actions
Copy link
Copy Markdown

Thanks for making a pull request! 😃
One of the maintainers will review and advise on the next steps.

@github-actions github-actions Bot added the fix label Sep 16, 2025
Signed-off-by: romit <romit@ibm.com>
…umentParser

Signed-off-by: romit <romit@ibm.com>
@romitjain romitjain marked this pull request as ready for review September 16, 2025 16:33
@romitjain romitjain marked this pull request as draft September 16, 2025 16:43
Comment thread tuning/config/peft_config.py Outdated
from typing import List, Optional

# Third Party
from peft import LoraConfig as _LoraConfig
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you rename this import as HFLoraConfig
like we have for other imports.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dushyantbehl I have fixed this, can you please review the PR again?

Signed-off-by: romit <romit@ibm.com>
Signed-off-by: romit <romit@ibm.com>
alora_config.task_type = task_type
hf_peft_config = alora_config
elif isinstance(tuning_config, peft_config.LoraConfig):
lora_config = asdict(tuning_config)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have removed this since tuning_config will now already be of type peft.LoraConfig.

Flattening the parameters using asdict recursively flattens all the dataclass parameters. This means that any parameter like: a.b.c is now converted to a[b][c]. When passed using **a, it does not preserve the dataclass structure of b which can cause issues if the underlying library accesses b.c instead of b[c]

@romitjain romitjain marked this pull request as ready for review September 17, 2025 08:48
romitjain and others added 3 commits September 25, 2025 10:22
Signed-off-by: r0 <11757603+romitjain@users.noreply.github.com>
Signed-off-by: romit <romit@ibm.com>
Copy link
Copy Markdown
Collaborator

@dushyantbehl dushyantbehl left a comment

Choose a reason for hiding this comment

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

largely looks good to me...just minor comments

)
bias = "none"
lora_dropout: float = 0.05
init_lora_weights: bool = field(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@romitjain per your comment on line 58 above the other arguments are incompatible with arg parser but do we need to have arguments like this too?

Copy link
Copy Markdown
Collaborator Author

@romitjain romitjain Sep 26, 2025

Choose a reason for hiding this comment

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

Yes, any field that accepts heterogeneous fields will need to be defined again.

For init_lora_weights, the original type is:

bool | Literal["gaussian", "eva", "olora", "pissa", "pissa_niter_[number of iters]", "corda", "loftq", "orthogonal"]

Comment thread tuning/sft_trainer.py
exp_metadata: Dict of key value pairs passed to train to be recoreded by the tracker.
quantized_lora_config: tuning.config.acceleration_configs.QuantizedLoraConfig \
Should be used in combination with peft_config.LoraConfig for Lora tuning \
Should be used in combination with LoraConfig for Lora tuning \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we add a reference to the HuggingFace loraconfig arguments here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: romit <romit@ibm.com>
Copy link
Copy Markdown
Collaborator

@dushyantbehl dushyantbehl left a comment

Choose a reason for hiding this comment

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

LGTM

@dushyantbehl dushyantbehl changed the title fix: Updated LoraConfig to subclass from peft.LoraConfig fix: subclass Lora config from upstream peft.LoraConfig Sep 26, 2025
@dushyantbehl dushyantbehl merged commit abeb12c into foundation-model-stack:main Sep 26, 2025
10 checks passed
@romitjain romitjain deleted the fix/lora-config branch September 26, 2025 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants