Skip to content

Commit b8abadf

Browse files
authored
Merge branch 'main' into dev1/hutton/fix_uint16
2 parents e4e2790 + ebc38b2 commit b8abadf

File tree

210 files changed

+5783
-2875
lines changed

Some content is hidden

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

210 files changed

+5783
-2875
lines changed

.ci/scripts/build_llama_android.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ install_executorch_and_backend_lib() {
2626
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
2727
-DEXECUTORCH_BUILD_XNNPACK=ON \
2828
-DEXECUTORCH_BUILD_OPTIMIZED=ON \
29+
-DEXECUTORCH_BUILD_QUANTIZED=ON \
2930
-DXNNPACK_ENABLE_ARM_BF16=OFF \
3031
-Bcmake-android-out .
3132

.ci/scripts/test_llama.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ cmake_install_executorch_libraries() {
7575
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
7676
-DEXECUTORCH_BUILD_CUSTOM="$CUSTOM" \
7777
-DEXECUTORCH_BUILD_OPTIMIZED=ON \
78+
-DEXECUTORCH_BUILD_QUANTIZED=ON \
7879
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
7980
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
8081
-Bcmake-out .

.github/workflows/apple.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
timeout: 90
5959
script: |
6060
BUILD_TOOL=cmake
61-
VERSION="0.1.0"
61+
VERSION="latest"
6262
FRAMEWORKS=(
6363
"executorch"
6464
"coreml_backend"

.github/workflows/doc-build.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ jobs:
9898
REF_TYPE=${{ github.ref_type }}
9999
REF_NAME=${{ github.ref_name }}
100100
101-
# If it's main branch, add noindex tag to all .html files to exclude from Google Search indexing.
102-
REF_NAME=$(echo "${{ github.ref }}")
103-
echo "Ref name: ${REF_NAME}"
104-
if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
105-
find docs -name "*.html" -print0 | xargs -0 sed -i '/<head>/a \ \ <meta name="robots" content="noindex">';
106-
fi
107-
108101
# If building for a release tag, branch, set the branch/tag name
109102
# as the target folder in the gh-pages branch. The artifacts created
110103
# during the build will be copied over to the target dir in the

.swift/coreml_backend/dummy.swift

Whitespace-only changes.

.swift/coreml_backend_debug/dummy.swift

Whitespace-only changes.

.swift/custom_backend/dummy.swift

Whitespace-only changes.

.swift/custom_backend_debug/dummy.swift

Whitespace-only changes.

.swift/executorch/dummy.swift

Whitespace-only changes.

.swift/executorch_debug/dummy.swift

Whitespace-only changes.

.swift/mps_backend/dummy.swift

Whitespace-only changes.

.swift/mps_backend_debug/dummy.swift

Whitespace-only changes.

.swift/optimized_backend/dummy.swift

Whitespace-only changes.

.swift/optimized_backend_debug/dummy.swift

Whitespace-only changes.

.swift/portable_backend/dummy.swift

Whitespace-only changes.

.swift/portable_backend_debug/dummy.swift

Whitespace-only changes.

.swift/quantized_backend/dummy.swift

Whitespace-only changes.

.swift/quantized_backend_debug/dummy.swift

Whitespace-only changes.

.swift/xnnpack_backend/dummy.swift

Whitespace-only changes.

.swift/xnnpack_backend_debug/dummy.swift

Whitespace-only changes.

CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ option(EXECUTORCH_BUILD_QNN "Build the Qualcomm backend" OFF)
164164

165165
option(EXECUTORCH_BUILD_OPTIMIZED "Build the optimized kernels" OFF)
166166

167+
option(EXECUTORCH_BUILD_QUANTIZED "Build the quantized kernels" OFF)
168+
167169
option(EXECUTORCH_BUILD_SDK "Build the ExecuTorch SDK")
168170

169171
option(EXECUTORCH_BUILD_SIZE_TEST "Build the size test" OFF)
@@ -411,7 +413,9 @@ if(EXECUTORCH_BUILD_OPTIMIZED)
411413
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/optimized)
412414
endif()
413415

414-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/quantized)
416+
if(EXECUTORCH_BUILD_QUANTIZED)
417+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/quantized)
418+
endif()
415419

416420
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/configurations)
417421

@@ -441,14 +445,19 @@ cmake_dependent_option(
441445
EXECUTORCH_BUILD_HOST_TARGETS OFF)
442446
if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
443447
# Baseline libraries that executor_runner will link against.
444-
set(_executor_runner_libs executorch gflags quantized_ops_lib)
448+
set(_executor_runner_libs executorch gflags)
445449

446450
if(EXECUTORCH_BUILD_OPTIMIZED)
447451
list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib)
448452
else()
449453
list(APPEND _executor_runner_libs portable_ops_lib)
450454
endif()
451455

456+
# Generate lib to register quantized ops
457+
if(EXECUTORCH_BUILD_QUANTIZED)
458+
list(APPEND _executor_runner_libs quantized_ops_lib)
459+
endif()
460+
452461
add_executable(executor_runner ${_executor_runner__srcs})
453462
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT APPLE)
454463
target_link_options(executor_runner PRIVATE "LINKER:--gc-sections")

Package.swift

Lines changed: 0 additions & 101 deletions
This file was deleted.

backends/apple/coreml/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ if(NOT EXECUTORCH_ROOT)
1313
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
1414
endif()
1515

16+
option(COREML_BUILD_EXECUTOR_RUNNER "Build CoreML executor runner." OFF)
17+
1618
# inmemoryfs sources
1719
set(INMEMORYFS_SOURCES
1820
runtime/inmemoryfs/inmemory_filesystem.cpp
@@ -181,6 +183,14 @@ target_link_libraries(coremldelegate
181183
${SQLITE_LIBRARY}
182184
)
183185

186+
if(COREML_BUILD_EXECUTOR_RUNNER)
187+
target_link_libraries(coremldelegate
188+
PRIVATE
189+
portable_ops_lib
190+
portable_kernels
191+
)
192+
endif()
193+
184194
target_compile_options(coremldelegate PRIVATE "-fobjc-arc")
185195
target_compile_options(coremldelegate PRIVATE "-fno-exceptions")
186196

backends/apple/coreml/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ For delegating the Program to the **Core ML** backend, the client must be respon
2828
import executorch.exir as exir
2929
import torch
3030

31+
from torch.export import export
32+
33+
from executorch.exir import to_edge
34+
3135
from executorch.exir.backend.backend_api import to_backend
3236

3337
from executorch.backends.apple.coreml.compiler import CoreMLBackend
@@ -42,7 +46,7 @@ class LowerableSubModel(torch.nn.Module):
4246
# Convert the lowerable module to Edge IR Representation
4347
to_be_lowered = LowerableSubModel()
4448
example_input = (torch.ones(1), )
45-
to_be_lowered_exir_submodule = exir.capture(to_be_lowered, example_input).to_edge()
49+
to_be_lowered_exir_submodule = to_edge(export(to_be_lowered, example_input))
4650

4751
# Lower to Core ML backend
4852
lowered_module = to_backend('CoreMLBackend', to_be_lowered_exir_submodule.exported_program, [])

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ - (NSUInteger)_compact:(NSUInteger)sizeInBytes error:(NSError * __autoreleasing
630630
}
631631

632632
if (_estimatedSizeInBytes <= sizeInBytes) {
633-
return YES;
633+
return _estimatedSizeInBytes;
634634
}
635635

636636
std::error_code ec;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ __attribute__((objc_subclassing_restricted))
2828
/// The model.
2929
@property (readonly, strong, nonatomic) ETCoreMLModel* model;
3030

31+
/// If set to `YES` then output backing are ignored.
32+
@property (readwrite, atomic) BOOL ignoreOutputBackings;
33+
3134
@end
3235

3336
NS_ASSUME_NONNULL_END

backends/apple/coreml/runtime/delegate/ETCoreMLDefaultModelExecutor.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ - (instancetype)initWithModel:(ETCoreMLModel *)model {
2626
loggingOptions:(const executorchcoreml::ModelLoggingOptions& __unused)loggingOptions
2727
eventLogger:(const executorchcoreml::ModelEventLogger* _Nullable __unused)eventLogger
2828
error:(NSError * __autoreleasing *)error {
29+
if (self.ignoreOutputBackings) {
30+
predictionOptions.outputBackings = @{};
31+
}
2932
id<MLFeatureProvider> outputs = [self.model.mlModel predictionFromFeatures:inputs
3033
options:predictionOptions
3134
error:error];

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#import <Foundation/Foundation.h>
99

10+
#import <executorch/runtime/platform/log.h>
1011
#import <os/log.h>
1112

1213
NS_ASSUME_NONNULL_BEGIN
@@ -48,7 +49,11 @@ typedef NS_ERROR_ENUM(ETCoreMLErrorDomain, ETCoreMLError) {
4849

4950
/// Record the error with `os_log_error` and fills `*errorOut` with `NSError`.
5051
#define ETCoreMLLogErrorAndSetNSError(errorOut, errorCode, formatString, ...) \
51-
os_log_error(ETCoreMLErrorUtils.loggingChannel, formatString, ##__VA_ARGS__); \
52+
if (ET_LOG_ENABLED) { \
53+
ET_LOG(Error, "%s", [NSString stringWithFormat:@formatString, ##__VA_ARGS__].UTF8String); \
54+
} else { \
55+
os_log_error(ETCoreMLErrorUtils.loggingChannel, formatString, ##__VA_ARGS__); \
56+
} \
5257
if (errorOut) { \
5358
*errorOut = \
5459
[NSError errorWithDomain:ETCoreMLErrorDomain \
@@ -58,24 +63,31 @@ typedef NS_ERROR_ENUM(ETCoreMLErrorDomain, ETCoreMLError) {
5863
}]; \
5964
}
6065

61-
/// Record the error and its underlying error with `os_log_error` and fills
62-
/// `*errorOut` with NSError.
66+
/// Record the error and its underlying error with `os_log_error` and fills `*errorOut` with `NSError`.
6367
#define ETCoreMLLogUnderlyingErrorAndSetNSError(errorOut, errorCode, underlyingNSError, formatString, ...) \
64-
os_log_error(ETCoreMLErrorUtils.loggingChannel, \
65-
formatString ", with underlying error= %@.", \
66-
##__VA_ARGS__, \
67-
(underlyingNSError).localizedDescription); \
68+
if (ET_LOG_ENABLED) { \
69+
ET_LOG(Error, "%s", [NSString stringWithFormat:@formatString, ##__VA_ARGS__].UTF8String); \
70+
} else { \
71+
os_log_error(ETCoreMLErrorUtils.loggingChannel, \
72+
formatString ", with underlying error= %@.", \
73+
##__VA_ARGS__, \
74+
(underlyingNSError).localizedDescription); \
75+
} \
6876
if (errorOut) { \
6977
*errorOut = [ETCoreMLErrorUtils errorWithCode:errorCode \
7078
underlyingError:underlyingNSError \
7179
format:@formatString, ##__VA_ARGS__]; \
7280
}
7381

74-
#define ETCoreMLLogError(error, formatString, ...) \
75-
os_log_error(ETCoreMLErrorUtils.loggingChannel, \
76-
formatString ", with error= %@.", \
77-
##__VA_ARGS__, \
78-
(error).localizedDescription);
82+
#define ETCoreMLLogError(error, formatString, ...) \
83+
if (ET_LOG_ENABLED) { \
84+
ET_LOG(Error, "%s", [NSString stringWithFormat:@formatString, ##__VA_ARGS__].UTF8String); \
85+
} else { \
86+
os_log_error(ETCoreMLErrorUtils.loggingChannel, \
87+
formatString ", with error= %@.", \
88+
##__VA_ARGS__, \
89+
(error).localizedDescription); \
90+
}
7991

8092

8193
#pragma clang diagnostic pop

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
// Please refer to the license found in the LICENSE file in the root directory of the source tree.
77

88
#import <CoreML/CoreML.h>
9+
#import <vector>
910

1011
NS_ASSUME_NONNULL_BEGIN
1112

1213
@class ETCoreMLAsset;
1314

15+
namespace executorchcoreml {
16+
class MultiArray;
17+
}
18+
1419
/// Represents a ML model, the class is a thin wrapper over `MLModel` with additional properties.
20+
__attribute__((objc_subclassing_restricted))
1521
@interface ETCoreMLModel : NSObject
1622

1723
- (instancetype)init NS_UNAVAILABLE;
@@ -31,6 +37,12 @@ NS_ASSUME_NONNULL_BEGIN
3137
orderedOutputNames:(NSOrderedSet<NSString*>*)orderedOutputNames
3238
error:(NSError* __autoreleasing*)error NS_DESIGNATED_INITIALIZER;
3339

40+
- (nullable NSArray<MLMultiArray*>*)prepareInputs:(const std::vector<executorchcoreml::MultiArray>&)inputs
41+
error:(NSError* __autoreleasing*)error;
42+
43+
- (nullable NSArray<MLMultiArray*>*)prepareOutputBackings:(const std::vector<executorchcoreml::MultiArray>&)outputs
44+
error:(NSError* __autoreleasing*)error;
45+
3446
/// The underlying MLModel.
3547
@property (strong, readonly, nonatomic) MLModel* mlModel;
3648

0 commit comments

Comments
 (0)