Skip to content

Commit bf33485

Browse files
committed
Merge remote-tracking branch 'origin/main' into jz/tt-llama-2
2 parents e5428de + 4e83f24 commit bf33485

File tree

78 files changed

+3038
-235
lines changed

Some content is hidden

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

78 files changed

+3038
-235
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c8a648d4dffb9f0133ff4a2ea0e660b42105d3ad
1+
19eff28ff3f19b50da46f5a9ff5f4d4d213806fe

.ci/scripts/gather_test_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"ic4": "linux.12xlarge",
2525
"resnet50": "linux.12xlarge",
2626
"llava": "linux.12xlarge",
27+
"llama3_2_vision_encoder": "linux.12xlarge",
2728
# This one causes timeout on smaller runner, the root cause is unclear (T161064121)
2829
"dl3": "linux.12xlarge",
2930
"emformer_join": "linux.12xlarge",

.ci/scripts/test_model.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ test_model() {
7777
# Install requirements for export_llama
7878
bash examples/models/llama/install_requirements.sh
7979
# Test export_llama script: python3 -m examples.models.llama.export_llama
80-
"${PYTHON_EXECUTABLE}" -m examples.models.llama.export_llama -c examples/models/llama/params/demo_rand_params.pth -p examples/models/llama/params/demo_config.json
80+
"${PYTHON_EXECUTABLE}" -m examples.models.llama.export_llama --model "${MODEL_NAME}" -c examples/models/llama/params/demo_rand_params.pth -p examples/models/llama/params/demo_config.json
8181
run_portable_executor_runner
8282
rm "./${MODEL_NAME}.pte"
8383
fi

.github/workflows/pull.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ jobs:
7272
conda activate "${CONDA_ENV}"
7373
7474
MODEL_NAME=${{ matrix.model }}
75+
# Install requirements for llama vision
76+
if [[ "$MODEL_NAME" == "llama3_2_vision_encoder" ]]; then
77+
bash examples/models/llama3_2_vision/install_requirements.sh
78+
fi
7579
BUILD_TOOL=${{ matrix.build-tool }}
7680
BACKEND=${{ matrix.backend }}
7781
DEMO_BACKEND_DELEGATION=${{ matrix.demo_backend_delegation }}

.github/workflows/trunk.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ jobs:
5858
bash .ci/scripts/setup-conda.sh
5959
# Setup MacOS dependencies as there is no Docker support on MacOS atm
6060
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"
61-
# Build and test xecutorch
61+
# Install requirements for llama vision
62+
if [[ "$MODEL_NAME" == "llama3_2_vision_encoder" ]]; then
63+
${CONDA_RUN} bash examples/models/llama3_2_vision/install_requirements.sh
64+
fi
65+
# Build and test executorch
6266
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}" "${DEMO_BACKEND_DELEGATION}"
6367
6468
test-custom-ops-macos:

.lintrunner.toml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,91 @@ command = [
196196
'@{{PATHSFILE}}',
197197
]
198198
is_formatter = true
199+
200+
[[linter]]
201+
code = 'NOSTDINC'
202+
include_patterns = [
203+
"**/*.c",
204+
"**/*.cpp",
205+
"**/*.h",
206+
"**/*.hpp",
207+
]
208+
exclude_patterns = [
209+
'**/devtools/**',
210+
'**/test/**',
211+
'**/testing_util/**',
212+
'**/third-party/**',
213+
'backends/**',
214+
'devtools/**',
215+
'examples/**',
216+
'extension/**',
217+
'kernels/optimized/**',
218+
'scripts/**',
219+
'third-party/**',
220+
'util/**',
221+
]
222+
command = [
223+
'python',
224+
'-m',
225+
'lintrunner_adapters',
226+
'run',
227+
'grep_linter',
228+
'--pattern=([^\\S\r\n]*#include\s*<(deque|exception|forward_list|functional|list|map|multimap|multiset|priority_queue|queue|set|stack|string|unordered_map|unordered_multimap|unordered_multiset|unordered_set|vector)>)',
229+
'--linter-name=NOSTDINC',
230+
'--error-name=Standard C++ container include in core',
231+
"""--error-description=\
232+
Standard library containers should not be included in ExecuTorch core \
233+
because they may call malloc, which is not allowed in core. \
234+
""",
235+
'--',
236+
'@{{PATHSFILE}}',
237+
]
238+
239+
[[linter]]
240+
code = 'NOTORCHINC'
241+
include_patterns = [
242+
"**/*.c",
243+
"**/*.cpp",
244+
"**/*.h",
245+
"**/*.hpp",
246+
]
247+
exclude_patterns = [
248+
'**/devtools/**',
249+
'**/fb/**',
250+
'**/test/**',
251+
'**/tests/**',
252+
'**/testing_util/**',
253+
'**/third-party/**',
254+
'backends/**',
255+
'codegen/templates/RegisterDispatchKeyCustomOps.cpp',
256+
'codegen/templates/RegisterSchema.cpp',
257+
'devtools/**',
258+
'examples/**',
259+
'exir/verification/bindings.cpp',
260+
'extension/**',
261+
'kernels/optimized/**',
262+
'runtime/core/exec_aten/**',
263+
'runtime/executor/tensor_parser_aten.cpp',
264+
'scripts/**',
265+
'test/**',
266+
'third-party/**',
267+
'util/**',
268+
]
269+
command = [
270+
'python',
271+
'-m',
272+
'lintrunner_adapters',
273+
'run',
274+
'grep_linter',
275+
'--pattern=#include\s+[<"](aten/|ATen/|torch/)',
276+
'--linter-name=NOTORCHINC',
277+
'--error-name=ATen or torch include',
278+
"""--error-description=\
279+
PyTorch includes in ExecuTorch core are prohibited to prevent \
280+
accidentally breaking core's requirements; please make sure this \
281+
header complies (e.g., no streams/malloc/syscalls) and then include \
282+
a patch to update this linter.\
283+
""",
284+
'--',
285+
'@{{PATHSFILE}}',
286+
]

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,19 @@ message(STATUS "Using python executable '${PYTHON_EXECUTABLE}'")
324324
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
325325

326326
# Let files say "include <executorch/path/to/header.h>".
327+
# TODO(#6475): This requires/assumes that the repo lives in a directory named
328+
# exactly `executorch`. Check the assumption first. Remove this check once we
329+
# stop relying on the assumption.
330+
cmake_path(GET CMAKE_CURRENT_SOURCE_DIR FILENAME _repo_dir_name)
331+
if(NOT "${_repo_dir_name}" STREQUAL "executorch")
332+
message(
333+
FATAL_ERROR
334+
"The ExecuTorch repo must be cloned into a directory named exactly "
335+
"`executorch`; found `${_repo_dir_name}`. See "
336+
"https://github.com/pytorch/executorch/issues/6475 for progress on a "
337+
"fix for this restriction."
338+
)
339+
endif()
327340
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/..)
328341

329342
#

backends/arm/TARGETS

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,27 @@ python_library(
2626
"fbsource//third-party/serialization_lib/python/serializer:serializer",
2727
"fbsource//third-party/serialization_lib/python/tosa:tosa",
2828
":arm_vela",
29+
":process_node",
2930
"//executorch/backends/arm/operators:lib",
3031
"//executorch/backends/arm/operators:node_visitor",
3132
"//executorch/backends/arm/_passes:passes",
3233
],
3334
)
3435

36+
python_library(
37+
name = "process_node",
38+
srcs = ["process_node.py"],
39+
typing = True,
40+
deps = [
41+
"fbsource//third-party/serialization_lib/python/tosa:tosa",
42+
"//executorch/backends/arm/operators:node_visitor",
43+
"//executorch/backends/arm:tosa_mapping",
44+
"//executorch/backends/arm:tosa_quant_utils",
45+
"//executorch/backends/arm:tosa_utils",
46+
"//executorch/exir:lib",
47+
],
48+
)
49+
3550
python_library(
3651
name = "arm_vela",
3752
srcs = [

backends/arm/test/misc/test_model_evaluator.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ def test_get_model_error(self):
3737
example_input,
3838
"tmp/output_tag0.tosa",
3939
)
40-
max_error, max_absolute_error, max_percentage_error, mae = (
41-
evaluator.get_model_error()
42-
)
4340

44-
self.assertEqual(max_error, 1.0)
45-
self.assertEqual(max_absolute_error, 1.0)
46-
self.assertEqual(max_percentage_error, 25.0)
47-
self.assertEqual(mae, 0.25)
41+
model_error_dict = evaluator.get_model_error()
42+
43+
self.assertEqual(model_error_dict["max_error"], [1.0])
44+
self.assertEqual(model_error_dict["max_absolute_error"], [1.0])
45+
self.assertEqual(model_error_dict["max_percentage_error"], [25.0])
46+
self.assertEqual(model_error_dict["mean_absolute_error"], [0.25])
4847

4948
def test_get_compression_ratio(self):
5049
with tempfile.NamedTemporaryFile(delete=True) as temp_bin:

backends/arm/util/arm_model_evaluator.py

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@
77
import os
88
import tempfile
99
import zipfile
10-
from typing import Any, Optional, Tuple
10+
from collections import defaultdict
11+
from typing import Optional, Tuple
1112

1213
import torch
1314

1415

16+
def flatten_args(args) -> tuple | list:
17+
flattened_args: list = []
18+
if isinstance(args, torch.Tensor):
19+
return [args]
20+
21+
for arg in args:
22+
if isinstance(arg, (tuple, list)):
23+
flattened_args.extend(arg)
24+
else:
25+
flattened_args.append(arg)
26+
27+
return tuple(flattened_args)
28+
29+
1530
class GenericModelEvaluator:
1631
def __init__(
1732
self,
@@ -32,31 +47,34 @@ def __init__(
3247
else:
3348
self.tosa_output_path = None
3449

35-
def get_model_error(self) -> tuple[float, float, float, float]:
50+
def get_model_error(self) -> defaultdict:
3651
"""
37-
Returns the following metrics between the outputs of the FP32 and INT8 model:
52+
Returns a dict containing the following metrics between the outputs of the FP32 and INT8 model:
3853
- Maximum error
3954
- Maximum absolute error
4055
- Maximum percentage error
4156
- Mean absolute error
4257
"""
43-
fp32_output = self.fp32_model(*self.example_input)
44-
int8_output = self.int8_model(*self.example_input)
45-
46-
difference = fp32_output - int8_output
47-
percentage_error = torch.div(difference, fp32_output) * 100
48-
49-
max_error = torch.max(difference).item()
50-
max_absolute_error = torch.max(torch.abs(difference)).item()
51-
max_percentage_error = torch.max(percentage_error).item()
52-
mean_absolute_error = torch.mean(torch.abs(difference).float()).item()
53-
54-
return (
55-
float(max_error),
56-
float(max_absolute_error),
57-
float(max_percentage_error),
58-
float(mean_absolute_error),
59-
)
58+
fp32_outputs = flatten_args(self.fp32_model(*self.example_input))
59+
int8_outputs = flatten_args(self.int8_model(*self.example_input))
60+
61+
model_error_dict = defaultdict(list)
62+
63+
for fp32_output, int8_output in zip(fp32_outputs, int8_outputs):
64+
difference = fp32_output - int8_output
65+
percentage_error = torch.div(difference, fp32_output) * 100
66+
model_error_dict["max_error"].append(torch.max(difference).item())
67+
model_error_dict["max_absolute_error"].append(
68+
torch.max(torch.abs(difference)).item()
69+
)
70+
model_error_dict["max_percentage_error"].append(
71+
torch.max(percentage_error).item()
72+
)
73+
model_error_dict["mean_absolute_error"].append(
74+
torch.mean(torch.abs(difference).float()).item()
75+
)
76+
77+
return model_error_dict
6078

6179
def get_compression_ratio(self) -> float:
6280
"""Compute the compression ratio of the outputted TOSA flatbuffer."""
@@ -72,19 +90,10 @@ def get_compression_ratio(self) -> float:
7290

7391
return compression_ratio
7492

75-
def evaluate(self) -> dict[str, Any]:
76-
max_error, max_absolute_error, max_percent_error, mean_absolute_error = (
77-
self.get_model_error()
78-
)
79-
output_metrics = {
80-
"name": self.model_name,
81-
"metrics": {
82-
"max_error": max_error,
83-
"max_absolute_error": max_absolute_error,
84-
"max_percentage_error": max_percent_error,
85-
"mean_absolute_error": mean_absolute_error,
86-
},
87-
}
93+
def evaluate(self) -> dict[any]:
94+
model_error_dict = self.get_model_error()
95+
96+
output_metrics = {"name": self.model_name, "metrics": dict(model_error_dict)}
8897

8998
if self.tosa_output_path:
9099
# We know output_metrics["metrics"] is list since we just defined it, safe to ignore.

0 commit comments

Comments
 (0)