Skip to content

test: direct unit suite for quantization core_utils (128 tests)#1904

Closed
arham766 wants to merge 1 commit into
NVIDIA:mainfrom
arham766:tests/test-core-utils
Closed

test: direct unit suite for quantization core_utils (128 tests)#1904
arham766 wants to merge 1 commit into
NVIDIA:mainfrom
arham766:tests/test-core-utils

Conversation

@arham766

@arham766 arham766 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: new tests

Part of the unit-coverage initiative in #1902 (one PR per module; this one is self-contained). Covers: reduce_amax/reduce_sum/reduce_block_amax/reduce_block_padding numerics (hand-derived expectations incl. FP8 upcast, non-divisible assertions, content-preserving padding), quantizer attr-name helpers, quantized-module predicates, all CPU-testable context managers incl. exception-safety contracts, quantizer state dict round-trip, MoE expert amax sync math, NVFP4 static promotion, kv-cache config update non-mutation.

Usage

N/A — tests only.

Testing

Suite is hermetic (CPU-only, no network, deterministic, <3s) and passes locally; the full collectable tests/unit tree passes with it (1999 passed). The suite was adversarially reviewed and verified to kill seeded mutations of the target module (details in #1902).

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?: N/A
  • Did you get Claude approval on this PR?: N/A (external contributor)

Additional Information

Issue: #1902

Summary by CodeRabbit

  • Tests
    • Added broad unit test coverage for quantization utilities, including reduction helpers, block-wise padding, axis conversion, and quantizer/module inspection helpers.
    • Validated state capture and restore behavior, along with context-manager toggles for quantization, calibration, gradients, and export mode.
    • Added checks for KV-cache quantization updates, MoE amax syncing, NVFP4 quantizer promotion, and expected behavior when values are missing or exceptions occur.

Hermetic CPU-only unit tests; adversarially reviewed and verified to
kill seeded mutations of the target module. Part of the coverage
initiative in NVIDIA#1902.

Signed-off-by: arham766 <arhamislam766@yahoo.com>
@arham766 arham766 requested a review from a team as a code owner July 5, 2026 20:10
@copy-pr-bot

copy-pr-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b6cc2cfb-001c-48f6-b1b1-254df9fb51cf

📥 Commits

Reviewing files that changed from the base of the PR and between b96a785 and 747fc94.

📒 Files selected for processing (1)
  • tests/unit/torch/quantization/test_core_utils.py

📝 Walkthrough

Walkthrough

This PR adds a single new unit test module, tests/unit/torch/quantization/test_core_utils.py, providing CPU-testable coverage for modelopt.torch.quantization.utils.core_utils, including reduction math, quantizer predicates/attribute helpers, adapter and context-manager utilities, FSDP contracts, MoE/KV-cache config helpers, and NVFP4 quantizer promotion. No public entities are altered.

Changes

Core utils test suite

Layer / File(s) Summary
Fixtures and helpers
tests/unit/torch/quantization/test_core_utils.py
Adds module docs and shared fixtures/helpers (FSDP2 param-group access, quantized model/expert fixtures) used across the suite.
Reduction and axis-conversion tests
tests/unit/torch/quantization/test_core_utils.py
Tests reduce_amax, reduce_sum, convert_quantization_axis_to_reduce_axis, reduce_block_amax, and reduce_block_padding for shape, dtype, gradient, and edge-case behaviors.
Attribute naming and predicate tests
tests/unit/torch/quantization/test_core_utils.py
Tests quantizer_attr_names, representative_weight_quantizer, weight_attr_names, and is_quantized*/parallel-linear predicates.
Adapter and context-manager tests
tests/unit/torch/quantization/test_core_utils.py
Tests calibrate_with_adapters, disable_lora_quantizers_in_config, replace_function, multi_context, export_torch_mode, is_pow2, enable_quant/disable_calib, enable_fake_quant, and no_requires_grad, including exception-path restoration behavior.
Module naming and quantizer state-dict tests
tests/unit/torch/quantization/test_core_utils.py
Tests _set_parameter, _get_module_name, _get_enclosing_fsdp_module, get_prefixed_param_names, and get_quantizer_state_dict/set_quantizer_state_dict round-trip and skip behavior.
FSDP, MoE/KV-cache, and NVFP4 promotion tests
tests/unit/torch/quantization/test_core_utils.py
Tests FSDP2 mp-dtype patch/restore contracts, update_quant_cfg_with_kv_cache_quant, sync_moe_expert_amax, and promote_nvfp4_static_quantizers promotion/skip/idempotency behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: a direct unit test suite for quantization core_utils.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns ✅ Passed Only a new test file changed; scan found no torch.load/numpy.load/trust_remote_code/eval/exec/# nosec or dependency additions.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@arham766

arham766 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Consolidated into #1927 per maintainer feedback in #1902 — the suite was trimmed to only the lines codecov reports uncovered, with parametrization clusters deduplicated. Closing in favor of that PR.

@arham766 arham766 closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant