Skip to content

Support symbolic shape inference #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/onnx_ir/passes/common/shape_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import onnx_ir as ir
from onnx_ir.passes.common import _c_api_utils
from .symbolic_shape_infer import SymbolicShapeInference

Check warning

Code scanning / lintrunner

RUFF/TID252 Warning

Prefer absolute imports over relative imports.
See https://docs.astral.sh/ruff/rules/relative-imports

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -72,12 +73,15 @@

def call(self, model: ir.Model) -> ir.passes.PassResult:
def partial_infer_shapes(proto: onnx.ModelProto) -> onnx.ModelProto:
return onnx.shape_inference.infer_shapes(
proto,
check_type=self.check_type,
strict_mode=self.strict_mode,
data_prop=self.data_prop,
)
try:
return SymbolicShapeInference.infer_shapes(proto, auto_merge=True)
except Exception:
return onnx.shape_inference.infer_shapes(

Check warning on line 79 in src/onnx_ir/passes/common/shape_inference.py

View check run for this annotation

Codecov / codecov/patch

src/onnx_ir/passes/common/shape_inference.py#L78-L79

Added lines #L78 - L79 were not covered by tests
proto,
check_type=self.check_type,
strict_mode=self.strict_mode,
data_prop=self.data_prop,
)

try:
inferred_model_proto = _c_api_utils.call_onnx_api(partial_infer_shapes, model)
Expand Down
Loading
Loading