From a1136b63ce015a760cafb0ea985b28367bc1ad24 Mon Sep 17 00:00:00 2001 From: Michiel Olieslagers Date: Fri, 24 Jul 2026 10:46:25 +0000 Subject: [PATCH] Arm backend: Fix TOSA INT flow tensor memory store 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. Signed-off-by: Michiel Olieslagers Change-Id: Ied846744b74477e76bf3e5b17db2f494072c207c --- backends/arm/test/misc/test_runner_utils.py | 24 +++++++++++++++++++-- backends/arm/test/runner_utils.py | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/backends/arm/test/misc/test_runner_utils.py b/backends/arm/test/misc/test_runner_utils.py index 54d41548a22..6acb04e054f 100644 --- a/backends/arm/test/misc/test_runner_utils.py +++ b/backends/arm/test/misc/test_runner_utils.py @@ -155,10 +155,30 @@ def test_numpy_to_torch_tensor_converts_dynamic_nhwc_output(monkeypatch) -> None result = runner_utils.numpy_to_torch_tensor(array, cast(Any, object())) assert result.shape == (1, 3, 4, 5) - assert result.is_contiguous(memory_format=torch.channels_last) + assert result.is_contiguous() torch.testing.assert_close(result, torch.from_numpy(array).permute(0, 3, 1, 2)) +def test_numpy_to_torch_tensor_converts_concrete_nhwc_output_to_contiguous( + monkeypatch, +) -> None: + output_tensor = SimpleNamespace( + shape=(1, 3, 4, 5), + dtype=torch.int8, + dim_order=lambda: runner_utils.NHWC_ORDER, + ) + monkeypatch.setattr( + runner_utils, "get_first_fake_tensor", lambda output_node: output_tensor + ) + array = np.arange(60, dtype=np.int8).reshape(1, 4, 5, 3) + + result = runner_utils.numpy_to_torch_tensor(array, cast(Any, object())) + expected = torch.from_numpy(array).permute(0, 3, 1, 2).contiguous() + + assert result.is_contiguous() + torch.testing.assert_close(result, expected) + + def test_numpy_to_torch_tensor_converts_dynamic_nnhwc_output(monkeypatch) -> None: symbolic_dim = object() output_tensor = SimpleNamespace( @@ -174,7 +194,7 @@ def test_numpy_to_torch_tensor_converts_dynamic_nnhwc_output(monkeypatch) -> Non result = runner_utils.numpy_to_torch_tensor(array, cast(Any, object())) assert result.shape == (1, 2, 3, 4, 5) - assert result.dim_order() == runner_utils.NNHWC_ORDER + assert result.is_contiguous() torch.testing.assert_close(result, torch.from_numpy(array).permute(0, 1, 4, 2, 3)) diff --git a/backends/arm/test/runner_utils.py b/backends/arm/test/runner_utils.py index 1cbfcd12754..7c23ee9dbc2 100644 --- a/backends/arm/test/runner_utils.py +++ b/backends/arm/test/runner_utils.py @@ -285,12 +285,12 @@ def to_torch_tensor() -> torch.Tensor: tensor = to_torch_tensor() if is_concrete_shape(shape): tensor = tensor.reshape([shape[i] for i in NHWC_ORDER]) - return tensor.permute(NHWC_INVERSE_ORDER).to(memory_format=torch.channels_last) + return tensor.permute(NHWC_INVERSE_ORDER).contiguous() elif dim_order == NNHWC_ORDER: tensor = to_torch_tensor() if is_concrete_shape(shape): tensor = tensor.reshape([shape[i] for i in NNHWC_ORDER]) - return tensor.permute(NNHWC_INVERSE_ORDER) + return tensor.permute(NNHWC_INVERSE_ORDER).contiguous() else: tensor = to_torch_tensor()