feat(loader): support published ONNX SAM composites#1136
Conversation
|
Explainer re-entry complete for model 5 only at current head Reviewer blockers are reflected in the durable PR body:
The PR remains draft with |
APPROVE — independent re-review (model 5 only)Reviewed exact PR head State, conversation, and checks
Seven prior blockers
Prior full evidence revalidatedThe prior independent evidence remains applicable because the four recipes and runtime implementation are unchanged by the remediation commit. It includes fresh 4/4 builds with Engineering review of the remediation found no new concern: graph-family matching remains contract-driven and model-ID-independent, ambiguity now fails closed, malformed graph sets still fail, and native-PyTorch fallback remains limited to the no-published-ONNX case. Verdict: APPROVE. Preserve Draft. |
Summary
Adds generalized support for published ONNX-only SAM composites, exercised on
Xenova/slimsam-77-uniformfor CPUmask-generationin fp32 and fp16. The L2 effort ships reusable two-graph discovery/build/eval support plus four component recipes; Goal L3 passed on both precision tuples. Current head487ff8a7ed976e28b9b2625acdd69a8346cb6c0ealso makes graph-pair selection fail closed when multiple equally preferred pairs are valid, adds genuine ambiguity/family-preference tests, and restores whole-package mypy.Model metadata
What the model does
SlimSAM is a promptable image-segmentation model: a user supplies a 1024-pixel-normalized RGB image plus spatial prompts, and the composite image encoder and prompt/mask decoder return three candidate masks with predicted IoU scores. Confidence: verified from the pinned model card and config.
Primary user stories
Supported tasks
mask-generation: checkpoint, Transformers, and WinML — verified.feature-extraction: Optimum ONNX and WinML — verified.Model architecture
5850ab45f587c112167512ffef949107115e26a0.Validation and support evidence
1. Baseline
Pinned baseline: winml-cli
e7509b1e908c74beff0a5655b8f8d7de69c5afae, WinML CLI0.2.0.5850ab45f587c112167512ffef949107115e26a0. It is ONNX-only and has no PyTorch weights.9f8433273a6750b587779baa0cf5508111001bf7e7acfcf585d370139fd366d0; prompt decoderf4514391764fbd56e08e119060d874ecd7d52994bfb1968af159e12d4943b5bb.feature-extraction; after WinML registration =feature-extraction,mask-generation; classification =VENDOR+OVERRIDE.winml config --task mask-generationexited 0, and inspect resolvedmask-generation/SAMMaskGeneration/SamMaskGenerationIOConfig.17.489 s, emitted no ONNX artifact, and reportedModel class 'SAMMaskGeneration' not found for task 'feature-extraction'. Build had fallen back tofeature-extractiondespite inspect/config resolvingmask-generation.1063.618/1055.979 ms(0.94 samples/s); one-point decoder mean/p5026.607/26.708 ms(37.58 samples/s).input_boxes; published fp16 graphs failed ORT initialization with a float/float16 Cast mismatch.2. Goal
No charter downgrade was issued.
3. Outcome
487ff8a7.5 passed; whole-package mypySuccess: no issues found in 403 source files; broad relevant suite1577 passed; four recipe builds4/4 PASSwithBuild complete,model.onnx, andwinml_build_config.json. All current GitHub checks pass, including lint, CodeQL, and all CI test partitions.c836baf13860a5ac02124284a6a3c6a7e2f9f574229219ac5aa7bd0312ac35b6at current head: terminal PASS; refreshed four builds plus bounded fp32 L1–L3 spot checks preserved artifact selection and execution contracts. Rebuilt bytes differ only by an unusedcom.microsoft.dmlopset import; graph I/O, node contracts/attributes, initializer values, IR, and used domains are execution-equivalent.7da173de, and clarification commitfc7c1165. These recordsam-001…sam-006,_meta-082, direct-ONNX evidence, and durable feature-gapFILE:references.Methodology friction observed: _meta-082 added.
Direct-ONNX HTP evidence
All four resolved build configs retain
export=null. Direct published-ONNX ingestion bypassesHTPExporter, so each artifact recordshtp_metadata=NOT_PRODUCED_DIRECT_ONNXandmetadata_exists=false; HTP parameter/module/trace counts are not fabricated. Substitute evidence is the pinned configuration/source architecture, exact graph I/O, topology, and node-scope component mapping.NOT_PRODUCED_DIRECT_ONNX1782nodes;vision_encoder;pixel_values→ image/positional embeddingsNOT_PRODUCED_DIRECT_ONNX810nodes;prompt_encoder,mask_decoder; points/labels + embeddings → IoU/masksNOT_PRODUCED_DIRECT_ONNX1785nodes; same graph boundary after WinML fp16 conversionNOT_PRODUCED_DIRECT_ONNX815nodes; same graph boundary after WinML fp16 conversionDurable feature-gap references:
FILE: copilot-skills/dev_skill/adding-model-support/agents/learner.md— direct-ONNX HTP evidence exception.FILE: copilot-skills/dev_skill/adding-model-support/agents/reviewer.md— direct-ONNX HTP review branch.FILE: src/winml/modelkit/commands/perf.py— expose graph-optimization/session options for converted SAM fp16 graphs requiringORT_DISABLE_ALL.FILE: copilot-skills/dev_skill/adding-model-support/agents/tester.md— preserve the pinned published fp32 pair as the L2 reference when the exact revision has no PyTorch weights; collect capable-host runtime evidence before promoting static EP rows.4. Per-EP/device/precision results — including perf and eval data
Goal ladder
ORT_DISABLE_ALLComposite perf (CPU, 3 warmups, 20 measured iterations)
1219.4138750011916 ms1213.7237499991897 ms1243.2789499987848 ms0.8200661157796181 samples/s1187.7435800022795 ms31.67029499891214 ms1584.7703800012823 ms1572.3618500051089 ms1608.407509996323 ms0.6310062407900322 samples/s1545.1620049978374 ms39.60837500344496 msL2 numeric comparison against the exact published fp32 pair
1.01.00.99999999999994870.99999999958871730.99302523960058210.99650041541831370.99999984994615530.9998631504023249L3 task evaluation
Dataset:
mattmdjaga/human_parsing_dataset, revisiondb120bb5c18c146a8fbd2160f7575a288269fe7d, splittrain, first five deterministic valid rowssample_0000..sample_0004, no shuffle, no streaming, seed42,prompt_mode=point.0.400135561732738950.52350868942095455 / 00.399185800131269250.52291506621344835 / 0-0.0009497616014697; Dice-0.0005936232075062fp16 ORT caveat: default ORT session creation fails for both components;
ORT_DISABLE_ALLpasses for both. Standardwinml perfexits 2 without JSON. Exact error:Attempting to get index by a name which does not exist: InsertedPrecisionFreeCast_/vision_encoder/layers.3/layer_norm1/Constant_output_0 for node /vision_encoder/layers.0/layer_norm1/Mul/SimplifiedLayerNormFusion/. Under the passing policy, fp16 is slower than fp32 on this CPU.5. Delta
Four new CPU/cpu component recipes:
quant.mode=fp16andfp16_keep_io_types=true; WinML converts the exact fp32 sources because the published fp16 variants are not runnable.Generalized source delta:
Current scope:
21 files,899 insertions,55 deletions— 4 recipes, 11 production Python files, and 6 unit-test files. The production recipe README is untouched.6. Analyze summary — component level and op level
ANALYZE-PARTIAL-SUCCESS: all four processes exited 1 because unavailable host EP plugins could not register, but each emitted valid fail-closed JSON for all 11 requested EP/device targets. This is static rules analysis, not measured runtime support; every static row records
runtime_support=false, and only CPU composite execution was measured.Component-level summary
1775 mapped / 7 unmappedMod, Reshape, Transpose; OpenVINO partial/unsupported arithmetic/casts809 mapped / 1 unmappedMul, Div1775 mapped / 10 unmapped809 mapped / 6 unmappedOp-level summary
1782 ops / 26 typesUnsqueeze 245; Add 201; Mul 166810 ops / 32 typesGather 137; Unsqueeze 124; Add 93Mul/Divunsupported; five rule-less targets all unknown1785 ops / 26 typesUnsqueeze 245; Add 201; Mul 166815 ops / 32 typesGather 137; Unsqueeze 124; Add 93Rules:
v0.2.0, archive SHA-2566dcabbe7f5493fbc2bd23de195ab6e35b3578d510f18c2e220bc5538a1f232cc,1746parquet files.7. Reproduce commands