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 operations in aten::masked_fill and element_wise operations #1654

Closed
wants to merge 5 commits into from

Conversation

apbose
Copy link
Collaborator

@apbose apbose commented Feb 8, 2023

Description

This PR addresses the broadcasting issue encountered in the NeMo Citrinet model. (Bug 1573).

Fixes # (issue)

This PR makes two main changes-

  1. The TensorRT broadcast rules are more limited as compared to Torch broadcast rules - #1629. Hence the aten::masked_fill is modified to make mask and self Tensors broadcastable according to TensorRT rules.At present only the mask tensor is padded if its no of dimensions is lesser than the self Tensor, but not vice versa.
    Modification : The mask tensor is unpadded if its dimensions is greater than the self Tensor and it has leading 1 dimensions

  2. The element_wise operations broadcasts the two tensors to get to the same dimensions.
    Modification : The tensor having extra dimensions is checked if it requires the leading 1 dimensions and accordingly unpadded. Else the other tensor is padded.

The above model fails with the runtime error-RuntimeError: expand(CUDABoolType{[1, 1, 1, 1488]}, size=[1, 256, 1488]): the number of sizes provided (3) must be greater or equal to the number of dimensions in the tensor (4)

out dimension = 1, 256, 1488
mask dimension = 1,1,1,1488
Cases with output = out.masked_fill_(mask,2 ) fail while output = torch.masked_fill(mask,2) passes

@github-actions github-actions bot added component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler labels Feb 8, 2023
@github-actions github-actions bot requested a review from peri044 February 8, 2023 23:08
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

@narendasan
Copy link
Collaborator

@apbose we need tests to verify these changes. Also the TS tests are failing

@apbose
Copy link
Collaborator Author

apbose commented Feb 13, 2023

Yes @narendasan , I am looking at debugging the failing ts test

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@github-actions github-actions bot added the component: tests Issues re: Tests label Aug 7, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

@apbose apbose marked this pull request as draft September 1, 2023 17:58
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Comment on lines 157 to 163
int diff = selfDim.size() - otherDim.size();
bool canSqueeze = true;
for (int i = 0; i < diff; i++) {
if (selfDim[i] != 1) {
canSqueeze = false;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this work if diff < 0?

Copy link
Collaborator Author

@apbose apbose Sep 22, 2023

Choose a reason for hiding this comment

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

Yes it probably should since the above condition ensures that the self has greater dimension than the other. But this is leading to dimensions getting mishandled in bert model, so I need to remove this logic

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@apbose apbose closed this Oct 6, 2023
@apbose apbose reopened this Oct 6, 2023
@apbose
Copy link
Collaborator Author

apbose commented Oct 6, 2023

The above model fails in torchscript. aten::masked_fill rules are different from aten::_masked_fill

@apbose apbose closed this Oct 6, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants