|
| 1 | +# Copyright 2026 Arm Limited and/or its affiliates. |
| 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 torch |
| 7 | +import torch.nn.functional as F |
| 8 | +from executorch.backends.arm.test import common |
| 9 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 10 | + EthosU55PipelineINT, |
| 11 | + EthosU85PipelineINT, |
| 12 | + TosaPipelineINT, |
| 13 | + VgfPipeline, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +class QwenDeltaGate(torch.nn.Module): |
| 18 | + a_log: torch.Tensor |
| 19 | + dt_bias: torch.Tensor |
| 20 | + |
| 21 | + def __init__(self) -> None: |
| 22 | + super().__init__() |
| 23 | + self.register_buffer("a_log", torch.log(torch.tensor([0.5, 1.0, 1.5, 2.0]))) |
| 24 | + self.register_buffer("dt_bias", torch.tensor([-2.0, -0.5, 0.5, 2.0])) |
| 25 | + |
| 26 | + def forward(self, a: torch.Tensor) -> torch.Tensor: |
| 27 | + g = -self.a_log.exp() * F.softplus(a + self.dt_bias) |
| 28 | + return g.exp() |
| 29 | + |
| 30 | + |
| 31 | +@common.XfailIfNoCorstone300 |
| 32 | +def test_qwen_gate_u55_int(): |
| 33 | + values = torch.linspace(-4.0, 4.0, 32).reshape(1, 8, 4) |
| 34 | + pipeline = EthosU55PipelineINT( |
| 35 | + QwenDeltaGate(), |
| 36 | + (values,), |
| 37 | + "torch.ops.aten.softplus.default", |
| 38 | + "executorch_exir_dialects_edge__ops_aten_softplus_default", |
| 39 | + run_on_fvp=True, |
| 40 | + ) |
| 41 | + pipeline.run() |
| 42 | + |
| 43 | + |
| 44 | +@common.XfailIfNoCorstone320 |
| 45 | +def test_qwen_gate_u85_int8(): |
| 46 | + values = torch.linspace(-4.0, 4.0, 32).reshape(1, 8, 4) |
| 47 | + pipeline = EthosU85PipelineINT( |
| 48 | + QwenDeltaGate(), |
| 49 | + (values,), |
| 50 | + "torch.ops.aten.softplus.default", |
| 51 | + "executorch_exir_dialects_edge__ops_aten_softplus_default", |
| 52 | + run_on_fvp=True, |
| 53 | + ) |
| 54 | + pipeline.run() |
| 55 | + |
| 56 | + |
| 57 | +@common.XfailIfNoCorstone320 |
| 58 | +def test_qwen_gate_u85_int16(): |
| 59 | + values = torch.linspace(-4.0, 4.0, 32).reshape(1, 8, 4) |
| 60 | + pipeline = EthosU85PipelineINT( |
| 61 | + QwenDeltaGate(), |
| 62 | + (values,), |
| 63 | + "torch.ops.aten.softplus.default", |
| 64 | + "executorch_exir_dialects_edge__ops_aten_softplus_default", |
| 65 | + run_on_fvp=True, |
| 66 | + a16w8_quantization=True, |
| 67 | + ) |
| 68 | + pipeline.run() |
| 69 | + |
| 70 | + |
| 71 | +@common.SkipIfNoModelConverter |
| 72 | +def test_qwen_gate_vgf_quant(): |
| 73 | + values = torch.linspace(-4.0, 4.0, 32).reshape(1, 8, 4) |
| 74 | + pipeline = VgfPipeline( |
| 75 | + QwenDeltaGate(), |
| 76 | + (values,), |
| 77 | + "torch.ops.aten.softplus.default", |
| 78 | + "executorch_exir_dialects_edge__ops_aten_softplus_default", |
| 79 | + run_on_vulkan_runtime=True, |
| 80 | + ) |
| 81 | + pipeline.run() |
| 82 | + |
| 83 | + |
| 84 | +def test_qwen_gate_tosa_int(): |
| 85 | + values = torch.linspace(-4.0, 4.0, 32).reshape(1, 8, 4) |
| 86 | + pipeline = TosaPipelineINT( |
| 87 | + QwenDeltaGate(), |
| 88 | + (values,), |
| 89 | + "torch.ops.aten.softplus.default", |
| 90 | + "executorch_exir_dialects_edge__ops_aten_softplus_default", |
| 91 | + ) |
| 92 | + pipeline.count_tosa_ops({"TABLE": 2}) |
| 93 | + pipeline.run() |
| 94 | + |
| 95 | + |
| 96 | +def test_qwen_gate_tosa_a16w8(): |
| 97 | + values = torch.linspace(-4.0, 4.0, 32).reshape(1, 8, 4) |
| 98 | + pipeline = TosaPipelineINT( |
| 99 | + QwenDeltaGate(), |
| 100 | + (values,), |
| 101 | + "torch.ops.aten.softplus.default", |
| 102 | + "executorch_exir_dialects_edge__ops_aten_softplus_default", |
| 103 | + tosa_extensions=["int16"], |
| 104 | + ) |
| 105 | + pipeline.count_tosa_ops({"TABLE": 2}) |
| 106 | + pipeline.run() |
0 commit comments