|
7 | 7 | # pyre-strict
|
8 | 8 |
|
9 | 9 | import io
|
| 10 | +import tempfile |
10 | 11 | import unittest
|
11 | 12 | from typing import Tuple
|
12 | 13 |
|
13 | 14 | import executorch.exir as exir
|
14 | 15 |
|
15 | 16 | import torch
|
| 17 | +from executorch.backends.xnnpack.partition.xnnpack_partitioner import ( |
| 18 | + XnnpackFloatingPointPartitioner, |
| 19 | +) |
16 | 20 | from executorch.exir import to_edge
|
17 | 21 | from executorch.exir.backend.backend_api import CompileSpec, to_backend
|
18 | 22 | from executorch.exir.backend.test.backend_with_compiler_demo import (
|
19 | 23 | BackendWithCompilerDemo,
|
20 | 24 | )
|
21 | 25 |
|
22 | 26 | from executorch.exir.backend.test.op_partitioner_demo import AddMulPartitionerDemo
|
| 27 | +from executorch.exir.program._program import ( |
| 28 | + EdgeProgramManager, |
| 29 | + to_edge_transform_and_lower, |
| 30 | +) |
23 | 31 | from executorch.exir.serde.serialize import deserialize, serialize
|
24 | 32 | from torch import nn
|
25 | 33 | from torch.export import export
|
@@ -202,6 +210,33 @@ def forward(self, a, x, b):
|
202 | 210 | edge_new = deserialize(serialize(edge.exported_program()))
|
203 | 211 | self.check_ep(edge.exported_program(), edge_new, inputs)
|
204 | 212 |
|
| 213 | + def test_delegate_xnnpack(self) -> None: |
| 214 | + class SimpleConv1DModel(nn.Module): |
| 215 | + def __init__(self): |
| 216 | + super(SimpleConv1DModel, self).__init__() |
| 217 | + self.conv1 = nn.Conv1d( |
| 218 | + in_channels=1, out_channels=16, kernel_size=3, stride=1, padding=1 |
| 219 | + ) |
| 220 | + |
| 221 | + def forward(self, x): |
| 222 | + x = self.conv1(x) |
| 223 | + return x |
| 224 | + |
| 225 | + x = torch.randn(64, 1, 100) |
| 226 | + model = SimpleConv1DModel() |
| 227 | + ep = torch.export.export(model, (x,)) |
| 228 | + edge_orig = to_edge_transform_and_lower( |
| 229 | + ep, partitioner=[XnnpackFloatingPointPartitioner()] |
| 230 | + ) |
| 231 | + |
| 232 | + with tempfile.NamedTemporaryFile() as f: |
| 233 | + exir.save(edge_orig.exported_program(), f) |
| 234 | + edge_deserialized = EdgeProgramManager(exir.load(f)) |
| 235 | + self.assertTrue( |
| 236 | + edge_orig.to_executorch().buffer |
| 237 | + == edge_deserialized.to_executorch().buffer |
| 238 | + ) |
| 239 | + |
205 | 240 | def test_meta_stack_trace_module_hierarchy(self) -> None:
|
206 | 241 | class Model(nn.Module):
|
207 | 242 | def __init__(self):
|
|
0 commit comments