Skip to content

feat(build): output analyze_result.json; fix --device npu config validation#673

Merged
DingmaomaoBJTU merged 2 commits into
mainfrom
qiowu/analyze-result-json-and-patch-device-fix
May 19, 2026
Merged

feat(build): output analyze_result.json; fix --device npu config validation#673
DingmaomaoBJTU merged 2 commits into
mainfrom
qiowu/analyze-result-json-and-patch-device-fix

Conversation

@DingmaomaoBJTU
Copy link
Copy Markdown
Collaborator

Summary

Details

analyze_result.json

  • analyze_onnx() gains an output_path parameter; when set, it writes AnalysisResult.to_json() to disk after each call
  • run_optimize_analyze_loop / _run_analyze_loop thread analyze_output_path through to every analyze_onnx() call
  • build/hf.py, build/onnx.py, and the CLI's _run_optimize_stage all supply analyze_result_path

_patch_device regression fix

_patch_device was replacing the entire cfg.quant object with the result of resolve_quant_compile_config(), which only carries weight_type/activation_type. This silently dropped task and model_name that generate_build_config() had already set, causing validation to fail for any device that requires quantization (i.e. NPU).

Fix: when an existing quant config is present, only update the precision fields instead of replacing the whole object.

# Before
cfg.quant = resolved_quant  # drops task, model_name

# After
if resolved_quant is None:
    cfg.quant = None
elif cfg.quant is None:
    cfg.quant = resolved_quant
else:
    cfg.quant.weight_type = resolved_quant.weight_type
    cfg.quant.activation_type = resolved_quant.activation_type

…evice dropping quant.task/model_name

### analyze_result.json output
- Add `output_path` param to `analyze_onnx()`: writes full `AnalysisResult`
  JSON after each call, each overwriting the previous
- Thread `analyze_output_path` through `run_optimize_analyze_loop` /
  `_run_analyze_loop` in `build/common.py`
- `build/hf.py` and `build/onnx.py` define `analyze_result_path` and
  pass it to the loop
- `commands/build.py` `_run_optimize_stage` accepts and forwards
  `analyze_output_path`; `_build_hf_pipeline` / `_build_onnx_pipeline`
  supply the path

### fix: _patch_device regression (introduced in ed7dbfd, #477)
When `--device` was explicitly provided on the CLI, `_patch_device`
replaced the entire `cfg.quant` object with a fresh
`WinMLQuantizationConfig` that only carried `weight_type` /
`activation_type`, silently dropping `task` and `model_name` that
`generate_build_config` had already populated. This caused
`winml build -m <model> --device npu` to always fail validation.

Fix: only update precision fields when an existing quant config is
present; fall back to assignment only when there was none.
@DingmaomaoBJTU DingmaomaoBJTU requested a review from a team as a code owner May 19, 2026 08:34
Comment thread tests/unit/build/test_hf.py Fixed
Comment thread tests/unit/build/test_hf.py Fixed
@DingmaomaoBJTU DingmaomaoBJTU merged commit 680cc32 into main May 19, 2026
9 checks passed
@DingmaomaoBJTU DingmaomaoBJTU deleted the qiowu/analyze-result-json-and-patch-device-fix branch May 19, 2026 09:08
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.

3 participants