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

[RELAY]Ops Dense, leaky_relu #1828

Merged
merged 10 commits into from
Oct 17, 2018
Merged

[RELAY]Ops Dense, leaky_relu #1828

merged 10 commits into from
Oct 17, 2018

Conversation

siju-samuel
Copy link
Member

#1799

  • Dense
  • Leaky Relu

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 others in the community.

@siju-samuel
Copy link
Member Author

@srkreddy1238 @yuruofeifei @tqchen please review.

runtime::detail::unpack_call<Expr, 3>(MakeDense, args, rv);
});

RELAY_REGISTER_OP("nn.dense")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add bias support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tqchen how about bias add support? needed? bias is optional for dense. any example for optional arg processing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think like conv where we kept bias away, we could do same here.

python/tvm/relay/op/nn/nn.py Show resolved Hide resolved
weight : relay.Expr
The weight expressions.

units : int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make units optional, and allow infer from weights just as channels in conv2d

@tqchen
Copy link
Member

tqchen commented Oct 6, 2018

please rebase against the most recent master

@siju-samuel siju-samuel force-pushed the relay_ops_1 branch 2 times, most recently from 418559f to 53dd84a Compare October 6, 2018 09:51
Array<tvm::Expr> wshape = weight->shape;

if (param->units != 0) {
// CHECK_EQ(param->units == wshape[wshape.size() - 1])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i want to do this comparison (Integer and Expr).. @srkreddy1238 @tqchen How can i do this comparison?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do CHECK(reporter->AssertEQ(param->units, wshape[wshape.size()-1]))

@siju-samuel siju-samuel force-pushed the relay_ops_1 branch 2 times, most recently from b9c294e to 0ce5eef Compare October 7, 2018 06:43
@@ -173,6 +173,26 @@ struct UpSamplingAttrs : public tvm::AttrsNode<UpSamplingAttrs> {
};


/*! \brief Attributes for dense operator */
struct DenseAttrs : public tvm::AttrsNode<DenseAttrs> {
int units;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make units optional(None) instead of 0 as None so use IndexExpr here, see conv2d as an example

@siju-samuel siju-samuel force-pushed the relay_ops_1 branch 2 times, most recently from 29a0633 to c8da946 Compare October 8, 2018 05:00
@yzhliu yzhliu added the status: need update need update based on feedbacks label Oct 9, 2018
CHECK(static_cast<int>(data->shape.size()) != 0);
Array<tvm::Expr> wshape = weight->shape;

if (param->units.defined()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if units is defined, we don't need weight to be present, instead we can directly assign to the weight, see the implementation of conv2d

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, need to assign to the weight here, this will infer the shape of the weight if necessary. Please also add a testcase similar to https://github.com/dmlc/tvm/blob/master/tests/python/relay/test_op_level2.py#L14 where weight's shape is not specified but get inferred

@siju-samuel siju-samuel force-pushed the relay_ops_1 branch 2 times, most recently from b0c0c23 to f437e2b Compare October 9, 2018 07:47
CHECK(static_cast<int>(data->shape.size()) != 0);
Array<tvm::Expr> wshape = weight->shape;

if (param->units.defined()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, need to assign to the weight here, this will infer the shape of the weight if necessary. Please also add a testcase similar to https://github.com/dmlc/tvm/blob/master/tests/python/relay/test_op_level2.py#L14 where weight's shape is not specified but get inferred


// validate the weight shape is proper if defined
if (weight != nullptr) {
CHECK(reporter->AssertEQ(weight->shape[0], dshape[dshape.size() - 1]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weight != nullptr but units can still be not defined, we could dispatch by weight units is defined, the require weight to be not null when units is not defined

@siju-samuel siju-samuel force-pushed the relay_ops_1 branch 3 times, most recently from d82dd93 to 0793ace Compare October 12, 2018 01:41
if (weight != nullptr) {
CHECK(reporter->AssertEQ(weight->shape[0], dshape[dshape.size() - 1]))
<< "Dense: shape of weight is inconsistent with input data.";
CHECK(reporter->AssertEQ(weight->shape[1], param->units))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to check weight !=nullptr, The Assign will run the check internally. Directly goto the assign logic is fine

<< "Dense: shape of weight is inconsistent with units.";
} else {
// Assign weight type
std::vector<IndexExpr> wshape({dshape[dshape.size() - 1], param->units});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create an Array since you directly send it to make

@tqchen tqchen merged commit d5d1944 into apache:master Oct 17, 2018
@tqchen
Copy link
Member

tqchen commented Oct 17, 2018

Thanks @siju-samuel @srkreddy1238 @yuruofeifei this is now merged

@tqchen tqchen added status: accepted and removed status: need update need update based on feedbacks labels Oct 17, 2018
FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants