feat(owlv2): add CPU fp32/fp16 recipes and Einsum op support#1187
feat(owlv2): add CPU fp32/fp16 recipes and Einsum op support#1187codykk wants to merge 4 commits into
Conversation
eaf10fa to
da914d9
Compare
DingmaomaoBJTU
left a comment
There was a problem hiding this comment.
Requesting changes for two issues in the Einsum runtime-checker coverage: equation semantics are currently excluded from matching, and the generic validation test skips at least one new equation. The OWLv2 recipes otherwise match existing conventions. Please also include a before/after analyze artifact for /class_head/Einsum; runtime-rule parquet files are external to this diff, so the artifact is needed to demonstrate that the shipped analysis result is supported rather than merely changing OpUnsupportedError to rules_not_found.
| The equation attribute has unbounded values (arbitrary strings), | ||
| and input shapes are also unbounded. | ||
| """ | ||
| return ["Inputs_shape", "Inputs_value", "attr_equation", "Inputs_is_constant"] |
There was a problem hiding this comment.
Could we avoid dropping attr_equation from the rule key until the equation is represented by derived semantic properties? derive_properties() currently keeps only num_inputs and the maximum rank, so equations with the same arity and rank but different contractions, ellipsis or broadcasting, repeated labels, reductions, or output permutations collapse to the same condition set. On an EP with equation-dependent support, that can either generalize a passing case to unsupported equations or make result processing report a conflict and omit the Einsum rule entirely. The conservative fix would be to match the exact equation, or derive a canonical semantic signature before treating the raw equation as infinite.
There was a problem hiding this comment.
attr_equation is no longer in get_infinite_property_names(), so each distinct equation string participates in exact rule matching. Additionally, derive_properties() now extracts 7 semantic properties (has_ellipsis, has_contraction, has_repeated_labels, etc.) to further distinguish equations even if we relax exact matching in the future.
| "Inputs": VariadicInputConstraint( | ||
| [InputShapeConstraint((2, 3, 4)), InputShapeConstraint((2, 4, 5))] | ||
| ), | ||
| "equation": "...ij,...jk->...ik", |
There was a problem hiding this comment.
Could we add a dedicated parametrized test that executes every equation and checks its output shape? The generic validate_inputs() groups cases only by _validation_input_constraints and stops after one case in a group succeeds. This case has the same two input shapes as bij,bjk->bik above, so it is skipped after that case passes; changing this equation to an invalid one would still leave the current test green. A rule-signature test for same-rank, different-equation cases would also cover the matching issue.
There was a problem hiding this comment.
Added TestEinsumEquationExecution — a dedicated parametrized test that builds a real ONNX Einsum node for each equation independently and verifies its output shape via ORT inference, bypassing the validate_inputs() grouping entirely. Also added test_same_rank_different_equations_produce_different_properties to assert that same-arity/same-rank equations produce distinct semantic signatures.
770f003 to
3efe061
Compare
Add verified CPU recipes for google/owlv2-large-patch14-ensemble (zero-shot-object-detection task) and register the Einsum operator in the runtime checker so static EP analysis no longer reports OpUnsupportedError for models using einsum contractions.
Address review feedback: - Extract has_ellipsis, has_explicit_output, is_full_reduction, has_repeated_labels, has_contraction, output_num_labels, and inputs_share_all_labels from attr_equation in derive_properties() so that equations with the same arity/rank but different semantics produce distinct rule keys. - Add dedicated parametrized tests verifying each equation's semantic properties and a regression test for same-rank-different-equation disambiguation. - Add TestEinsumEquationExecution that independently executes every equation via ORT to verify output shape (bypasses validate_inputs grouping). Follows the pattern established by ReductionInputGenerator (axes semantics) and ConvInputGenerator (dilations/strides/pads semantics).
Use 'from onnx' imports instead of mixing 'import onnx' with 'from onnx', resolving the "module imported with both import and import from" CodeQL alert.
3efe061 to
c3d7e33
Compare
Place third-party 'import' before 'from' imports per isort convention.
Summary
Add verified CPU execution provider support for
google/owlv2-large-patch14-ensemblewith fp32 and fp16 recipes. Register theEinsumoperator in the runtime checker with a conservative exact-match strategy to eliminate falseOpUnsupportedErrorduring static EP analysis. Highest outcome: L1 (perf PASS on both precisions).Model metadata
What the model does: OWLv2 is an open-vocabulary object detection model that localizes objects in images given free-form text queries, without requiring predefined categories.
Primary user stories: Zero-shot object detection — detect arbitrary objects described by natural language prompts in any image, without retraining or fine-tuning.
Supported tasks:
zero-shot-object-detectionModel architecture:
google/owlv2-large-patch14-ensembleconfig +Owlv2ForObjectDetectionsource class (verified).Validation and support evidence
Baseline
On
main,winml buildsucceeds for OWLv2 butwinml analyzereportsOpUnsupportedErrorfor the/class_head/Einsumnode — noOpInputGeneratoris registered for theEinsumop type, so static EP analysis cannot evaluate it.Goal
Outcome
L1 PASS on CPU EP for both fp32 and fp16.
EinsumInputGeneratorregistered with 12 equation combinations covering the OWLv2 class head's...pd,...qd->...pqpattern. Conservative exact-match approach adopted per reviewer feedback.Per-EP/device/precision results
Delta
Code changes (from baseline where Einsum had no InputGenerator):
src/winml/modelkit/pattern/op_input_gen/einsum_input_generator.py—EinsumInputGeneratorclass with:get_input_and_infinite_attribute_combinations(): 12 equation patterns (transpose, identity, matmul, dot, outer, element-wise, batched matmul variants, OWLv2 pattern)derive_properties(): extracts 7 semantic features from equation string (has_ellipsis, has_explicit_output, is_full_reduction, has_repeated_labels, has_contraction, output_num_labels, inputs_share_all_labels)get_infinite_property_names(): returns["Inputs_shape", "Inputs_value", "Inputs_is_constant"]—attr_equationdeliberately excluded (conservative exact-match)src/winml/modelkit/pattern/op_input_gen/__init__.pytests/unit/analyze/test_input_generators.py—TestEinsumDeriveProperties(8 parametrized tests) +TestEinsumEquationExecution(12 ORT execution tests)examples/recipes/google_owlv2-large-patch14-ensemble/cpu/cpu/(fp32 + fp16 configs, opset 17, batch_size=1, gelu_fusion + matmul_add_fusion)Production recipe README remains untouched.
Analyze summary —
/class_head/EinsumBefore (main branch)
/class_head/Einsum:
Status: OpUnsupportedError
Reason: No OpInputGenerator registered for op type "Einsum"
No runtime rule is generated for Einsum → any Einsum node is reported as unsupported.
After (this PR)
EinsumInputGeneratorregistered with 12 input combinations.attr_equationis a finite (exact-match) property — each distinct equation string generates its own rule, avoiding false generalizations across different contraction patterns (conservative approach per review feedback).Rule matching key (finite properties for /class_head/Einsum):
attr_equation: ...pd,...qd->...pq
has_contraction: True
has_ellipsis: True
has_explicit_output: True
has_repeated_labels: False
inputs_share_all_labels: False
is_full_reduction: False
num_inputs: 2
output_num_labels: 2
Inputs_dim: 3
Result: rule keyed on exact equation → /class_head/Einsum matches → supported
ORT execution verification
Equation validated independently via ONNX Runtime (shapes from model graph):
OWLv2 /class_head/Einsum (equation: ...pd,...qd->...pq)
Input shapes: (1, 576, 768), (1, 2, 768)
Expected output shape: (1, 576, 2)
EP: CPUExecutionProvider
Status: PASS (TestEinsumEquationExecution covers this case)
Why
supportedand notrules_not_found...pd,...qd->...pqis explicitly listed inget_input_and_infinite_attribute_combinations()attr_equationis a finite (exact-match) key inget_infinite_property_names()/class_head/Einsum, the node's properties match the rule exactly →supportedReproduce commands