Skip to content

Commit e4dd23a

Browse files
author
zhenyanzhang
committed
Update on "[0.6 documentation] Fix Page Developer Tools: Bundled Program"
#10193 - Update the hyperlink of “Generate Sample ExecuTorch program”, as this part has been heavily revamped in v0.6: - Update to https://pytorch.org/executorch/0.6/getting-started.html#exporting - Fixed the emit stage sample code: - Use `register_buffer` as warning suggests. - Update `to_edge` to be `to_edge_transform_and_lower`, as updated in https://pytorch.org/executorch/0.6/getting-started.html. - Remove function blocks for `get_program_data`, `load_bundled_input` and `load_bundled_output`, as there are no other similar usage in the doc. - Changed to links of real-world examples. - Remove hard-coded cpp code examples. - For APIs, provide links to real-world examples. - For runtime example, change to a ready-to-use snippet for people to quickly try out. Differential Revision: [D73027728](https://our.internmc.facebook.com/intern/diff/D73027728/) [ghstack-poisoned]
2 parents 0299a71 + 2ebd013 commit e4dd23a

File tree

19 files changed

+222
-48
lines changed

19 files changed

+222
-48
lines changed

.ci/scripts/gather_benchmark_configs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"samsung_galaxy_s22": "arn:aws:devicefarm:us-west-2:308535385114:devicepool:02a2cf0f-6d9b-45ee-ba1a-a086587469e6/e59f866a-30aa-4aa1-87b7-4510e5820dfa",
2424
"samsung_galaxy_s24": "arn:aws:devicefarm:us-west-2:308535385114:devicepool:02a2cf0f-6d9b-45ee-ba1a-a086587469e6/98f8788c-2e25-4a3c-8bb2-0d1e8897c0db",
2525
"google_pixel_8_pro": "arn:aws:devicefarm:us-west-2:308535385114:devicepool:02a2cf0f-6d9b-45ee-ba1a-a086587469e6/d65096ab-900b-4521-be8b-a3619b69236a",
26+
"google_pixel_3_private_rooted": "arn:aws:devicefarm:us-west-2:308535385114:devicepool:02a2cf0f-6d9b-45ee-ba1a-a086587469e6/98d23ca8-ea9e-4fb7-b725-d402017b198d",
2627
}
2728

2829
# Predefined benchmark configurations
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: android-perf (private devices)
2+
3+
on:
4+
schedule:
5+
- cron: 0 0,4,8,12,16,20 * * *
6+
pull_request:
7+
paths:
8+
- .github/workflows/android-perf-private-device-experiment.yml
9+
push:
10+
branches:
11+
- main
12+
paths:
13+
- .github/workflows/android-perf-private-device-experiment.yml
14+
# Note: GitHub has an upper limit of 10 inputs
15+
workflow_dispatch:
16+
inputs:
17+
models:
18+
description: Models to be benchmarked
19+
required: false
20+
type: string
21+
default: mv3,meta-llama/Llama-3.2-1B-Instruct-SpinQuant_INT4_EO8,meta-llama/Llama-3.2-1B-Instruct-QLORA_INT4_EO8
22+
devices:
23+
description: Target devices to run benchmark
24+
required: false
25+
type: string
26+
default: google_pixel_3_private_rooted
27+
benchmark_configs:
28+
description: The list of configs used the benchmark
29+
required: false
30+
type: string
31+
workflow_call:
32+
inputs:
33+
models:
34+
description: Models to be benchmarked
35+
required: false
36+
type: string
37+
default: mv3,meta-llama/Llama-3.2-1B-Instruct-SpinQuant_INT4_EO8,meta-llama/Llama-3.2-1B-Instruct-QLORA_INT4_EO8
38+
devices:
39+
description: Target devices to run benchmark
40+
required: false
41+
type: string
42+
default: google_pixel_3_private_rooted
43+
benchmark_configs:
44+
description: The list of configs used the benchmark
45+
required: false
46+
type: string
47+
48+
concurrency:
49+
group: android-perf-private-devices-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
50+
cancel-in-progress: true
51+
52+
jobs:
53+
android:
54+
uses: ./.github/workflows/android-perf.yml
55+
secrets: inherit
56+
permissions:
57+
id-token: write
58+
contents: read
59+
with:
60+
models: ${{ inputs.models }}
61+
devices: google_pixel_3_private_rooted
62+
benchmark_configs: ${{ inputs.benchmark_configs }}

.github/workflows/android-release-artifacts.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ jobs:
4949
contents: read
5050
with:
5151
secrets-env: EXECUTORCH_MAVEN_SIGNING_KEYID EXECUTORCH_MAVEN_SIGNING_PASSWORD EXECUTORCH_MAVEN_CENTRAL_PASSWORD EXECUTORCH_MAVEN_CENTRAL_USERNAME EXECUTORCH_MAVEN_SIGNING_GPG_KEY_CONTENTS
52-
runner: linux.2xlarge
52+
# As this job has access to Maven credential, run this on a fresh ephemeral runner
53+
runner: ephemeral.linux.2xlarge
5354
docker-image: executorch-ubuntu-22.04-clang12-android
5455
submodules: 'recursive'
5556
ref: ${{ github.sha }}

backends/arm/operator_support/tosa_supported_operators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def is_node_supported(
229229
exir_ops.edge.aten.__lshift__.Scalar,
230230
torch.ops.aten.scalar_tensor.default,
231231
exir_ops.edge.aten.gelu.default,
232+
exir_ops.edge.aten.alias_copy.default,
232233
]
233234

234235
return supported

backends/arm/operators/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
op_erf,
2323
op_exp,
2424
op_ge,
25-
op_get_item,
2625
op_gt,
2726
op_le,
2827
op_log,
@@ -51,5 +50,6 @@
5150
op_view,
5251
op_where,
5352
ops_binary,
53+
ops_identity,
5454
ops_unary,
5555
)

backends/arm/operators/op_get_item.py

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2025 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+
# pyre-unsafe
7+
8+
from typing import List
9+
10+
import torch
11+
import torch.fx
12+
13+
import tosa_tools.v0_80.serializer.tosa_serializer as ts
14+
15+
from executorch.backends.arm.operators.node_visitor import (
16+
NodeVisitor,
17+
register_node_visitor,
18+
)
19+
from executorch.backends.arm.tosa_mapping import TosaArg
20+
21+
22+
def identity_operator_factory(identity_target: str):
23+
"""
24+
Creates and registers NodeVisitors for operators that map directly
25+
to a TOSA IDENTITY op.
26+
"""
27+
28+
class IdentityOperatorVisitor(NodeVisitor):
29+
target = identity_target
30+
31+
def define_node(
32+
self,
33+
node: torch.fx.Node,
34+
tosa_graph: ts.TosaSerializer,
35+
inputs: List[TosaArg],
36+
output: TosaArg,
37+
) -> None:
38+
# Simply add an identityOp
39+
tosa_graph.addOperator(
40+
ts.TosaOp.Op().IDENTITY, [inputs[0].name], [output.name]
41+
)
42+
43+
register_node_visitor(IdentityOperatorVisitor)
44+
45+
46+
identity_operator_factory("getitem")
47+
identity_operator_factory("aten.alias_copy.default")

backends/arm/quantizer/quantization_annotator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ def _match_pattern(
244244
operator.getitem,
245245
]
246246

247+
_one_to_one_shared_input_or_input_act_qspec = [
248+
torch.ops.aten.adaptive_avg_pool2d.default,
249+
torch.ops.aten.alias_copy.default,
250+
]
251+
247252

248253
def get_quant_properties( # noqa: C901
249254
node: Node, gm: torch.fx.GraphModule, quantization_config
@@ -332,7 +337,7 @@ def any_or_hardtanh_min_zero(n: Node):
332337
_QuantProperty(2, shared_qspec), # type: ignore[arg-type]
333338
]
334339
quant_properties.quant_output = _QuantProperty(0, shared_qspec) # type: ignore[arg-type]
335-
elif node.target == torch.ops.aten.adaptive_avg_pool2d.default:
340+
elif node.target in _one_to_one_shared_input_or_input_act_qspec:
336341
input_qspec = (
337342
SharedQuantizationSpec(node.args[0]) # type: ignore[arg-type]
338343
if arm_quantizer_utils.is_output_annotated(node.args[0]) # type: ignore
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2025 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+
from typing import Tuple
7+
8+
import torch
9+
from executorch.backends.arm.test import common
10+
from executorch.backends.arm.test.tester.test_pipeline import (
11+
EthosU55PipelineBI,
12+
EthosU85PipelineBI,
13+
TosaPipelineBI,
14+
TosaPipelineMI,
15+
)
16+
17+
input_t1 = Tuple[torch.Tensor]
18+
19+
20+
class AliasCopy(torch.nn.Module):
21+
"""
22+
Tests proper handling of alias_copy when used directly.
23+
24+
alias_copy can also appear from PyTorch/ExecuTorch optimizations
25+
such as `x.transpose(0, 0)`. This is optimized to an alias_copy but
26+
not before dq/q operators are added.
27+
"""
28+
29+
aten_op = "torch.ops.aten.alias_copy.default"
30+
exir_op = "executorch_exir_dialects_edge__ops_aten_alias_copy_default"
31+
32+
test_data: dict[input_t1] = {
33+
"1d_ramp": (torch.arange(-16, 16, 0.2),),
34+
"2d_ones": (torch.ones(5, 5),),
35+
"3d_rand": (torch.rand(3, 5, 5),),
36+
"4d_zeros": (torch.zeros(1, 10, 10, 10),),
37+
}
38+
39+
def __init__(self):
40+
super().__init__()
41+
42+
def forward(self, x: torch.Tensor):
43+
return torch.alias_copy(x)
44+
45+
46+
@common.parametrize("test_data", AliasCopy.test_data)
47+
def test_alias_copy_tosa_MI(test_data: input_t1):
48+
TosaPipelineMI[input_t1](
49+
AliasCopy(),
50+
test_data,
51+
AliasCopy.aten_op,
52+
AliasCopy.exir_op,
53+
).run()
54+
55+
56+
@common.parametrize("test_data", AliasCopy.test_data)
57+
def test_alias_copy_tosa_BI(test_data: input_t1):
58+
TosaPipelineBI[input_t1](
59+
AliasCopy(),
60+
test_data,
61+
AliasCopy.aten_op,
62+
AliasCopy.exir_op,
63+
).run()
64+
65+
66+
@common.parametrize("test_data", AliasCopy.test_data)
67+
def test_alias_copy_u55_BI(test_data: input_t1):
68+
EthosU55PipelineBI[input_t1](
69+
AliasCopy(),
70+
test_data,
71+
AliasCopy.aten_op,
72+
AliasCopy.exir_op,
73+
).run()
74+
75+
76+
@common.parametrize("test_data", AliasCopy.test_data)
77+
def test_alias_copy_u85_BI(test_data: input_t1):
78+
EthosU85PipelineBI[input_t1](
79+
AliasCopy(),
80+
test_data,
81+
AliasCopy.aten_op,
82+
AliasCopy.exir_op,
83+
).run()

docs/source/bundled-io.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ cd executorch
217217
./cmake-out/examples/devtools/example_runner --bundled_program_path {your-bpte-file} --output_verification
218218
```
219219

220-
It is expected to see no input from running the above mentioned snippet.
220+
It is expected to see no output from running the above mentioned snippet.
221221

222222
For a detailed example of how the runner should be like, please refer to our [example runner](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/example_runner/example_runner.cpp).
223223

0 commit comments

Comments
 (0)