feat(loader): support Qualcomm Segment Anything Model 2#1166
Draft
ssss141414 wants to merge 5 commits into
Draft
feat(loader): support Qualcomm Segment Anything Model 2#1166ssss141414 wants to merge 5 commits into
ssss141414 wants to merge 5 commits into
Conversation
Contributor
Author
Reviewer-blocker follow-up — re-review requestedThe Draft PR body and evidence are refreshed for head
Fresh tester-r2 evidence remains L3 PASS for CPU fp32/fp16: semantic runtime, publisher parity, and pinned two-sample eval were rerun. Analyze is explicitly hash-reused only because all analyzed Please re-review this exact head. The PR intentionally remains Draft and retains |
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.
Summary
This L2 contribution adds class-wide support for release-asset ONNX composites and uses it to build and run
qualcomm/Segment-Anything-Model-2as a prompt-bearing image encoder plus embedding-only mask decoder. It ships four exact CPU recipes covering fp32/fp16 encoder and decoder artifacts, with no model-ID hardcoding. Fresh tester-r2 evidence at448b3508740f1e3b7fc4bb0c004af6020cad9a8breached L3 PASS with full planned CPU fp32/fp16 coverage. Static analysis remains ANALYZE-PARTIAL-SUCCESS: its prior complete results are reused only because every analyzed model payload has the same SHA-256 at the repaired head.Model metadata
What the model does
Qualcomm's SAM 2.1 tiny release is a promptable image-segmentation pipeline: it accepts a 1024 x 1024 RGB image plus positive/negative point prompts, computes reusable image and prompt embeddings, and returns a low-resolution binary-mask logit map with an estimated mask quality score. Confidence: verified.
Evidence: the pinned model card identifies SAM 2 and
sam2.1_hiera_t; Qualcomm AI Hub Models v0.58.0 definesSAM2Encoder.forward(image, norm_coords, labels)andSAM2Decoder.forward(image_embeddings, high_res_features1, high_res_features2, sparse_embedding); the exact published float graphs expose that encoder/decoder boundary and returnmasksasFLOAT[1,1,256,256]plusscoresasFLOAT[1,1].Primary user stories
1=positive,0=negative, and-1=no prompt. Confidence: verified.encoder.onnxanddecoder.onnxwith matchingimage_embeddings,high_res_features1,high_res_features2, andsparse_embeddingboundaries. Confidence: mapped.Supported tasks
pipeline_tag=image-segmentation, and Qualcomm metadata classifies the use case as semantic segmentation. Confidence: verified.facebook/sam2.1-hiera-tinyfamily is a Transformers mask-generation model; WinML already registerssam2/sam2_videomask generation, but frozen main cannot resolve this config-less Qualcomm release as that family. Confidence: mapped.Model architecture
3b3d83fb21782fac65b75464e4f9e118be835534, exact release graph I/O, ONNX checker, and CPU Runtime execution. The exported-component mapping is mapped, not cryptographically source-to-graph verified; runtime pre/postprocessing boundaries are verified.Validation and support evidence
Baseline
microsoft/winml-climain4daf0f19097d03e92aeb3c4f9713b7d037e0be3d,winml, version 0.2.0.config.json/model_type:Unrecognized model ... should have a model_type key in config.json.image,unnorm_coords, andlabels; it expected only an image input orpixel_values. No baseline task metric is claimed.Goal
Outcome
examples/recipes/qualcomm_Segment-Anything-Model-2/cpu/cpu/, plus generalized release-asset/composite loader, build/config, evaluation, task, SAM, and pattern-analysis changes with tests.sam-007throughsam-010;sam-011required no claim change because all recipe hashes remain identical._meta-091and_meta-087were refreshed separately in Lane A Draft PR gim-home/ModelKitArtifacts#170; no skill files are included here.Per-EP/device/precision results — including perf and eval data
Goal ladder
L1 semantic composite runtime — CPUExecutionProvider
Two warmups and ten measured iterations. The route sends
image,unnorm_coords, andlabelsinto the encoder, then routes the four named embeddings into the decoder.On this CPU, fp16 was 18.6869% slower by mean, 17.2138% slower by p50, 15.7447% lower in throughput, and used 258.046875 MB (38.9700%) more RSS delta. This is a performance/resource result, not an accuracy failure.
L2 publisher ONNX parity
Reference: SHA-pinned Qualcomm AI Hub Models v0.58.0 published float pair, executed with CPUExecutionProvider.
All compared tensors were finite and shape-identical.
L3 pinned two-sample task metric
Dataset provenance is fixed to
mattmdjaga/human_parsing_datasetrevisiondb120bb5c18c146a8fbd2160f7575a288269fe7d,trainsplit, first 2 rows,--no-shuffle, no subset, seed 42, and zero skipped samples.Schema-v2 provenance, cache integrity, and security
b79dd7131b5409ff0c74d1c2793656305403476c; release manifest SHA-256:8d05f332a0b78994adbbf60589b70fbfc2d33688d14a9f80c34bab79c9205641; archive SHA-256:6c47f7e4eacfad4212d512c434277dfab60d980fea467b4b13d4110baa7f25cf.d0e5eee1603ac256babf93058997b5a90354470595349f6a5433a112b3caf157; decoderbcf847720ec944a87704e3965556602d137f1523deb78b5d2ec7e2c29759fea6. Sidecar hashes: encoder97fdcb37bdb1723aa1187356fc152d1c864666ebda4d3e6d7abf1895b635785f; decodereb0ddcfbd041fce511ef5ee57b58fce7858299d2cd56214b817d201cfb852818.microsoft/resnet-50config exited 0 underHF_HUB_OFFLINE=1andTRANSFORMERS_OFFLINE=1, producing SHA-2562b7f28c35ebd8a88467f3e973d7ca2a1cc178842cb9f6693587b6754c26bb339.Artifact and recipe hashes
All eight fresh model payloads are byte-identical to the prior tester artifacts; acquisition/provenance nevertheless reran under schema v2, and runtime/perf/parity/eval were refreshed.
a0b0814788a62e149de019592fe2410fb26dafbeb4b404eb49990316c080de06cc5557e9d311b395fa0eaf69bc88a3473974fd918e66f1859baadc04101a1d9dca482f77f063955c7a2ac40a2f27920732cfa91dc3f356aef083a095982b5f2c8336ad34070ed8e003e926d28764ef99173a5db27a98bf809ff41eb9149d41134256c472d1934b4680cb6867c5f0871d6ac020753eb55f551d6053de88fa5942cf929b58cae6c6ea966391490ad84c0ad0630066fd7222467d1766bf4138c2b2f83e0da8b5153b513fc8ab5a7b7036f965faf610f75c484660cf1f66b1eeb8db26381e648acf214f204341110506d5074764ad68420fd8a8a9f8ad126eafe2cdEach checked-in recipe is semantically and byte-for-byte identical to its tester-passed producer candidate.
Quality and CI
commands2386 passed, 8 skipped, 2 deselected;models/loader/export 1369 passed, 6 skipped, 1 xfailed. Producer's focused blocker regression set: 41 passed.uv lock --check, andgit diff --checkpassed.scripts/sam3_reference_check.py; this PR does not claim a clean repository-wide Ruff run.448b3508740f1e3b7fc4bb0c004af6020cad9a8b: CodeQL, Analyze (Python), lint, test (commands), test (analyze), test (models), test (optim), test (remaining), and license/cla all SUCCESS. Merge state remains blocked only by required review; this PR remains Draft.Delta
Recipe delta
Frozen-main config generation produced no recipe, so the comparison is honestly NOT-COMPARABLE, not an invented old/new diff.
/export = null,/optim = {},/quant = null,/compile = null,/loader/task = image-feature-extraction,/loader/component_name = image-encoder./loader/task = mask-generation,/loader/component_name = prompt-decoder./quant/mode = fp16with/quant/fp16_keep_io_types = true.All four promoted recipes passed portable rebuilds.
examples/recipes/README.mdremains untouched.Generalized code delta
(model_type, task)preflight avoids unnecessary checkpoint/Hub probing. Optional release discovery preserves the established path on offline/connectivity failures while malformed published metadata still fails closed.from onnx import ...style in the release-asset tests.The behavior is metadata/graph-contract derived, contains no
qualcomm/Segment-Anything-Model-2source hardcoding, is reducible consistently with the L2 charter, and passed recipe-free class acceptance for fp32/fp16.Analyze summary — component level and op level
ANALYZE-PARTIAL-SUCCESS (hash-reused): the complete prior static results are preserved because the analyzer consumes
model.onnxbytes and the repaired head reproduces the exact same set of four analyzed model SHA-256 values:4256c472...,a0b08147...,ca482f77..., andf83e0da8.... Schema-v2 provenance JSON changed but is not an analyzer input. The prior four commands each exited 1 while retaining complete metadata and all 11 requested target classifications; this is static rule analysis, not runtime execution.Component-level summary
Padpartial on NvTensorRT GPU, QNN NPU/GPU, and OpenVINO NPU/GPU/CPUPadpartial on NvTensorRT GPU, QNN NPU/GPU, and OpenVINO NPU/GPU/CPUThe frozen overview maps each complete exported graph by tensor boundary but does not provide exhaustive node-name partitions for nested Hiera backbone, prompt encoder, two-way transformer, and output heads. That mapping gap remains explicit rather than guessed.
Op-level summary
Padpartial;Resize/Mulunknown. Five targets all-unknown.Concatunknown; no partial/unsupported. Five targets all-unknown.Padpartial;Resize/Mulunknown. Five targets all-unknown.Concat/Castunknown; no partial/unsupported. Five targets all-unknown.The six partially classified targets are NvTensorRT/GPU, QNN/NPU, QNN/GPU, and OpenVINO/NPU/GPU/CPU. CUDA/GPU, MIGraphX/GPU, DML/GPU, CPU/CPU, and VitisAI/NPU have no matching public rules here, so every operator type is unknown. All analyzer rows report
runtime_support=false; the measured CPU runtime/eval rows above are the only runtime claims.Reproduce commands
Run from a fresh Windows PowerShell checkout. The checkout is detached at the exact tested head so later branch changes cannot silently alter the evidence. The targeted cache-integrity test covers cache reuse, graph/sidecar/inventory tamper repair, and archive tamper/reacquisition; the isolated
$env:HF_HOMEthen exercises fresh recipe-free and checked-in recipe acquisition.