-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
chore: support pytorch format in lora #22790
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
Conversation
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds support for loading LoRA adapters from .pt
files. The implementation correctly adds the file path and loading logic. However, it misses a critical validation step to check for unexpected modules, which is already present for .bin
files. I've added a comment to include this check to prevent potential issues with incompatible adapters.
vllm/lora/models.py
Outdated
elif os.path.isfile(lora_pt_file_path): | ||
tensors = torch.load(lora_pt_file_path, | ||
map_location=device, | ||
weights_only=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to check for unexpected modules is missing for .pt
files. This check is present for .bin
files and is crucial to ensure that the loaded LoRA adapter is compatible with the model, preventing potential errors and incorrect behavior. The same validation should be applied here.
While this suggestion duplicates code, a follow-up refactoring could consolidate the logic for both .bin
and .pt
files to improve maintainability.
elif os.path.isfile(lora_pt_file_path):
# When a pt file is provided, we rely on config to find unexpected
# modules.
unexpected_modules = []
target_modules = peft_helper.target_modules
if not isinstance(target_modules, list):
target_modules = [target_modules]
for module in target_modules:
# Compatible with more modules,
# such as:layers.11.self_attn.k_proj
part_name = module.split(".")[-1]
if part_name not in expected_lora_modules:
unexpected_modules.append(module)
# loaded lora's target modules must be a subset of
# expected_lora_modules. It is not reliable. See
# https://github.com/vllm-project/vllm/pull/5909. But there's no
# other better mechanism.
if unexpected_modules and not is_regex_target_modules(
peft_helper.target_modules, expected_lora_modules):
raise ValueError(
f"While loading {lora_dir}, expected"
f" target modules in {expected_lora_modules}"
f" but received {unexpected_modules}."
f" Please verify that the loaded LoRA module is correct")
tensors = torch.load(lora_pt_file_path,
map_location=device,
weights_only=True)
QQ:does the .pt format exist? Can you provide an example? |
Wow, thank you for your reply.. |
Signed-off-by: jaeeun.kil <[email protected]>
Signed-off-by: 길재은 <[email protected]>
@jeejeelee |
vllm/lora/models.py
Outdated
tensors = torch.load(lora_bin_file_path, | ||
map_location=device, | ||
weights_only=True) | ||
elif os.path.isfile(lora_pt_file_path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The processing logic for lora_pt_file_path
and lora_bin_file_path
looks the same. Can we merge them to avoid redundant code?
Signed-off-by: 길재은 <[email protected]>
Please fix the pre-commit failure, and then LGTM |
Signed-off-by: 길재은 <[email protected]>
Signed-off-by: 길재은 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contribution
Signed-off-by: Jee Jee Li <[email protected]>
Signed-off-by: jaeeun.kil <[email protected]> Signed-off-by: 길재은 <[email protected]>
Signed-off-by: jaeeun.kil <[email protected]> Signed-off-by: 길재은 <[email protected]>
Signed-off-by: jaeeun.kil <[email protected]> Signed-off-by: 길재은 <[email protected]> Signed-off-by: Duncan Moss <[email protected]>
Signed-off-by: jaeeun.kil <[email protected]> Signed-off-by: 길재은 <[email protected]>
Signed-off-by: jaeeun.kil <[email protected]> Signed-off-by: 길재은 <[email protected]> Signed-off-by: Xiao Yu <[email protected]>
Signed-off-by: jaeeun.kil <[email protected]> Signed-off-by: 길재은 <[email protected]>
Signed-off-by: jaeeun.kil <[email protected]> Signed-off-by: 길재은 <[email protected]>
Signed-off-by: jaeeun.kil <[email protected]> Signed-off-by: 길재은 <[email protected]>
Signed-off-by: jaeeun.kil <[email protected]> Signed-off-by: 길재은 <[email protected]>
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.Purpose
Test Plan
Test Result
(Optional) Documentation Update