Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: New python based entry point for containers #1686

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devops/full-cuda.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ ENV LLAMA_CUBLAS=1

RUN make

ENTRYPOINT ["/app/.devops/tools.sh"]
ENTRYPOINT ["/app/.devops/tools.py"]
2 changes: 1 addition & 1 deletion .devops/full-rocm.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ ENV CXX=/opt/rocm/llvm/bin/clang++

RUN make

ENTRYPOINT ["/app/.devops/tools.sh"]
ENTRYPOINT ["/app/.devops/tools.py"]
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"]
56 changes: 56 additions & 0 deletions .devops/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/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")
server = subparsers.add_parser("server", help="Execute in server mode ex: -m /models/7B/ggml-model-q4_0.bin -c 2048 -ngl 43 -mg 1 --port 8080")

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

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-*.gguf'))
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.")
if known_args.command == "server":
sp.run(['./server', '-m', model_path] + unknown_args, check=True)

exit()