-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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][Frontend] Add reverse op to relay #2800
Conversation
include/tvm/relay/attrs/transform.h
Outdated
TVM_ATTR_FIELD(axis).set_default(NullValue<Integer>()) | ||
.describe(" The axis along which to reverse elements."); | ||
} | ||
}; // struct RepeatAttrs |
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.
Typo. Change to ReverseAttrs.
tests/python/relay/test_op_level3.py
Outdated
intrp = relay.create_executor(kind, ctx=ctx, target=target) | ||
op_res = intrp.evaluate(func)(x_data) | ||
tvm.testing.assert_allclose(op_res.asnumpy(), ref_res, rtol=1e-5) | ||
verify_reverse((2, 3, 4), 1 ) |
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.
Remove the extra space
src/relay/op/tensor/transform.cc
Outdated
const auto* param = attrs.as<ReverseAttrs>(); | ||
const int ndim = static_cast<int>(data->shape.size()); | ||
const int axis = param->axis; | ||
CHECK(-ndim - 1 <= axis && axis <= ndim) |
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.
Should it be axis < ndim
?
src/relay/op/tensor/transform.cc
Outdated
} | ||
|
||
Expr MakeReverse(Expr data, | ||
int axis) { |
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.
Fix indent
include/tvm/relay/attrs/transform.h
Outdated
Integer axis; | ||
TVM_DECLARE_ATTRS(ReverseAttrs, "relay.attrs.ReverseAttrs") { | ||
TVM_ATTR_FIELD(axis).set_default(NullValue<Integer>()) | ||
.describe(" The axis along which to reverse elements."); |
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.
Remove the extra space
python/tvm/relay/op/transform.py
Outdated
The axis along which to reverse elements. | ||
|
||
.. note:: | ||
Reverse and flip are equivalent. |
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.
I don't think we need this note since we don't have flip op in Relay.
python/tvm/relay/op/transform.py
Outdated
-------- | ||
.. code-block:: python | ||
|
||
x = [[1, 2], [3, 4]] |
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.
Use float value to be consistent
src/relay/op/tensor/transform.cc
Outdated
for (int i = 0; i < ndim; ++i) { | ||
oshape.emplace_back(data->shape[i]); | ||
} | ||
reporter->Assign(types[1], TensorTypeNode::make(oshape, data->dtype)); |
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.
You can directly use reporter->Assign(types[1], types[0]);
. No need to create oshape
.
src/relay/op/tensor/transform.cc
Outdated
const auto* param = attrs.as<ReverseAttrs>(); | ||
const int ndim = static_cast<int>(data->shape.size()); | ||
const int axis = param->axis; | ||
CHECK(-ndim - 1 < axis && axis < ndim) |
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 just use -ndim <= axis
to simplify the expr.
Thanks @Laurawly. This is now merged. |
* start adding reverse * reverse updated * reverse uses topi::flip * typo fixed * comment addressed * exp simplified
* start adding reverse * reverse updated * reverse uses topi::flip * typo fixed * comment addressed * exp simplified
Thanks for contributing to TVM! Please refer to guideline https://docs.tvm.ai/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from Reviewers.