1+ import logging
12from enum import Enum
23from typing import Annotated , Optional
34
89from inference_cli .lib .env import ROBOFLOW_API_KEY
910from inference_cli .lib .utils import read_env_file
1011
11- inference_compiler_app = typer .Typer (name = "Inference compiler" )
12+ logger = logging .getLogger ("inference_cli.inference_compiler" )
13+
14+ inference_compiler_app = typer .Typer (
15+ name = "Inference compiler" ,
16+ help = "Compile Roboflow models into optimized TensorRT engines for GPU-accelerated inference on NVIDIA GPUs and Jetson devices." ,
17+ )
1218
1319
1420class CompilationMode (str , Enum ):
@@ -22,7 +28,13 @@ def compiler_callback():
2228 pass
2329
2430
25- @inference_compiler_app .command (name = "compile-model" )
31+ @inference_compiler_app .command (
32+ name = "compile-model" ,
33+ help = "Compile an ONNX model from Roboflow into a TensorRT engine optimized for your GPU. "
34+ "The compiled engine is registered back to the Roboflow platform so it can be served to "
35+ "matching devices automatically. Compilation can run in-process (requires TensorRT and "
36+ "inference-models) or inside a Docker container." ,
37+ )
2638def compile_model (
2739 model_id : Annotated [
2840 str ,
@@ -37,68 +49,67 @@ def compile_model(
3749 typer .Option (
3850 "--api-key" ,
3951 "-a" ,
40- help = "Roboflow API key for your workspace. If not given - env variable `ROBOFLOW_API_KEY` will be used" ,
52+ help = "Roboflow API key for your workspace. If not provided, the `ROBOFLOW_API_KEY` environment variable is used. " ,
4153 ),
4254 ] = None ,
4355 debug_mode : Annotated [
4456 bool ,
4557 typer .Option (
4658 "--debug-mode/--no-debug-mode" ,
47- help = "Flag enabling errors stack traces to be displayed (helpful for debugging) " ,
59+ help = "Display full stack traces on errors. " ,
4860 ),
4961 ] = False ,
5062 trt_forward_compatible : Annotated [
5163 bool ,
5264 typer .Option (
5365 "--trt-forward-compatible/--no-trt-forward-compatible" ,
54- help = "Flag to decide if forward-compatibility mode in TRT compilation should be enabled " ,
66+ help = "Enable TensorRT forward-compatibility mode, allowing engines to run on newer TRT versions. " ,
5567 ),
5668 ] = False ,
5769 trt_same_cc_compatible : Annotated [
5870 bool ,
5971 typer .Option (
6072 "--trt-same-cc-compatible/--no-trt-same-cc-compatible" ,
61- help = "Flag to decide if engine should be compiled to be compatible with devices sharing the same CUDA CC "
62- "to the one running compilation procedure" ,
73+ help = "Compile the engine to be portable across GPUs with the same CUDA compute capability." ,
6374 ),
6475 ] = False ,
6576 compilation_mode : Annotated [
6677 CompilationMode ,
6778 typer .Option (
6879 "--compilation-mode" ,
69- help = "Selection of compilation mode - `container` runs the procedure inside `inference` server, "
70- "`python` runs in-process. `auto` (default) inspect environment dependencies to verify if "
71- "the procedure can be run in-process, if not - offloading to the server ." ,
80+ help = "Selection of compilation mode. `container` runs the procedure inside an Inference server container , "
81+ "`python` runs in-process. `auto` (default) inspects environment dependencies to verify if "
82+ "the procedure can run in-process; if not, it offloads to the container ." ,
7283 ),
7384 ] = CompilationMode .AUTO ,
7485 image : Annotated [
7586 Optional [str ],
7687 typer .Option (
7788 "--image" ,
78- help = "Point specific docker image you would like to run with command (useful for development of custom "
79- "builds of inference server)" ,
89+ help = "Specify a Docker image to use for compilation (useful for custom builds of the Inference server)." ,
8090 ),
8191 ] = None ,
8292 use_local_images : Annotated [
8393 bool ,
8494 typer .Option (
8595 "--use-local-images/--not-use-local-images" ,
86- help = "Flag to allow using local images (if set False image is always attempted to be pulled) " ,
96+ help = "Allow using local Docker images. If false, the image is always pulled from the registry. " ,
8797 ),
8898 ] = False ,
8999 env_file_path : Annotated [
90100 Optional [str ],
91101 typer .Option (
92102 "--env-file-path" ,
93- help = "Path to key-value .env file to inject into compilation container (if you run in Python package, "
94- "just export variables to env) " ,
103+ help = "Path to a key-value .env file to inject into the compilation container. "
104+ "For Python mode, export the variables to your environment instead. " ,
95105 ),
96106 ] = None ,
97107) -> None :
98108 console = Console ()
99109 console .print (
100- "You are running component licensed under Roboflow Enterprise License - please acknowledge the "
101- "terms of use: https://github.com/roboflow/inference/blob/main/inference/enterprise/LICENSE.txt" ,
110+ "Inference Compiler is licensed under the Roboflow Enterprise License. "
111+ "By continuing, you acknowledge the terms of use: "
112+ "https://github.com/roboflow/inference/blob/main/inference/enterprise/LICENSE.txt" ,
102113 )
103114 if api_key is None :
104115 api_key = ROBOFLOW_API_KEY
@@ -151,9 +162,12 @@ def compilation_to_run_in_container(
151162 import inference_models
152163
153164 except Exception as error :
165+ logger .info (
166+ "Could not import inference-models, offloading to container: %s" , error
167+ )
154168 console .print (
155- "Inference compiler running in `auto` mode could not import `inference-models`, which is required "
156- f"to compile package in process - offloading to container. Error: { error } " ,
169+ "Compiler running in `auto` mode could not import `inference-models`, which is required "
170+ f"to compile in- process. Offloading to container. Error: { error } " ,
157171 )
158172 return True
159173 try :
@@ -168,9 +182,10 @@ def compilation_to_run_in_container(
168182 x_ray_result .trt_python_package_available
169183 ), "TensorRT Python package not detected"
170184 except Exception as error :
185+ logger .info ("TensorRT not available, offloading to container: %s" , error )
171186 console .print (
172- "Inference compiler running in `auto` mode could not import `tensorrt`, which is required "
173- f"to compile package in process - offloading to container. Error: { error } " ,
187+ "Compiler running in `auto` mode could not import `tensorrt`, which is required "
188+ f"to compile in- process. Offloading to container. Error: { error } " ,
174189 )
175190 return True
176191 return False
@@ -192,9 +207,9 @@ def run_compilation_in_container(
192207 image = get_image ()
193208 if "-cpu" in image :
194209 raise ValueError (
195- "Attempted to run compilation using `inference- server` CPU image, which does not support TRT compilation. "
196- "This error may be result of pointing invalid docker image with `--image` parameter or image "
197- "auto-selection choice, due to lack of GPU detected."
210+ "Attempted to run compilation using an Inference server CPU image, which does not support TRT compilation. "
211+ "This may be caused by specifying an invalid Docker image with the `--image` parameter, or by "
212+ "automatic image selection when no GPU is detected."
198213 )
199214 is_gpu = "gpu" in image and "jetson" not in image
200215 is_jetson = "jetson" in image
@@ -209,7 +224,13 @@ def run_compilation_in_container(
209224 privileged = True
210225 docker_run_kwargs = {"runtime" : "nvidia" }
211226 pull_image (image , use_local_images = use_local_images )
212- console .print ("Starting model compilation inside docker container" )
227+ logger .info (
228+ "Starting container compilation: image=%s, is_gpu=%s, is_jetson=%s" ,
229+ image ,
230+ is_gpu ,
231+ is_jetson ,
232+ )
233+ console .print ("Starting model compilation inside Docker container" )
213234 command = build_container_command (
214235 model_id = model_id ,
215236 api_key = api_key ,
@@ -286,6 +307,7 @@ def run_compilation_in_python(
286307 trt_same_cc_compatible : bool = False ,
287308 console : Optional [Console ] = None ,
288309) -> None :
310+ logger .info ("Running compilation in-process (Python mode)" )
289311 from inference_cli .lib .enterprise .inference_compiler .core import compiler
290312
291313 compiler .compile_model (
0 commit comments