Skip to content

Commit d27291b

Browse files
authored
Merge branch 'main' into nil-is-all-patch-1
2 parents 1292f32 + 6d8583d commit d27291b

File tree

73 files changed

+1503
-378
lines changed

Some content is hidden

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

73 files changed

+1503
-378
lines changed

.ci/scripts/unittest-buck2.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ set -eux
99
# TODO: expand this to //...
1010
# TODO: can't query cadence & vulkan backends
1111
# TODO: can't query //kernels/prim_ops because of non-buckified stuff in OSS.
12-
buck2 query "//backends/apple/... + //backends/example/... + \
12+
# TODO: Make //backends/arm tests use runtime wrapper so we can just query //backends/arm/...
13+
buck2 query "//backends/apple/... + //backends/arm: + //backends/arm/debug/... + \
14+
//backends/arm/operator_support/... + //backends/arm/operators/... + \
15+
//backends/arm/_passes/... + //backends/arm/runtime/... + //backends/arm/tosa/... \
16+
+ //backends/example/... + \
1317
//backends/mediatek/... + //backends/transforms/... + \
1418
//backends/xnnpack/... + //configurations/... + //extension/flat_tensor: + \
1519
//extension/llm/runner: + //kernels/aten/... + //kernels/optimized/... + \

backends/apple/coreml/test/test_coreml_recipes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Please refer to the license found in the LICENSE file in the root directory of the source tree.
44

55

6+
import copy
67
import unittest
78

89
import coremltools as ct
@@ -152,8 +153,9 @@ def forward(self, x):
152153
# Test with different group sizes
153154
for group_size in [8, 16, 32]:
154155
with self.subTest(group_size=group_size):
156+
model_to_export = copy.deepcopy(model)
155157
session = export(
156-
model=model,
158+
model=model_to_export,
157159
example_inputs=example_inputs,
158160
export_recipe=ExportRecipe.get_recipe(
159161
CoreMLRecipeType.TORCHAO_INT4_WEIGHT_ONLY_PER_GROUP,
@@ -219,8 +221,9 @@ def forward(self, x):
219221
# Test with different group sizes
220222
for group_size in [16, 32, 64]:
221223
with self.subTest(group_size=group_size):
224+
model_to_export = copy.deepcopy(model)
222225
session = export(
223-
model=model,
226+
model=model_to_export,
224227
example_inputs=example_inputs,
225228
export_recipe=ExportRecipe.get_recipe(
226229
CoreMLRecipeType.TORCHAO_INT8_WEIGHT_ONLY_PER_GROUP,

backends/arm/TARGETS

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ runtime.python_library(
1414
"ethosu/partitioner.py"
1515
],
1616
deps = [
17-
":arm_partitioner",
17+
":arm_vela",
18+
"//executorch/backends/arm/tosa:arm_partitioner",
1819
]
1920
)
2021
runtime.python_library(
@@ -25,7 +26,7 @@ runtime.python_library(
2526
"vgf/partitioner.py"
2627
],
2728
deps = [
28-
":arm_partitioner",
29+
"//executorch/backends/arm/tosa:arm_partitioner",
2930
]
3031
)
3132
runtime.python_library(
@@ -50,21 +51,6 @@ runtime.python_library(
5051
"//executorch/exir:lib",
5152
],
5253
)
53-
runtime.python_library(
54-
name = "arm_partitioner",
55-
srcs = [
56-
"tosa/backend.py",
57-
"tosa/partitioner.py",
58-
],
59-
deps = [
60-
":arm_backend",
61-
":constants",
62-
"//executorch/backends/arm/debug:schema",
63-
"//executorch/backends/arm/operator_support:operator_support",
64-
"//executorch/backends/arm/_passes:passes",
65-
"//executorch/exir:lib",
66-
],
67-
)
6854
runtime.python_library(
6955
name = "arm_backend",
7056
srcs = [
@@ -77,7 +63,6 @@ runtime.python_library(
7763
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/serializer:serializer",
7864
"fbsource//third-party/tosa_tools/v0.80/serialization_lib/python/tosa:tosa",
7965
"fbsource//third-party/tosa_tools/v1.00/serialization_lib/python/tosa:tosa",
80-
":arm_vela",
8166
":process_node",
8267
"//executorch/backends/arm/operators:lib",
8368
"//executorch/backends/arm/operators:node_visitor",

backends/arm/scripts/build_executor_runner_vkml.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ fi
6464

6565
echo "Building with extra flags: ${build_with_etdump_flags} ${extra_build_flags}"
6666
cmake \
67+
-Wall \
68+
-Werror \
6769
-DCMAKE_BUILD_TYPE=${build_type} \
6870
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
6971
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \

backends/arm/test/ops/test_acos.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# LICENSE file in the root directory of this source tree.
55
from typing import Tuple
66

7+
import pytest
78
import torch
89

910
from executorch.backends.arm.test import common
@@ -102,8 +103,12 @@ def test_acos_vgf_FP(test_data: Tuple):
102103
[],
103104
[],
104105
tosa_version="TOSA-1.0+FP",
106+
run_on_vulkan_runtime=True,
105107
)
106-
pipeline.run()
108+
try:
109+
pipeline.run()
110+
except FileNotFoundError as e:
111+
pytest.skip(f"VKML executor_runner not found - not built - skip {e}")
107112

108113

109114
@common.parametrize("test_data", test_data_suite)
@@ -115,5 +120,9 @@ def test_acos_vgf_INT(test_data: Tuple):
115120
[],
116121
[],
117122
tosa_version="TOSA-1.0+INT",
123+
run_on_vulkan_runtime=True,
118124
)
119-
pipeline.run()
125+
try:
126+
pipeline.run()
127+
except FileNotFoundError as e:
128+
pytest.skip(f"VKML executor_runner not found - not built - skip {e}")

backends/arm/test/ops/test_add.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,7 @@ def test_add_tensor_u85_INT_2(test_data: input_t2):
202202
pipeline.run()
203203

204204

205-
# TODO/MLETORCH-1282: remove once inputs are not hard coded to ones
206-
skip_keys = {"5d_float", "1d_ones", "1d_randn"}
207-
filtered_test_data = {k: v for k, v in Add.test_data.items() if k not in skip_keys}
208-
209-
210-
@common.parametrize("test_data", filtered_test_data)
205+
@common.parametrize("test_data", Add.test_data)
211206
@common.SkipIfNoModelConverter
212207
def test_add_tensor_vgf_FP(test_data: input_t1):
213208
pipeline = VgfPipeline[input_t1](
@@ -224,7 +219,7 @@ def test_add_tensor_vgf_FP(test_data: input_t1):
224219
pytest.skip(f"VKML executor_runner not found - not built - skip {e}")
225220

226221

227-
@common.parametrize("test_data", filtered_test_data)
222+
@common.parametrize("test_data", Add.test_data)
228223
@common.SkipIfNoModelConverter
229224
def test_add_tensor_vgf_INT(test_data: input_t1):
230225
pipeline = VgfPipeline[input_t1](

backends/arm/test/runner_utils.py

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,48 @@ def run_target(
223223
elif target_board == "vkml_emulation_layer":
224224
return run_vkml_emulation_layer(
225225
executorch_program_manager,
226+
inputs,
226227
intermediate_path,
227228
elf_path,
228229
)
229230

230231

232+
def save_inputs_to_file(
233+
exported_program: ExportedProgram,
234+
inputs: Tuple[torch.Tensor],
235+
intermediate_path: str | Path,
236+
):
237+
input_file_paths = []
238+
input_names = get_input_names(exported_program)
239+
for input_name, input_ in zip(input_names, inputs):
240+
input_path = save_bytes(intermediate_path, input_, input_name)
241+
input_file_paths.append(input_path)
242+
243+
return input_file_paths
244+
245+
246+
def get_output_from_file(
247+
exported_program: ExportedProgram,
248+
intermediate_path: str | Path,
249+
output_base_name: str,
250+
):
251+
output_np = []
252+
output_node = exported_program.graph_module.graph.output_node()
253+
for i, node in enumerate(output_node.args[0]):
254+
output_shape = node.meta["val"].shape
255+
output_dtype = node.meta["val"].dtype
256+
tosa_ref_output = np.fromfile(
257+
os.path.join(intermediate_path, f"{output_base_name}-{i}.bin"),
258+
_torch_to_numpy_dtype_dict[output_dtype],
259+
)
260+
261+
output_np.append(torch.from_numpy(tosa_ref_output).reshape(output_shape))
262+
return tuple(output_np)
263+
264+
231265
def run_vkml_emulation_layer(
232266
executorch_program_manager: ExecutorchProgramManager,
267+
inputs: Tuple[torch.Tensor],
233268
intermediate_path: str | Path,
234269
elf_path: str | Path,
235270
):
@@ -239,7 +274,7 @@ def run_vkml_emulation_layer(
239274
`intermediate_path`: Directory to save the .pte and capture outputs.
240275
`elf_path`: Path to the Vulkan-capable executor_runner binary.
241276
"""
242-
277+
exported_program = executorch_program_manager.exported_program()
243278
intermediate_path = Path(intermediate_path)
244279
intermediate_path.mkdir(exist_ok=True)
245280
elf_path = Path(elf_path)
@@ -251,26 +286,29 @@ def run_vkml_emulation_layer(
251286
with open(pte_path, "wb") as f:
252287
f.write(executorch_program_manager.buffer)
253288

254-
cmd_line = [str(elf_path), "-model_path", pte_path]
289+
output_base_name = "out"
290+
out_path = os.path.join(intermediate_path, output_base_name)
291+
292+
cmd_line = f"{elf_path} -model_path {pte_path} -output_file {out_path}"
293+
294+
input_string = None
295+
input_paths = save_inputs_to_file(exported_program, inputs, intermediate_path)
296+
for input_path in input_paths:
297+
if input_string is None:
298+
input_string = f" -inputs={input_path}"
299+
else:
300+
input_string += f",{input_path}"
301+
if input_string is not None:
302+
cmd_line += input_string
303+
cmd_line = cmd_line.split()
304+
255305
result = _run_cmd(cmd_line)
256306

257-
result_stdout = result.stdout.decode() # noqa: F841
258307
# TODO: MLETORCH-1234: Support VGF e2e tests in VgfPipeline
259308
# TODO: Add regex to check for error or fault messages in stdout from Emulation Layer
260-
# Regex to extract tensor values from stdout
261-
output_np = []
262-
matches = re.findall(
263-
r"Output\s+\d+:\s+tensor\(sizes=\[(.*?)\],\s+\[(.*?)\]\)",
264-
result_stdout,
265-
re.DOTALL,
266-
)
267-
268-
for shape_str, values_str in matches:
269-
shape = list(map(int, shape_str.split(",")))
270-
values = list(map(float, re.findall(r"[-+]?\d*\.\d+|\d+", values_str)))
271-
output_np.append(torch.tensor(values).reshape(shape))
309+
result_stdout = result.stdout.decode() # noqa: F841
272310

273-
return tuple(output_np)
311+
return get_output_from_file(exported_program, intermediate_path, output_base_name)
274312

275313

276314
def run_corstone(
@@ -312,14 +350,10 @@ def run_corstone(
312350
with open(pte_path, "wb") as f:
313351
f.write(executorch_program_manager.buffer)
314352

315-
# Save inputs to file
316-
input_names = get_input_names(exported_program)
317-
input_paths = []
318-
for input_name, input_ in zip(input_names, inputs):
319-
input_path = save_bytes(intermediate_path, input_, input_name)
320-
input_paths.append(input_path)
353+
input_paths = save_inputs_to_file(exported_program, inputs, intermediate_path)
321354

322-
out_path = os.path.join(intermediate_path, "out")
355+
output_base_name = "out"
356+
out_path = os.path.join(intermediate_path, output_base_name)
323357

324358
cmd_line = f"executor_runner -m {pte_path} -o {out_path}"
325359
for input_path in input_paths:
@@ -401,18 +435,7 @@ def run_corstone(
401435
f"Corstone simulation failed:\ncmd: {' '.join(command_args)}\nlog: \n {result_stdout}\n{result.stderr.decode()}"
402436
)
403437

404-
output_np = []
405-
output_node = exported_program.graph_module.graph.output_node()
406-
for i, node in enumerate(output_node.args[0]):
407-
output_shape = node.meta["val"].shape
408-
output_dtype = node.meta["val"].dtype
409-
tosa_ref_output = np.fromfile(
410-
os.path.join(intermediate_path, f"out-{i}.bin"),
411-
_torch_to_numpy_dtype_dict[output_dtype],
412-
)
413-
414-
output_np.append(torch.from_numpy(tosa_ref_output).reshape(output_shape))
415-
return tuple(output_np)
438+
return get_output_from_file(exported_program, intermediate_path, output_base_name)
416439

417440

418441
def prep_data_for_save(

backends/arm/tosa/TARGETS

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,20 @@ runtime.python_library(
5959
":specification",
6060
],
6161
)
62+
63+
runtime.python_library(
64+
name = "arm_partitioner",
65+
srcs = [
66+
"backend.py",
67+
"partitioner.py",
68+
],
69+
deps = [
70+
"//executorch/backends/arm:arm_backend",
71+
"//executorch/backends/arm:constants",
72+
"//executorch/backends/arm:process_node",
73+
"//executorch/backends/arm/debug:schema",
74+
"//executorch/backends/arm/operator_support:operator_support",
75+
"//executorch/backends/arm/_passes:passes",
76+
"//executorch/exir:lib",
77+
],
78+
)

backends/cadence/aot/TARGETS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ load(
1212
"CXX",
1313
)
1414
load("@fbsource//xplat/executorch/codegen:codegen.bzl", "executorch_generated_lib")
15-
load("@fbcode_macros//build_defs:cpp_python_extension.bzl", "cpp_python_extension")
1615

1716
oncall("odai_jarvis")
1817

0 commit comments

Comments
 (0)