Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Load development ONNX Runtime from install cache

laurenspriem32ef8578fb34
diff --git a/desktop/docs/dependencies.md b/desktop/docs/dependencies.md
index 16978d921a..a3a4af7d36 100644
--- a/desktop/docs/dependencies.md
+++ b/desktop/docs/dependencies.md
@@ -76,7 +76,7 @@ On macOS, we use the `sips` CLI tool for these tasks, but that is already availa
The ML pipeline (natural language search using CLIP, and face detection and recognition) is implemented by the Rust crate shared with the mobile apps (`rust/crates/photos`), exposed to us as a Node native addon built from source by `scripts/napi.js` (see "[Note: ML with Rust]"). `cargo codegen napi` generates only the TypeScript declarations for that addon.
-The addon loads [ONNX Runtime](https://onnxruntime.ai) dynamically at runtime, using Ente's pinned custom builds (CoreML-enabled on macOS) that `scripts/ort.js` installs during postinstall and stages into the extra resources (`build`) folder. See "[Note: ONNX Runtime binaries]".
+The addon loads [ONNX Runtime](https://onnxruntime.ai) dynamically at runtime, using Ente's pinned custom builds (CoreML-enabled on macOS) that `scripts/ort.js` installs during postinstall. Development loads the libraries directly from the install cache; packaging stages them into the extra resources (`build`) folder. See "[Note: ONNX Runtime binaries]".
### ZIP
diff --git a/desktop/scripts/ort.js b/desktop/scripts/ort.js
index 791120ca2c..437cd40cee 100644
--- a/desktop/scripts/ort.js
+++ b/desktop/scripts/ort.js
@@ -8,9 +8,8 @@
*
* This script is the only place that downloads those builds. Postinstall runs
* it once to acquire both architectures for the host platform. The extracted
- * libraries are kept under `node_modules/.cache/ente-onnxruntime/`, separate
- * from compilation and packaging. It also stages the host libraries into
- * `build/onnxruntime/` for development.
+ * libraries are kept under `node_modules/.cache/ente-onnxruntime/`, where the
+ * development app loads them directly.
*
* During packaging, `beforeBuild.js` calls {@link stageONNXRuntime} to copy the
* already-installed libraries needed by the current target into
@@ -142,10 +141,6 @@ const stageONNXRuntime = async (platform, arch, appDir) => {
const installONNXRuntime = async (platform, appDir) => {
for (const arch of ["arm64", "x64"])
await downloadONNXRuntimeIfNeeded(platform, arch, appDir);
-
- // Make the host runtime available to the development app. macOS needs
- // both libraries because its packaged application is universal.
- await stageONNXRuntime(platform, process.arch, appDir);
};
const main = () => {
diff --git a/desktop/src/main/services/ml-native.ts b/desktop/src/main/services/ml-native.ts
index 4856bbb5a6..a4bb2d24d8 100644
--- a/desktop/src/main/services/ml-native.ts
+++ b/desktop/src/main/services/ml-native.ts
@@ -14,11 +14,10 @@
* in scripts/ort.js).
*
* During development, `scripts/napi.js` (invoked by `npm run dev`) builds the
- * addon into the gitignored `rust-bindings/` directory. When packaging,
- * `beforeBuild.js` builds and stages the addon for the target architectures
- * into `build/napi/`, which electron-builder copies (along with the ONNX
- * Runtime libraries staged in `build/onnxruntime/`) into the app's resources
- * directory.
+ * addon into the gitignored `rust-bindings/` directory, while ONNX Runtime is
+ * loaded directly from the postinstall cache. When packaging, `beforeBuild.js`
+ * stages both the addon and ONNX Runtime for the target architectures, and
+ * electron-builder copies them into the app's resources directory.
*/
import path from "node:path";
@@ -77,9 +76,11 @@ export const mlNativePaths = (): MLNativePaths => {
const addon = isDev
? path.resolve("rust-bindings", addonName)
: path.join(process.resourcesPath, "napi", addonName);
+ const onnxRuntimeRoot = isDev
+ ? path.resolve("node_modules", ".cache", "ente-onnxruntime")
+ : path.join(process.resourcesPath, "onnxruntime");
const onnxRuntimeLibrary = path.join(
- isDev ? path.resolve("build") : process.resourcesPath,
- "onnxruntime",
+ onnxRuntimeRoot,
process.arch,
onnxRuntimeLibraryName(),
);