Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add positional args to PeftModelForCausalLM.generate #1393

Merged
merged 2 commits into from
Jan 30, 2024

Conversation

SumanthRH
Copy link
Contributor

What does this PR do?

A small PR for adding positional arguments to the generate method for PeftModelForCausalLM. The motivation is that PeftModel classes like PeftModelForCausalLM should feel more like a wrapper for AutoModel and shouldn't break existing code which uses positional args. Given that the messy internals of input processing are handled in the prepare_inputs_for_generation method, I think this is a safe feature. Also, it looks like PeftModelForSeq2SeqLM needs some refactoring for the prompt learning methods (to shift logic from .generate to prepare_inputs_for_generation), so I'm leaving that refactoring + positional args support to another PR.

_maybe_include_all_linear_layers,
check_target_module_exists,
inspect_matched_modules,
)
from peft.utils import INCLUDE_LINEAR_LAYERS_SHORTHAND
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a minor edit to import the constant from the right place

@@ -672,10 +686,6 @@ def _test_generate_half_prec(self, model_id, config_cls, config_kwargs):
# check if `generate` works
_ = model.generate(input_ids=input_ids, attention_mask=attention_mask)

with self.assertRaises(TypeError):
# check if `generate` raises an error if no positional arguments are passed
_ = model.generate(input_ids, attention_mask=attention_mask)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a redundant check on positional args (behaviour is captured in test_generate already) so I've removed it

Copy link
Contributor

@pacman100 pacman100 left a comment

Choose a reason for hiding this comment

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

Thank you @SumanthRH for adding support for positional args to generate method of CausalLM. LGTM! 🤗

Given that the messy internals of input processing are handled in the prepare_inputs_for_generation method, I think this is a safe feature.

Yes, while reviewing the PR I was thinking the same, makes sense.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

This is very nice and fixes un-consistency between PreTrainedModel API and PeftModel classes ! Thanks a lot @SumanthRH !

@pacman100 pacman100 merged commit 9d94367 into huggingface:main Jan 30, 2024
14 checks passed
@SumanthRH SumanthRH deleted the add-positional-to-generate branch January 30, 2024 21:11
BenjaminBossan pushed a commit to BenjaminBossan/peft that referenced this pull request Mar 14, 2024
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.

4 participants