Skip to content

Commit 5e53c89

Browse files
authored
[Bugfix] [CI] Fix Tensorizer LoRA test (#20760)
Signed-off-by: Sanger Steel <sangersteel@gmail.com>
1 parent c66e38e commit 5e53c89

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

tests/lora/test_llama_tp.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import sys
55
from typing import Union
66

7-
import pytest
8-
97
import vllm
108
from vllm import LLM
119
from vllm.lora.request import LoRARequest
@@ -151,8 +149,6 @@ def test_llama_lora_tp4_fully_sharded_loras(sql_lora_files):
151149
generate_and_test(llm, sql_lora_files)
152150

153151

154-
@pytest.mark.skip(reason=("Skipping this test as tensorizer is not "
155-
"working with LoRA as of #19619"))
156152
@multi_gpu_test(num_gpus=2)
157153
@create_new_process_for_each_test()
158154
def test_tp2_serialize_and_deserialize_lora(tmp_path, sql_lora_files,
@@ -189,7 +185,6 @@ def test_tp2_serialize_and_deserialize_lora(tmp_path, sql_lora_files,
189185

190186
model_uri = tmp_path / "vllm" / model_ref / suffix / model_name
191187
tensorizer_config = TensorizerConfig(tensorizer_uri=str(model_uri))
192-
tensorizer_config.lora_dir = tensorizer_config.tensorizer_dir
193188

194189
loaded_vllm_model = LLM(model=model_ref,
195190
load_format="tensorizer",
@@ -200,16 +195,16 @@ def test_tp2_serialize_and_deserialize_lora(tmp_path, sql_lora_files,
200195
tensor_parallel_size=2,
201196
max_loras=2)
202197

203-
tensorizer_config_dict = tensorizer_config.to_serializable()
198+
tc_as_dict = tensorizer_config.to_serializable()
204199

205200
print("lora adapter created")
206201
assert do_sample(loaded_vllm_model,
207202
sql_lora_files,
208-
tensorizer_config_dict=tensorizer_config_dict,
203+
tensorizer_config_dict=tc_as_dict,
209204
lora_id=0) == EXPECTED_NO_LORA_OUTPUT
210205

211206
print("lora 1")
212207
assert do_sample(loaded_vllm_model,
213208
sql_lora_files,
214-
tensorizer_config_dict=tensorizer_config_dict,
209+
tensorizer_config_dict=tc_as_dict,
215210
lora_id=1) == EXPECTED_LORA_OUTPUT

vllm/lora/peft_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ def from_local_dir(
102102
tensorizer_config = TensorizerConfig(**tensorizer_config_dict)
103103
tensorizer_args = tensorizer_config._construct_tensorizer_args()
104104
from tensorizer.stream_io import open_stream
105-
lora_config_path = os.path.join(tensorizer_config.lora_dir,
105+
lora_config_path = os.path.join(tensorizer_config.tensorizer_dir,
106106
"adapter_config.json")
107107
with open_stream(lora_config_path,
108108
mode="rb",
109109
**tensorizer_args.stream_kwargs) as f:
110110
config = json.load(f)
111111

112112
logger.info("Successfully deserialized LoRA config from %s",
113-
tensorizer_config.lora_dir)
113+
tensorizer_config.tensorizer_dir)
114114

115115
else:
116116
with open(lora_config_path) as f:

vllm/model_executor/model_loader/tensorizer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,17 @@ def __post_init__(self):
222222
self._is_sharded = isinstance(self.tensorizer_uri, str) \
223223
and re.search(r'%0\dd', self.tensorizer_uri) is not None
224224

225+
if self.tensorizer_dir and self.lora_dir:
226+
raise ValueError(
227+
"Only one of tensorizer_dir or lora_dir may be specified. "
228+
"Use lora_dir exclusively when serializing LoRA adapters, "
229+
"and tensorizer_dir or tensorizer_uri otherwise.")
225230
if self.tensorizer_dir and self.tensorizer_uri:
226231
logger.warning_once(
227232
"Provided both tensorizer_dir and tensorizer_uri. "
228233
"Inferring tensorizer_dir from tensorizer_uri as the "
229234
"latter takes precedence.")
230235
self.tensorizer_dir = os.path.dirname(self.tensorizer_uri)
231-
if self.tensorizer_dir and self.lora_dir:
232-
raise ValueError(
233-
"Only one of tensorizer_dir or lora_dir may be specified. "
234-
"Use lora_dir exclusively when serializing LoRA adapters, "
235-
"and tensorizer_dir or tensorizer_uri otherwise.")
236236
if not self.tensorizer_uri:
237237
if self.lora_dir:
238238
self.tensorizer_uri = f"{self.lora_dir}/adapter_model.tensors"
@@ -695,7 +695,7 @@ def tensorize_lora_adapter(lora_path: str,
695695
needed to load a LoRA adapter are a safetensors-format file called
696696
adapter_model.safetensors and a json config file called adapter_config.json.
697697
698-
Serializes the files in the tensorizer_config.lora_dir
698+
Serializes the files in the tensorizer_config.tensorizer_dir
699699
"""
700700
import safetensors
701701

@@ -725,13 +725,13 @@ def tensorize_lora_adapter(lora_path: str,
725725

726726
tensorizer_args = tensorizer_config._construct_tensorizer_args()
727727

728-
with open_stream(f"{tensorizer_config.lora_dir}/adapter_config.json",
728+
with open_stream(f"{tensorizer_config.tensorizer_dir}/adapter_config.json",
729729
mode="wb+",
730730
**tensorizer_args.stream_kwargs) as f:
731731

732732
f.write(json.dumps(config).encode("utf-8"))
733733

734-
lora_uri = (f"{tensorizer_config.lora_dir}"
734+
lora_uri = (f"{tensorizer_config.tensorizer_dir}"
735735
f"/adapter_model.tensors")
736736
with open_stream(lora_uri, mode="wb+",
737737
**tensorizer_args.stream_kwargs) as f:
@@ -740,4 +740,4 @@ def tensorize_lora_adapter(lora_path: str,
740740
serializer.close()
741741

742742
logger.info("Successfully serialized LoRA files to %s",
743-
str(tensorizer_config.lora_dir))
743+
str(tensorizer_config.tensorizer_dir))

0 commit comments

Comments
 (0)