Skip to content

[ONNX] Use static broadcast_to for ONNX's Expand operator if possible#8522

Closed
JoeyChou-SiMa-ai wants to merge 1 commit intoapache:mainfrom
JoeyChou-SiMa-ai:frontends/onnx_expand_use_static_shape
Closed

[ONNX] Use static broadcast_to for ONNX's Expand operator if possible#8522
JoeyChou-SiMa-ai wants to merge 1 commit intoapache:mainfrom
JoeyChou-SiMa-ai:frontends/onnx_expand_use_static_shape

Conversation

@JoeyChou-SiMa-ai
Copy link
Contributor

While translating ONNX's Expand operator, if the value in shape input tensor are known at the compile time, use it to get the output shape of Expand operator so it can create a static broadcast_to instead of a dynamic one.

Copy link
Contributor

@mbrookhart mbrookhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test?

@@ -2099,6 +2099,14 @@ def expand_shape(in_shape, shape):
new_shape = _op.maximum(in_shape, shape)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would do the same thing to add fold_constant here? I don't love the use of params, but I'm not strictly opposed to it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FoldConstant seems not help here, as it has been used after this function (L2110: shape = fold_constant(expand_shape(in_shape, shape))).

Meanwhile, I also agree that using parameters to avoid dynamic ops is not a good practice. From compiler's perspective, they are "parameters" because their values can be changed anytime, so we should not make any assumption here. A good practice is going through from_onnx -> bind_param_by_name -> fold_constant -> dynamic_to_static. Since parameters become constants after binding, it's now safe to say these ops can be static.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that (1) not using the param and (2) using dynamic_to_static are the right solution here. I was simply thinking about getting all static operators from this frozen model but the concept is not correct here.

I will decline this PR. Thank you for the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants