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

[Caffe Frontend] adding Reduction op #8015

Merged
merged 9 commits into from
Jan 13, 2022
Merged

[Caffe Frontend] adding Reduction op #8015

merged 9 commits into from
Jan 13, 2022

Conversation

zotanika
Copy link
Contributor

@zotanika zotanika commented May 11, 2021

Reduction op for Caffe frontend, supporting SUM, ASUM, SUMSQ, MEAN methods.

@tqchen
Copy link
Member

tqchen commented May 12, 2021

cc @jcf94 @kazum @FrozenGene please help to manage this PR. Thank you!

@@ -558,6 +559,36 @@ def convert_tanh(self, op):
out = _op.tanh(in_expr)
return out

def convert_reduction(self, op):
""" Convert Reduction layer """
reduction_dic = ["NOP", "SUM", "ASUM", "SUMSQ", "MEAN"]
Copy link
Member

Choose a reason for hiding this comment

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

I don't find logic code to handle NOP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOP was placed in reduction_dic to remind users(and me) of the attribution of Caffe Reduction op, default operation SUM is starting from 1; https://caffe.berkeleyvision.org/tutorial/layers/reduction.html.
If warning against the wrong attribution 0 is considered redundant, I'll remove it..

"reduction method:{} is invalid in Caffe frontend.".format(method)
)

out = _op.multiply(out, coeff_expr)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could do a little optimization for this. For example, if coeff_expr is not 1, we call multiply.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this suggestion is included in new commit.

reduction_op = {"SUM": 1, "ASUM": 2, "SUMSQ": 3, "MEAN": 4}
_test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0)
_test_reduction(
np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0, coeff=0.0
Copy link
Member

Choose a reason for hiding this comment

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

Let us add more values for axis and coeff to cover more conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this suggestion is included in new commit. some more codes were introduced to handle reductions on non-tail axis and give back the result equivalent to Caffe framework.

zotanika added 4 commits May 18, 2021 14:41
- adding more test cases; handling '0 < axis < num_axes - 1' case to give the result equivalent to Caffe framework
- skipping Relay multiplication if coeff is 1

Signed-off-by: zotanika <[email protected]>
@junrushao
Copy link
Member

@FrozenGene Please take another look :-)

Copy link
Member

@FrozenGene FrozenGene left a comment

Choose a reason for hiding this comment

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

nitty comment.

tests/python/frontend/caffe/test_forward.py Show resolved Hide resolved
@masahi
Copy link
Member

masahi commented Jan 9, 2022

@zotanika please resolve the conflict.

@masahi masahi closed this Jan 9, 2022
@masahi masahi reopened this Jan 9, 2022
@zotanika zotanika requested a review from yzhliu as a code owner January 12, 2022 04:49
@masahi masahi merged commit 920c380 into apache:main Jan 13, 2022
crazydemo pushed a commit to crazydemo/tvm that referenced this pull request Jan 27, 2022
* [Caffe Frontend] adding Reduction op

* reformatting Reduction op test script

* reformatting Reduction test script

* [Caffe frontend] Reduction op
- adding more test cases; handling '0 < axis < num_axes - 1' case to give the result equivalent to Caffe framework
- skipping Relay multiplication if coeff is 1

Signed-off-by: zotanika <[email protected]>

* linting test script

* linting

* typo fix

Co-authored-by: sunchul.jung <[email protected]>
Raghav-Chakravarthy pushed a commit to Raghav-Chakravarthy/tvm that referenced this pull request Jan 28, 2022
* [Caffe Frontend] adding Reduction op

* reformatting Reduction op test script

* reformatting Reduction test script

* [Caffe frontend] Reduction op
- adding more test cases; handling '0 < axis < num_axes - 1' case to give the result equivalent to Caffe framework
- skipping Relay multiplication if coeff is 1

Signed-off-by: zotanika <[email protected]>

* linting test script

* linting

* typo fix

Co-authored-by: sunchul.jung <[email protected]>
ylc pushed a commit to ylc/tvm that referenced this pull request Feb 16, 2022
* [Caffe Frontend] adding Reduction op

* reformatting Reduction op test script

* reformatting Reduction test script

* [Caffe frontend] Reduction op
- adding more test cases; handling '0 < axis < num_axes - 1' case to give the result equivalent to Caffe framework
- skipping Relay multiplication if coeff is 1

Signed-off-by: zotanika <[email protected]>

* linting test script

* linting

* typo fix

Co-authored-by: sunchul.jung <[email protected]>
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