Skip to content

Add composite model support to build command#1058

Open
xieofxie wants to merge 2 commits into
mainfrom
hualxie/fix_composite_build
Open

Add composite model support to build command#1058
xieofxie wants to merge 2 commits into
mainfrom
hualxie/fix_composite_build

Conversation

@xieofxie

@xieofxie xieofxie commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds composite (seq2seq) model detection and fan-out to winml build, mirroring the pattern already implemented in winml export. Previously, running winml build on a composite model like Qwen3 would attempt a single-model build and fail. Now, composite models are automatically detected and each sub-component is built independently into its own subdirectory.

Changes

src/winml/modelkit/commands/build.py

  • Added _warn_partial_composite_build() helper that warns when a composite build fails mid-run, listing completed components without deleting them (same safety semantics as export's _warn_partial_composite).
  • In the single-model branch, added composite detection via resolve_composite_components with the same error handling as export:
    • ValueErrorUsageError (e.g. ambiguous composite needing explicit --task)
    • RuntimeError re-raised (empty registry guard)
    • OSError suppressed (model ref not resolvable as HF config)
    • Unexpected errors → ClickException
  • When composite is detected:
    • Rejects --use-cache (cache keys are ambiguous for multi-component builds)
    • Generates a config per component via generate_build_config(task=component_task)
    • Carries over quant/compile from the outer config (already patched by CLI overrides)
    • Runs _run_single_build per component into output_dir/<component_name>/
    • Tracks completed components for partial-failure warnings

tests/unit/commands/test_build.py

  • Added TestBuildComposite class with 6 tests:
    • Fan-out runs one _run_single_build per component into correct subdirectories
    • --use-cache rejected for composite models
    • ValueError during composite resolution surfaces as usage error
    • Unexpected errors during detection are surfaced, not masked
    • Partial build failure warns and keeps completed directories
    • Sub-model configs inherit quant/compile from outer config

Detect composite (seq2seq) models like Qwen3 and fan out into
one build per sub-component, each written to a subdirectory under
the output dir (e.g. output/decoder_prefill/, output/decoder_gen/).

- Add _warn_partial_composite_build() helper for mid-run failures
- Composite detection reuses resolve_composite_components from loader
- Per-component configs are auto-generated with generate_build_config,
  inheriting quant/compile settings from the outer config
- Reject --use-cache for composite models (cache keys are ambiguous)
- Error handling mirrors export command: ValueError -> UsageError,
  RuntimeError re-raised, OSError suppressed, unexpected -> ClickException
- Add 6 unit tests covering fan-out, --use-cache rejection, error
  surfacing, partial build warnings, and quant/compile carry-over
@xieofxie xieofxie requested a review from a team as a code owner July 6, 2026 07:11
- Remove redundant second optimizer.optimize() call in optimize_onnx()
  that caused ORT SymbolicShapeInference to segfault on Qwen3 graphs
- Make pattern matcher edge lookup graceful: return None for orphaned
  edges (missing producer after ORT graph optimization) instead of
  asserting, so pattern matching skips unresolvable edges cleanly
- Update tests to match new behavior
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