2
2
# users the ability to be able to run it independently without
3
3
# having to install vllm as a dependency
4
4
import argparse
5
- import sys
6
5
from pathlib import Path
7
6
8
7
import torch
@@ -30,17 +29,15 @@ def convert_pt_to_peft(input_dir: str, output_dir: str) -> None:
30
29
# read decoder.pt file
31
30
decoder_pt_path = Path (input_dir ) / "decoder.pt"
32
31
if not decoder_pt_path .exists ():
33
- print (f"No decoder.pt model found in path { decoder_pt_path } " ) # noqa: T201
34
- sys .exit ()
32
+ raise ValueError (f"No decoder.pt model found in path { decoder_pt_path } " )
35
33
36
34
# error if encoder.pt file exists
37
35
encoder_pt_path = Path (input_dir ) / "encoder.pt"
38
36
if encoder_pt_path .exists ():
39
- print ( # noqa: T201
37
+ raise ValueError (
40
38
f"encoder.pt model found in path { encoder_pt_path } , \
41
39
encoder-decoder models are not yet supported, sorry!"
42
40
)
43
- sys .exit ()
44
41
45
42
# check output dir
46
43
if output_dir is None :
@@ -58,8 +55,7 @@ def convert_pt_to_peft(input_dir: str, output_dir: str) -> None:
58
55
59
56
# error if output_dir is file
60
57
if output_path .is_file ():
61
- print (f"File found instead of dir { output_path } , exiting..." ) # noqa: T201
62
- sys .exit ()
58
+ raise ValueError (f"File found instead of dir { output_path } " )
63
59
64
60
# load tensors from decoder.pt and save to .safetensors
65
61
decoder_tensors = torch .load (decoder_pt_path , weights_only = True )
@@ -73,6 +69,7 @@ def convert_pt_to_peft(input_dir: str, output_dir: str) -> None:
73
69
adapter_config = {
74
70
"num_virtual_tokens" : decoder_tensors .shape [0 ],
75
71
"peft_type" : "PROMPT_TUNING" ,
72
+ "base_model_name_or_path" : "this-is-a/temporary-conversion" ,
76
73
}
77
74
78
75
with open (output_path / "adapter_config.json" , "w" ) as config_file :
0 commit comments