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

Fix inconsistent IR when printing R.nn.pad operator #17567

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/tvm/relax/attrs/nn.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ struct AttentionAttrs : public tvm::AttrsNode<AttentionAttrs> {
/*! \brief Attributes used for the padding operator */
struct PadAttrs : public tvm::AttrsNode<PadAttrs> {
Array<Integer> pad_width;
Expr pad_value;
tvm::String pad_mode;

TVM_DECLARE_ATTRS(PadAttrs, "relay.attrs.PadAttrs") {
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/relax/transform/legalize_ops/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _nn_pad(bb: BlockBuilder, call: Call) -> Expr:
pad_after = pad_widths[1::2]
return bb.call_te(
topi.nn.pad,
call.args[0],
call.attrs.pad_value,
pad_before=pad_before,
pad_after=pad_after,
pad_value=float(call.args[1].data.numpy()),
Expand Down
6 changes: 3 additions & 3 deletions src/relax/op/nn/nn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ Expr pad(Expr data, Array<Integer> pad_width, Expr pad_value, String pad_mode) {
auto attrs = make_object<PadAttrs>();
attrs->pad_width = std::move(pad_width);
attrs->pad_mode = std::move(pad_mode);
attrs->pad_value = std::move(pad_value);
static const Op& op = Op::Get("relax.nn.pad");
return Call(op, {data, pad_value}, Attrs(attrs), {});
return Call(op, {data}, Attrs(attrs), {});
}

TVM_REGISTER_GLOBAL("relax.op.nn.pad").set_body_typed(pad);
Expand Down Expand Up @@ -161,9 +162,8 @@ StructInfo InferStructInfoPad(const Call& call, const BlockBuilder& ctx) {
}

TVM_REGISTER_OP("relax.nn.pad")
.set_num_inputs(2)
.set_num_inputs(1)
.add_argument("data", "Tensor", "The input tensor.")
.add_argument("pad_value", "Tensor", "The value to fill in padded area with.")
.set_attrs_type<PadAttrs>()
.set_attr<FInferStructInfo>("FInferStructInfo", InferStructInfoPad)
.set_attr<Bool>("FPurity", Bool(true));
Expand Down
Loading