mirror of
https://github.com/NVIDIA/Model-Optimizer.git
synced 2026-11-01 07:53:10 +08:00
metrics.py -- cos_dist asymmetric zero handling ============================================== Follow-up on the earlier ``np.where(norm > 0, ..., 1.0)`` fix (commit 21675561): guarding on the product ``p_norm * q_norm`` conflates "both vectors zero" (semantically identical, distance 0) with "only one vector zero" (not identical, orthogonal, distance 1). Under the previous code, a probe whose reference output was non-zero but whose quantized output collapsed to zero (or vice-versa) would score as maximally similar rather than maximally sensitive. Fix: compute ``p_norm`` and ``q_norm`` separately, use a ``both_zero = (p_norm == 0) & (q_norm == 0)`` mask, and only substitute the "identical" 1.0 when both are zero. All other zero-norm cases fall through to the dot / (p_norm * q_norm + _EPS) path, which correctly yields 0 / eps -> 0 (distance 1). Added ``test_asymmetric_zero_vectors_return_max_distance`` in ``test_metrics.py`` as a regression witness. Verified all six cases locally: both zero -> 0, asymmetric zero (either direction) -> 1, parallel non-zero -> 0, orthogonal -> 1, anti-parallel -> 2. __main__.py -- glob at module scope =================================== Moved ``import glob`` from inside ``_validate_calibration_dir`` to the module-level import block. ``glob`` is a lightweight stdlib module with no exception for local placement, and CONTRIBUTING.md requires imports at the top of the file. test_score.py -- CoAtNet quantitative assertion =============================================== ``test_coatnet_op_type_matches_manual_groundtruth`` claims in its docstring that the top-4 ops (Add / Mul / LayerNormalization / ReduceMean) each score above ``1.5`` KL, but the assertions only verified membership in the top-4 plus ``Conv < 0.5``. Added ``assert all(scores[name] > 1.5 for name in expected_top4)`` to pin the quantitative claim so a regression that keeps the top-4 ordering but collapses their absolute scores (e.g., a calibration path change that loses signal magnitude) surfaces here rather than silently. Related CodeRabbit findings still open in review threads ======================================================== * ``score.py`` log target-names: kept per the reasoning-and-precedent reply on that thread (target names are load-bearing for the primitive's primary purpose; ``moq.quantize()`` and ``configure_ort`` log the same at INFO). * ``__main__.py`` uncompressed NPZ size bound: deferred to a follow-up hardening PR (the check needs to live in ``_load_calibration_from_path`` to cover both CLI and direct-caller paths, expanding the primitive's public-API failure surface). Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com> Co-Authored-By: modelopt-fix-agent-bot (Opus 4.7) <noreply@anthropic.com>