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

Adding EyeLike generator op. #1428

Merged
merged 5 commits into from
Sep 23, 2018

Conversation

spandantiwari
Copy link
Contributor

This is a generator ops for producing identity-like matrices with ones on the major diagonal and zeros everywhere else. This generator op is quite useful for models and most major frameworks have it.

Note that the input is restricted to 2D because that is the most dominant use case and most of the frameworks have support restricted to 2D for this (similar) op.

@spandantiwari
Copy link
Contributor Author

All CI checks are passing. Friendly ping to get a review.

Copy link
Member

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

LG, some nits to address

.TypeAndShapeInferenceFunction([](InferenceContext& ctx) {
if (ctx.getAttribute("dtype") != nullptr)
propagateElemTypeFromAttributeToOutput(ctx, "dtype", 0);
else
Copy link
Member

Choose a reason for hiding this comment

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

Nit: add {} even if there is only one stmt.

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.

onnx/defs/generator/defs.cc Show resolved Hide resolved
OPTIONAL)
.Input(
0,
"input",
Copy link
Member

Choose a reason for hiding this comment

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

why not have number of rows and columns as parameters rather than infer it from an input tensor? numpy, pytorch and mxnet all have explicit rows and cols as parameters.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can have another operator called Eye which takes rows and columns as inputs.

Copy link
Member

Choose a reason for hiding this comment

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

won't that be like duplicating the functionality? are there examples where this Eyelike operator is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the idea. The *Like ops take the properties such as shape and type from the input tensor. This design is similar to Numpy (ones_like, zero_like) and also other ops in ONNX such as ConstantLike, RandomNormalLike and RandonUniformLike.

We can have a separate PR for Eye if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@anirudhacharya - I don't think this is exactly duplicating functionality. There are several frameworks that subscribe to the design where there are two parallel set of generator ops - one that take tensor as input and one that take explicit shape as input, e.g. (ones, ones_like), (zeros, zeros_like). This kind of op is quite useful, e.g. creating epsilon covariance matrices matrices for regularization, and matrix factorization scenarios.

Also, note that I have not added Eye in this PR in order avoid adding more ops than necessary, because something like Eye, with static shape, can be supported using Constant op in current spec.

@spandantiwari
Copy link
Contributor Author

Updated the PR based on the feedback.

Copy link
Member

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

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

@spandantiwari spandantiwari merged commit a133ec2 into onnx:master Sep 23, 2018
@spandantiwari
Copy link
Contributor Author

@houseroad , @anirudhacharya - Thanks for the review.

@fdwr
Copy link
Contributor

fdwr commented Apr 30, 2019

@spandantiwari : Would it be useful to keep the 2D restriction (I can't think of any use case extending identity matrices to 3D/4D given matmul's are 2D anyway) but treat any higher dimensions as a batch count? I mean, if this operator is useful for processing one image, then it should be useful for processing a batch of images in parallel like MatMul and Conv2D (without Concat'enating a bunch of EyeLike outputs). I'm asking because GPU's are better at processing a lot of similar data in parallel than repeating lots of smaller varied executions.

@satyajithj
Copy link

Hello. I am new to ONNX and I am trying to understand how to add operators.
I am not unable to find the part where the logic for the op is.
Can someone help me understand this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants