Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
0bfa1c4f
Unverified
Commit
0bfa1c4f
authored
Jun 10, 2024
by
Cyrus Leung
Committed by
GitHub
Jun 10, 2024
Browse files
[Misc] Improve error message when LoRA parsing fails (#5194)
parent
c81da5f5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
9 deletions
+20
-9
tests/lora/test_utils.py
tests/lora/test_utils.py
+13
-1
vllm/lora/utils.py
vllm/lora/utils.py
+7
-8
No files found.
tests/lora/test_utils.py
View file @
0bfa1c4f
from
collections
import
OrderedDict
from
collections
import
OrderedDict
import
pytest
from
torch
import
nn
from
torch
import
nn
from
vllm.lora.utils
import
parse_fine_tuned_lora_name
,
replace_submodule
from
vllm.lora.utils
import
parse_fine_tuned_lora_name
,
replace_submodule
from
vllm.utils
import
LRUCache
from
vllm.utils
import
LRUCache
def
test_parse_fine_tuned_lora_name
():
def
test_parse_fine_tuned_lora_name
_valid
():
fixture
=
{
fixture
=
{
(
"base_model.model.lm_head.lora_A.weight"
,
"lm_head"
,
True
),
(
"base_model.model.lm_head.lora_A.weight"
,
"lm_head"
,
True
),
(
"base_model.model.lm_head.lora_B.weight"
,
"lm_head"
,
False
),
(
"base_model.model.lm_head.lora_B.weight"
,
"lm_head"
,
False
),
...
@@ -35,6 +36,17 @@ def test_parse_fine_tuned_lora_name():
...
@@ -35,6 +36,17 @@ def test_parse_fine_tuned_lora_name():
assert
(
module_name
,
is_lora_a
)
==
parse_fine_tuned_lora_name
(
name
)
assert
(
module_name
,
is_lora_a
)
==
parse_fine_tuned_lora_name
(
name
)
def
test_parse_fine_tuned_lora_name_invalid
():
fixture
=
{
"weight"
,
"base_model.weight"
,
"base_model.model.weight"
,
}
for
name
in
fixture
:
with
pytest
.
raises
(
ValueError
,
match
=
"unsupported LoRA weight"
):
parse_fine_tuned_lora_name
(
name
)
def
test_replace_submodule
():
def
test_replace_submodule
():
model
=
nn
.
Sequential
(
model
=
nn
.
Sequential
(
OrderedDict
([
OrderedDict
([
...
...
vllm/lora/utils.py
View file @
0bfa1c4f
...
@@ -94,13 +94,12 @@ def parse_fine_tuned_lora_name(name: str) -> Tuple[str, bool]:
...
@@ -94,13 +94,12 @@ def parse_fine_tuned_lora_name(name: str) -> Tuple[str, bool]:
is_lora_a whether the tensor is lora_a or lora_b.
is_lora_a whether the tensor is lora_a or lora_b.
"""
"""
parts
=
name
.
split
(
"."
)
parts
=
name
.
split
(
"."
)
assert
parts
[
0
]
==
"base_model"
assert
parts
[
1
]
==
"model"
if
len
(
parts
)
>=
2
and
parts
[
0
]
==
"base_model"
and
parts
[
1
]
==
"model"
:
if
parts
[
-
1
]
==
"weight"
:
if
parts
[
-
1
]
==
"weight"
:
assert
parts
[
-
2
]
==
"lora_A"
or
parts
[
-
2
]
==
"lora_B"
if
parts
[
-
2
]
==
"lora_A"
or
parts
[
-
2
]
==
"lora_B"
:
return
"."
.
join
(
parts
[
2
:
-
2
]),
parts
[
-
2
]
==
"lora_A"
return
"."
.
join
(
parts
[
2
:
-
2
]),
parts
[
-
2
]
==
"lora_A"
elif
parts
[
-
1
]
==
"lora_embedding_A"
or
parts
[
-
1
]
==
"lora_embedding_B"
:
if
parts
[
-
1
]
==
"lora_embedding_A"
or
parts
[
-
1
]
==
"lora_embedding_B"
:
return
"."
.
join
(
parts
[
2
:
-
1
]),
parts
[
-
1
]
==
"lora_embedding_A"
return
"."
.
join
(
parts
[
2
:
-
1
]),
parts
[
-
1
]
==
"lora_embedding_A"
raise
ValueError
(
f
"
{
name
}
is unsupported
forma
t"
)
raise
ValueError
(
f
"
{
name
}
is unsupported
LoRA weigh
t"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment