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

Support for negative indices in 'Gather', 'GatherElements', 'ScatterElements', 'OneHot' #2260

Merged
merged 24 commits into from
Sep 11, 2019

Conversation

neginraoof
Copy link
Contributor

We would need to support negative indices for these operators, since PyTorch does support this case. Using Select/Gather ops with -1 index is quite common among PyTorch models.

@neginraoof neginraoof requested a review from a team as a code owner August 26, 2019 21:27
Copy link
Contributor

@BowenBao BowenBao left a comment

Choose a reason for hiding this comment

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

Some inline comments

onnx/backend/test/case/node/gather.py Outdated Show resolved Hide resolved
onnx/backend/test/case/node/gather.py Outdated Show resolved Hide resolved
onnx/backend/test/case/node/gatherelements.py Outdated Show resolved Hide resolved
onnx/backend/test/case/node/gatherelements.py Outdated Show resolved Hide resolved
onnx/defs/tensor/defs.cc Outdated Show resolved Hide resolved
onnx/defs/tensor/defs.cc Show resolved Hide resolved
onnx/defs/tensor/defs.cc Outdated Show resolved Hide resolved
@prasanthpul prasanthpul added the operator Issues related to ONNX operators label Aug 27, 2019
@neginraoof neginraoof changed the title Support for negative indices in 'Gather', 'GatherElements', 'ScatterElements' Support for negative indices in 'Gather', 'GatherElements', 'ScatterElements', 'OneHot' Aug 27, 2019
@hariharans29
Copy link
Contributor

Should I make a similar change for Gather_Nd. Alternatively, could you please include Gather_Nd when the op gets in (hopefully tomorrow) in this PR? That way all the negative indices spec updates can go in together ? :)

@neginraoof
Copy link
Contributor Author

@hariharans29 I can add GatherND in this PR

@hariharans29
Copy link
Contributor

@hariharans29 I can add GatherND in this PR

Thanks @neginraoof. I actually had to make some formatting changes in the doc, so I went ahead and made the Gather_ND spec support negative indices (based on your change here). As part of your change, I think you can refine the sentence in GathertND if you want. Thanks!

@neginraoof
Copy link
Contributor Author

neginraoof commented Aug 30, 2019

@hariharans29 Thanks, I just rebased. The docs are consistent now.

docs/Changelog.md Outdated Show resolved Hide resolved
onnx/defs/tensor/defs.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@wschin wschin left a comment

Choose a reason for hiding this comment

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

Thank you so much for this great work! Overall LGTM. Just make sure my last minor comments are addressed.

neginraoof and others added 3 commits September 4, 2019 14:20
Co-Authored-By: Wei-Sheng Chin <wschin@outlook.com>
Co-Authored-By: Wei-Sheng Chin <wschin@outlook.com>
@neginraoof
Copy link
Contributor Author

@wschin Sure. I updated the PR as requested.

@neginraoof neginraoof removed the request for review from a team September 6, 2019 04:01
@neginraoof
Copy link
Contributor Author

neginraoof commented Sep 6, 2019

Copy link
Contributor

@spandantiwari spandantiwari left a comment

Choose a reason for hiding this comment

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

LGTM. Added a couple of minor comments.

docs/Operators.md Outdated Show resolved Hide resolved
fail_type_inference("OneHot node must have three inputs.");
}
// Input 'depth' must be a scalar or a single-element vector.
// TODO: Ideally to match spec for this input only allow Scalar should be allowed.
Copy link
Contributor

Choose a reason for hiding this comment

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

This sentence is not phrased well. We should correct it.

@neginraoof
Copy link
Contributor Author

cc @gramalingam @ebarsoum please review

neginraoof and others added 4 commits September 10, 2019 14:33
…gativeIndices

# Conflicts:
#	docs/Changelog.md
#	docs/Operators.md
#	docs/TestCoverage.md
#	onnx/backend/test/case/node/onehot.py
#	onnx/defs/operator_sets.h
#	onnx/defs/tensor/defs.cc
#	onnx/defs/tensor/old.cc
@wschin wschin merged commit 797cdd0 into onnx:master Sep 11, 2019
jcwchen pushed a commit to jcwchen/onnx that referenced this pull request Sep 23, 2020
…lements', 'OneHot' (onnx#2260)

* modified gather docs to support negative indices

* added support for negatice indices to gather_elements and scatter_elements

* fixed documentation formatting as per comments

* Added negatice indices to docs for OneHot op

* GatheND spec for negative indices editted

* fix for comments

* fixed formatting for gather op

* Update onnx/defs/tensor/defs.cc

Co-Authored-By: Wei-Sheng Chin <wschin@outlook.com>

* Update docs/Changelog.md

Co-Authored-By: Wei-Sheng Chin <wschin@outlook.com>

* added print examples to onehot and gather as per comments

* adding modifies model tests for onehot

* updated doc files

* updating unsqueeze test

* typo fix as per comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
operator Issues related to ONNX operators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants