Skip to content

Commit eb3715c

Browse files
committed
Update
[ghstack-poisoned]
1 parent efa5b13 commit eb3715c

File tree

4 files changed

+54
-32
lines changed

4 files changed

+54
-32
lines changed

.ci/scripts/wheel/post_build_script_windows.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

.ci/scripts/wheel/test_windows.py

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,71 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8-
import os
9-
import subprocess
10-
import test_base
11-
from examples.models import Backend, Model
12-
from test_base import ModelTest
138
from typing import List
149

15-
def map_backend_name(name: str) -> str:
16-
# Map the backend name to the string used by the Windows test jobs, which use
17-
# a slightly different convention. This is an artifact of us being mid-update
18-
# of the model test logic.
19-
# TODO(gjcomer) Clean this up when we update the model test CI.
10+
import torch
11+
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
12+
from executorch.examples.models import Backend, Model, MODEL_NAME_TO_MODEL
13+
from executorch.examples.models.model_factory import EagerModelFactory
14+
from executorch.examples.xnnpack import MODEL_NAME_TO_OPTIONS
15+
from executorch.examples.xnnpack.quantization.utils import quantize as quantize_xnn
16+
from executorch.exir import EdgeCompileConfig, to_edge_transform_and_lower
17+
from executorch.extension.pybindings.portable_lib import (
18+
_load_for_executorch_from_buffer,
19+
)
20+
from test_base import ModelTest
21+
22+
23+
def test_model_xnnpack(model: Model, quantize: bool) -> None:
24+
model_instance, example_inputs, _, _ = EagerModelFactory.create_model(
25+
*MODEL_NAME_TO_MODEL[str(model)]
26+
)
27+
28+
model_instance.eval()
29+
ref_outputs = model_instance(*example_inputs)
30+
31+
if quantize:
32+
quant_type = MODEL_NAME_TO_OPTIONS[str(model)].quantization
33+
model_instance = torch.export.export_for_training(
34+
model_instance, example_inputs
35+
)
36+
model_instance = quantize_xnn(
37+
model_instance.module(), example_inputs, quant_type
38+
)
39+
40+
lowered = to_edge_transform_and_lower(
41+
torch.export.export(model_instance, example_inputs),
42+
partitioner=[XnnpackPartitioner()],
43+
compile_config=EdgeCompileConfig(
44+
_check_ir_validity=False,
45+
),
46+
).to_executorch()
47+
48+
loaded_model = _load_for_executorch_from_buffer(lowered.buffer)
49+
et_outputs = loaded_model([*example_inputs])
50+
51+
if isinstance(ref_outputs, torch.Tensor):
52+
ref_outputs = (ref_outputs,)
53+
54+
assert len(ref_outputs) == len(et_outputs)
55+
for i in range(len(ref_outputs)):
56+
assert torch.allclose(ref_outputs[i], et_outputs[i], atol=1e-5)
2057

21-
if name == "xnnpack-quantization-delegation":
22-
return "xnnpack-q8"
23-
else:
24-
return name
2558

2659
def run_tests(model_tests: List[ModelTest]) -> None:
2760
for model_test in model_tests:
28-
subprocess.run(
29-
[
30-
"powershell.exe",
31-
os.path.join(test_base._repository_root_dir(), ".ci/scripts/test_model.ps1"),
32-
"-ModelName",
33-
str(model_test.model),
34-
"-Backend",
35-
map_backend_name(str(model_test.backend)),
36-
],
37-
check=True,
38-
cwd=test_base._repository_root_dir(),
39-
)
61+
if model_test.backend == Backend.Xnnpack:
62+
test_model_xnnpack(model_test.model, quantize=False)
63+
else:
64+
raise RuntimeError(f"Unsupported backend {model_test.backend}.")
4065

4166

4267
if __name__ == "__main__":
4368
run_tests(
4469
model_tests=[
4570
ModelTest(
4671
model=Model.Mv3,
47-
backend=Backend.XnnpackQuantizationDelegation,
72+
backend=Backend.Xnnpack,
4873
),
4974
]
5075
)

.github/workflows/build-wheels-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- repository: pytorch/executorch
3939
pre-script: .ci\\scripts\\wheel\\pre_build_script.sh
4040
env-script: .ci\\scripts\\wheel\\vc_env_helper.bat
41-
post-script: .ci\\scripts\\wheel\\post_build_script_windows.sh
41+
post-script: .ci\\scripts\\wheel\\post_build_script.sh
4242
smoke-test-script: .ci/scripts/wheel/test_windows.py
4343
package-name: executorch
4444
name: ${{ matrix.repository }}

examples/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __str__(self) -> str:
4444

4545

4646
class Backend(str, Enum):
47+
Xnnpack = ("xnnpack",)
4748
XnnpackQuantizationDelegation = "xnnpack-quantization-delegation"
4849
CoreMlExportOnly = "coreml"
4950
CoreMlExportAndTest = "coreml-test" # AOT export + test with runner

0 commit comments

Comments
 (0)