|
| 1 | +# Copyright 2026 NXP |
| 2 | +# |
| 3 | +# This source code is licensed under the BSD-style license found in the |
| 4 | +# LICENSE file in the root directory of this source tree. |
| 5 | + |
| 6 | +import numpy as np |
| 7 | + |
| 8 | +# noinspection PyUnusedImports |
| 9 | +import pytest |
| 10 | +import torch |
| 11 | + |
| 12 | +from executorch.backends.nxp.tests.graph_verifier import DetailedGraphVerifier |
| 13 | +from executorch.backends.nxp.tests.nsys_testing import lower_run_compare |
| 14 | +from executorch.backends.nxp.tests.ops_aliases import Exp |
| 15 | +from executorch.backends.nxp.tests.use_qat import * # noqa F403 |
| 16 | +from executorch.backends.nxp.tests.dataset_creator import ( |
| 17 | + LinearRampDatasetCreator, |
| 18 | + RandomDatasetCreator, |
| 19 | +) |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture(autouse=True) |
| 23 | +def reseed_model_per_test_run(): |
| 24 | + torch.manual_seed(42) |
| 25 | + np.random.seed(23) |
| 26 | + |
| 27 | + |
| 28 | +class ExpModule(torch.nn.Module): |
| 29 | + |
| 30 | + def __init__(self): |
| 31 | + super().__init__() |
| 32 | + |
| 33 | + def forward(self, x): |
| 34 | + return torch.exp(x) |
| 35 | + |
| 36 | + |
| 37 | +class TestExpNewNeutronFlow: |
| 38 | + def test__basic_nsys_inference(self, mocker, request): |
| 39 | + input_shape = (256,) |
| 40 | + model = ExpModule() |
| 41 | + graph_verifier = DetailedGraphVerifier( |
| 42 | + mocker, expected_delegated_ops={Exp: 1}, expected_non_delegated_ops={} |
| 43 | + ) |
| 44 | + lower_run_compare( |
| 45 | + model, |
| 46 | + input_shape, |
| 47 | + graph_verifier, |
| 48 | + request, |
| 49 | + dataset_creator=LinearRampDatasetCreator(), |
| 50 | + ) |
| 51 | + |
| 52 | + @pytest.mark.parametrize( |
| 53 | + "input_shape", |
| 54 | + [ |
| 55 | + pytest.param((17, 2), id="2D"), |
| 56 | + pytest.param((1, 3, 10), id="3D"), |
| 57 | + pytest.param((1, 3, 16, 16), id="4D"), |
| 58 | + ], |
| 59 | + ) |
| 60 | + def test__basic_nsys_inference__qat(self, mocker, request, input_shape, use_qat): |
| 61 | + model = ExpModule() |
| 62 | + graph_verifier = DetailedGraphVerifier( |
| 63 | + mocker, expected_delegated_ops={Exp: 1}, expected_non_delegated_ops={} |
| 64 | + ) |
| 65 | + lower_run_compare( |
| 66 | + model, |
| 67 | + input_shape, |
| 68 | + graph_verifier, |
| 69 | + request, |
| 70 | + dataset_creator=RandomDatasetCreator(low=-1.0, high=1.0), |
| 71 | + use_qat=use_qat, |
| 72 | + ) |
0 commit comments