-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: `index_select` op has been [available](https://github.com/facebookincubator/AITemplate/blob/main/python/aitemplate/compiler/ops/tensor/index_select.py) in AIT for a while, but we never had an fx2ait converter for it. This diff adds one. Differential Revision: D50119460 fbshipit-source-id: 48693c640495d651674d8a24b10252991428efb8
- Loading branch information
1 parent
5a01ce7
commit 0333b5e
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
import torch | ||
from fx2ait.acc_tracer import acc_ops | ||
from fx2ait.tools.common_fx2ait import AITTestCase | ||
from parameterized import param, parameterized | ||
|
||
|
||
class TestIndexSelectConverter(AITTestCase): | ||
@parameterized.expand( | ||
[ | ||
param( | ||
"first_dim", | ||
torch.randn(5, 10, 20), | ||
0, | ||
torch.randint(low=0, high=5, size=(3,)), | ||
), | ||
param( | ||
"mid_dim", | ||
torch.randn(5, 10, 20), | ||
1, | ||
torch.randint(low=0, high=10, size=(20,)), | ||
), | ||
param( | ||
"last_dim", | ||
torch.randn(5, 10, 20), | ||
2, | ||
torch.randint(low=0, high=20, size=(10,)), | ||
), | ||
] | ||
) | ||
def test_index_select(self, _, inp, dim, index): | ||
class TestModule(torch.nn.Module): | ||
def forward( | ||
self, | ||
inp: torch.Tensor, | ||
index: torch.Tensor, | ||
) -> torch.Tensor: | ||
return torch.index_select(inp, dim, index=index) | ||
|
||
model = TestModule().eval().half().cuda() | ||
inputs = [inp.cuda(), index.cuda()] | ||
|
||
self.run_test(model, inputs, expected_ops={acc_ops.index_select}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters