|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +"""Pattern-Based Q/DQ Autotuning for ONNX Models. |
| 17 | +
|
| 18 | +This package provides automated optimization of Quantize/Dequantize (Q/DQ) node placement |
| 19 | +in ONNX computation graphs to minimize TensorRT inference latency. It uses pattern-based |
| 20 | +region analysis to efficiently explore and optimize Q/DQ insertion strategies. |
| 21 | +
|
| 22 | +**Core Components:** |
| 23 | +
|
| 24 | +Autotuner Classes: |
| 25 | + - QDQAutotuner: Main autotuner with automatic hierarchical region discovery |
| 26 | + - QDQAutotunerBase: Base class for custom region identification strategies |
| 27 | +
|
| 28 | +Region Management: |
| 29 | + - Region: Hierarchical subgraph representation (nodes + children) |
| 30 | + - RegionType: Enumeration (LEAF, COMPOSITE, ROOT) |
| 31 | + - CombinedRegionSearch: Two-phase region discovery (partitioning + refinement) |
| 32 | + - RegionPattern: Structural pattern analysis and matching for region grouping |
| 33 | +
|
| 34 | +Q/DQ Insertion Points: |
| 35 | + - InsertionScheme: Collection of Q/DQ insertion points for a region pattern |
| 36 | + - NodeInputInsertionPoint: Q/DQ insertion at specific node inputs |
| 37 | + - ChildRegionInputInsertionPoint: Q/DQ insertion at child region input boundaries |
| 38 | + - RegionOutputInsertionPoint: Q/DQ insertion at region output boundaries |
| 39 | +
|
| 40 | +Configuration & State: |
| 41 | + - Config: Autotuning parameters (quant type, thresholds, verbosity) |
| 42 | + - PatternCache: Top-performing schemes indexed by pattern (warm-start) |
| 43 | + - PatternSchemes: Scheme collection and measurement results for a pattern |
| 44 | +
|
| 45 | +Benchmarking: |
| 46 | + - Benchmark: Abstract base class for model benchmarking |
| 47 | + - TensorRTPyBenchmark: Benchmark using TensorRT Python API (recommended) |
| 48 | + - TrtExecBenchmark: Benchmark using trtexec command-line tool (legacy) |
| 49 | +
|
| 50 | +**See Also:** |
| 51 | +
|
| 52 | + - workflows.region_pattern_autotuning_workflow: Complete end-to-end optimization |
| 53 | + - QDQAutotuner: Main autotuner class documentation |
| 54 | + - RegionPattern: Pattern matching and signature computation |
| 55 | +""" |
| 56 | + |
| 57 | +# Core data structures |
| 58 | +from .common import ( |
| 59 | + AutotunerError, |
| 60 | + AutotunerNotInitializedError, |
| 61 | + Config, |
| 62 | + InsertionScheme, |
| 63 | + InvalidSchemeError, |
| 64 | + PatternCache, |
| 65 | + PatternSchemes, |
| 66 | + Region, |
| 67 | + RegionError, |
| 68 | + RegionType, |
| 69 | +) |
| 70 | +from .insertion_points import ( |
| 71 | + ChildRegionInputInsertionPoint, |
| 72 | + NodeInputInsertionPoint, |
| 73 | + RegionOutputInsertionPoint, |
| 74 | + ResolvedInsertionPoint, |
| 75 | +) |
| 76 | +from .region_pattern import RegionPattern |
| 77 | +from .region_search import CombinedRegionSearch |
| 78 | + |
| 79 | +__all__ = [ |
| 80 | + "AutotunerError", |
| 81 | + "AutotunerNotInitializedError", |
| 82 | + "ChildRegionInputInsertionPoint", |
| 83 | + "CombinedRegionSearch", |
| 84 | + "Config", |
| 85 | + "InsertionScheme", |
| 86 | + "InvalidSchemeError", |
| 87 | + "NodeInputInsertionPoint", |
| 88 | + "PatternCache", |
| 89 | + "PatternSchemes", |
| 90 | + "Region", |
| 91 | + "RegionError", |
| 92 | + "RegionOutputInsertionPoint", |
| 93 | + "RegionPattern", |
| 94 | + "RegionType", |
| 95 | + "ResolvedInsertionPoint", |
| 96 | +] |
0 commit comments