Skip to content

Commit

Permalink
New python based entry point for containers
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Podivin <[email protected]>
  • Loading branch information
jpodivin committed Jun 8, 2023
1 parent 0bf7cf1 commit 89e7976
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .devops/full.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ RUN make

ENV LC_ALL=C.utf8

ENTRYPOINT ["/app/.devops/tools.sh"]
ENTRYPOINT ["/app/.devops/tools.py"]
52 changes: 52 additions & 0 deletions .devops/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/env python3

import argparse
import os
import subprocess as sp
from glob import glob

parser = argparse.ArgumentParser()

subparsers = parser.add_subparsers(dest='command')

parser.add_argument(
'-m', "--model", type=str, required=True,
help="Directory containing model file, or model file itself (*.pth, *.pt, *.bin)")

run = subparsers.add_parser("run", help="Run a model previously converted into ggml")
convert = subparsers.add_parser("convert", help="Convert a llama model into ggml")
quantize = subparsers.add_parser("quantize", help="Optimize with quantization process ggml")
allinone = subparsers.add_parser("all-in-one", help="Execute --convert & --quantize")

known_args, unknown_args = parser.parse_known_args()
model_path = known_args.model
converted_models = glob(os.path.join(model_path, 'ggml-model-*.bin'))

if known_args.command == 'convert':
sp.run(['python3', './convert.py', model_path] + unknown_args, check=True)

if known_args.command == 'run':
sp.run(['./main', '-m', model_path] + unknown_args, check=True)

if known_args.command == 'quantize':
if not converted_models:
print(f"No models ready for quantization found in {model_path}")
exit(1)
sp.run(['./quantize', converted_models[0]] + unknown_args, check=True)

if known_args.command == 'all-in-one':
if not converted_models:
sp.run(['python3', './convert.py', model_path], check=True)
converted_models = glob(os.path.join(model_path, 'ggml-model-*.bin'))
else:
print(
f"Converted models found {converted_models}! No need to convert.")

quantized_models = glob(os.path.join(model_path, f'ggml-model-q*_*.bin'))

if not quantized_models:
sp.run(['./quantize', converted_models[0]] + unknown_args, check=True)
else:
print(
f"Quantized models found {quantized_models}! No need to quantize.")
exit()

0 comments on commit 89e7976

Please sign in to comment.