1414parser = argparse .ArgumentParser (description = "Convert model to ExLlamaV2" )
1515parser .add_argument ("-i" , "--in_dir" , type = str , help = "Input directory" , default = "" )
1616parser .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)" )
1718parser .add_argument ("-nr" , "--no_resume" , action = "store_true" , help = "Do not resume an interrupted job (deletes all files in the output directory)" )
1819parser .add_argument ("-cf" , "--compile_full" , type = str , help = "Output folder for compiled model with all config/tokenizer files" )
1920parser .add_argument ("-c" , "--cal_dataset" , type = str , help = "Calibration dataset (.parquet file)" )
3738
3839# Check some args
3940
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)" )
4248 sys .exit ()
4349
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 )" )
4652 sys .exit ()
4753
4854if args .length > 2048 or args .measurement_length > 2048 :
6369 print (f" ## Error: Directory not found: { args .out_dir } " )
6470 sys .exit ()
6571
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-
7772# Create job
7873
7974def save_job ():
@@ -133,7 +128,8 @@ def save_job():
133128
134129else :
135130 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" )
137133
138134 with open (job_file , "r" , encoding = "utf8" ) as f :
139135 resume_job = json .load (f )
@@ -146,6 +142,10 @@ def save_job():
146142 print (" ** Error: Corrupted job" )
147143 sys .exit ()
148144
145+ if job ["progress" ] == "finished" :
146+ print (" !! Job is already finished" )
147+ sys .exit ()
148+
149149# Feedback
150150
151151print (f" -- Input: { job ['in_dir' ]} " )
@@ -161,7 +161,6 @@ def save_job():
161161 print (f" -- Measurement will be saved to { job ['output_measurement' ]} " )
162162 print (f" !! Conversion script will end after measurement pass" )
163163
164-
165164if job ['rope_scale' ]: print (f" -- RoPE scale: { job ['rope_scale' ]:.2f} " )
166165if job ['rope_alpha' ]: print (f" -- RoPE alpha: { job ['rope_alpha' ]:.2f} " )
167166
@@ -180,6 +179,17 @@ def save_job():
180179if not os .path .exists (out_tensor_dir ):
181180 os .makedirs (out_tensor_dir )
182181
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+
183193# Set scaling for input model
184194
185195if job ["rope_scale" ] is not None : config .scale_pos_emb = job ["rope_scale" ]
0 commit comments