Skip to content

Commit dd4985d

Browse files
Arm backend: Upstreamed NFRU model testing. (pytorch#22887)
Change-Id: I6f1a93ff1b7c1b4064aba7f4531857c5272bd2b9 cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani Signed-off-by: Michiel Olieslagers <michiel.olieslagers@arm.com>
1 parent 62ef2af commit dd4985d

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

‎backends/arm/test/models/test_nfru.py‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
# LICENSE file in the root directory of this source tree.
55

66
import os
7+
from typing import Tuple
78

89
os.environ.setdefault("HF_HUB_DISABLE_XET", "1")
910

1011
import pytest
12+
1113
import torch
1214

1315
from executorch.backends.arm.test import common
1416
from executorch.backends.arm.test.tester.test_pipeline import (
17+
TosaPipelineFP,
1518
TosaPipelineINT,
1619
VgfPipeline,
1720
)
@@ -20,6 +23,7 @@
2023
NFRUAutoEncoder,
2124
)
2225

26+
input_t = Tuple[torch.Tensor] # Input x
2327

2428
_RELEASE_REFS = (
2529
os.environ.get("GITHUB_REF", ""),
@@ -38,6 +42,7 @@
3842

3943

4044
def nfru() -> NFRUAutoEncoder:
45+
"""Get an instance of NFRU with FP32 weights loaded."""
4146
weights = hf_hub_download( # nosec B615
4247
repo_id="Arm/neural-frame-rate-upscaling",
4348
filename="nfru_v1_fp32.pt",
@@ -60,6 +65,85 @@ def nfru() -> NFRUAutoEncoder:
6065
return model
6166

6267

68+
def example_inputs(memory_format: torch.memory_format = torch.channels_last):
69+
return (torch.randn((1, 16, 270, 480)).to(memory_format=memory_format),)
70+
71+
72+
def test_nfru_tosa_FP():
73+
pipeline = TosaPipelineFP[input_t](
74+
nfru().eval(),
75+
example_inputs(),
76+
aten_op=[],
77+
exir_op=[],
78+
)
79+
pipeline.run()
80+
81+
82+
def test_nfru_tosa_INT():
83+
pipeline = TosaPipelineINT[input_t](
84+
nfru().eval(),
85+
example_inputs(),
86+
aten_op=[],
87+
exir_op=[],
88+
atol=0.2,
89+
)
90+
pipeline.run()
91+
92+
93+
def test_nfru_tosa_INT_a16w8():
94+
pipeline = TosaPipelineINT[input_t](
95+
nfru().eval(),
96+
example_inputs(),
97+
aten_op=[],
98+
exir_op=[],
99+
tosa_extensions=["int16"],
100+
atol=0.1,
101+
)
102+
pipeline.run()
103+
104+
105+
@common.SkipIfNoModelConverter
106+
def test_nfru_vgf_no_quant():
107+
pipeline = VgfPipeline[input_t](
108+
nfru().eval(),
109+
example_inputs(),
110+
aten_op=[],
111+
exir_op=[],
112+
tosa_version="TOSA-1.0+FP",
113+
quantize=False,
114+
)
115+
pipeline.run()
116+
117+
118+
@common.SkipIfNoModelConverter
119+
def test_nfru_vgf_quant():
120+
pipeline = VgfPipeline[input_t](
121+
nfru().eval(),
122+
example_inputs(),
123+
aten_op=[],
124+
exir_op=[],
125+
tosa_version="TOSA-1.0+INT",
126+
symmetric_io_quantization=True,
127+
atol=0.2,
128+
)
129+
pipeline.run()
130+
131+
132+
@common.SkipIfNoModelConverter
133+
def test_nfru_vgf_quant_a16w8():
134+
pipeline = VgfPipeline[input_t](
135+
nfru().eval(),
136+
example_inputs(),
137+
aten_op=[],
138+
exir_op=[],
139+
tosa_version="TOSA-1.0+INT",
140+
tosa_extensions=["int16"],
141+
symmetric_io_quantization=True,
142+
atol=0.2,
143+
)
144+
pipeline.run()
145+
146+
63147
def test_nfru_qat_tosa_INT() -> None:
64148
pipeline = TosaPipelineINT(
65149
nfru(),

0 commit comments

Comments
 (0)