Skip to content

Commit 878df64

Browse files
committed
New python based entry point for containers
Signed-off-by: Jiri Podivin <[email protected]>
1 parent d8bd001 commit 878df64

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

.devops/full.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ COPY . .
1616

1717
RUN make
1818

19-
ENTRYPOINT ["/app/.devops/tools.sh"]
19+
ENTRYPOINT ["/app/.devops/tools.py"]

.devops/tools.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/env python3
2+
3+
import argparse
4+
import os
5+
import subprocess as sp
6+
from glob import glob
7+
8+
parser = argparse.ArgumentParser()
9+
10+
subparsers = parser.add_subparsers(dest='command')
11+
12+
parser.add_argument(
13+
'-m', "--model", type=str, required=True,
14+
help="Directory containing model file, or model file itself (*.pth, *.pt, *.bin)")
15+
16+
run = subparsers.add_parser("run", help="Run a model previously converted into ggml")
17+
convert = subparsers.add_parser("convert", help="Convert a llama model into ggml")
18+
quantize = subparsers.add_parser("quantize", help="Optimize with quantization process ggml")
19+
allinone = subparsers.add_parser("all-in-one", help="Execute --convert & --quantize")
20+
21+
known_args, unknown_args = parser.parse_known_args()
22+
model_path = known_args.model
23+
converted_models = glob(os.path.join(model_path, 'ggml-model-*.bin'))
24+
25+
if known_args.command == 'convert':
26+
sp.run(['python3', './convert.py', model_path] + unknown_args, check=True)
27+
28+
if known_args.command == 'run':
29+
sp.run(['./main', '-m', model_path] + unknown_args, check=True)
30+
31+
if known_args.command == 'quantize':
32+
if not converted_models:
33+
print(f"No models ready for quantization found in {model_path}")
34+
exit(1)
35+
sp.run(['./quantize', converted_models[0]] + unknown_args, check=True)
36+
37+
if known_args.command == 'all-in-one':
38+
if not converted_models:
39+
sp.run(['python3', './convert.py', model_path], check=True)
40+
converted_models = glob(os.path.join(model_path, 'ggml-model-*.bin'))
41+
else:
42+
print(
43+
f"Converted models found {converted_models}! No need to convert.")
44+
45+
quantized_models = glob(os.path.join(model_path, f'ggml-model-q*_*.bin'))
46+
47+
if not quantized_models:
48+
sp.run(['./quantize', converted_models[0]] + unknown_args, check=True)
49+
else:
50+
print(
51+
f"Quantized models found {quantized_models}! No need to quantize.")
52+
exit()

0 commit comments

Comments
 (0)