Files
Maxfield AllisonandGitHub 1addbb9ab8 build: add Docker and Compose quickstart with optional CUDA (#45)
* build: add Docker quickstart with CPU and CUDA support

* feat: expose quickstart settings through environment variables

* docs: add annotated Compose example and configuration guide

* docs: keep Docker quickstart compatible with upstream updates
2026-09-23 12:44:02 +05:30

35 lines
1.2 KiB
Python

"""Run one SDK request using the adjacent example input."""
import json
import os
from pathlib import Path
import torch
from laya import Router, load
def main():
device = os.environ.get("LAYA_DEVICE", "cpu")
if torch.device(device).type == "cuda" and not torch.cuda.is_available():
raise RuntimeError(
"CUDA was requested but is unavailable. "
"Check the GPU override, host driver and NVIDIA Container Toolkit."
)
request_file = os.environ.get("LAYA_REQUEST_FILE") or Path(__file__).with_name("request.json")
request = json.loads(Path(request_file).read_text(encoding="utf-8"))
model_path = os.environ.get("LAYA_MODEL_PATH")
model = os.environ.get("LAYA_MODEL", "auto") or "auto"
if model_path:
if model != "auto":
raise ValueError("Set either LAYA_MODEL or LAYA_MODEL_PATH, not both")
result = load(model_path, device=device).predict(request["state"], request["questions"])
else:
result = Router(device=device).predict(
request["state"], request["questions"], model=None if model == "auto" else model
)
print(json.dumps(result, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()