Skip to content

Commit b02fef1

Browse files
committed
resolve comments
Signed-off-by: Will Guo <willg@nvidia.com>
1 parent 0f41470 commit b02fef1

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

File renamed without changes.

tests/unit/onnx/quantization/autotune/autotune/test_autotuner.py renamed to tests/unit/onnx/quantization/autotune/test_autotuner.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,8 @@
2121
"""
2222

2323
import os
24-
import sys
2524
import tempfile
2625

27-
# Add parent and current directory to path
28-
_test_dir = os.path.dirname(os.path.abspath(__file__))
29-
sys.path.insert(0, os.path.dirname(_test_dir))
30-
sys.path.insert(0, _test_dir)
31-
3226
import models as _test_models
3327
import onnx
3428
import onnx_graphsurgeon as gs
@@ -205,20 +199,47 @@ def test_set_profile_region(self, simple_conv_model):
205199
pytest.skip("No regions discovered")
206200

207201
def test_generate_scheme(self, simple_conv_model):
208-
"""Test generating an insertion scheme."""
202+
"""Test generating multiple schemes and that Q/DQ nodes appear in exported model."""
209203
autotuner = QDQAutotuner(simple_conv_model)
210204
config = _create_test_config()
211205
autotuner.initialize(config)
212206

213-
if len(autotuner.regions) > 0:
214-
region = autotuner.regions[0]
215-
autotuner.set_profile_region(region)
216-
# Generate a scheme
207+
if len(autotuner.regions) == 0:
208+
pytest.skip("No regions discovered")
209+
210+
autotuner.submit(10.0) # baseline
211+
region = autotuner.regions[0]
212+
autotuner.set_profile_region(region)
213+
214+
# Generate multiple schemes and submit a latency for each
215+
num_generated = 0
216+
while True:
217217
scheme_idx = autotuner.generate()
218-
# Should return a valid index (>= 0) or -1 if no more unique schemes
218+
if scheme_idx < 0:
219+
break
219220
assert isinstance(scheme_idx, int)
220-
else:
221-
pytest.skip("No regions discovered")
221+
autotuner.submit(10.0 + num_generated * 0.1) # dummy latency
222+
num_generated += 1
223+
if num_generated >= 5: # cap iterations
224+
break
225+
226+
assert num_generated > 0, "Expected at least one scheme to be generated"
227+
autotuner.set_profile_region(None, commit=True)
228+
229+
# Export with Q/DQ and verify Q/DQ nodes are in the model
230+
with tempfile.NamedTemporaryFile(suffix=".onnx", delete=False) as f:
231+
output_path = f.name
232+
try:
233+
autotuner.export_onnx(output_path, insert_qdq=True)
234+
exported = onnx.load(output_path)
235+
node_ops = [n.op_type for n in exported.graph.node]
236+
assert "QuantizeLinear" in node_ops, "Expected QuantizeLinear nodes in exported model"
237+
assert "DequantizeLinear" in node_ops, (
238+
"Expected DequantizeLinear nodes in exported model"
239+
)
240+
finally:
241+
if os.path.exists(output_path):
242+
os.unlink(output_path)
222243

223244
def test_submit_latency(self, simple_conv_model):
224245
"""Test submitting performance measurement."""

0 commit comments

Comments
 (0)