Skip to content

Commit 86320e0

Browse files
authored
Merge branch 'release/0.4' into cherry-pick-6051-by-pytorch_bot_bot_
2 parents 982372b + 6e788c7 commit 86320e0

File tree

180 files changed

+2821
-1300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+2821
-1300
lines changed

.ci/scripts/test_llama.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ else
171171
fi
172172

173173
# Check dtype.
174-
EXPORTED_MODEL_NAME="llama2"
174+
EXPORTED_MODEL_NAME="tinyllama_${MODE}_${DTYPE}"
175175
if [[ "${DTYPE}" == "fp16" ]]; then
176176
EXPORTED_MODEL_NAME="${EXPORTED_MODEL_NAME}_h"
177177
elif [[ "${DTYPE}" == "fp32" ]]; then

.ci/scripts/test_model.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,30 +155,24 @@ test_model_with_qnn() {
155155

156156
if [[ "${MODEL_NAME}" == "dl3" ]]; then
157157
EXPORT_SCRIPT=deeplab_v3
158-
EXPORTED_MODEL_NAME=dlv3_qnn.pte
159158
elif [[ "${MODEL_NAME}" == "mv3" ]]; then
160159
EXPORT_SCRIPT=mobilenet_v3
161-
EXPORTED_MODEL_NAME=mv3_qnn.pte
162160
elif [[ "${MODEL_NAME}" == "mv2" ]]; then
163161
EXPORT_SCRIPT=mobilenet_v2
164-
EXPORTED_MODEL_NAME=mv2_qnn.pte
165162
elif [[ "${MODEL_NAME}" == "ic4" ]]; then
166163
EXPORT_SCRIPT=inception_v4
167-
EXPORTED_MODEL_NAME=ic4_qnn.pte
168164
elif [[ "${MODEL_NAME}" == "ic3" ]]; then
169165
EXPORT_SCRIPT=inception_v3
170-
EXPORTED_MODEL_NAME=ic3_qnn.pte
171166
elif [[ "${MODEL_NAME}" == "vit" ]]; then
172167
EXPORT_SCRIPT=torchvision_vit
173-
EXPORTED_MODEL_NAME=vit_qnn.pte
174168
fi
175169

176170
# Use SM8450 for S22, SM8550 for S23, and SM8560 for S24
177171
# TODO(guangyang): Make QNN chipset matches the target device
178172
QNN_CHIPSET=SM8450
179173

180174
"${PYTHON_EXECUTABLE}" -m examples.qualcomm.scripts.${EXPORT_SCRIPT} -b ${CMAKE_OUTPUT_DIR} -m ${QNN_CHIPSET} --compile_only
181-
EXPORTED_MODEL=./${EXPORT_SCRIPT}/${EXPORTED_MODEL_NAME}
175+
EXPORTED_MODEL=$(find "./${EXPORT_SCRIPT}" -type f -name "${MODEL_NAME}*.pte" -print -quit)
182176
}
183177

184178
test_model_with_coreml() {
@@ -187,8 +181,20 @@ test_model_with_coreml() {
187181
exit 1
188182
fi
189183

190-
"${PYTHON_EXECUTABLE}" -m examples.apple.coreml.scripts.export --model_name="${MODEL_NAME}"
184+
DTYPE=float16
185+
186+
"${PYTHON_EXECUTABLE}" -m examples.apple.coreml.scripts.export --model_name="${MODEL_NAME}" --compute_precision "${DTYPE}"
191187
EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*.pte" -print -quit)
188+
# TODO:
189+
if [ -n "$EXPORTED_MODEL" ]; then
190+
EXPORTED_MODEL_WITH_DTYPE="${EXPORTED_MODEL%.pte}_${DTYPE}.pte"
191+
mv "$EXPORTED_MODEL" "$EXPORTED_MODEL_WITH_DTYPE"
192+
EXPORTED_MODEL="$EXPORTED_MODEL_WITH_DTYPE"
193+
echo "Renamed file path: $EXPORTED_MODEL"
194+
else
195+
echo "No .pte file found"
196+
exit 1
197+
fi
192198
}
193199

194200
if [[ "${BACKEND}" == "portable" ]]; then

backends/arm/TARGETS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ python_library(
88
typing = True,
99
deps = [
1010
":arm_backend",
11-
"//executorch/backends/arm/passes:passes",
11+
"//executorch/backends/arm/_passes:passes",
1212
"//executorch/exir:lib",
1313
],
1414
)
@@ -27,7 +27,7 @@ python_library(
2727
":arm_vela",
2828
"//executorch/backends/arm/operators:lib",
2929
"//executorch/backends/arm/operators:node_visitor",
30-
"//executorch/backends/arm/passes:passes",
30+
"//executorch/backends/arm/_passes:passes",
3131
],
3232
)
3333

File renamed without changes.

backends/arm/passes/arm_pass_manager.py renamed to backends/arm/_passes/arm_pass_manager.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
# pyre-unsafe
99

1010
import torch
11-
from executorch.backends.arm.passes.annotate_channels_last_dim_order_pass import (
11+
from executorch.backends.arm._passes.annotate_channels_last_dim_order_pass import (
1212
AnnotateChannelsLastDimOrder,
1313
)
14-
from executorch.backends.arm.passes.convert_expand_copy_to_repeat import (
14+
from executorch.backends.arm._passes.convert_expand_copy_to_repeat import (
1515
ConvertExpandCopyToRepeatPass,
1616
)
17-
from executorch.backends.arm.passes.convert_split_to_slice import (
17+
from executorch.backends.arm._passes.convert_split_to_slice import (
1818
ConvertSplitToSlicePass,
1919
)
20-
from executorch.backends.arm.passes.meandim_to_averagepool_pass import (
20+
from executorch.backends.arm._passes.meandim_to_averagepool_pass import (
2121
ConvertMeanDimToAveragePool,
2222
)
23-
from executorch.backends.arm.passes.remove_clone_pass import RemoveClonePass
24-
from executorch.backends.arm.passes.size_adjust_conv2d_pass import SizeAdjustConv2DPass
23+
from executorch.backends.arm._passes.remove_clone_pass import RemoveClonePass
24+
from executorch.backends.arm._passes.size_adjust_conv2d_pass import SizeAdjustConv2DPass
2525
from executorch.exir.backend.compile_spec_schema import CompileSpec
2626
from executorch.exir.pass_manager import PassManager
2727

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2024 Arm Limited and/or its 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+
from typing import Optional
8+
9+
import torch
10+
11+
from executorch.exir.dialects._ops import ops as exir_ops
12+
from torch._ops import OpOverload
13+
14+
15+
def create_node(
16+
graph: torch.fx.Graph,
17+
op_target: OpOverload,
18+
args: tuple = (),
19+
kwargs: Optional[dict] = None,
20+
quantize: bool = False,
21+
q_params: Optional[tuple] = None,
22+
):
23+
"""
24+
Adds a node to 'graph'. graph.inserting_before/after() should be used before the call to decide where to insert the node.
25+
If quantize is true and q_params is not None, a q dq pair is inserted after the newly created node.
26+
"""
27+
28+
node = graph.create_node(
29+
"call_function",
30+
op_target,
31+
args=args,
32+
kwargs=kwargs or {},
33+
)
34+
if quantize and q_params:
35+
return insert_q_dq_pair(graph, node, q_params)
36+
return node
37+
38+
39+
def insert_q_dq_pair(
40+
graph: torch.fx.Graph,
41+
anchor: torch.fx.Node,
42+
q_params: tuple,
43+
):
44+
"""
45+
Inserts a q dq node pair after the node 'anchor'.
46+
"""
47+
48+
with graph.inserting_after(anchor):
49+
q = create_node(
50+
graph=graph,
51+
op_target=exir_ops.edge.quantized_decomposed.quantize_per_tensor.default,
52+
args=(), # We add the argument last
53+
)
54+
q.meta = anchor.meta
55+
with graph.inserting_after(q):
56+
dq = create_node(
57+
graph=graph,
58+
op_target=exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default,
59+
args=(q,) + q_params,
60+
)
61+
dq.meta = q.meta
62+
anchor.replace_all_uses_with(dq)
63+
# We add this last so the replace all uses above does not replace the quantized
64+
# node's first use
65+
q.args = (anchor,) + q_params
66+
return dq
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2024 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+
import torch
7+
from executorch.exir.pass_base import ExportPass, PassResult
8+
9+
10+
class CastInt64ToInt32Pass(ExportPass):
11+
def __init__(self, exported_program: torch.export.ExportedProgram):
12+
super(CastInt64ToInt32Pass, self).__init__()
13+
self.exported_program = exported_program
14+
15+
def _to_int32(self, graph_module: torch.fx.GraphModule):
16+
for node in graph_module.graph.nodes:
17+
fake_tensor = node.meta["val"]
18+
if isinstance(fake_tensor, torch._subclasses.fake_tensor.FakeTensor):
19+
if node.meta["val"].dtype == torch.int64:
20+
node.meta["val"] = node.meta["val"].to(torch.int32)
21+
buffer_name = (
22+
self.exported_program.graph_signature.inputs_to_buffers[
23+
node.name
24+
]
25+
)
26+
new_tensor = self.exported_program.state_dict[buffer_name].to(
27+
torch.int32
28+
)
29+
self.exported_program.state_dict[buffer_name] = new_tensor
30+
31+
def call(self, graph_module: torch.fx.GraphModule):
32+
self._to_int32(graph_module)
33+
graph_module.recompile()
34+
graph_module = super().call(graph_module).graph_module
35+
return PassResult(graph_module, True)

0 commit comments

Comments
 (0)