Skip to content

Fix CLI option / config file value priority across commands#720

Merged
zhenchaoni merged 5 commits into
mainfrom
private/zhenni/fix_config_default
May 25, 2026
Merged

Fix CLI option / config file value priority across commands#720
zhenchaoni merged 5 commits into
mainfrom
private/zhenni/fix_config_default

Conversation

@zhenchaoni
Copy link
Copy Markdown
Member

@zhenchaoni zhenchaoni commented May 25, 2026

Fixes #721

Problem

Commands accepting both CLI options and a -c/--config JSON 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.json with {"compile": {}} forced cfg.ep = "qnn" regardless of the host's available EPs (would crash on Linux / non-Qualcomm Windows).
  • winml eval -c config.json with {"quant": {}} silently reduced the eval dataset to 10 samples (calibration default) instead of the CLI default 100.
  • Even with explicit {"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):

_, raw_cfg = cli_utils.load_build_config(config_file)
section = raw_cfg.get("section") or {}
if not cli_utils.is_cli_provided(ctx, "opt") and "key" in section:
    opt = section["key"]

Reads only raw JSON keys, so missing keys are distinguishable from dataclass defaults by design.

Changes per file:

  • utils/cli.pyload_build_config now 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 into config_kwargs) with a raw export section.
  • commands/eval.py — same merge-block fix for cfg.task and cfg.ep, plus removed the "quant fields as fallback" block entirely: quant.samples / quant.dataset_name are 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 older test_cli_config_precedence.py) defines a structured 4-tier priority contract and exercises it across all 6 commands:

  • T1 CLI explicit > T2 JSON explicit > T3 CLI default > T4 dataclass default (T4 must not shadow T3)
  • 32 FieldCase-parametrized tests + 7 targeted regression guards = 39 tests
  • Adapters per command capture the effective WinMLCompileConfig / BenchmarkConfig / WinMLExportConfig / WinMLQuantizationConfig / WinMLEvaluationConfig at 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 affects winml eval's dataset size. Use {"eval": {"dataset": {"samples": N}}} for eval-side overrides. (Calibration-only knobs in quant remain valid for build pipelines.)

@zhenchaoni zhenchaoni requested a review from a team as a code owner May 25, 2026 07:08
Comment thread src/winml/modelkit/commands/perf.py
Comment thread tests/unit/eval/test_eval.py
Comment thread src/winml/modelkit/commands/eval.py
@zhenchaoni zhenchaoni merged commit 30c3100 into main May 25, 2026
13 of 14 checks passed
@zhenchaoni zhenchaoni deleted the private/zhenni/fix_config_default branch May 25, 2026 09:11
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.

Dataclass defaults silently override CLI option defaults when -c/--config is used

3 participants