test: direct unit suite for opt config_loader (106 cases)#1914
test: direct unit suite for opt config_loader (106 cases)#1914arham766 wants to merge 2 commits into
Conversation
Hermetic unit tests for the config loading/import machinery via a
synthetic schema module injected under a private modelopt name
(registered/removed per test; the real-schema integration surface is
owned by tests/unit/recipe/test_loader.py, and the duplication is
layered unit-vs-integration by design). Covers ExMy parsing, path
probing and local-shadows-builtin precedence, multi-document merging,
$import replace/extend/inline-override/later-wins/cycle rules with
exact error messages, schema resolution diagnostics, and typing
helpers. Adversarially reviewed: 16 expectations re-derived, 7/7
seeded mutations killed - including a merge-order flip the recipe
suite's non-conflicting-keys test would not catch.
Also documents (NOTE test) that a null first YAML document followed by
a list body silently loads as {}, discarding the body.
Part of the coverage initiative in NVIDIA#1902.
Signed-off-by: arham766 <arhamislam766@yahoo.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds a comprehensive unit test suite for ChangesConfig loader test suite
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested labels: tests, torch, opt Suggested reviewers: none identified 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unit/torch/opt/test_config_loader.py (1)
244-250: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTests couple to real built-in config content.
test_resolve_config_path_builtin_libraryandtest_load_raw_config_builtin_traversableassert on the actual shippedconfigs/numerics/fp8.yamlcontents (e.g.,{"num_bits": (4, 3), "axis": None}). An unrelated future edit to that built-in config's values would break these unit tests even though the path-resolution/loading logic under test is unaffected. Consider writing a temporary file underBUILTIN_CONFIG_ROOT(or monkeypatching that constant to a tmp directory) to fully decouple from production config content.Also applies to: 423-428
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/torch/opt/test_config_loader.py` around lines 244 - 250, The config loader tests are tied to the shipped built-in fp8 config content instead of only validating path resolution/loading behavior. Update test_resolve_config_path_builtin_library and test_load_raw_config_builtin_traversable to use a temporary built-in config tree by writing a test file under BUITIN_CONFIG_ROOT or monkeypatching that constant, and assert against the test fixture content rather than the real configs/numerics/fp8.yaml values. Keep the checks focused on _resolve_config_path and _load_raw_config behavior so future production config edits do not break these unit tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/unit/torch/opt/test_config_loader.py`:
- Around line 244-250: The config loader tests are tied to the shipped built-in
fp8 config content instead of only validating path resolution/loading behavior.
Update test_resolve_config_path_builtin_library and
test_load_raw_config_builtin_traversable to use a temporary built-in config tree
by writing a test file under BUITIN_CONFIG_ROOT or monkeypatching that constant,
and assert against the test fixture content rather than the real
configs/numerics/fp8.yaml values. Keep the checks focused on
_resolve_config_path and _load_raw_config behavior so future production config
edits do not break these unit tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 37b96803-9f8c-4b1e-b0cf-393ea9656bad
📒 Files selected for processing (1)
tests/unit/torch/opt/test_config_loader.py
…ippet Signed-off-by: arham766 <arhamislam766@yahoo.com>
What does this PR do?
Type of change: new tests
Part of the unit-coverage initiative in #1902. Direct unit suite (106 cases) for modelopt/torch/opt/config_loader.py — the config loading/$import machinery. Design: a synthetic schema module is injected under a private modelopt.* name per-test (registered as the last setup statement, popped in teardown), keeping the suite hermetic and independent of the quantization stack; real-schema integration remains owned by tests/unit/recipe/test_loader.py — the overlap is deliberately layered (unit vs integration), and mutation testing showed the unit versions are sharper (a header/content merge-order flip is caught here but not by the recipe suite's non-conflicting-keys test).
Covers: ExMy num_bits/scale_bits parsing rules; path resolution (.yml-before-.yaml probe order, local-shadows-builtin precedence, error paths); modelopt-schema comment parsing; multi-document YAML merging (content-wins) and list snippets; $import resolution (replace/extend/inline-override precedence, later-wins, recursion, cycle/self-import detection) with exact error-message assertions; schema-resolution diagnostics incl. the initializing-module circular-import message; typing helpers (_unwrap_schema_type, _list_element_schema union ambiguity, _child_schema).
Bug documented in-test (NOTE comment; one-line fix available if preferred as a follow-up): a file whose first document is an explicit null followed by a list body (null / --- / - item) silently loads as {} — the docs[0] is None early-return fires before the two-document branch (config_loader.py:196), silently discarding the body.
Usage
N/A — tests only.
Testing
106 cases, ~1s, hermetic (tmp_path, no network, deterministic, Windows/Linux-safe paths). Adversarial review: 16 expectations independently re-derived from source, 7/7 seeded mutations killed, no vacuous tests, no sys.modules leak (teardown verified to run on failure; name collision-checked against the real package).
Before your PR is "Ready for review"
Additional Information
Issue: #1902
Summary by CodeRabbit
$importbehaviors (precedence, nested merging, list/dict splicing) plus clear error reporting for unknown, missing, invalid, or circular imports.