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

ait: Explicitly throw when indexing a boolean tensor for masking #992

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fx2ait/fx2ait/converters/ait_converters.py
Original file line number Diff line number Diff line change
@@ -668,6 +668,13 @@ def acc_ops_getitem(
isinstance(idx, Sequence) and any(isinstance(x, slice) for x in idx)
):
return acc_ops_slice(target, args, kwargs, name)

if isinstance(idx, AITTensor) and idx.dtype() == "bool":
# TODO: could do something similar to acc_ops_masked_select
raise NotImplementedError(
"AIT does not support tensor[boolean_tensor] masking yet"
)

if isinstance(input_val, AITTensor):
return acc_ops_slice(target, args, kwargs, name)

19 changes: 19 additions & 0 deletions fx2ait/fx2ait/test/converters/test_ait_binary_op.py
Original file line number Diff line number Diff line change
@@ -154,6 +154,25 @@ def forward(self, input: torch.Tensor) -> torch.Tensor:
expected_ops={acc_op},
)

def test_getitem_boolean_index(self) -> None:
"""Verify that NotImplementatedError is thrown encountering
tensor[boolean_mask_tensor]
"""

class TestModule(torch.nn.Module):
def forward(self, x: torch.Tensor, mask: torch.Tensor) -> torch.Tensor:
return x[mask]

mod = TestModule().cuda()
x = torch.rand(10, 4).half().cuda()
mask = (torch.rand((10,)) > 0.5).cuda()
mod(x, mask)

self.assertRaises(
NotImplementedError,
lambda: self.run_test(mod, [x, mask], expected_ops={}),
)

# This is a common binary op combo usage for ads models.
def test_binary_op_combo(self) -> None:
class TestModule(torch.nn.Module):