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

Add npx op 'index_add' #18089

Merged
merged 31 commits into from
Jun 2, 2020
Merged

Add npx op 'index_add' #18089

merged 31 commits into from
Jun 2, 2020

Conversation

JiangZhaoh
Copy link
Contributor

Description

Forward for index_add.

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 https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@JiangZhaoh JiangZhaoh requested a review from szha as a code owner April 17, 2020 10:08
@mxnet-bot
Copy link

Hey @JiangZhaoh , Thanks for submitting the PR
All tests are already queued to run once. If tests fail, you can trigger one or more tests again with the following commands:

  • To trigger all jobs: @mxnet-bot run ci [all]
  • To trigger specific jobs: @mxnet-bot run ci [job1, job2]

CI supported jobs: [website, centos-gpu, centos-cpu, sanity, windows-cpu, unix-cpu, unix-gpu, windows-gpu, clang, edge, miscellaneous]


Note:
Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin.
All CI tests must pass before the PR can be merged.

@haojin2 haojin2 added the Numpy label Apr 17, 2020
@haojin2 haojin2 requested review from sxjscience and removed request for szha April 17, 2020 18:44
@sxjscience
Copy link
Member

Is it using the new FFI?

@zheyuye
Copy link
Contributor

zheyuye commented May 14, 2020

Related to #17823

@zheyuye
Copy link
Contributor

zheyuye commented May 14, 2020

It seems that this operation currently only supports floating type. In addition, it would be great if the data types of indices can be extended to np.ndarray instead of only tuple and list as

import mxnet as mx
a = mx.np.zeros((2,6))
val = mx.np.arange(6)
x = [1,0,0,0,0,0]
y = [0,2,3,4,0,1]
# indices = [list, list]
mx.npx.index_add(a, val, [x, y])
# indices = (list, list)
mx.npx.index_add(a, val, (x, y))
# indices = [np.ndarray, np.ndarray]
x = mx.np.array(x).astype('int32')
y = mx.np.array(y).astype('int32')
mx.npx.index_add(a, val, [x, y])

>>> MXNetError: MXNetError: Invalid Parameter format for ind expect tuple of <Shape(tuple)> 
but value='[array([1, 0, 0, 0, 0, 0], dtype=int32), array([0, 2, 3, 4, 0, 1], dtype=int32)]', in 
operator _npx_index_add(name="", ind="[array([1, 0, 0, 0, 0, 0], dtype=int32), array([0, 2, 3, 4, 0, 1], dtype=int32)]")

@JiangZhaoh
Copy link
Contributor Author

JiangZhaoh commented May 20, 2020

For npx.index_add(a, ind, val), now it supports int32 or int64 tensor ind, and both int or float tensor a and val. But it requires the dtype of a and val keep same.

@sxjscience
Copy link
Member

LGTM overall. Needs to fix the CudaMalloc + cudaFree.

@JiangZhaoh
Copy link
Contributor Author

@mxnet-bot run ci [unix-gpu, windows-cpu, windows-gpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [windows-cpu, windows-gpu, unix-gpu]

@JiangZhaoh
Copy link
Contributor Author

@mxnet-bot run ci [unix-gpu, unix-cpu, centos-gpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [unix-cpu, unix-gpu, centos-gpu]

ret.emplace_back(a_grad);
ret.emplace_back(idx_grad);
ret.emplace_back(val_grad);
return ret;
Copy link
Member

Choose a reason for hiding this comment

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

@yzhliu I've suggested @JiangZhaoh to write the gradient op by reusing the forward op. This has multiple benefits:

  1. We can do more optimization in the graph pass
  2. It's easy to support higher-order gradient.

I think we may add the document about such usage since not many people are aware of that.

@sxjscience
Copy link
Member

@mxnet-bot run ci [centos-gpu] [unix-cpu] [unix-gpu] [windows-cpu] [windows-gpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [centos-gpu]

@leezu
Copy link
Contributor

leezu commented Jun 1, 2020

@mxnet-bot run ci [unix-cpu, unix-gpu, windows-cpu, windows-gpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [unix-cpu, windows-gpu, windows-cpu, unix-gpu]

@sxjscience sxjscience merged commit c3fcbf3 into apache:master Jun 2, 2020
@sxjscience
Copy link
Member

Thanks @JiangZhaoh , this is merged.

ys2843 pushed a commit to ys2843/incubator-mxnet that referenced this pull request Jun 2, 2020
* part cpu

* index_add forward & test

* fix wrong doc

* fix index_add_sanity_error

* index_update_test

* remove index_update & implement index_add backward

* fix sanity error

* reduce code length

* depart into two file

* test CI compiler

* test CI

* test CI

* reduce mshadow & allow more dtype

* fix sanity error

* fix conflict

* reduce fwd macro code

* reduce bwd macro code

* fix compile error

* tensor ind

* remove cudaMalloc/cudaFree

* fix windows compile error

* fix compile error

* use value instead of references

* remove pragma

* fix naive engine error

* try to pass CI

* fix sanity error

* depart gradient into three node

* resolve comment & initialize mshadow::Shape

* fix werror

Co-authored-by: Ubuntu <[email protected]>
Co-authored-by: Ubuntu <[email protected]>
Co-authored-by: Xingjian Shi <[email protected]>
yijunc pushed a commit to yijunc/incubator-mxnet that referenced this pull request Jun 9, 2020
* part cpu

* index_add forward & test

* fix wrong doc

* fix index_add_sanity_error

* index_update_test

* remove index_update & implement index_add backward

* fix sanity error

* reduce code length

* depart into two file

* test CI compiler

* test CI

* test CI

* reduce mshadow & allow more dtype

* fix sanity error

* fix conflict

* reduce fwd macro code

* reduce bwd macro code

* fix compile error

* tensor ind

* remove cudaMalloc/cudaFree

* fix windows compile error

* fix compile error

* use value instead of references

* remove pragma

* fix naive engine error

* try to pass CI

* fix sanity error

* depart gradient into three node

* resolve comment & initialize mshadow::Shape

* fix werror

Co-authored-by: Ubuntu <[email protected]>
Co-authored-by: Ubuntu <[email protected]>
Co-authored-by: Xingjian Shi <[email protected]>
AntiZpvoh pushed a commit to AntiZpvoh/incubator-mxnet that referenced this pull request Jul 6, 2020
* part cpu

* index_add forward & test

* fix wrong doc

* fix index_add_sanity_error

* index_update_test

* remove index_update & implement index_add backward

* fix sanity error

* reduce code length

* depart into two file

* test CI compiler

* test CI

* test CI

* reduce mshadow & allow more dtype

* fix sanity error

* fix conflict

* reduce fwd macro code

* reduce bwd macro code

* fix compile error

* tensor ind

* remove cudaMalloc/cudaFree

* fix windows compile error

* fix compile error

* use value instead of references

* remove pragma

* fix naive engine error

* try to pass CI

* fix sanity error

* depart gradient into three node

* resolve comment & initialize mshadow::Shape

* fix werror

Co-authored-by: Ubuntu <[email protected]>
Co-authored-by: Ubuntu <[email protected]>
Co-authored-by: Xingjian Shi <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants