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

[ops ] guard shape for decimal and negative values #7014

Merged
merged 3 commits into from
Nov 4, 2022
Merged

Conversation

pyu10055
Copy link
Collaborator

@pyu10055 pyu10055 commented Nov 4, 2022

fixed #7008 and #6987

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


This change is Reviewable

Copy link
Collaborator

@Linchenn Linchenn left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

Copy link
Member

@mattsoulanille mattsoulanille left a comment

Choose a reason for hiding this comment

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

LGTM with a suggestion.

@@ -50,6 +51,8 @@ function broadcastTo_<R extends Rank>(
throw new Error(`broadcastTo(): Invalid broadcast shape [${shape}].`);
}

assertNonNegativeIntegerDimensions(shape);
Copy link
Member

Choose a reason for hiding this comment

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

We can avoid having to check this for values we get from convertToTensor if we add this check to every convertToTensor call. We already check dtype, so checking shape as well seems fine to me.

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, I don't think there's a similar fix for ops that make new tensors unless we make changes to the op function, and even then, it's probably not really possible since you don't know the order of the args.

Copy link
Collaborator Author

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 2 of 1 approvals obtained (waiting on @mattsoulanille)


tfjs-core/src/ops/broadcast_to.ts line 54 at r1 (raw file):

Previously, mattsoulanille (Matthew Soulanille) wrote…

Unfortunately, I don't think there's a similar fix for ops that make new tensors unless we make changes to the op function, and even then, it's probably not really possible since you don't know the order of the args.

are you suggesting to add shape check to convertToTensor method? That method does not have shape value issue, since it is either from a existing tensor or from an array of array, the shape is derived.

Copy link
Collaborator Author

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 2 of 1 approvals obtained (waiting on @mattsoulanille)


tfjs-core/src/ops/broadcast_to.ts line 54 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

are you suggesting to add shape check to convertToTensor method? That method does not have shape value issue, since it is either from a existing tensor or from an array of array, the shape is derived.

but looks like the previous line is doing the shape check for negative and integer. I will consolidate.

Copy link
Member

@mattsoulanille mattsoulanille left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 2 of 1 approvals obtained (waiting on @pyu10055)


tfjs-core/src/ops/broadcast_to.ts line 54 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

but looks like the previous line is doing the shape check for negative and integer. I will consolidate.

Oh. oops. That was the wrong line.

Here's where we check for dtype in convertToTensor when the input is a TensorLike and not a Tensor. I think we can add a shape check there as well

https://github.com/tensorflow/tfjs/blob/master/tfjs-core/src/tensor_util_env.ts#L108

Copy link
Member

@mattsoulanille mattsoulanille left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 2 of 1 approvals obtained


tfjs-core/src/ops/broadcast_to.ts line 54 at r1 (raw file):

Previously, mattsoulanille (Matthew Soulanille) wrote…

Oh. oops. That was the wrong line.

Here's where we check for dtype in convertToTensor when the input is a TensorLike and not a Tensor. I think we can add a shape check there as well

https://github.com/tensorflow/tfjs/blob/master/tfjs-core/src/tensor_util_env.ts#L108

Wait, actually, I misread the type of convertToTensor and thought it was using a TensorInfo. TensorLike should not need its shape checked for decimals or negatives.

@pyu10055 pyu10055 merged commit e6fd00a into master Nov 4, 2022
@pyu10055 pyu10055 deleted the shape_guard branch November 4, 2022 22:25
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.

[all] guard against decimal shape value across TF ops
3 participants