ATLAS Offline Software
Loading...
Searching...
No Matches
python.TritonToolConfig Namespace Reference

Functions

 TritonToolCfg (flags, str model_name, str url, int port=8001, str model_version="", float timeout=0.0, bool ssl=False, name="TritonTool", **kwargs)

Function Documentation

◆ TritonToolCfg()

python.TritonToolConfig.TritonToolCfg ( flags,
str model_name,
str url,
int port = 8001,
str model_version = "",
float timeout = 0.0,
bool ssl = False,
name = "TritonTool",
** kwargs )
Configure TritonTool in Control/AthOnnx/AthTritonComps/src

Definition at line 7 of file TritonToolConfig.py.

17):
18 """Configure TritonTool in Control/AthOnnx/AthTritonComps/src"""
19
20 acc = ComponentAccumulator()
21
22 # Check if triton server is active
23 from AthenaCommon.Logging import log as msg
24 from urllib.parse import urlsplit
25
26 split_url = urlsplit(url) if "//" in url else urlsplit(f"http://{url}")
27 host = split_url.hostname
28 if host == "":
29 host = split_url.path
30 if split_url.port is not None and split_url.port != port:
31 raise RuntimeError(
32 f"Triton URL is {url} and port is {port}"
33 f" which differs from port in URL"
34 )
35 if port != 8001:
36 msg.info(
37 "Triton port is not set to 8001."
38 " Can't assume HTTP port is 8000, not checking health."
39 )
40 elif ssl:
41 msg.info("SSL is turned on for Triton, not checking health")
42 else:
43 import requests
44
45 try:
46 r = requests.get(f"http://{host}:8000/v2/health/live")
47 except requests.exceptions.ConnectionError:
48 raise RuntimeError(
49 f"No running triton server found at http://{host}:8000/")
50 if r.status_code != 200:
51 raise RuntimeError(
52 f"No running triton server found at http://{host}:8000/")
53 if model_version != "":
54 r = requests.get(
55 f"http://{host}:8000/v2/models/{model_name}"
56 f"/versions/{model_version}/ready"
57 )
58 model_str = f"{model_name} (version {model_version})"
59 else:
60 r = requests.get(
61 f"http://{host}:8000/v2/models/{model_name}/ready")
62 model_str = model_name
63 if r.status_code != 200:
64 raise RuntimeError(
65 f"The {model_str} model is not ready for inference on {host}"
66 )
67
68 kwargs.setdefault("ModelName", model_name)
69 kwargs.setdefault("URL", url)
70 kwargs.setdefault("Port", port)
71 kwargs.setdefault("ModelVersion", model_version)
72 kwargs.setdefault("ClientTimeout", timeout)
73
74 if port == 443: # If the port is 443, that's typically used for HTTPS.
75 ssl = True
76
77 kwargs.setdefault("UseSSL", ssl) # Default to not using SSL
78
79 acc.setPrivateTools(CompFactory.AthInfer.TritonTool(name=name, **kwargs))
80 return acc