14
14
parser = argparse .ArgumentParser (description = "Convert model to ExLlamaV2" )
15
15
parser .add_argument ("-i" , "--in_dir" , type = str , help = "Input directory" , default = "" )
16
16
parser .add_argument ("-o" , "--out_dir" , type = str , help = "Output (working) directory" )
17
+ parser .add_argument ("-res" , "--resume" , action = "store_true" , help = "Resume job from specified output directory (without specifying other options)" )
17
18
parser .add_argument ("-nr" , "--no_resume" , action = "store_true" , help = "Do not resume an interrupted job (deletes all files in the output directory)" )
18
19
parser .add_argument ("-cf" , "--compile_full" , type = str , help = "Output folder for compiled model with all config/tokenizer files" )
19
20
parser .add_argument ("-c" , "--cal_dataset" , type = str , help = "Calibration dataset (.parquet file)" )
37
38
38
39
# Check some args
39
40
40
- if not args .in_dir :
41
- print (" ## Please specify input model directory (-i, --in_dir)" )
41
+ resuming = False
42
+ if args .out_dir :
43
+ if not args .no_resume :
44
+ if os .path .exists (os .path .join (args .out_dir , "job_new.json" )):
45
+ resuming = True
46
+ else :
47
+ print (" ## Please specify output/working directory (-o, --out_dir)" )
42
48
sys .exit ()
43
49
44
- if not args .out_dir :
45
- print (" ## Please specify output/working directory (-o , --out_dir )" )
50
+ if not args .in_dir and not resuming :
51
+ print (" ## Please specify input model directory (-i , --in_dir )" )
46
52
sys .exit ()
47
53
48
54
if args .length > 2048 or args .measurement_length > 2048 :
63
69
print (f" ## Error: Directory not found: { args .out_dir } " )
64
70
sys .exit ()
65
71
66
- # Create config
67
-
68
- config = ExLlamaV2Config ()
69
- config .model_dir = args .in_dir
70
- config .qkv_embed = False
71
- config .prepare ()
72
-
73
- # Tokenizer
74
-
75
- tokenizer = ExLlamaV2Tokenizer (config )
76
-
77
72
# Create job
78
73
79
74
def save_job ():
@@ -133,7 +128,8 @@ def save_job():
133
128
134
129
else :
135
130
print (f" -- Resuming job" )
136
- print (f" !! Note: Overriding options with settings from existing job" )
131
+ if args .in_dir :
132
+ print (f" !! Note: Overriding options with settings from existing job" )
137
133
138
134
with open (job_file , "r" , encoding = "utf8" ) as f :
139
135
resume_job = json .load (f )
@@ -146,6 +142,10 @@ def save_job():
146
142
print (" ** Error: Corrupted job" )
147
143
sys .exit ()
148
144
145
+ if job ["progress" ] == "finished" :
146
+ print (" !! Job is already finished" )
147
+ sys .exit ()
148
+
149
149
# Feedback
150
150
151
151
print (f" -- Input: { job ['in_dir' ]} " )
@@ -161,7 +161,6 @@ def save_job():
161
161
print (f" -- Measurement will be saved to { job ['output_measurement' ]} " )
162
162
print (f" !! Conversion script will end after measurement pass" )
163
163
164
-
165
164
if job ['rope_scale' ]: print (f" -- RoPE scale: { job ['rope_scale' ]:.2f} " )
166
165
if job ['rope_alpha' ]: print (f" -- RoPE alpha: { job ['rope_alpha' ]:.2f} " )
167
166
@@ -180,6 +179,17 @@ def save_job():
180
179
if not os .path .exists (out_tensor_dir ):
181
180
os .makedirs (out_tensor_dir )
182
181
182
+ # Create config
183
+
184
+ config = ExLlamaV2Config ()
185
+ config .model_dir = job ['in_dir' ]
186
+ config .qkv_embed = False
187
+ config .prepare ()
188
+
189
+ # Tokenizer
190
+
191
+ tokenizer = ExLlamaV2Tokenizer (config )
192
+
183
193
# Set scaling for input model
184
194
185
195
if job ["rope_scale" ] is not None : config .scale_pos_emb = job ["rope_scale" ]
0 commit comments