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

✨broadcast utility in converter utilities to broadcast two tensors in masked_fill and make the dimensions equal to torch output dimensions #1629

Closed
apbose opened this issue Jan 30, 2023 · 2 comments
Assignees
Labels
feature request New feature or request No Activity

Comments

@apbose
Copy link
Collaborator

apbose commented Jan 30, 2023

Feature context

In the implementation of aten::masked_fill(Tensor self, Tensor mask, Scalar value) in core/conversion/converters/impl/select.cpp the converter implementation is such that the masked rank is padded to match the rank of self if the rank of mask is less than self Tensor. This creates an issue when the broadcastable is checked in util::broadcastable, since they might be broadcastable according to the masked_fill torch rules, but the TensorRT select layer will restrict since they would not be broadcastable.

Reference to Issue 1573 after PR 1609

Workaround

At present padding both the self tensor, when mask tensor has dimension greater than the self tensor causes issue. eg: mask tensor is of shape [1,1,1,1488] and the self tensor is [1,512, 1488] then padding self to mask with additional 1s, causes error down the line in aten::matmul when last dimension of input0 is 1 (should be 512 )and second last dimension of input 1 is 512.

if(mask->getDimensions().nbDims < self->getDimensions().nbDims) {
        mask = addPadding(ctx, n, mask, self->getDimensions().nbDims, false, true);
 } else {
         self = addPadding(ctx, n, self, mask->getDimensions().nbDims, false, true);
 }

Hence we would want a broadcasting utility in converter_utils.cpp which would broadcast the self and mask tensor according to torch rules. It would remove the unnecessary 1s from the dimensions.

@github-actions
Copy link

github-actions bot commented May 1, 2023

This issue has not seen activity for 90 days, Remove stale label or comment or this will be closed in 10 days

@github-actions
Copy link

This issue has not seen activity for 90 days, Remove stale label or comment or this will be closed in 10 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request No Activity
Projects
None yet
Development

No branches or pull requests

2 participants