Skip to content

Commit d8c574d

Browse files
Merge branch 'main' into mixed_dtype
2 parents 863a175 + 51c8e2a commit d8c574d

27 files changed

Lines changed: 628 additions & 74 deletions

backends/aoti/export.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#pragma once
1010

1111
// Define export macro for Windows DLL
12-
// When building the aoti_cuda library, EXPORT_AOTI_FUNCTIONS is defined by
13-
// CMake, which causes this macro to export symbols using __declspec(dllexport).
14-
// When consuming the library, the macro imports symbols using
12+
// When building the aoti_cuda_backend library, EXPORT_AOTI_FUNCTIONS is defined
13+
// by CMake, which causes this macro to export symbols using
14+
// __declspec(dllexport). When consuming the library, the macro imports symbols
15+
// using
1516
// __declspec(dllimport). On non-Windows platforms, the macro is empty and has
1617
// no effect.
1718
#ifdef _WIN32

backends/apple/coreml/compiler/torch_ops.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
NUM_TO_TORCH_DTYPE,
2121
split,
2222
to,
23-
transpose,
24-
unbind,
2523
)
2624
from coremltools.converters.mil.frontend.torch.torch_op_registry import (
2725
register_torch_op,
@@ -30,18 +28,6 @@
3028
from executorch.exir.dim_order_utils import get_memory_format
3129

3230

33-
# https://github.com/apple/coremltools/pull/2556
34-
@register_torch_op(override=False)
35-
def transpose_copy(context, node):
36-
transpose(context, node)
37-
38-
39-
# https://github.com/apple/coremltools/pull/2557
40-
@register_torch_op(override=False)
41-
def unbind_copy(context, node):
42-
unbind(context, node)
43-
44-
4531
# https://github.com/apple/coremltools/pull/2563
4632
@register_torch_op(override=False)
4733
def split_copy(context, node):
@@ -117,7 +103,9 @@ def _clone_dim_order(context, node):
117103
# https://github.com/apple/coremltools/pull/2558
118104
@register_torch_op(
119105
torch_alias=["torchao::dequantize_affine", "torchao.dequantize_affine"],
120-
override=False,
106+
# coremltools did not merge the fix into 9.0 (https://github.com/apple/coremltools/pull/2589),
107+
# so we override here
108+
override=True,
121109
)
122110
def dequantize_affine(context, node):
123111
inputs = _get_inputs(context, node, expected=[7, 8])

backends/apple/coreml/test/test_coreml_recipes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def forward(self, x):
326326
)
327327
self.check_fully_delegated(session)
328328

329-
self._compare_eager_quantized_model_outputs(session, example_inputs, atol=1e-3)
329+
self._compare_eager_quantized_model_outputs(session, example_inputs, atol=1e-2)
330330
self._compare_eager_unquantized_model_outputs(session, model, example_inputs)
331331

332332
def test_int8_weight_only_pt2e(self):

backends/arm/CMakeLists.txt

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,44 @@ endif()
4848

4949
# VGF backend builds
5050
if(EXECUTORCH_BUILD_VGF)
51-
52-
# include libvgf
53-
set(LIBVGF_PATH
54-
"${EXECUTORCH_ROOT}/examples/arm/ethos-u-scratch/ml-sdk-for-vulkan-manifest/sw/vgf-lib/"
55-
)
56-
5751
set(VULKAN_THIRD_PARTY_PATH ${EXECUTORCH_ROOT}/backends/vulkan/third-party)
5852
set(VULKAN_HEADERS_PATH ${VULKAN_THIRD_PARTY_PATH}/Vulkan-Headers/include)
5953
set(VOLK_HEADERS_PATH ${VULKAN_THIRD_PARTY_PATH}/volk)
6054

61-
set(LIBVGF_STATIC "${LIBVGF_PATH}/build/src/libvgf.a")
55+
if(APPLE
56+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)$"
57+
OR EXISTS
58+
"${EXECUTORCH_ROOT}/examples/arm/ethos-u-scratch/ml-sdk-for-vulkan-manifest/"
59+
)
60+
message(STATUS "libvgf sourced from local scratch tree")
61+
62+
# Legacy layout: libvgf sourced from local scratch tree
63+
set(LIBVGF_PATH
64+
"${EXECUTORCH_ROOT}/examples/arm/ethos-u-scratch/ml-sdk-for-vulkan-manifest/sw/vgf-lib/"
65+
)
66+
set(LIBVGF_STATIC "${LIBVGF_PATH}/build/src/libvgf.a")
67+
else()
68+
message(STATUS "libvgf installed from pip package")
69+
70+
set(Python3_FIND_VIRTUALENV FIRST)
71+
if(EXECUTORCH_ROOT AND EXISTS "${EXECUTORCH_ROOT}/env")
72+
set(Python3_EXECUTABLE "${EXECUTORCH_ROOT}/env/bin/python3")
73+
endif()
74+
75+
find_package(Python3 REQUIRED COMPONENTS Interpreter)
76+
77+
# Prefer arch-specific site-packages if present, else pure
78+
set(_vgf_site_arch "${Python3_SITEARCH}/vgf_lib/binaries")
79+
set(_vgf_site_pure "${Python3_SITELIB}/vgf_lib/binaries")
80+
if(EXISTS "${_vgf_site_arch}")
81+
set(LIBVGF_PATH "${_vgf_site_arch}")
82+
else()
83+
set(LIBVGF_PATH "${_vgf_site_pure}")
84+
endif()
85+
86+
set(LIBVGF_STATIC "${LIBVGF_PATH}/lib/libvgf.a")
87+
endif()
88+
6289
set(LIBVGF_INCLUDE "${LIBVGF_PATH}/include/")
6390

6491
add_library(vgf STATIC IMPORTED)

backends/arm/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ runtime.python_library(
6868
"vgf/__init__.py",
6969
"vgf/backend.py",
7070
"vgf/compile_spec.py",
71+
"vgf/model_converter.py",
7172
"vgf/partitioner.py",
7273
],
7374
deps = [
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
ai_ml_emulation_layer_for_vulkan == 0.7.0
7+
ai_ml_sdk_model_converter == 0.7.0
8+
ai_ml_sdk_vgf_library == 0.7.0

backends/arm/scripts/mlsdk_utils.sh

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,51 @@ function setup_path_emulation_layer() {
205205
model_emulation_layer_path="$(cd "${mlsdk_manifest_dir}/sw/emulation-layer/" && pwd)"
206206
prepend_env_in_setup_path LD_LIBRARY_PATH "${model_emulation_layer_path}/deploy/lib"
207207
prepend_env_in_setup_path DYLD_LIBRARY_PATH "${model_emulation_layer_path}/deploy/lib"
208+
prepend_env_in_setup_path VK_LAYER_PATH "${model_emulation_layer_path}/deploy/share/vulkan/explicit_layer.d"
208209
prepend_env_in_setup_path VK_INSTANCE_LAYERS VK_LAYER_ML_Tensor_Emulation
209210
prepend_env_in_setup_path VK_INSTANCE_LAYERS VK_LAYER_ML_Graph_Emulation
210-
prepend_env_in_setup_path VK_LAYER_PATH "${model_emulation_layer_path}/deploy/share/vulkan/explicit_layer.d"
211+
}
212+
213+
function setup_path_emulation_layer_from_pip() {
214+
if ! command -v emulation_layer >/dev/null 2>&1; then
215+
echo "[mlsdk_utils] 'emulation_layer' command not found; skipping pip emulation layer path setup"
216+
return
217+
fi
218+
219+
local output
220+
if ! output=$(emulation_layer 2>/dev/null); then
221+
echo "[mlsdk_utils] Failed to query emulation_layer environment; skipping"
222+
return
223+
fi
224+
225+
local exports
226+
exports=$(echo "$output" | grep '^export ' || true)
227+
228+
local ld_line
229+
ld_line=$(echo "$exports" | grep 'LD_LIBRARY_PATH=' || true)
230+
if [[ -n "${ld_line}" ]]; then
231+
local ld_value=${ld_line#export LD_LIBRARY_PATH=}
232+
ld_value=${ld_value%%:\$LD_LIBRARY_PATH*}
233+
if [[ -n "${ld_value}" ]]; then
234+
prepend_env_in_setup_path LD_LIBRARY_PATH "${ld_value}"
235+
fi
236+
fi
237+
238+
local vk_add_line
239+
vk_add_line=$(echo "$exports" | grep 'VK_ADD_LAYER_PATH=' || true)
240+
if [[ -n "${vk_add_line}" ]]; then
241+
local vk_add_value=${vk_add_line#export VK_ADD_LAYER_PATH=}
242+
if [[ -n "${vk_add_value}" ]]; then
243+
prepend_env_in_setup_path VK_ADD_LAYER_PATH "${vk_add_value}"
244+
fi
245+
fi
246+
247+
local vk_instance_line
248+
vk_instance_line=$(echo "$exports" | grep 'VK_INSTANCE_LAYERS=' || true)
249+
if [[ -n "${vk_instance_line}" ]]; then
250+
local vk_instance_value=${vk_instance_line#export VK_INSTANCE_LAYERS=}
251+
if [[ -n "${vk_instance_value}" ]]; then
252+
prepend_env_in_setup_path VK_INSTANCE_LAYERS "${vk_instance_value}"
253+
fi
254+
fi
211255
}

backends/arm/scripts/run_vkml.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ if [[ -z ${model} ]]; then echo "Model name needs to be provided"; exit 1; fi
5050

5151
source ${setup_path_script}
5252

53-
# basic checks before we get started
54-
hash ${converter} \
55-
|| { echo "Could not find ${converter} on PATH, ${_setup_msg}"; exit 1; }
53+
if ! command -v "${converter}" >/dev/null 2>&1; then
54+
if command -v model_converter >/dev/null 2>&1; then
55+
converter="model_converter"
56+
fi
57+
fi
58+
59+
command -v "${converter}" >/dev/null 2>&1 \
60+
|| { echo "Could not find a model converter executable (tried model-converter, model_converter). ${_setup_msg}"; exit 1; }
5661

5762

5863

backends/arm/test/misc/test_call_operator_submodule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
55

6-
from typing import Any
6+
from typing import Any, Optional
77

88
import torch
99

@@ -24,7 +24,7 @@ def __init__(self, initial_graph_module):
2424
self.submodule = None
2525
self.num_submodules_called = 0
2626

27-
def call_operator(self, op, args, kwargs, meta, updated: bool = False):
27+
def call_operator(self, op, args, kwargs, meta, updated: Optional[bool] = False):
2828
"""Should only be called from the top-level graph module."""
2929
self.depths.append(self.submodule_depth)
3030
assert self.submodule == self.initial_submodule

backends/arm/test/runner_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from executorch.backends.arm.tosa.compile_spec import TosaCompileSpec
3232
from executorch.backends.arm.tosa.specification import Tosa_1_00, TosaSpecification
3333
from executorch.backends.arm.vgf import VgfCompileSpec
34+
from executorch.backends.arm.vgf.model_converter import find_model_converter_binary
3435
from executorch.exir import ExecutorchProgramManager, ExportedProgram
3536
from executorch.exir.lowered_backend_module import LoweredBackendModule
3637
from torch.fx.node import Node
@@ -678,11 +679,15 @@ def corstone320_installed() -> bool:
678679

679680

680681
def model_converter_installed() -> bool:
681-
cmd = ["model-converter", "--version"]
682+
model_converter = find_model_converter_binary()
683+
if model_converter is None:
684+
return False
685+
682686
try:
683-
_run_cmd(cmd, check=True)
684-
except:
687+
_run_cmd([model_converter, "--version"], check=True)
688+
except Exception:
685689
return False
690+
686691
return True
687692

688693

0 commit comments

Comments
 (0)