Can `slice` from relay support empty result?

Hi

For strided_slice(data, begin, end, strides=None) , when begin=[0] and end=[0], strided_slice should return an empty array. Currently strided_slice will raise an error.

Can we adjust the code so strided_slice will return an empty array instead of raising an error?

I have the same problem and add judgment:

if end == 0:
    return _expr.const([],dtype = dtype)

A new error is encountered later, and I’m not sure if it’s related to this return value

There’s another piece of information,an error occurred while obtaining the end value:

def _stridedSlice():
     xxxx
     end = _get_list_param(params, inputs[2])
     xxxx

error info:
<class 'tvm.relay.expr.Call'> has no attribute name_hint

So,I change the code:

try:
    end = _get_list_param(params, inputs[2])
except (IndexError, KeyError, AttributeError):
    end = _infer_value(inputs[2], params).asnumpy().tolist()

Finally,I get the ‘end’ value of 0(end = [0]).But begin = [-1], after running ‘_transform_mask’ function, begin = [3] (because input shape is (4,),so [-1:] == [3:]).

I think the ‘end = _infer_value(inputs[2], params).asnumpy().tolist()’ is wrong. if not have ‘end’,the ‘enc’ value may be ‘len(inputs[0])’. example:

input.shape = (4,)
input[-1:] = input[-1:4] = input[3:4]

@kevinthesun As @lsy643 said, Can we adjust the code so strided_slice will return an empty array instead of raising an error?

Such as when ‘begin > end’ or ‘end == 0’ or etc, we return an empty array or ‘_expr.const([],dtype = dtype)’

https://github.com/apache/incubator-tvm/blob/e89b19d95d/topi/include/topi/transform.h#L620 begin == end case is already supported.

@kevinthesun My code has been updated recently, but still error:

tvm/src/relay/op/tensor/transform.cc: Check failed: begin_v < end_v (0 vs 0) :stride_slice get empty slice at axis 1

begin = [0,0]
end = [15,0]

When have an ‘end_v < begin_v error’ , it still seems to throw an error instead of continuing. It’s not just “end_v == begin_v”.

In this case, same change need to be made for relay: CHECK_LT(begin_v, end_v) -> CHECK_LE(begin_v, end_v)

@heliqi @lsy643 I encountered a similar problem, did you solve it ?

this error:

strided_slice(%307, meta[relay.Constant][0], meta[relay.Constant][1], meta[relay.Constant][2], begin=[0, 3, 0, 0], end=[1, 0, 1, 512], strides=[1, 1, 1, 1]) 
an internal invariant was violated while typechecking your program [12:17:52]  
/root/worker/tvm/src/relay/op/tensor/transform.cc:2074: 
Check failed: begin_v <= end_v (3 vs. 0) : strided_slice get invalid slice at axis 1 

What is the sematics of begin=3 and end=0 in the original framework? This relay node is illegal since it generates negative slice.

Test model is MobileNetV3, use TF to load saved model to test, it works right.

For tf.strided_slice(input_, begin, end, strides=None, …) , if begin > end, it will return empty list [] instead of raising an error.

Hi,

I got the exactly same error when I running TF SSD-ResNet34 model downloaded from MLperf model zoo https://zenodo.org/record/3345892/files/tf_ssd_resnet34_22.1.zip?download=1

fn (%map/TensorArrayUnstack/TensorArrayScatter/TensorArrayScatterV3_loop_var: List[static_tensor_float32_15130_4_t[]], %map/Const_loop_var: int32) {
  %0 = take(%map/Const_loop_var, 0);
  %1 = @tensor_array_read_float32_15130_4(%map/TensorArrayUnstack/TensorArrayScatter/TensorArrayScatterV3_loop_var, %0);
  %2 = @tensor_get_data_float32_15130_4(%1);
  strided_slice(%2, begin=[0, 3], end=[15130, 0], strides=[1, 1]) an internal invariant was violated while typechecking your program [09:38:40] /home/ww/2020/tvm_latest/incubator-tvm/src/relay/op/tensor/transform.cc:2102: Check failed: begin_v <= end_v (3 vs. 0) : strided_slice get invalid slice at axis 1

And I use ./incubator-tvm/tests/python/frontend/tensorflow/test_forward.py test_forward_ssd() to do the test. I just modify model_path, shape, in_node and out_node

model_path = './tf_ssd_resnet34_22.1/resnet34_tf.22.1.pb' 
data = np.random.uniform(0.0, 255.0, size=(1, 3, 1200, 1200)).astype('float32')
in_node = "image"
out_node = ['detection_bboxes', "detection_scores", "detection_classes"]

Hi, have you solve the problem? Could you give me some advice about the following error:

Check failed: begin_v <= end_v (3 vs. 0) : strided_slice get invalid slice at axis 1