Skip to content

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

Closed
@apbose

Description

@apbose

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions