Skip to content

Commit 002b35d

Browse files
committed
Empty_like evaluator
1 parent 7f14221 commit 002b35d

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

py/torch_tensorrt/dynamo/conversion/ops_evaluators.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ def aten_ops_arange_start_step(
4747
name: str,
4848
) -> Union[TRTTensor, Sequence[TRTTensor]]:
4949
return np.arange(*args)
50+
51+
52+
@dynamo_tensorrt_converter(torch.ops.aten.empty_like.default)
53+
def aten_ops_empty_like(
54+
ctx: ConversionContext,
55+
target: Target,
56+
args: Tuple[Argument, ...],
57+
kwargs: Dict[str, Argument],
58+
name: str,
59+
) -> TRTTensor:
60+
return np.empty_like(*args)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import torch
2+
import torch.nn as nn
3+
from parameterized import parameterized
4+
from torch.testing._internal.common_utils import run_tests
5+
6+
from .harness import DispatchTestCase
7+
8+
9+
class TestEmptyLikeConverter(DispatchTestCase):
10+
@parameterized.expand(
11+
[
12+
((1), torch.int),
13+
((1, 2), torch.int),
14+
((2, 1), torch.int),
15+
((2, 2), torch.int),
16+
((1, 2, 3), torch.int),
17+
((1, 3, 2), torch.int),
18+
((1), torch.int32),
19+
((1, 2), torch.int32),
20+
((2, 1), torch.int32),
21+
((2, 2), torch.int32),
22+
((1, 2, 3), torch.int32),
23+
((1, 3, 2), torch.int32),
24+
]
25+
)
26+
def test_empty_like(self, input_shape, dtype):
27+
class Empty_Like(nn.Module):
28+
def forward(self, x):
29+
return torch.ops.aten.empty_like(x, dtype)
30+
31+
inputs = [torch.empty(input_shape)]
32+
self.run_test(
33+
Empty_Like(),
34+
inputs,
35+
use_dynamo_tracer=True,
36+
)
37+
38+
39+
if __name__ == "__main__":
40+
run_tests()

0 commit comments

Comments
 (0)