| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | from vllm.lora.utils import is_in_target_modules |
| 5 | |
| 6 | |
| 7 | class TestIsInTargetModules: |
| 8 | """Tests for is_in_target_modules (deployment-time filter).""" |
| 9 | |
| 10 | def test_none_allows_all(self): |
| 11 | assert is_in_target_modules("model.layers.0.self_attn.o_proj", None) |
| 12 | |
| 13 | def test_suffix_in_target(self): |
| 14 | assert is_in_target_modules( |
| 15 | "model.layers.0.self_attn.o_proj", ["o_proj", "q_proj"] |
| 16 | ) |
| 17 | |
| 18 | def test_suffix_not_in_target(self): |
| 19 | assert not is_in_target_modules( |
| 20 | "model.layers.0.self_attn.o_proj", ["q_proj", "k_proj"] |
| 21 | ) |
| 22 | |
| 23 | def test_empty_target_modules(self): |
| 24 | assert not is_in_target_modules("model.layers.0.self_attn.o_proj", []) |
| 25 | |
| 26 | def test_exact_name_match(self): |
| 27 | assert is_in_target_modules("dense1", ["dense1", "dense2"]) |
| 28 | |
| 29 | def test_exact_name_no_match(self): |
| 30 | assert not is_in_target_modules("dense3", ["dense1", "dense2"]) |
| 31 | |
| 32 | def test_packed_parent_matches_child_target_modules(self): |
| 33 | assert is_in_target_modules( |
| 34 | "model.layers.0.mlp.gate_up_proj", |
| 35 | ["gate_proj", "up_proj"], |
| 36 | {"gate_up_proj": ["gate_proj", "up_proj"]}, |
| 37 | ) |
| 38 | |
| 39 | def test_packed_child_matches_parent_target_modules(self): |
| 40 | assert is_in_target_modules( |
| 41 | "model.layers.0.mlp.gate_proj", |
| 42 | ["gate_up_proj"], |
| 43 | {"gate_up_proj": ["gate_proj", "up_proj"]}, |
| 44 | ) |
| 45 | |
| 46 | def test_fused_parent_matches_child_target_modules(self): |
| 47 | assert is_in_target_modules( |
| 48 | "model.layers.0.self_attn.fused_qkv_a_proj", |
| 49 | ["q_a_proj", "kv_a_proj_with_mqa"], |
| 50 | {"fused_qkv_a_proj": ["q_a_proj", "kv_a_proj_with_mqa"]}, |
| 51 | ) |