-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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][TF] Make StridedSlice support dynamic input and constant attrs #6024
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2146,7 +2146,18 @@ Array<te::Tensor> StridedSliceCompute(const Attrs& attrs, const Array<te::Tensor | |
const Type& out_type) { | ||
const StridedSliceAttrs* param = attrs.as<StridedSliceAttrs>(); | ||
CHECK(param != nullptr); | ||
if (param->begin && param->end && param->strides) { | ||
|
||
bool dyn = false; | ||
for (auto& v : out_type.as<TensorTypeNode>()->shape) { | ||
if (const tir::VarNode* var_node = v.as<tir::VarNode>()) { | ||
if (var_node->name_hint == "any_dim") { | ||
dyn = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (param->begin && param->end && param->strides && !dyn) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I printed output_shape in topi::strided_slice and it is (0, 0) for that modified test_any case, which causes an runtime error. Maybe we can fix this bug directly in topi::strided_slice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. topi::strided_slice requires static shape because it will get value from each dim. Should we change this requirement or just use DynamicStrideSlice?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. I think it would be more complicated to fix topi. Probably we can use dynamic stridedslice compute. |
||
Array<Integer> begin, end, strides; | ||
begin = param->begin.value(); | ||
end = param->end.value(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to special hand this in tf frontend and skip mask transformation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because mask transformation needs a concrete shape which doesn't work for dynamic shape input. I think there is more to do to handle mask in dynamic case but I'm afraid it can't support all mask transformation without concrete shape.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use shape_of to get data shape. In this case all shape dim will be relay expression and transform mask should be able to handle them. Anyway I don't think we should silently skip it since the output can be wrong and cause latter type infer error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lixiaoquan Can you simply raise an error here and add a TODO? We can merge this PR so that backend changes can take effect.