Created
April 13, 2026 20:56
-
-
Save t8/3b2d826b0aeb0e748b41568f8c15a249 to your computer and use it in GitHub Desktop.
Reproducer: OpenVINO Select kernel fails on dynamic shapes with broadcast inputs
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
| """ | |
| Diagnose: do dynamic shapes cause the Select broadcast failure? | |
| """ | |
| import sys | |
| sys.stdout.reconfigure(line_buffering=True) | |
| import openvino as ov | |
| from openvino import opset13 as opset | |
| import numpy as np | |
| print(f"OpenVINO: {ov.__version__}") | |
| def test_select(cond_shape, val_shape, val_is_dynamic, name): | |
| print(f"\n{'='*60}") | |
| print(f" {name}") | |
| print(f"{'='*60}") | |
| cond = opset.constant(np.ones(cond_shape, dtype=np.bool_)) | |
| zeros = opset.constant(np.float32(0.0)) | |
| if val_is_dynamic: | |
| # Use -1 for dynamic dims | |
| dyn_shape = [-1 if d > 1 else 1 for d in val_shape] | |
| val_param = opset.parameter(dyn_shape, dtype=np.float32, name="value") | |
| else: | |
| val_param = opset.parameter(val_shape, dtype=np.float32, name="value") | |
| selected = opset.select(cond, zeros, val_param) | |
| model = ov.Model([selected], [val_param], name) | |
| for op in model.get_ordered_ops(): | |
| if op.get_type_name() == "Select": | |
| for i, inp in enumerate(op.inputs()): | |
| shape = list(inp.get_partial_shape()) | |
| src = inp.get_source_output().get_node().get_type_name() | |
| print(f" Input {i}: rank={len(shape)} shape={shape} ({src})") | |
| for i, out in enumerate(op.outputs()): | |
| shape = list(out.get_partial_shape()) | |
| print(f" Output: rank={len(shape)} shape={shape}") | |
| try: | |
| compiled = ov.Core().compile_model(model, "GPU") | |
| print(f" GPU compile: OK") | |
| except RuntimeError as e: | |
| msg = str(e) | |
| if "too many arguments" in msg: | |
| print(f" GPU compile: FAILED (MASK macro)") | |
| else: | |
| print(f" GPU compile: FAILED ({msg[:150]})") | |
| # Static shapes -- expect OK | |
| test_select([16, 16], [1, 4, 2, 16, 16], val_is_dynamic=False, name="2D cond, STATIC 5D val") | |
| # Dynamic shapes -- might fail | |
| test_select([16, 16], [1, 4, 2, 16, 16], val_is_dynamic=True, name="2D cond, DYNAMIC 5D val") | |
| # 4D static vs dynamic | |
| test_select([1, 1, 16, 16], [1, 4, 2, 16, 16], val_is_dynamic=False, name="4D cond, STATIC 5D val") | |
| test_select([1, 1, 16, 16], [1, 4, 2, 16, 16], val_is_dynamic=True, name="4D cond, DYNAMIC 5D val") | |
| print("\nDone.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment