Skip to content

Commit 3a18cd1

Browse files
committed
Removing stride and device since - 1. converting to torch Tensor would lead to faketensor 2. Also get_trt_tensor in the forward pass while creating the engine does not retain the memory_format
1 parent a135bab commit 3a18cd1

File tree

2 files changed

+9
-65
lines changed

2 files changed

+9
-65
lines changed

py/torch_tensorrt/dynamo/conversion/ops_evaluators.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,4 @@ def aten_ops_empty(
149149
else:
150150
# default returns np.float64. Verify the correctness of this
151151
empty_np_tensor = np.empty(tuple(args[0]))
152-
153-
empty_tensor = torch.Tensor(empty_np_tensor)
154-
# device
155-
if kwargs.get("device") is not None:
156-
empty_tensor = empty_tensor.to(device=kwargs.get("device"))
157-
158-
# memory_format. default is torch.contiguous_format
159-
if memory_format == torch.channels_last:
160-
# shape of args[0] must be 4
161-
empty_tensor = empty_tensor.to(memory_format=torch.channels_last)
162-
elif memory_format == torch.channels_last_3d:
163-
# shape of args[0] must be 5
164-
empty_tensor = empty_tensor.to(memory_format=torch.channels_last_3d)
165-
166-
return empty_tensor
152+
return empty_np_tensor

tests/py/dynamo/conversion/test_empty_aten.py

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,76 +12,45 @@
1212
"empty_one_dimension",
1313
[1],
1414
None,
15-
None,
16-
None,
1715
),
1816
(
1917
"empty_two_dimension",
2018
[1, 2],
2119
None,
22-
None,
23-
None,
2420
),
2521
(
2622
"empty_three_dimension",
2723
[2, 3, 4],
2824
None,
29-
None,
30-
None,
3125
),
3226
(
3327
"empty_one_dimension_dtype",
3428
[1],
3529
torch.float32,
36-
None,
37-
None,
3830
),
3931
(
4032
"empty_two_dimension_dtype",
4133
[2, 3],
4234
torch.float32,
43-
None,
44-
None,
45-
),
46-
(
47-
"empty_one_dimension_dtype_device",
48-
[1],
49-
torch.float32,
50-
"cuda",
51-
None,
52-
),
53-
(
54-
"empty_two_dimension_dtype_device",
55-
[2, 3],
56-
torch.float32,
57-
"cuda",
58-
None,
5935
),
6036
(
61-
"empty_four_dimension_memformat",
37+
"empty_four_dimension_dtype",
6238
[1, 2, 2, 1],
6339
torch.float32,
64-
"cuda",
65-
torch.channels_last,
6640
),
6741
(
68-
"empty_five_dimension_memformat",
42+
"empty_five_dimension_dtype",
6943
[1, 2, 2, 2, 1],
7044
torch.float32,
71-
"cuda",
72-
torch.channels_last_3d,
7345
),
7446
]
7547

7648

7749
class TestEmptyConverter(DispatchTestCase):
7850
@parameterized.expand(
79-
[
80-
(empty_op[0], empty_op[1], empty_op[2], empty_op[3], empty_op[4])
81-
for empty_op in empty_ops
82-
]
51+
[(empty_op[0], empty_op[1], empty_op[2]) for empty_op in empty_ops]
8352
)
84-
def test_empty(self, name, shape_or_input, data_type, device, memory_format):
53+
def test_empty(self, name, shape_or_input, data_type):
8554
class TestModule(nn.Module):
8655
def __init__(self):
8756
super().__init__()
@@ -91,42 +60,31 @@ def forward(self, x):
9160
return torch.ops.aten.empty.memory_format(
9261
shape_or_input,
9362
dtype=data_type,
94-
memory_format=memory_format,
95-
device=device,
9663
)
9764

9865
empty_model = TestModule()
9966

10067
inputs = [torch.randint(1, 3, shape_or_input, dtype=torch.int32)]
10168
comparator_shape_dtype_device = (
102-
lambda x, y, check_dtype, check_device: x.shape == y.shape
69+
lambda x, y, check_dtype: x.shape == y.shape
10370
and (x.stride() == y.stride())
10471
and (x.dtype == y.dtype if check_dtype else True)
105-
and (x.get_device() == y.get_device() if check_device else True)
10672
)
10773
expected_ops = []
108-
if "device" in name:
109-
self.run_test_compare_tensor_attributes_only(
110-
empty_model,
111-
inputs,
112-
expected_ops,
113-
[(comparator_shape_dtype_device, [True, True])],
114-
use_dynamo_tracer=True,
115-
)
116-
elif "dtype" in name:
74+
if "dtype" in name:
11775
self.run_test_compare_tensor_attributes_only(
11876
empty_model,
11977
inputs,
12078
expected_ops,
121-
[(comparator_shape_dtype_device, [True, False])],
79+
[(comparator_shape_dtype_device, [True])],
12280
use_dynamo_tracer=True,
12381
)
12482
else:
12583
self.run_test_compare_tensor_attributes_only(
12684
empty_model,
12785
inputs,
12886
expected_ops,
129-
[(comparator_shape_dtype_device, [False, False])],
87+
[(comparator_shape_dtype_device, [False])],
13088
use_dynamo_tracer=True,
13189
)
13290

0 commit comments

Comments
 (0)