Skip to content

Commit f4d2185

Browse files
committed
resolve copilot comments
Signed-off-by: Will Guo <willg@nvidia.com>
1 parent 16f3c6d commit f4d2185

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

modelopt/onnx/quantization/autotune/common.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,11 @@ def from_dict(
447447
def __str__(self) -> str:
448448
"""String representation for debugging."""
449449
best_latency = self.best_scheme.latency_ms if self.best_scheme else 0.0
450+
pattern_str = self.pattern_signature[:40] + (
451+
"..." if len(self.pattern_signature) > 40 else ""
452+
)
450453
return (
451-
f"PatternSchemes(pattern='{self.pattern_signature[:40]}...', "
454+
f"PatternSchemes(pattern='{pattern_str}', "
452455
f"schemes={self.num_schemes}, best_latency={best_latency:.3f}ms)"
453456
)
454457

@@ -516,19 +519,22 @@ def add_pattern_schemes(self, pattern_schemes: PatternSchemes) -> None:
516519
for scheme in sorted_schemes:
517520
# Check if this scheme is too similar to any already-filtered scheme
518521
too_similar = False
522+
existing_to_remove = None # at most one; remove after inner loop
519523
for existing_scheme in filtered_schemes:
520524
distance = scheme.distance(existing_scheme)
521525
if distance < self.minimum_distance:
522526
# Schemes are too similar, keep the better one
523527
if scheme.latency_ms < existing_scheme.latency_ms:
524-
# New scheme is better, remove existing and add new
525-
filtered_schemes.remove(existing_scheme)
528+
# New scheme is better; mark existing for removal
529+
existing_to_remove = existing_scheme
526530
break
527531
else:
528532
# Existing scheme is better, skip new one
529533
too_similar = True
530534
break
531535

536+
if existing_to_remove is not None:
537+
filtered_schemes.remove(existing_to_remove)
532538
if not too_similar:
533539
filtered_schemes.append(scheme)
534540

modelopt/onnx/quantization/autotune/workflows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def init_benchmark_instance(
8484
timing_cache_file: str | None = None,
8585
warmup_runs: int = 5,
8686
timing_runs: int = 20,
87-
trtexec_args: str | None = None,
87+
trtexec_args: list[str] | None = None,
8888
):
8989
"""Initialize global TensorRT benchmark instance for model performance measurement.
9090

tests/gpu/onnx/quantization/autotune/test_workflow.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515

1616
import os
17+
import shutil
1718
import tempfile
1819
from pathlib import Path
1920

@@ -48,7 +49,7 @@ def test_export_quantized_model(use_trtexec, simple_conv_model):
4849
# Save baseline model
4950
onnx.save(simple_conv_model, baseline_model_path)
5051

51-
output_dir = baseline_model_path.strip(".onnx")
52+
output_dir = baseline_model_path.replace(".onnx", "")
5253
output_path = output_dir + ".quant.onnx"
5354

5455
try:
@@ -75,3 +76,7 @@ def test_export_quantized_model(use_trtexec, simple_conv_model):
7576
finally:
7677
if os.path.exists(output_path):
7778
os.unlink(output_path)
79+
if os.path.exists(baseline_model_path):
80+
os.unlink(baseline_model_path)
81+
if os.path.isdir(output_dir):
82+
shutil.rmtree(output_dir)

0 commit comments

Comments
 (0)