Skip to content

Commit fff7e02

Browse files
committed
Update base for Update on "make aoti_torch_empty_strided support creating incontiguous tensor"
This diff modifies the `aoti_torch_empty_strided` function to support the creation of incontiguous tensors. To achieve it, this diff: 1. update the way to calculate the memory size by using both tensor size and the stride 2. skip stride check in ETensor by adding and checking cmake macro `USE_CUDA_BACKEND` when building with CUDA backend support. we will soon bring the ETensor check back for every backend after migrating to use slimtensor. Differential Revision: [D84938258](https://our.internmc.facebook.com/intern/diff/D84938258/) [ghstack-poisoned]
2 parents 9acd52b + aeee757 commit fff7e02

File tree

48 files changed

+1799
-409
lines changed

Some content is hidden

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

48 files changed

+1799
-409
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
53a2908a10f414a2f85caa06703a26a40e873869
1+
e6f766c7d750d40603eee3f66c5915bac606b3ea

.ci/scripts/utils.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,44 @@ install_pip_dependencies() {
4444
popd || return
4545
}
4646

47+
dedupe_macos_loader_path_rpaths() {
48+
if [[ "$(uname)" != "Darwin" ]]; then
49+
return
50+
fi
51+
52+
local torch_lib_dir
53+
pushd ..
54+
torch_lib_dir=$(python -c "import importlib.util; print(importlib.util.find_spec('torch').submodule_search_locations[0])")/lib
55+
popd
56+
57+
if [[ -z "${torch_lib_dir}" || ! -d "${torch_lib_dir}" ]]; then
58+
return
59+
fi
60+
61+
local torch_libs=(
62+
"libtorch_cpu.dylib"
63+
"libtorch.dylib"
64+
"libc10.dylib"
65+
)
66+
67+
for lib_name in "${torch_libs[@]}"; do
68+
local lib_path="${torch_lib_dir}/${lib_name}"
69+
if [[ ! -f "${lib_path}" ]]; then
70+
continue
71+
fi
72+
73+
local removed=0
74+
# Repeatedly remove the @loader_path rpath entries until none remain.
75+
while install_name_tool -delete_rpath @loader_path "${lib_path}" 2>/dev/null; do
76+
removed=1
77+
done
78+
79+
if [[ "${removed}" == "1" ]]; then
80+
install_name_tool -add_rpath @loader_path "${lib_path}" || true
81+
fi
82+
done
83+
}
84+
4785
install_domains() {
4886
echo "Install torchvision and torchaudio"
4987
pip install --no-use-pep517 --user "git+https://github.com/pytorch/audio.git@${TORCHAUDIO_VERSION}"
@@ -101,6 +139,7 @@ install_pytorch_and_domains() {
101139
echo "Use cached wheel at ${cached_torch_wheel}"
102140
fi
103141

142+
dedupe_macos_loader_path_rpaths
104143
# Grab the pinned audio and vision commits from PyTorch
105144
TORCHAUDIO_VERSION=$(cat .github/ci_commit_pins/audio.txt)
106145
export TORCHAUDIO_VERSION

.github/workflows/pull.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ jobs:
351351
352352
# reinstall executorch
353353
bash ./install_executorch.sh --minimal
354+
pip list
354355
355356
# run python unittest
356357
python -m unittest examples.models.moshi.mimi.test_mimi

CMakeLists.txt

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,6 @@ announce_configured_options(CCACHE_PROGRAM)
9999

100100
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
101101

102-
# Setup RPATH. See
103-
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
104-
# Use separate rpaths during build and install phases
105-
set(CMAKE_SKIP_BUILD_RPATH OFF)
106-
# Don't use the install-rpath during the build phase
107-
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
108-
# Automatically add all linked folders that are NOT in the build directory to
109-
# the rpath (per library?)
110-
#
111-
# TODO: Doesn't work for us right now because we are not installing .so's into
112-
# the correct locations. For example we have libcustom_ops_aot_lib.so depending
113-
# on _portable_lib.so, which was eventually put under
114-
# <site-packages>/executorch/extension/pybindings/ but this rpath is not
115-
# automatically added because at build time it seems `portable_lib` is being
116-
# built under the same directory, so no extra rpath is being added. To properly
117-
# fix this we need to install `portable_lib` into the correct path.
118-
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
119-
# ------------------------------ OPTIONS -------------------------------------
120-
# WARNING: Please don't add example specific options in this CMakeLists.txt.
121-
# Instead please use `find_package(executorch REQUIRED)` in the example
122-
# directory and add a new executable in the example `CMakeLists.txt`.
123-
124102
if(NOT EXECUTORCH_ENABLE_LOGGING)
125103
# Avoid pulling in the logging strings, which can be large. Note that this
126104
# will set the compiler flag for all targets in this directory, and for all
@@ -909,12 +887,13 @@ if(EXECUTORCH_BUILD_PYBIND)
909887

910888
# Set RPATH to find PyTorch libraries relative to the installation location
911889
# This goes from executorch/extension/pybindings up to site-packages, then to
912-
# torch/lib
890+
# torch/lib. Don't do this to APPLE, as it will error out on the following
891+
# error:
892+
#
913893
if(APPLE)
914-
set_target_properties(
915-
portable_lib PROPERTIES BUILD_RPATH "@loader_path/../../../torch/lib"
916-
INSTALL_RPATH "@loader_path/../../../torch/lib"
917-
)
894+
# Skip setting @loader_path for APPLE, since it causes error like ld:
895+
# duplicate LC_RPATH '@loader_path' in '<site-packages>/torch/lib/
896+
# libtorch_cpu.dylib'
918897
else()
919898
set_target_properties(
920899
portable_lib PROPERTIES BUILD_RPATH "$ORIGIN/../../../torch/lib"

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Copyright (c) 2023 Apple Inc.
99
Copyright (c) 2024 MediaTek Inc.
1010
Copyright 2023 NXP
1111
Copyright (c) 2025 Samsung Electronics Co. LTD
12+
Copyright (c) Intel Corporation
1213

1314
Redistribution and use in source and binary forms, with or without modification,
1415
are permitted provided that the following conditions are met:

backends/aoti/aoti_delegate_handle.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ using AOTInductorModelContainerGetNumConstantsFunc = AOTIRuntimeError (*)(
7171
AOTInductorModelContainerHandle container_handle,
7272
size_t* num_constants);
7373

74+
// Update the model container with the constant tensors
75+
using AOTInductorModelUpdateConstantsFromBlobFunc = AOTIRuntimeError (*)(
76+
AOTInductorModelContainerHandle container_handle,
77+
const uint8_t* weight_blob_ptr);
78+
7479
} // extern "C"
7580

7681
// AOTI Delegate Handle structure
@@ -87,6 +92,7 @@ struct AOTIDelegateHandle {
8792
AOTInductorModelContainerGetNumInputsFunc get_num_inputs;
8893
AOTInductorModelContainerGetNumOutputsFunc get_num_outputs;
8994
AOTInductorModelContainerRunFunc run;
95+
AOTInductorModelUpdateConstantsFromBlobFunc update_constants_from_blob;
9096
};
9197

9298
} // namespace aoti

backends/apple/coreml/runtime/delegate/ETCoreMLAssetManager.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ NS_ASSUME_NONNULL_BEGIN
9999
- (NSUInteger)compact:(NSUInteger)sizeInBytes error:(NSError* __autoreleasing*)error;
100100

101101

102+
/// Executes a block with a unique temporary directory.
103+
///
104+
/// A new temporary subdirectory URL is created inside the receiver’s designated
105+
/// base directory. The directory is passed to the block, which can use it to
106+
/// perform temporary file operations. After the block finishes executing,
107+
/// the directory and its contents are removed.
108+
///
109+
/// @param block A block to execute. The block receives a unique URL.
110+
- (void)withTemporaryDirectory:(void (^)(NSURL* directoryURL))block;
111+
112+
102113
/// Purges the assets storage. The assets are moved to the trash directory and are asynchronously
103114
/// deleted.
104115
///
@@ -117,6 +128,12 @@ NS_ASSUME_NONNULL_BEGIN
117128
/// contents are deleted asynchronously.
118129
@property (copy, readonly, nonatomic) NSURL* trashDirectoryURL;
119130

131+
132+
/// The staging directory URL, used to hold assets that are being prepared or processed
133+
/// before they are moved into their final location. The contents of this directory
134+
/// are temporary and may be cleared when no longer needed.
135+
@property (copy, readonly, nonatomic) NSURL* stagingDirectoryURL;
136+
120137
/// The file manager.
121138
@property (strong, readonly, nonatomic) NSFileManager* fileManager;
122139

0 commit comments

Comments
 (0)