Skip to content

Conversation

@willg-nv
Copy link

@willg-nv willg-nv commented Dec 17, 2025

What does this PR do?

Type of change: new feature

Overview: This PR integrate automated Q/DQ placement tool to ModelOpt. This PR is 2/4 parts of the cahnges.

Part 1: #701
Part 2: #702
Part 3: #703
Part 4: #704

This PR contains the following changes:

  1. Implement RegionPattern to represent the topology structure of Regions. InsertionPoints are also defined on RegionPattern. Regions with same pattern are optimized at the same time
  2. Implement RegionSearch class to divide ONNX graph into small regions
  3. RegionSearch python file also provides an entry point to print out the region structures.
  4. Unit tests for new classse.

Usage

python -m modelopt.onnx.quantization.autotune.region_search --model model.onnx --verbose

Example output:

    ├─ Region 212 (Level 0, Type: COMPOSITE)
    │  ├─ Direct nodes: 0
    │  ├─ Total nodes (recursive): 9
    │  ├─ Children: 1
    │  ├─ Inputs: 3 tensors
    │  │    - xxx
    │  │    - xxx
    │  │    - xxx
    │  └─ Outputs: 1 tensors
    │       - xxx
    │
    │  Child regions:
    │
      ├─ Region 209 (Level 2, Type: LEAF) 
      │  ├─ Direct nodes: 9
      │  ├─ Total nodes (recursive): 9
      │  ├─ Children: 0
      │  ├─ Inputs: 11 tensors
      │  │    - xxx

Testing

Implemented unit tests for new classes. All unit tests could get pass locally.

Before your PR is "Ready for review"

  • Make sure you read and follow Contributor guidelines and your commits are signed.
  • Is this change backward compatible?: Yes
  • Did you write any new necessary tests?: Yes
  • Did you add or update any necessary documentation?: No, document change will be in part 4.
  • Did you update Changelog?: No. Change log will be included in part 4.

Additional Information

@willg-nv willg-nv requested a review from a team as a code owner December 17, 2025 06:29
@willg-nv willg-nv requested a review from ajrasane December 17, 2025 06:29
@copy-pr-bot
Copy link

copy-pr-bot bot commented Dec 17, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@willg-nv willg-nv changed the title Dev willg integrate auto qdq placement part2 Integrate Automated QDQ placement tool - Part 2 Dec 17, 2025
@willg-nv
Copy link
Author

Hi @ajrasane , could you help me review this PR, thanks!

@willg-nv willg-nv force-pushed the dev-willg-integrate-auto-qdq-placement-part2 branch from 3f7ff31 to d3a6765 Compare December 31, 2025 02:16

return scheme

def format_tree(self, region: Region, graph: gs.Graph, indent: int = 0) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide a small example of how this tree looks?

Copy link
Author

@willg-nv willg-nv Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added tests for region search to print tree structure, below is an example:

tests/unit/onnx/quantization/autotune/test_region_search.py::TestPrintTree::test_print_tree_top_down_builder
============================================================
Region Tree Structure:
============================================================
├─ Region 0 (Level 0, Type: LEAF)
│  ├─ Direct nodes: 2
│  ├─ Total nodes (recursive): 2
│  ├─ Children: 0
│  ├─ Inputs: 1 tensors
│  │    - input
│  └─ Outputs: 1 tensors
│       - output
│
│  Nodes in this region:
│    - Node 0: Conv (name: conv)
│    - Node 1: Relu (name: relu)
|
  ├─ <child region if exists>
============================================================

Currently, the 2 stage region partitioner only creates regions with depth <= 2.

Signature formats:
- Empty region: "EMPTY"
- Leaf region: "Op1->Op2->Op3" or "Op1[params]->Op2[params]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be saved as LEAF(ops)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why additional LEAF is needed? I think op1->op2->...opn is okay to represent op sequence. Adding LEAF would make complex region too long.

region_node_indices: Set of node indices in the current region
Returns:
Signature string examples:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will the signatures of custom ops look? Could you provide an example?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example res-block signature:

COMPOSITE(Conv[kernel_shape=3x3]->BatchNormalization->Relu->Conv[kernel_shape=3x3]->BatchNormalization+Conv[kernel_shape=1x1]->BatchNormalization+Add->Relu)

graph structure:

                         Input
                           │
            ┌──────────────┴──────────────┐
            │                             │
            ▼                             ▼
    ┌───────────────┐             ┌───────────────┐
    │ Conv (3x3)    │             │ Conv (1x1)    │ (projection)
    └───────────────┘             └───────────────┘
            │                             │
            ▼                             ▼
    ┌───────────────┐             ┌───────────────┐
    │ BatchNorm     │             │ BatchNorm     │
    └───────────────┘             └───────────────┘
            │                             │
            ▼                             │
    ┌───────────────┐                     │
    │ Relu          │                     │
    └───────────────┘                     │
            │                             │
            ▼                             │
    ┌───────────────┐                     │
    │ Conv (3x3)    │                     │
    └───────────────┘                     │
            │                             │
            ▼                             │
    ┌───────────────┐                     │
    │ BatchNorm     │                     │
    └───────────────┘                     │
            │                             │
            └──────────────┬──────────────┘
                           ▼
                      ┌─────────┐
                      │   Add   │
                      └─────────┘
                           │
                           ▼
                      ┌─────────┐
                      │  Relu   │
                      └─────────┘

For custom plugin node, thier name will also be added to the signature.

@willg-nv willg-nv force-pushed the dev-willg-integrate-auto-qdq-placement-part2 branch 2 times, most recently from 616285d to c95939a Compare January 8, 2026 08:35
quantized_tensors = set()

for node in onnx_model.graph.node:
if node.op_type == "QuantizeLinear":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If --dq_only is enabled, there may only be the DQ node indicating that a tensor is being quantized. Please verify that those cases are supporting with this function.

See

@willg-nv willg-nv force-pushed the dev-willg-integrate-auto-qdq-placement-part2 branch 2 times, most recently from 0c4f114 to 4468ca2 Compare January 9, 2026 05:00
@willg-nv willg-nv force-pushed the dev-willg-integrate-auto-qdq-placement-part2 branch from 4468ca2 to bc87ca7 Compare January 9, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants