Skip to content
Merged
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
86 changes: 86 additions & 0 deletions instill/helpers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import shutil
import subprocess
import tempfile
import time
import uuid

import ray
import yaml
Expand Down Expand Up @@ -88,6 +90,27 @@ def cli():
required=False,
)

# run
run_parser = subcommands.add_parser("run", help="Run inference on model image")
run_parser.set_defaults(func=run)
run_parser.add_argument(
"name",
help="user and model namespace, in the format of <user-id>/<model-id>",
)
run_parser.add_argument(
"-t",
"--tag",
help="tag for the model image, default to `latest`",
default="latest",
required=False,
)
run_parser.add_argument(
"-i",
"--input",
help="inference input json",
required=True,
)

args = parser.parse_args()
args.func(args)

Expand Down Expand Up @@ -227,5 +250,68 @@ def push(args):
Logger.i("[Instill Builder] Done")


def run(args):
try:
name = uuid.uuid4()

Logger.i("[Instill Builder] Starting model image...")
subprocess.run(
[
"docker",
"run",
"--rm",
"-d",
"--name",
str(name),
f"{args.name}:{args.tag}",
"serve",
"run",
"_model:entrypoint",
],
check=True,
)
time.sleep(10)
subprocess.run(
[
"docker",
"exec",
str(name),
"/bin/bash",
"-c",
"until serve status --name default | grep 'RUNNING: 1' > /dev/null; do sleep 1; done;",
],
check=True,
)
Logger.i("[Instill Builder] Model running")
subprocess.run(
[
"docker",
"exec",
str(name),
"python",
"-m",
"instill.helpers.test",
"-i",
args.input,
],
check=True,
)
subprocess.run(
[
"docker",
"stop",
str(name),
],
check=True,
)
except subprocess.CalledProcessError:
Logger.e("[Instill Builder] Run failed")
except Exception as e:
Logger.e("[Instill Builder] Prepare failed")
Logger.e(e)
finally:
Logger.i("[Instill Builder] Done")


if __name__ == "__main__":
cli()
5 changes: 2 additions & 3 deletions instill/helpers/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from enum import Enum
from typing import Any, Dict, List, Union

import numpy as np
from PIL import Image

PROMPT_ROLES = ["user", "assistant", "system"]
Expand Down Expand Up @@ -40,7 +39,7 @@ class ConversationInput:

class ConversationMultiModelInput:
conversation: List[Union[Dict[str, Union[str, Dict[str, str]]]]]
prompt_images: Union[List[np.ndarray], None] = None
prompt_images: Union[List[Image.Image], None] = None
max_new_tokens: int = 100
temperature: float = 0.8
top_k: int = 1
Expand All @@ -60,7 +59,7 @@ class TextToImageInput:

class ImageToImageInput:
prompt = ""
prompt_image: Union[np.ndarray, None] = None
prompt_image: Union[Image.Image, None] = None
steps: int = 5
cfg_scale: float = 7.5
seed: int = 0
Expand Down
Loading