Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Conversation

@vandanavk
Copy link
Contributor

@vandanavk vandanavk commented Sep 24, 2018

Description

Enabling export of Square operator and Sum operator

v2: Added reduce_sum tests based on @anirudhacharya's review
v3: Addressed @Roshrini's and @zhreshold's review comments

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Export mx.sym.Square using Power operator in ONNX
  • Export mx.sym.Sum using ReduceSum operator in ONNX
  • Added tests for ReduceSum

Comments

  • Tested onnx_backend_test.py

@vandanavk
Copy link
Contributor Author

@mxnet-label-bot[pr-awaiting-review]

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Sep 24, 2018
@vandanavk vandanavk force-pushed the onnx_op branch 2 times, most recently from f228e06 to 3d9372d Compare September 25, 2018 18:22
Copy link
Member

@anirudhacharya anirudhacharya left a comment

Choose a reason for hiding this comment

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

this should wait on #12633 and please add tests for these operators.

@vandanavk
Copy link
Contributor Author

Rebased on top of #12633.
Added tests for ReduceSum.
Test for square is taken care by the existing tests for Pow operator.

@anirudhacharya @Roshrini @zhreshold This PR is ready for review again.

mx_axis = attrs.get("axis", None)
axes = convert_string_to_list(str(mx_axis)) if mx_axis is not None else None

keepdims = 1 if ("keepdims" in attrs) and \
Copy link
Member

Choose a reason for hiding this comment

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

do you need the first condition ("keepdims" in attrs) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's an optional parameter. so added this check just in case.

Copy link
Member

@anirudhacharya anirudhacharya Oct 2, 2018

Choose a reason for hiding this comment

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

no, my point was since you are doing attrs.get("keepdims") the first condition is a redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, considering changing it to

keepdims = attrs.get("keepdims", 0)
keepdims = 1 if keepdims in ["True", "1"] else 0

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking of this -

keepdims = 1 if attrs.get("keepdims", 0) in ["True", "1"] else 0

but this should be ok i guess.

axes = convert_string_to_list(str(mx_axis)) if mx_axis is not None else None

keepdims = 1 if ("keepdims" in attrs) and \
attrs.get("keepdims") in ["True", "1"] else 0
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't attrs.get("keepdims") be cast to str before making this comparison? I am curious how it passed the unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the value has always been "True" or "1" or "0" when it reaches this function. same is the case with similar functions such as Reduce*, Arg*. I will figure out where this change in type occurs and get back to you.

keepdims=keepdims,
name=name
)

Copy link
Member

Choose a reason for hiding this comment

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

nit: could you remove new line here and in line 2150. Or maybe you could have a single return statement after the if else block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will change it to a common return statement

"Pow",
[input_node_a, power2_name],
[name],
name=None
Copy link
Member

Choose a reason for hiding this comment

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

why name=None here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was a copy from Pow operator. No reason to have it as None. Will add a name. and change it in Pow as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like name wasn't added to Pow because of the error "pow() got an unexpected keyword argument 'name'". Submitting the fix for this in this PR itself (separate commit).

@Roshrini
Copy link
Member

Roshrini commented Oct 2, 2018

LGTM

@vandanavk
Copy link
Contributor Author

@anirudhacharya @zhreshold ping for review

new_attrs = translation_utils._remove_attributes(new_attrs, ['broadcast'])
return 'broadcast_power', new_attrs, inputs
return 'pow', new_attrs, inputs
mxnet_op = symbol.pow(inputs[0], inputs[1])
Copy link
Member

Choose a reason for hiding this comment

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

why this change? you probably made this change to accommodate op_set version 7 of ONNX. will we support op_set versions older than 7?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverting back to the older commit. Will figure out supporting different op_set versions and work on the Power operator separately.

@vandanavk
Copy link
Contributor Author

@zhreshold @Roshrini @anirudhacharya review comments addressed. is this PR good to go?

Copy link
Member

@anirudhacharya anirudhacharya left a comment

Choose a reason for hiding this comment

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

lgtm

inputs = node["inputs"]

input_node_a_id = kwargs["index_lookup"][inputs[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.

nit: in general feel that there are a lot of unnecessary blank lines in this method. also you can remove line 2096 have np.array([2]) directly. but this change is not a blocker


initializer = kwargs["initializer"]
power2 = [2]
np_arr = np.array(power2)
Copy link
Member

Choose a reason for hiding this comment

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

what is the point of setting power2 as a temporary variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. Re-submitting after editing this.

axes = convert_string_to_list(str(mx_axis)) if mx_axis is not None else None

keepdims = attrs.get("keepdims", 0)
keepdims = 1 if keepdims in ["True", "1"] else 0
Copy link
Member

Choose a reason for hiding this comment

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

should reuse the function in #12646

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. Re-submitting with this change.

@vandanavk
Copy link
Contributor Author

Since this PR uses changes in #12646, combining the 2 PRs. This will be closed in favor of #12646 once the changes are pushed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

pr-awaiting-review PR is waiting for code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants