[6437794] Fix ONNX autotune verbose logging (#3382)

### What does this PR do?

Type of change: Bug fix

Makes `--autotune_verbose` select DEBUG logging throughout ONNX
autotuning, including the downstream INT8/FP8 quantizer and final
performance guard. It also makes the standalone autotune CLI's
documented `--verbose` flag enable DEBUG logging. Previously both flags
left some or all autotuner debug messages suppressed at INFO.

### Usage

```bash
python -m modelopt.onnx.quantization \
  --onnx_path model.onnx \
  --autotune=quick \
  --autotune_verbose
```

### Testing

- `.venv/bin/pytest -q tests/unit/onnx/quantization/autotune
tests/unit/onnx/quantization/test_quantize_api.py --disable-warnings
--maxfail=1` (216 passed)
- `.venv/bin/ruff check modelopt/onnx/quantization/quantize.py
modelopt/onnx/quantization/autotune/__main__.py
tests/unit/onnx/quantization/test_quantize_api.py
tests/unit/onnx/quantization/autotune/test_autotune_config.py`
- `.venv/bin/ruff format --check modelopt/onnx/quantization/quantize.py
modelopt/onnx/quantization/autotune/__main__.py
tests/unit/onnx/quantization/test_quantize_api.py
tests/unit/onnx/quantization/autotune/test_autotune_config.py`
- `pre-commit run --files modelopt/onnx/quantization/quantize.py
modelopt/onnx/quantization/autotune/__main__.py
tests/unit/onnx/quantization/test_quantize_api.py
tests/unit/onnx/quantization/autotune/test_autotune_config.py`

### Before your PR is "*Ready for review*"

- Is this change backward compatible?: ✅
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`: N/A
- Did you write any new necessary tests?: ✅
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
N/A — this is a focused logging bug fix.
- Did you get Claude approval on this PR?: N/A

### Additional Information

Review baseline: `e169b4c2bc62a32c45aaef793cde7599dee2c1b2`.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Enabled debug-level logging when both autotuning and verbose
autotuning are enabled.
* The autotuning command-line tool now uses debug-level logging with
`--verbose` and info-level logging otherwise.
* Preserved the requested log level when autotuning is enabled without
verbose mode.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
This commit is contained in:
Gwena Cunha
2026-11-13 20:48:01 +00:00
committed by GitHub
parent e169b4c2bc
commit ef893e7708
4 changed files with 74 additions and 1 deletions
@@ -19,7 +19,7 @@ import argparse
import sys
from pathlib import Path
from modelopt.onnx.logging_config import logger
from modelopt.onnx.logging_config import configure_logging, logger
from modelopt.onnx.quantization.autotune.benchmark import default_timing_cache_file
from modelopt.onnx.quantization.autotune.utils import (
DEFAULT_NUM_SCHEMES,
@@ -93,6 +93,7 @@ def run_autotune() -> int:
"""
args = get_parser().parse_args()
apply_mode_presets(args)
configure_logging("DEBUG" if args.verbose else "INFO")
args.timing_cache = args.timing_cache or default_timing_cache_file()
model_path = validate_file_path(args.onnx_path, "Model file")
validate_file_path(args.qdq_baseline, "QDQ baseline model")
+2
View File
@@ -715,6 +715,8 @@ def quantize(
"Remove --trt_plugins or select the classic TensorRT EP."
)
if autotune and autotune_verbose:
log_level = "DEBUG"
configure_logging(log_level.upper(), log_file)
logger.info(f"Starting quantization process for model: {onnx_path}")
logger.info(f"Quantization mode: {quantize_mode}")
@@ -20,6 +20,11 @@ Tests configuration parameter validation, defaults, and CLI --mode preset
selection and explicit-flag precedence.
"""
import logging
import sys
from modelopt.onnx.logging_config import configure_logging, logger
from modelopt.onnx.quantization.autotune import __main__ as autotune_cli
from modelopt.onnx.quantization.autotune.__main__ import (
MODE_PRESETS,
apply_mode_presets,
@@ -28,6 +33,23 @@ from modelopt.onnx.quantization.autotune.__main__ import (
from modelopt.onnx.quantization.autotune.common import Config
def test_verbose_cli_enables_debug_logging(monkeypatch, tmp_path):
model_path = tmp_path / "model.onnx"
model_path.write_bytes(b"")
monkeypatch.setattr(
sys, "argv", ["modelopt.onnx.quantization.autotune", "--onnx_path", str(model_path), "-v"]
)
monkeypatch.setattr(autotune_cli, "init_benchmark_instance", lambda **kwargs: None)
original_level = logger.level
configure_logging(logging.INFO)
try:
assert autotune_cli.run_autotune() == 1
assert logger.isEnabledFor(logging.DEBUG)
finally:
configure_logging(original_level)
class TestConfig:
"""Test Config class functionality."""
@@ -400,6 +400,54 @@ def test_quantize_opset_handling(
)
@pytest.mark.parametrize(
("autotune_verbose", "log_level", "expected_log_level"),
[(False, "WARNING", "WARNING"), (True, "ERROR", "DEBUG")],
)
def test_autotune_verbose_sets_quantizer_log_level(
monkeypatch, tmp_path, autotune_verbose, log_level, expected_log_level
):
quantize_module = importlib.import_module("modelopt.onnx.quantization.quantize")
onnx_path = tmp_path / "model.onnx"
onnx_path.write_bytes(b"")
captured = {}
monkeypatch.setattr(
quantize_module,
"_preprocess_onnx",
lambda *args, **kwargs: (str(onnx_path), object(), [], False, False, False, {}, {}),
)
monkeypatch.setattr(quantize_module, "_has_qdq_site", lambda *args: False)
monkeypatch.setattr(quantize_module, "validate_op_types_spelling", lambda *args: None)
monkeypatch.setattr(quantize_module, "find_nodes_from_mha_to_exclude", lambda *args: [])
monkeypatch.setattr(
quantize_module,
"_find_nodes_to_quantize_autotune",
lambda *args, **kwargs: quantize_module._AutotuneContext(
ort_config=([], [], [], []),
baseline_model=object(),
performance_threshold=1.02,
output_dir=tmp_path,
),
)
monkeypatch.setattr(
quantize_module,
"quantize_int8",
lambda **kwargs: captured.update(log_level=kwargs["log_level"]),
)
monkeypatch.setattr(quantize_module.onnx.checker, "check_model", lambda *args: None)
moq.quantize(
str(onnx_path),
calibration_data_reader=object(),
autotune=True,
autotune_verbose=autotune_verbose,
log_level=log_level,
)
assert captured["log_level"] == expected_log_level
@pytest.mark.parametrize(
("args", "expected"),
[