Skip to content
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

[Relay, Tests] Make expressions in the DynamicToStatic pass tests more dynamic #8989

Merged
merged 1 commit into from
Sep 13, 2021

Conversation

jtuyls
Copy link
Contributor

@jtuyls jtuyls commented Sep 12, 2021

While experimenting with dyn.strided_slice I noticed that some of the DynamicToStatic pass tests are not testing dynamic expressions. For example, the created strided_slice function here

func = relay.Function([x], z)

looks like this:

fn (%x: Tensor[(1, 3, 10, 10), float32]) {
  strided_slice(%x, begin=[0, 0, 0, 0], end=[1, 3, 10, 10], strides=[1, 1, 1, 1], axes=None)
}

which I think doesn't test the DynamicToStatic pass being executed on this expression. With the small changes in this PR, the above function looks like this:

fn (%x: Tensor[(1, 3, 10, 10), float32], %begin: Tensor[(4), int64], %end: Tensor[(4), int64], %strides: Tensor[(4), int64]) {
  %0 = cast_like(0, %begin);
  %1 = shape_of(%x, dtype="int32");
  %2 = cast_like(%1, %begin);
  %3 = slice_like(%2, %begin, axes=None);
  %4 = less(%begin, %0);
  %5 = add(%begin, %3);
  %6 = where(%4, %5, %begin);
  %7 = greater_equal(%6, %3);
  %8 = where(%7, %3, %6);
  dyn.strided_slice(%x, %8, %end, %strides, begin=None, end=None, strides=None, axes=None)
}

which I think is a better test for the DynamicToStatic pass.

Similarly, tests for topk, resize2d, upsampling, upsampling3d and pad have been adjusted.

@mbrookhart Could you help with reviewing this PR?

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.

LGTM! Thanks

I think about six months ago (after these tests were written), I went back and added code to ops like relay.op.strided_slice to check the inputs for Constant-ness and return the static op if they were constant. I must have forgotten to check these tests to ensure they remained dynamic. Thank you!

@mbrookhart mbrookhart merged commit 1914462 into apache:main Sep 13, 2021
@jtuyls jtuyls deleted the update-dyn-to-static-tests branch September 13, 2021 19:06
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.

2 participants