Files
Model-Optimizer/tests/_test_utils
gcunhaseandmodelopt-fix-agent-bot faa6b80980 tests: restructure sensitivity suite into a sub-package; address reviewer feedback
Restructure
===========

Mirror the ``autotune/`` test-suite layout for the new sensitivity
sub-package:

    tests/
    ├── _test_utils/onnx/quantization/sensitivity/
    │   └── models.py                    (shared builders + fixtures)
    ├── unit/onnx/quantization/sensitivity/
    │   ├── test_metrics.py              (new; direct kl_div / mse / cos)
    │   └── test_picker.py               (moved from test_sensitivity_picker.py)
    └── gpu/onnx/quantization/sensitivity/
        └── test_score.py                (all synthetic + CoAtNet tiers)

Files deleted:

* ``tests/gpu/onnx/quantization/test_sensitivity.py`` -- content
  redistributed into the sub-package.
* ``tests/unit/onnx/quantization/test_sensitivity_picker.py`` -- moved
  into ``tests/unit/onnx/quantization/sensitivity/test_picker.py``.
* ``tests/unit/onnx/quantization/test_nodes_to_quantize.py`` -- merged
  into ``tests/unit/onnx/quantization/test_quantize_api.py`` as
  ``test_quantize_honors_nodes_to_quantize_allowlist``.  See "reviewer
  feedback" below.

Placement caveat noted by the reviewer under
``CUDA_VISIBLE_DEVICES=""``: the synthetic scorer tests reach
``trt.Builder()`` inside ``quantize()``'s preprocessing even with
``calibration_eps=["cpu"]``, so they belong in the GPU lane despite
using CPU inference.  Kept them in ``tests/gpu/`` accordingly.

The four synthetic-graph tests keep ``calibration_eps=["cpu"]`` for
deterministic scoring; the two CoAtNet tests use
``calibration_eps=["cuda:0", "cpu"]`` and are gated by
``@pytest.mark.slow`` / ``@pytest.mark.slow_gpu``.

Reviewer feedback: :pr:`comment:3846986854` (blocks + metrics tests)
==================================================================

* ``TestBlocks`` in ``test_picker.py`` (7 methods) pins ``blocks=`` /
  ``block_agg=`` semantics: first-match-wins across iteration order,
  singleton-group fallback for unmatched nodes, sum / max / mean
  aggregation, ``ValueError`` on invalid ``block_agg``, union-of-members
  return, and the ``threshold=0.1, block_agg="max"`` ≡
  ``coverage=1.0, max_nodes=6, block_agg="sum"`` equivalence claim from
  the RST guide.
* ``test_metrics.py`` covers ``kl_div`` / ``mse`` / ``cos_dist``
  identity, orthogonal / anti-parallel vectors, scale sensitivity
  differences, and ``_flatten_per_sample`` 0-D / 1-D / 4-D handling.

Reviewer feedback: :pr:`comment:3846986859` (CLI DRY / size guard)
=================================================================

Addressed in the source-side commit above; this commit only removes the
now-unused fixture references.

Reviewer feedback: :pr:`comment:3846986865` (Tier placement + stale
comment)
==================================================================

* Sensitivity tests moved into ``sensitivity/`` sub-packages under
  ``tests/unit/`` and ``tests/gpu/``.
* Dropped the stale ``_SYNTHETIC_OP_SCOPE`` rationale comment
  (referenced ``get_autotuner_quantizable_ops()``, which
  ``_default_op_types_scope()`` replaced).

Reviewer feedback (:pr:`review:5053256813` by @ajrasane)
=======================================================

* ``test_nodes_to_quantize.py`` moved into
  ``test_quantize_api.py`` as
  ``test_quantize_honors_nodes_to_quantize_allowlist``.  The bespoke
  2-Conv builder and ``_has_dq_predecessor`` helper replaced with
  ``build_conv_concat_model()`` (4-Conv, channel-safe) and
  ``assert_nodes_are_quantized()`` from ``_test_utils``.  Net delta on
  the deleted file / new function: -136 LOC.
* ``TestNearTieWarning`` fixtures shrunk from 20 scores to 4 while
  preserving the cutoff behavior (verified numerically:
  ``{a:6.0, b:3.06, c:3.05, d:0.1}`` at ``coverage=0.75`` cuts between
  b and c; ratio 3.05/3.06 = 0.9967 > default 0.99 -> warning fires).
* Assertions in ``TestNearTieWarning`` switched from
  ``[r.message for r in caplog.records]; assert any(...)`` to
  ``assert "..." in caplog.text``.
* ``TestCoverageMode.test_full_coverage_returns_all_nodes`` +
  ``test_returns_sorted_by_kl_desc`` folded into a parametrized
  ``test_full_coverage_returns_all_sorted_by_score_desc``.
* Three empty / zero cases folded into a single parametrized
  ``test_returns_empty_for_boundary_cases``.
* ``test_synthetic_deterministic_ln_highest`` now shares a
  module-scoped ``synthetic_onnx_path`` fixture (``tmp_path_factory``)
  across the three ``kl_div`` / ``mse`` / ``cos`` parametrizations
  instead of rebuilding the ONNX once per case.
* Dropped redundant ``assert scores`` and ``assert_ln_over_conv(scores)``
  in ``test_synthetic_deterministic_ln_highest`` -- the
  ``top_op == "LayerNormalization"`` assertion already implies both.
* Collapsed ``top_k = 10; bottom_k = 10`` into a single ``k = 10`` in
  ``test_coatnet_per_node_matches_manual_groundtruth``.

Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
Co-Authored-By: modelopt-fix-agent-bot (Opus 4.7) <noreply@anthropic.com>
2026-09-01 00:54:40 +00:00
..