Skip to content

Commit 50a5db6

Browse files
Arm backend: Fix TOSA INT flow tensor memory store (pytorch#21398)
Tensors for TOSA INT test flow were represented as certain type of memory store but were not contiguous in memory. This resulted in a mismatch between representation and actual memory layout. This commit fixes the issue by changing the memory store type to a contiguous one. Change-Id: Ied846744b74477e76bf3e5b17db2f494072c207c cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani Signed-off-by: Michiel Olieslagers <michiel.olieslagers@arm.com>
1 parent b3d69a9 commit 50a5db6

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎backends/arm/test/misc/test_runner_utils.py‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,30 @@ def test_numpy_to_torch_tensor_converts_dynamic_nhwc_output(monkeypatch) -> None
155155
result = runner_utils.numpy_to_torch_tensor(array, cast(Any, object()))
156156

157157
assert result.shape == (1, 3, 4, 5)
158-
assert result.is_contiguous(memory_format=torch.channels_last)
158+
assert result.is_contiguous()
159159
torch.testing.assert_close(result, torch.from_numpy(array).permute(0, 3, 1, 2))
160160

161161

162+
def test_numpy_to_torch_tensor_converts_concrete_nhwc_output_to_contiguous(
163+
monkeypatch,
164+
) -> None:
165+
output_tensor = SimpleNamespace(
166+
shape=(1, 3, 4, 5),
167+
dtype=torch.int8,
168+
dim_order=lambda: runner_utils.NHWC_ORDER,
169+
)
170+
monkeypatch.setattr(
171+
runner_utils, "get_first_fake_tensor", lambda output_node: output_tensor
172+
)
173+
array = np.arange(60, dtype=np.int8).reshape(1, 4, 5, 3)
174+
175+
result = runner_utils.numpy_to_torch_tensor(array, cast(Any, object()))
176+
expected = torch.from_numpy(array).permute(0, 3, 1, 2).contiguous()
177+
178+
assert result.is_contiguous()
179+
torch.testing.assert_close(result, expected)
180+
181+
162182
def test_numpy_to_torch_tensor_converts_dynamic_nnhwc_output(monkeypatch) -> None:
163183
symbolic_dim = object()
164184
output_tensor = SimpleNamespace(
@@ -174,7 +194,7 @@ def test_numpy_to_torch_tensor_converts_dynamic_nnhwc_output(monkeypatch) -> Non
174194
result = runner_utils.numpy_to_torch_tensor(array, cast(Any, object()))
175195

176196
assert result.shape == (1, 2, 3, 4, 5)
177-
assert result.dim_order() == runner_utils.NNHWC_ORDER
197+
assert result.is_contiguous()
178198
torch.testing.assert_close(result, torch.from_numpy(array).permute(0, 1, 4, 2, 3))
179199

180200

‎backends/arm/test/runner_utils.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,12 @@ def to_torch_tensor() -> torch.Tensor:
285285
tensor = to_torch_tensor()
286286
if is_concrete_shape(shape):
287287
tensor = tensor.reshape([shape[i] for i in NHWC_ORDER])
288-
return tensor.permute(NHWC_INVERSE_ORDER).to(memory_format=torch.channels_last)
288+
return tensor.permute(NHWC_INVERSE_ORDER).contiguous()
289289
elif dim_order == NNHWC_ORDER:
290290
tensor = to_torch_tensor()
291291
if is_concrete_shape(shape):
292292
tensor = tensor.reshape([shape[i] for i in NNHWC_ORDER])
293-
return tensor.permute(NNHWC_INVERSE_ORDER)
293+
return tensor.permute(NNHWC_INVERSE_ORDER).contiguous()
294294
else:
295295
tensor = to_torch_tensor()
296296

0 commit comments

Comments
 (0)