Skip to content

Commit 6030517

Browse files
committed
Option to resume conversion job with no other args
1 parent de05ac6 commit 6030517

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

convert.py

+27-17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
parser = argparse.ArgumentParser(description = "Convert model to ExLlamaV2")
1515
parser.add_argument("-i", "--in_dir", type = str, help = "Input directory", default = "")
1616
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)")
1718
parser.add_argument("-nr", "--no_resume", action = "store_true", help = "Do not resume an interrupted job (deletes all files in the output directory)")
1819
parser.add_argument("-cf", "--compile_full", type = str, help = "Output folder for compiled model with all config/tokenizer files")
1920
parser.add_argument("-c", "--cal_dataset", type = str, help = "Calibration dataset (.parquet file)")
@@ -37,12 +38,17 @@
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

4854
if args.length > 2048 or args.measurement_length > 2048:
@@ -63,17 +69,6 @@
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

7974
def save_job():
@@ -133,7 +128,8 @@ def save_job():
133128

134129
else:
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

151151
print(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-
165164
if job['rope_scale']: print(f" -- RoPE scale: {job['rope_scale']:.2f}")
166165
if job['rope_alpha']: print(f" -- RoPE alpha: {job['rope_alpha']:.2f}")
167166

@@ -180,6 +179,17 @@ def save_job():
180179
if 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

185195
if job["rope_scale"] is not None: config.scale_pos_emb = job["rope_scale"]

doc/convert.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Here are the arguments to `convert.py`:
66

7-
- **-i / --in_dir *directory***: _(required)_ The source model to convert, in HF format (FP16). The directory should
7+
- **-i / --in_dir *directory***: _(required if not resuming)_ The source model to convert, in HF format (FP16). The directory should
88
contain at least a `config.json` file, a `tokenizer.model` file and one or more `.safetensors` files containing weights.
99
If there are multiple weights files, they will all be indexed and searched for the neccessary tensors, so sharded models are
1010
supported.
@@ -132,6 +132,13 @@ python convert.py \
132132
-b 4.5
133133
```
134134

135+
If the working `-o` directory is not empty and you do not specify `-nr`, any existing job in that directory
136+
will be resumed. You can resume a job with no other arguments:
137+
138+
```sh
139+
python convert.py -o /mnt/temp/exl2/
140+
```
141+
135142
### Notes
136143

137144
- If the conversion script seems to stop on the "Solving..." step, give it a moment. It's attempting to find the

0 commit comments

Comments
 (0)