-
-
Notifications
You must be signed in to change notification settings - Fork 16.8k
[Misc][LoRA] Add --lora-target-modules to restrict LoRA to specific modules #34984
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
255125d
[Misc][LoRA] Add --lora-target-modules to restrict LoRA to specific m…
bhoomit 2ac7621
[Misc][LoRA] Warn when adapter modules are not in supported target mo…
bhoomit 18d2edc
[Misc][LoRA] Apply suggestion from @hmellor
bhoomit 8dce456
[Misc][LoRA] fix: Use correct lora_kwargs key for target_modules
bhoomit 1af3a6d
[Misc][LoRA] fix(lora): Use suffix matching for unsupported module wa…
bhoomit c183eec
[Misc][LoRA] refactor(lora): extract _test_target_modules helper to r…
bhoomit 5aba606
[Misc][LoRA] fix(lora): align warning logic with _match_target_module…
bhoomit c61fbc3
[Misc][LoRA] Extract is_supported_lora_module and is_in_target_module…
bhoomit 8a51df3
Merge branch 'main' into lora-target-modules
bhoomit 40c77b5
Merge branch 'main' into lora-target-modules
jeejeelee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
|
|
||
| from vllm.lora.utils import is_in_target_modules, is_supported_lora_module | ||
|
|
||
|
|
||
| class TestIsSupportedLoraModule: | ||
| """Tests for is_supported_lora_module (model-definition check).""" | ||
|
|
||
| def test_suffix_match(self): | ||
| assert is_supported_lora_module( | ||
| "model.layers.0.self_attn.o_proj", ["o_proj", "q_proj"] | ||
| ) | ||
|
|
||
| def test_no_match(self): | ||
| assert not is_supported_lora_module( | ||
| "model.layers.0.self_attn.o_proj", ["q_proj", "k_proj"] | ||
| ) | ||
|
|
||
| def test_exact_match(self): | ||
| assert is_supported_lora_module("o_proj", ["o_proj"]) | ||
|
|
||
| def test_regex_suffix_matching(self): | ||
| """Regex anchors to end — partial suffix should not match.""" | ||
| assert not is_supported_lora_module("model.layers.0.self_attn.o_proj", ["proj"]) | ||
|
|
||
| def test_empty_supported_modules(self): | ||
| assert not is_supported_lora_module("model.layers.0.self_attn.o_proj", []) | ||
|
|
||
| def test_multiple_supported_modules(self): | ||
| supported = ["q_proj", "k_proj", "v_proj", "o_proj"] | ||
| assert is_supported_lora_module("model.layers.0.self_attn.v_proj", supported) | ||
| assert not is_supported_lora_module("model.layers.0.mlp.gate_proj", supported) | ||
|
|
||
|
|
||
| class TestIsInTargetModules: | ||
| """Tests for is_in_target_modules (deployment-time filter).""" | ||
|
|
||
| def test_none_allows_all(self): | ||
| assert is_in_target_modules("model.layers.0.self_attn.o_proj", None) | ||
|
|
||
| def test_suffix_in_target(self): | ||
| assert is_in_target_modules( | ||
| "model.layers.0.self_attn.o_proj", ["o_proj", "q_proj"] | ||
| ) | ||
|
|
||
| def test_suffix_not_in_target(self): | ||
| assert not is_in_target_modules( | ||
| "model.layers.0.self_attn.o_proj", ["q_proj", "k_proj"] | ||
| ) | ||
|
|
||
| def test_empty_target_modules(self): | ||
| assert not is_in_target_modules("model.layers.0.self_attn.o_proj", []) | ||
|
|
||
| def test_exact_name_match(self): | ||
| assert is_in_target_modules("dense1", ["dense1", "dense2"]) | ||
|
|
||
| def test_exact_name_no_match(self): | ||
| assert not is_in_target_modules("dense3", ["dense1", "dense2"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.