Fix CLI option / config file value priority across commands#720
Merged
Conversation
ssss141414
approved these changes
May 25, 2026
xieofxie
reviewed
May 25, 2026
zhenchaoni
commented
May 25, 2026
xieofxie
reviewed
May 25, 2026
xieofxie
approved these changes
May 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #721
Problem
Commands accepting both CLI options and a
-c/--configJSON file were leaking dataclass defaults into CLI behavior. When a JSON section was empty (or absent),WinMLBuildConfig.from_dict(json)populated missing keys with dataclass field defaults, and the merge logic could not distinguish "user explicitly set this in JSON" from "dataclass picked the default". The dataclass default then silently overrode the CLI option's default.Concrete user-visible bugs:
winml eval -c config.jsonwith{"compile": {}}forcedcfg.ep = "qnn"regardless of the host's available EPs (would crash on Linux / non-Qualcomm Windows).winml eval -c config.jsonwith{"quant": {}}silently reduced the eval dataset to 10 samples (calibration default) instead of the CLI default 100.{"quant": {"samples": N, "dataset_name": ...}}, those calibration values bled into the eval dataset config — two unrelated concepts conflated.Fix
Establish a single uniform priority-merge pattern across all 6 commands (
compile,perf,analyze,export,quantize,eval):Reads only raw JSON keys, so missing keys are distinguishable from dataclass defaults by design.
Changes per file:
utils/cli.py—load_build_confignow returns(build_cfg, raw_dict).commands/compile.py,perf.py,analyze.py,quantize.py— switched merge blocks to raw-dict reads.commands/export.py— same merge-block fix, plus replaced_build_export_cfg.to_dict()(which leaked dataclass defaults intoconfig_kwargs) with a rawexportsection.commands/eval.py— same merge-block fix forcfg.taskandcfg.ep, plus removed the "quant fields as fallback" block entirely:quant.samples/quant.dataset_nameare calibration knobs and must not bleed into the eval dataset config. Users wanting eval-side overrides should use{"eval": {"dataset": {...}}}.Tests
New file
tests/unit/commands/test_config_value_priority.py(replaces the oldertest_cli_config_precedence.py) defines a structured 4-tier priority contract and exercises it across all 6 commands:FieldCase-parametrized tests + 7 targeted regression guards = 39 testsWinMLCompileConfig/BenchmarkConfig/WinMLExportConfig/WinMLQuantizationConfig/WinMLEvaluationConfigat the boundary where the command body hands off to business logic.Each bug fix was driven TDD-style: tests written first, observed failing on pre-fix code, then turning green with the fix.
Migration note
{"quant": {"samples": N}}in a config file no longer affectswinml eval's dataset size. Use{"eval": {"dataset": {"samples": N}}}for eval-side overrides. (Calibration-only knobs inquantremain valid for build pipelines.)