Skip to content

Commit 43555d2

Browse files
authored
Add mobilenet_v2 and resnet50 to the examples
Differential Revision: D66132529 Pull Request resolved: #6940
1 parent 50b4ac3 commit 43555d2

File tree

6 files changed

+92
-2
lines changed

6 files changed

+92
-2
lines changed

backends/cadence/aot/functions.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@
7777
- arg_meta: null
7878
kernel_name: torch::executor::gelu_out
7979

80+
- op: hardtanh.out
81+
kernels:
82+
- arg_meta: null
83+
kernel_name: torch::executor::hardtanh_out
84+
85+
- op: max_pool2d_with_indices.out
86+
kernels:
87+
- arg_meta: null
88+
kernel_name: torch::executor::max_pool2d_with_indices_out
89+
8090
- op: mean.out
8191
kernels:
8292
- arg_meta: null

backends/cadence/aot/functions_hifi.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,26 @@
6262
- arg_meta: null
6363
kernel_name: torch::executor::full_out
6464

65+
- op: gelu.out
66+
kernels:
67+
- arg_meta: null
68+
kernel_name: torch::executor::gelu_out
69+
70+
- op: hardtanh.out
71+
kernels:
72+
- arg_meta: null
73+
kernel_name: torch::executor::hardtanh_out
74+
75+
- op: max_pool2d_with_indices.out
76+
kernels:
77+
- arg_meta: null
78+
kernel_name: torch::executor::max_pool2d_with_indices_out
79+
6580
- op: mean.out
6681
kernels:
6782
- arg_meta: null
68-
kernel_name: cadence::impl::HiFi::mean_dim_out
69-
83+
kernel_name: cadence::impl::HiFi::mean_dim_out
84+
7085
- op: mul.out
7186
kernels:
7287
- arg_meta: null

backends/cadence/hifi/operators/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ set(_aten_ops__srcs
3333
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_clone.cpp"
3434
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_embedding.cpp"
3535
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_full.cpp"
36+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_gelu.cpp"
37+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_hardtanh.cpp"
38+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_max_pool2d_with_indices.cpp"
3639
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_permute_copy.cpp"
3740
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_slice_copy.cpp"
3841
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_softmax.cpp"

backends/cadence/reference/operators/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ set(_aten_ops__srcs
3939
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_cat.cpp"
4040
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_clone.cpp"
4141
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_div.cpp"
42+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_hardtanh.cpp"
43+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_max_pool2d_with_indices.cpp"
4244
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_mean.cpp"
4345
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_mul.cpp"
4446
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_permute_copy.cpp"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Example script for exporting simple models to flatbuffer
8+
9+
import logging
10+
11+
import torch
12+
13+
from executorch.backends.cadence.aot.ops_registrations import * # noqa
14+
15+
16+
from executorch.backends.cadence.aot.export_example import export_model
17+
from torchvision.models import mobilenet_v2, MobileNet_V2_Weights
18+
19+
20+
FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
21+
logging.basicConfig(level=logging.INFO, format=FORMAT)
22+
23+
24+
if __name__ == "__main__":
25+
26+
model = mobilenet_v2(weights=MobileNet_V2_Weights.DEFAULT)
27+
model.eval()
28+
example_inputs = (torch.randn(1, 3, 64, 64),)
29+
30+
export_model(model, example_inputs)

examples/cadence/models/resnet50.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Example script for exporting simple models to flatbuffer
8+
9+
import logging
10+
11+
import torch
12+
13+
from executorch.backends.cadence.aot.ops_registrations import * # noqa
14+
15+
16+
from executorch.backends.cadence.aot.export_example import export_model
17+
from torchvision.models import resnet50, ResNet50_Weights
18+
19+
20+
FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
21+
logging.basicConfig(level=logging.INFO, format=FORMAT)
22+
23+
24+
if __name__ == "__main__":
25+
26+
model = resnet50(weights=ResNet50_Weights.DEFAULT)
27+
model.eval()
28+
example_inputs = (torch.randn(1, 3, 64, 64),)
29+
30+
export_model(model, example_inputs)

0 commit comments

Comments
 (0)