Slice_like can't be constant folded

The slice_like operator takes two inputs:

  1. Data tensor to be sliced.
  2. Tensor, from which shape will be used to slice input 1.

In many object detection networks, input 1 is a constant and the shape of input 2 is known statically. To perform this operation only the shape of input 2 is needed. However, the FoldConstant pass doesn’t know this and will see that since input 2 is not a constant, the operation will not be constant folded.

To fix this, I want to add a pass to simplify slice_like to strided_slice when the necessary shapes of input 2 are available statically. Any thoughts?

I am not sure. But I sort of remember that striced_slice may also need to change the begin and end into expr for dynamic shapes. @kevinthesun and @yongwww can comment more on this.

In the long term, we probably want to improve FoldConstant to hint that for some op such as shapeof, we just need its input shape to be constant. In the short term, I’m not very sure about whether we need a pass specifically for it. Another way is we just modify the frontend to infer_value for the second input of slice_like.