-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
293ca67
commit 532ce98
Showing
2 changed files
with
105 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import argparse | ||
from typing import Literal, TypedDict | ||
|
||
|
||
class Args(TypedDict): | ||
device: Literal["cpu", "cuda"] | ||
backend: Literal["onnx", "llama_cpp"] | ||
model_path: str | ||
|
||
batch_size: int | ||
sessions: int | ||
workers: int | ||
|
||
|
||
def init_server_args() -> Args: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-d", | ||
"--device", | ||
dest="device", | ||
action="store", | ||
default="cpu", | ||
choices=["cpu", "cuda"], | ||
help="Device to use for inference. (cpu/cuda, default: cpu)" | ||
) | ||
parser.add_argument( | ||
"-b", | ||
"--batch-size", | ||
dest="batch_size", | ||
action="store", | ||
default="1", | ||
type=int, | ||
help="Batch size for inference. (default: 1)" | ||
) | ||
parser.add_argument( | ||
"-f", | ||
"--backend", | ||
dest="backend", | ||
action="store", | ||
default="onnx", | ||
choices=["onnx", "llama_cpp"], | ||
help="Inference backend to use. (onnx/llama_cpp, default: onnx)" | ||
) | ||
parser.add_argument( | ||
"-s", | ||
"--sessions", | ||
dest="sessions", | ||
action="store", | ||
default="1", | ||
type=int, | ||
help="Number of session instances for parallel processing. (default: 1)" | ||
) | ||
parser.add_argument( | ||
"-w", | ||
"--workers", | ||
dest="workers", | ||
action="store", | ||
default="1", | ||
type=int, | ||
help="Number of uvicorn worker process. (default: 1)" | ||
) | ||
parser.add_argument( | ||
"-m", | ||
"--model-path", | ||
dest="model_path", | ||
action="store", | ||
type=str, | ||
help="Path to the model file. Required for model inference." | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
return Args( | ||
device=args.device, | ||
batch_size=args.batch_size, | ||
backend=args.backend, | ||
sessions=args.sessions, | ||
workers=args.workers, | ||
model_path=args.model_path | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters