-
Notifications
You must be signed in to change notification settings - Fork 559
Add TensorRT-RTX ABI EP support for ONNX quantization #2262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,16 +44,26 @@ If you install ModelOpt-Windows without the extra ``[onnx]`` option, only the mi | |||||||||||||||||||||
| The Post-Training Quantization (PTQ) process for ONNX models usually involves running the base model with user-supplied inputs, a process called calibration. The user-supplied model inputs are referred to as calibration data. To perform calibration, the base model must be run using a suitable ONNX Execution Provider (EP), such as *DmlExecutionProvider* (DirectML EP) or *CUDAExecutionProvider* (CUDA EP). There are different ONNX Runtime packages for each EP: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - *onnxruntime-directml* provides the DirectML EP. | ||||||||||||||||||||||
| - *onnxruntime-trt-rtx* provides TensorRT-RTX EP. | ||||||||||||||||||||||
| - *onnxruntime-ep-nv-tensorrt-rtx-cu13* provides the standalone TensorRT-RTX EP ABI plugin. | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest we keep mention of both legacy and EP ABI paths for TRTRTX EP - for completeness. |
||||||||||||||||||||||
| - *onnxruntime-gpu* provides the CUDA EP. | ||||||||||||||||||||||
| - *onnxruntime* provides the CPU EP. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| By default, ModelOpt-Windows installs *onnxruntime-gpu*. The default CUDA version needed for *onnxruntime-gpu* since v1.19.0 is 12.x. The *onnxruntime-gpu* package (i.e. CUDA EP) has CUDA and cuDNN dependencies: | ||||||||||||||||||||||
| By default, ModelOpt-Windows on Windows x64 installs *onnxruntime-gpu* together with the | ||||||||||||||||||||||
| standalone TensorRT-RTX EP ABI plugin. Keeping *onnxruntime-gpu* allows calibration to | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this "in-between" addition of EP ABI plugin stuff doesn't look right placement for adding TRTRTX EP related instructions. ORT-GPU content should be together and then we should add any other dependency related instructions. Also, this line "The default CUDA version needed for onnxruntime-gpu since v1.19.0 is 12.x." appears to be deleted. |
||||||||||||||||||||||
| switch between CUDA EP and TensorRT-RTX. Select the TensorRT-RTX ABI implementation with | ||||||||||||||||||||||
| ``--calibration_eps NvTensorRtRtx --trt_rtx_backend abi``. The legacy backend remains | ||||||||||||||||||||||
| available and uses TensorRT-RTX libraries supplied through ``PATH``. | ||||||||||||||||||||||
|
Comment on lines
+51
to
+55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Qualify the default-install statement by Python version.
Update the sentence to include the Python condition. Proposed wording-By default, ModelOpt-Windows on Windows x64 installs *onnxruntime-gpu* together with the
+By default, ModelOpt-Windows on Windows x64 with Python >3.10 installs *onnxruntime-gpu* together with the📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The ABI plugin requires an Ampere-or-newer RTX GPU and an NVIDIA driver with CUDA 13 support. | ||||||||||||||||||||||
| Python 3.10 and Windows architectures other than x64 continue to use the legacy backend. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The *onnxruntime-gpu* package (i.e. CUDA EP) has CUDA and cuDNN dependencies: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - Install CUDA and cuDNN: | ||||||||||||||||||||||
| - For the ONNX Runtime GPU package, you need to install the appropriate version of CUDA and cuDNN. Refer to the `CUDA Execution Provider requirements <https://onnxruntime.ai/docs/install/#cuda-and-cudnn/>`_ for compatible versions of CUDA and cuDNN. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| If you need to use any other EP for calibration, you can uninstall the existing *onnxruntime-gpu* package and install the corresponding package. For example, to use the DirectML EP, you can uninstall the existing *onnxruntime-gpu* package and install the *onnxruntime-directml* package: | ||||||||||||||||||||||
| If you need to use an incompatible ORT package for calibration, uninstall the existing | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Earlier wordings look better and explicit. Can you revert to that? |
||||||||||||||||||||||
| *onnxruntime-gpu* package before installing it. For example, to use the DirectML EP: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| .. code-block:: bash | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -95,9 +105,10 @@ Ensure the following steps are verified: | |||||||||||||||||||||
| - **Python Interpreter**: Open the command line and type python. The Python interpreter should start, displaying the Python version. | ||||||||||||||||||||||
| - **Onnxruntime Package**: Ensure that exactly one of the following is installed: | ||||||||||||||||||||||
| - *onnxruntime-directml* (DirectML EP) | ||||||||||||||||||||||
| - *onnxruntime-trt-rtx* (TensorRT-RTX EP) | ||||||||||||||||||||||
| - *onnxruntime-gpu* (CUDA EP) | ||||||||||||||||||||||
| - *onnxruntime* (CPU EP) | ||||||||||||||||||||||
| The *onnxruntime-ep-nv-tensorrt-rtx-cu13* plugin is installed alongside the selected | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest keeping both legacy and EP ABI rows for completeness. |
||||||||||||||||||||||
| ONNX Runtime package; it does not replace *onnxruntime-gpu*. | ||||||||||||||||||||||
| - **CUDA Toolkit**: For CUDA workflows, verify that the selected Toolkit is found first and that ``nvcc`` reports the expected major version: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| .. code-block:: bat | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -390,6 +390,7 @@ def main(args): | |
| calibration_method=args.algo, | ||
| calibration_data_reader=None if args.use_random_calib else calib_inputs, | ||
| calibration_eps=args.calibration_eps, | ||
| trt_rtx_backend=args.trt_rtx_backend, | ||
| use_zero_point=args.use_zero_point, | ||
| block_size=args.block_size, | ||
| input_shapes_profile=input_shapes_profile_data, | ||
|
|
@@ -569,6 +570,12 @@ def main(args): | |
| default=["cuda", "cpu"], # Default as a list | ||
| help="Comma-separated list of calibration endpoints. Choose from 'cuda', 'cpu', 'dml', 'NvTensorRtRtx'.", | ||
| ) | ||
| parser.add_argument( | ||
| "--trt_rtx_backend", | ||
| choices=["legacy", "abi"], | ||
| default="legacy", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this default be "legacy" or "ABI"? I guess EP ABI is the default path now for TRTRTX EP. Can you check on this and confirm, update required places? |
||
| help="TensorRT-RTX backend used with NvTensorRtRtx calibration: legacy or abi.", | ||
| ) | ||
| parser.add_argument( | ||
| "--trust_remote_code", | ||
| help="Set trust_remote_code for Huggingface models and tokenizers", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -292,6 +292,10 @@ def _create_inference_session_with_ep_config(calibrator, **kwargs): | |||||||||||
| model_path = kwargs.get("model_path") | ||||||||||||
| logger.debug("Creating inference session with Execution Provider configuration") | ||||||||||||
|
|
||||||||||||
| trt_rtx_backend = kwargs.get("trt_rtx_backend", "legacy") | ||||||||||||
| if trt_rtx_backend not in ("legacy", "abi"): | ||||||||||||
| raise ValueError(f"trt_rtx_backend must be 'legacy' or 'abi', got {trt_rtx_backend!r}") | ||||||||||||
|
|
||||||||||||
| sess_options = ort.SessionOptions() | ||||||||||||
| sess_options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL | ||||||||||||
| sess_options.add_session_config_entry("session.use_device_allocator_for_initializers", "1") | ||||||||||||
|
|
@@ -302,8 +306,7 @@ def _create_inference_session_with_ep_config(calibrator, **kwargs): | |||||||||||
|
|
||||||||||||
| # Note. This path can be an empty string, which denotes that the model has custom ops and TRT EP is needed. | ||||||||||||
| calibrator.trt_extra_plugin_lib_paths = kwargs.get("trt_extra_plugin_lib_paths") | ||||||||||||
|
|
||||||||||||
| if calibrator.trt_extra_plugin_lib_paths is not None: | ||||||||||||
| if trt_rtx_backend != "abi" and calibrator.trt_extra_plugin_lib_paths is not None: | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Configure classic TensorRT when ABI mode also selects it for custom plugins. When Keep the skip only for ABI-only provider lists. Add a regression test for ABI mode with custom operators and plugin paths. Proposed fix- if trt_rtx_backend != "abi" and calibrator.trt_extra_plugin_lib_paths is not None:
+ if (
+ calibrator.trt_extra_plugin_lib_paths is not None
+ and (trt_rtx_backend != "abi" or "TensorrtExecutionProvider" in providers)
+ ):📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| logger.debug(f"TRT extra plugin paths: {calibrator.trt_extra_plugin_lib_paths}") | ||||||||||||
| if "TensorrtExecutionProvider" not in ort.get_available_providers(): | ||||||||||||
| raise RuntimeError( | ||||||||||||
|
|
@@ -336,20 +339,12 @@ def _update_provider_config(provider, config): | |||||||||||
| providers[i], {"arena_extend_strategy": "kSameAsRequested"} | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| if model_path is None: | ||||||||||||
| # Create the inference session with EP configuration on augmented_model | ||||||||||||
| calibrator.infer_session = ort.InferenceSession( | ||||||||||||
| calibrator.augmented_model_path, | ||||||||||||
| sess_options=sess_options, | ||||||||||||
| providers=providers, | ||||||||||||
| ) | ||||||||||||
| else: | ||||||||||||
| # Create the inference session with EP configuration on provided model path | ||||||||||||
| calibrator.infer_session = ort.InferenceSession( | ||||||||||||
| model_path, | ||||||||||||
| sess_options=sess_options, | ||||||||||||
| providers=providers, | ||||||||||||
| ) | ||||||||||||
| session_path = calibrator.augmented_model_path if model_path is None else model_path | ||||||||||||
| calibrator.infer_session = ort.InferenceSession( | ||||||||||||
| session_path, | ||||||||||||
| sess_options=sess_options, | ||||||||||||
| providers=providers, | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| # Group qdq tensors will have the same scaling factor. | ||||||||||||
| calibrator.group_qdq_tensors = kwargs.get("group_qdq_tensors") | ||||||||||||
|
|
@@ -1568,6 +1563,8 @@ def _quantize_static( | |||||||||||
| ExecutionProviders = list[string] : | ||||||||||||
| Default is [("CUDAExecutionProvider", {"device_id": 0}), "CPUExecutionProvider", | ||||||||||||
| "TensorrtExecutionProvider"] | ||||||||||||
| TrtRtxBackend = string : | ||||||||||||
| Selects the legacy or ABI TensorRT-RTX execution provider implementation. | ||||||||||||
| """ | ||||||||||||
| logger.info("Starting static quantization") | ||||||||||||
| logger.debug(f"Quantization format: {quant_format}") | ||||||||||||
|
|
@@ -1607,6 +1604,7 @@ def _quantize_static( | |||||||||||
| # ====================== Modification ====================== | ||||||||||||
| ("TrtExtraPluginLibraryPaths", "trt_extra_plugin_lib_paths"), | ||||||||||||
| ("ExecutionProviders", "execution_providers"), | ||||||||||||
| ("TrtRtxBackend", "trt_rtx_backend"), | ||||||||||||
| ("group_qdq_tensors", "group_qdq_tensors"), | ||||||||||||
| ("QDQDisableWeightAdjustForInt32Bias", "disable_int32_weight_adjustment"), | ||||||||||||
| # ========================================================== | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go in 0.46.1 if that becomes the next release version (for modelopt+woa support).