Skip to content

armgit / ente

Public Imported from GitHub
0

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

Upgrade ONNX Runtime packages to 1.31.0-r1

laurenspriem761fb3e160e0
diff --git a/android/apps/ensu/rust/build.gradle.kts b/android/apps/ensu/rust/build.gradle.kts
index f2dc740339..3b54036a55 100644
--- a/android/apps/ensu/rust/build.gradle.kts
+++ b/android/apps/ensu/rust/build.gradle.kts
@@ -230,7 +230,7 @@ dependencies {
// Custom WebGPU/XNNPACK build; the Rust runtime dynamically loads its
// libonnxruntime.so. Resolved from the Ivy repository declared in
// settings.gradle.kts and SHA-256 pinned in android/gradle/verification-metadata.xml.
- api("io.ente.onnxruntime:onnxruntime-webgpu-android:1.28.1-r1@aar")
+ api("io.ente.onnxruntime:onnxruntime-webgpu-android:1.31.0-r1@aar")
api("net.java.dev.jna:jna:5.18.1@aar")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
}
diff --git a/android/gradle/verification-metadata.xml b/android/gradle/verification-metadata.xml
index 47d3bd0460..22ad677e1f 100644
--- a/android/gradle/verification-metadata.xml
+++ b/android/gradle/verification-metadata.xml
@@ -18,9 +18,9 @@
</trusted-artifacts>
</configuration>
<components>
- <component group="io.ente.onnxruntime" name="onnxruntime-webgpu-android" version="1.28.1-r1">
- <artifact name="onnxruntime-webgpu-android-1.28.1-r1.aar">
- <sha256 value="c7926c66eb7eee75b95297b20fa28c76417f06cba2d20f6877817fd7efd2e2bd"/>
+ <component group="io.ente.onnxruntime" name="onnxruntime-webgpu-android" version="1.31.0-r1">
+ <artifact name="onnxruntime-webgpu-android-1.31.0-r1.aar">
+ <sha256 value="e1a55bd0fe8f03c7c0a2ee4e1f9e90fd0630302bed79cba5cb78418450749f48"/>
</artifact>
</component>
</components>
diff --git a/apple/packages/EnteOnnxRuntime/EnteOnnxRuntime.podspec b/apple/packages/EnteOnnxRuntime/EnteOnnxRuntime.podspec
index afb8a89a64..149fec3b9b 100644
--- a/apple/packages/EnteOnnxRuntime/EnteOnnxRuntime.podspec
+++ b/apple/packages/EnteOnnxRuntime/EnteOnnxRuntime.podspec
@@ -5,14 +5,14 @@
# XCFramework's static archive for the active platform via ORT_LIB_PATH.
Pod::Spec.new do |s|
s.name = 'EnteOnnxRuntime'
- s.version = '1.28.1-r1'
+ s.version = '1.31.0-r1'
s.summary = "Ente's custom prebuilt ONNX Runtime static-library XCFramework for iOS."
s.homepage = 'https://github.com/ente/ort-packaging'
s.authors = { 'Ente' => '[email protected]' }
s.license = { :type => 'MIT', :file => 'ONNXRUNTIME-LICENSE' }
s.source = {
- :http => 'https://github.com/ente/ort-packaging/releases/download/ort-1.28.1-r1/onnxruntime-coreml-ios-1.28.1-r1.zip',
- :sha256 => '774b986bdd8a9f729a3e80ce7f7e7e695f0387be6f66633feaa9835c05e8557e',
+ :http => 'https://github.com/ente/ort-packaging/releases/download/ort-1.31.0-r1/onnxruntime-coreml-ios-1.31.0-r1.zip',
+ :sha256 => '4e4b12ce37e4a5c971cc758c96446b067c8e25818384e85aeed6be15decd3b86',
}
s.platform = :ios, '15.1'
diff --git a/apple/packages/EnteOnnxRuntime/Package.swift b/apple/packages/EnteOnnxRuntime/Package.swift
index d1333d33d4..f4d1e45dbc 100644
--- a/apple/packages/EnteOnnxRuntime/Package.swift
+++ b/apple/packages/EnteOnnxRuntime/Package.swift
@@ -19,8 +19,8 @@ let package = Package(
.binaryTarget(
name: "onnxruntime",
url:
- "https://github.com/ente/ort-packaging/releases/download/ort-1.28.1-r1/onnxruntime-coreml-ios-1.28.1-r1.zip",
- checksum: "774b986bdd8a9f729a3e80ce7f7e7e695f0387be6f66633feaa9835c05e8557e"
+ "https://github.com/ente/ort-packaging/releases/download/ort-1.31.0-r1/onnxruntime-coreml-ios-1.31.0-r1.zip",
+ checksum: "4e4b12ce37e4a5c971cc758c96446b067c8e25818384e85aeed6be15decd3b86"
)
]
)
diff --git a/desktop/scripts/ort.js b/desktop/scripts/ort.js
index 4ac0cae3c5..f83d536de3 100644
--- a/desktop/scripts/ort.js
+++ b/desktop/scripts/ort.js
@@ -3,7 +3,7 @@ const fsp = require("node:fs/promises");
const path = require("node:path");
const { execFileSync } = require("node:child_process");
-const ortVersion = "1.28.1-r1";
+const ortVersion = "1.31.0-r1";
// Our packaging enables CoreML on macOS and WebGPU elsewhere.
const ortReleaseURL = `https://github.com/ente/ort-packaging/releases/download/ort-${ortVersion}`;
@@ -12,17 +12,17 @@ const ortReleaseURL = `https://github.com/ente/ort-packaging/releases/download/o
// release's .sha256 sidecars.
const ortAssetSHA256s = {
"darwin-arm64":
- "12890a871d0e658dd064be187fa63d27c6b692e69f94d4750532fd8f4d179c1e",
+ "287567756b9aa6aae1a8a0cb85f5deaf5bd30e9a14a33a8dd0def569e773542f",
"darwin-x64":
- "8c96da8568343b5ab496e93d112a5d6126c01e5dcc4e6719219aa678ad6abe25",
+ "26f8d498f103795b2a7eaf865827670cae7420f77ba138575b5aa291224a80ee",
"linux-arm64":
- "2eb71ced50e16b4e2d4ab20b924276d50d123417962a7d874a0cdb7f0171c63d",
+ "98d35a7f3240ffe96af478bf0e0d05c7febeed53cf968d13ca5b0dc15eb15aaa",
"linux-x64":
- "94e55336214e891e9f648901f0c815f113d1534cecae82ecef9c3828cd73d4f4",
+ "7d634d98b5eaaca72ee27c306c82f1dd9f32b3139ae6bb8ddfeaec429afc21fd",
"win32-arm64":
- "88f6d088a76d6708e34ba769362f298911c53362f1ee5d3c8b918027d85d2028",
+ "024870ea204767cf712ea76a03af7d65e25b3fa3cf94b8c5714ae1d726ed34d3",
"win32-x64":
- "88747ac8b6870041c0e09410d1202b4e8911f07150b7d397f66952688d8be5a1",
+ "f582247d2bc903d57288bfc35b592187520bb9fa223b74953654003049c78d00",
};
const ortAssetName = (platform, arch) => {
diff --git a/desktop/src/main/services/ml-native.ts b/desktop/src/main/services/ml-native.ts
index 7c15f0ed48..2985da46ce 100644
--- a/desktop/src/main/services/ml-native.ts
+++ b/desktop/src/main/services/ml-native.ts
@@ -30,9 +30,9 @@ const napiTriple = () => {
const onnxRuntimeLibraryName = () => {
switch (process.platform) {
case "darwin":
- return "libonnxruntime.1.28.1.dylib";
+ return "libonnxruntime.1.31.0.dylib";
case "linux":
- return "libonnxruntime.so.1.28.1";
+ return "libonnxruntime.so.1.31.0";
case "win32":
return "onnxruntime.dll";
default:
diff --git a/infra/ml/test/ml_indexing/assets.json b/infra/ml/test/ml_indexing/assets.json
index 1868d18e31..c227826fa6 100644
--- a/infra/ml/test/ml_indexing/assets.json
+++ b/infra/ml/test/ml_indexing/assets.json
@@ -15,28 +15,28 @@
"sha256": "2def6506e098234abc2e6e10febd820b8e3e66d6ad4c9525cb4f1cec3418f9b6"
},
"onnx_runtime": {
- "version": "1.28.1-r1",
+ "version": "1.31.0-r1",
"archives": {
"aarch64-apple-darwin": {
- "url": "https://github.com/ente/ort-packaging/releases/download/ort-1.28.1-r1/onnxruntime-coreml-macos-arm64-1.28.1-r1.tar.gz",
- "size": 7997883,
- "sha256": "12890a871d0e658dd064be187fa63d27c6b692e69f94d4750532fd8f4d179c1e",
- "library_path": "./libonnxruntime.1.28.1.dylib",
- "library_sha256": "11a4bb659860e56448aae6dfac2cd31eaddf2218588d435eb26d6f79a07b91bc"
+ "url": "https://github.com/ente/ort-packaging/releases/download/ort-1.31.0-r1/onnxruntime-coreml-macos-arm64-1.31.0-r1.tar.gz",
+ "size": 8469740,
+ "sha256": "287567756b9aa6aae1a8a0cb85f5deaf5bd30e9a14a33a8dd0def569e773542f",
+ "library_path": "./libonnxruntime.1.31.0.dylib",
+ "library_sha256": "33b709a7d35c463a398e2bfc81b936c0dbb155175f2de026df470e0e9df237b8"
},
"x86_64-unknown-linux-gnu": {
- "url": "https://github.com/ente/ort-packaging/releases/download/ort-1.28.1-r1/onnxruntime-webgpu-linux-x64-1.28.1-r1.tar.gz",
- "size": 12484422,
- "sha256": "94e55336214e891e9f648901f0c815f113d1534cecae82ecef9c3828cd73d4f4",
- "library_path": "./libonnxruntime.so.1.28.1",
- "library_sha256": "1750d82f5b8c3c4924fd0301de7ac92747e33d852f4748e1e9da97406f257bed"
+ "url": "https://github.com/ente/ort-packaging/releases/download/ort-1.31.0-r1/onnxruntime-webgpu-linux-x64-1.31.0-r1.tar.gz",
+ "size": 14456646,
+ "sha256": "7d634d98b5eaaca72ee27c306c82f1dd9f32b3139ae6bb8ddfeaec429afc21fd",
+ "library_path": "./libonnxruntime.so.1.31.0",
+ "library_sha256": "620f5c8cb817679de8dd7f9733407a3efd61265b22d07248a8fa5a6c3924f202"
},
"aarch64-unknown-linux-gnu": {
- "url": "https://github.com/ente/ort-packaging/releases/download/ort-1.28.1-r1/onnxruntime-webgpu-linux-arm64-1.28.1-r1.tar.gz",
- "size": 12985661,
- "sha256": "2eb71ced50e16b4e2d4ab20b924276d50d123417962a7d874a0cdb7f0171c63d",
- "library_path": "./libonnxruntime.so.1.28.1",
- "library_sha256": "5d801e125ca434b5b699e900ee841d44bf5dbb5a660645265f2fcf71d7dd7bec"
+ "url": "https://github.com/ente/ort-packaging/releases/download/ort-1.31.0-r1/onnxruntime-webgpu-linux-arm64-1.31.0-r1.tar.gz",
+ "size": 15104115,
+ "sha256": "98d35a7f3240ffe96af478bf0e0d05c7febeed53cf968d13ca5b0dc15eb15aaa",
+ "library_path": "./libonnxruntime.so.1.31.0",
+ "library_sha256": "4895fffab66ee58f7f9d1f38bb0d17c518d73b91b18d3734719689ea20c2bb72"
}
}
},
diff --git a/mobile/apps/locker/android/app/build.gradle b/mobile/apps/locker/android/app/build.gradle
index 8e827a35e7..928cffd467 100644
--- a/mobile/apps/locker/android/app/build.gradle
+++ b/mobile/apps/locker/android/app/build.gradle
@@ -104,5 +104,5 @@ dependencies {
// Needed at runtime for Tink since R8 strips these annotations otherwise.
implementation 'com.google.errorprone:error_prone_annotations:2.24.0'
// Loaded at runtime via dlopen by the Rust document scanner.
- implementation 'io.ente.onnxruntime:onnxruntime-webgpu-android:1.28.1-r1@aar'
+ implementation 'io.ente.onnxruntime:onnxruntime-webgpu-android:1.31.0-r1@aar'
}
diff --git a/mobile/apps/locker/android/gradle/verification-metadata.xml b/mobile/apps/locker/android/gradle/verification-metadata.xml
index 47d3bd0460..22ad677e1f 100644
--- a/mobile/apps/locker/android/gradle/verification-metadata.xml
+++ b/mobile/apps/locker/android/gradle/verification-metadata.xml
@@ -18,9 +18,9 @@
</trusted-artifacts>
</configuration>
<components>
- <component group="io.ente.onnxruntime" name="onnxruntime-webgpu-android" version="1.28.1-r1">
- <artifact name="onnxruntime-webgpu-android-1.28.1-r1.aar">
- <sha256 value="c7926c66eb7eee75b95297b20fa28c76417f06cba2d20f6877817fd7efd2e2bd"/>
+ <component group="io.ente.onnxruntime" name="onnxruntime-webgpu-android" version="1.31.0-r1">
+ <artifact name="onnxruntime-webgpu-android-1.31.0-r1.aar">
+ <sha256 value="e1a55bd0fe8f03c7c0a2ee4e1f9e90fd0630302bed79cba5cb78418450749f48"/>
</artifact>
</component>
</components>
diff --git a/mobile/apps/locker/ios/Podfile.lock b/mobile/apps/locker/ios/Podfile.lock
index 4a0975fc99..750e63b557 100644
--- a/mobile/apps/locker/ios/Podfile.lock
+++ b/mobile/apps/locker/ios/Podfile.lock
@@ -44,7 +44,7 @@ PODS:
- Flutter
- ente_screen_cover (0.0.1):
- Flutter
- - EnteOnnxRuntime (1.28.1-r1)
+ - EnteOnnxRuntime (1.31.0-r1)
- file_picker (0.0.1):
- DKImagePickerController/PhotoGallery
- Flutter
@@ -222,7 +222,7 @@ SPEC CHECKSUMS:
ente_mail: f0569c7ea17e8324ef28f36a93c49fa1f3de724f
ente_pdf_renderer: aaf425420589887ef3aeab27344ccba3cb820d2f
ente_screen_cover: 6792566774f1c83939f9c1d03ed0a1f1ded45ae4
- EnteOnnxRuntime: 7baa83a95717a6c9c8d0d4599f9f2c90b72d2905
+ EnteOnnxRuntime: e8cd50b12fc3dc8ecd2102dfdf52c8ca9352e296
file_picker: a0560bc09d61de87f12d246fc47d2119e6ef37be
file_saver: 6cdbcddd690cb02b0c1a0c225b37cd805c2bf8b6
Flutter: 71a624a5bc0c04062bf19101d501e466baf2fb47
diff --git a/mobile/apps/photos/android/app/build.gradle b/mobile/apps/photos/android/app/build.gradle
index 26afc77233..7154fa30da 100644
--- a/mobile/apps/photos/android/app/build.gradle
+++ b/mobile/apps/photos/android/app/build.gradle
@@ -178,7 +178,7 @@ dependencies {
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
// Custom WebGPU/XNNPACK build required by Rust ML, which dynamically
// loads libonnxruntime.so.
- implementation 'io.ente.onnxruntime:onnxruntime-webgpu-android:1.28.1-r1@aar'
+ implementation 'io.ente.onnxruntime:onnxruntime-webgpu-android:1.31.0-r1@aar'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
diff --git a/mobile/apps/photos/android/gradle/verification-metadata.xml b/mobile/apps/photos/android/gradle/verification-metadata.xml
index 47d3bd0460..22ad677e1f 100644
--- a/mobile/apps/photos/android/gradle/verification-metadata.xml
+++ b/mobile/apps/photos/android/gradle/verification-metadata.xml
@@ -18,9 +18,9 @@
</trusted-artifacts>
</configuration>
<components>
- <component group="io.ente.onnxruntime" name="onnxruntime-webgpu-android" version="1.28.1-r1">
- <artifact name="onnxruntime-webgpu-android-1.28.1-r1.aar">
- <sha256 value="c7926c66eb7eee75b95297b20fa28c76417f06cba2d20f6877817fd7efd2e2bd"/>
+ <component group="io.ente.onnxruntime" name="onnxruntime-webgpu-android" version="1.31.0-r1">
+ <artifact name="onnxruntime-webgpu-android-1.31.0-r1.aar">
+ <sha256 value="e1a55bd0fe8f03c7c0a2ee4e1f9e90fd0630302bed79cba5cb78418450749f48"/>
</artifact>
</component>
</components>
diff --git a/mobile/apps/photos/ios/Podfile.lock b/mobile/apps/photos/ios/Podfile.lock
index bd796a3bb3..b1a064fe79 100644
--- a/mobile/apps/photos/ios/Podfile.lock
+++ b/mobile/apps/photos/ios/Podfile.lock
@@ -32,7 +32,7 @@ PODS:
- Flutter
- ente_vision (0.0.1):
- Flutter
- - EnteOnnxRuntime (1.28.1-r1)
+ - EnteOnnxRuntime (1.31.0-r1)
- file_saver (0.0.1):
- Flutter
- Firebase/CoreOnly (12.19.0):
@@ -453,7 +453,7 @@ SPEC CHECKSUMS:
ente_screen_brightness: 7dd13c361508ee6098a2578908ebf35e9f567e28
ente_screen_cover: 6792566774f1c83939f9c1d03ed0a1f1ded45ae4
ente_vision: 260965fb4a3bda0c0cb72c5f15eb8748fef7c897
- EnteOnnxRuntime: 7baa83a95717a6c9c8d0d4599f9f2c90b72d2905
+ EnteOnnxRuntime: e8cd50b12fc3dc8ecd2102dfdf52c8ca9352e296
file_saver: 6cdbcddd690cb02b0c1a0c225b37cd805c2bf8b6
Firebase: 7ca191e43724142f79fae653547b3382c45413cc
firebase_core: aa2923f301f5b09667356bb91e59308e6e2e38d3
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index be5926bee6..e6fcd023ac 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -6793,9 +6793,9 @@ dependencies = [
[[package]]
name = "ort"
-version = "2.0.0-rc.13"
+version = "2.0.0-rc.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4336a1e2b38848325241c72889086886004e589b7c74f335e60a8e8db5138a0b"
+checksum = "37c87aa7a90b7ff3e0fe36cccd475df8d67f15f07f4d6c370c4b38464232813c"
dependencies = [
"half",
"libloading 0.9.0",
@@ -6807,9 +6807,9 @@ dependencies = [
[[package]]
name = "ort-sys"
-version = "2.0.0-rc.13"
+version = "2.0.0-rc.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf211e3776eea6aec988552fa118dd746d70e1b1e5e244058d1c98015f3e5872"
+checksum = "8d22b0417f1838db5a3ac0b3f98dfe39f6fb73624aa0a27c6bbb5040b9c7db2b"
dependencies = [
"glob",
]
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index ababe23be2..86a205e3fd 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -106,8 +106,8 @@ md-5 = "0.11.0"
mockito = "1.7.2"
moxcms = "0.9.1"
open = "5.4.4"
-ort = { version = "=2.0.0-rc.13", default-features = false }
-ort-sys = { version = "=2.0.0-rc.13", default-features = false }
+ort = { version = "=2.0.0-rc.15", default-features = false }
+ort-sys = { version = "=2.0.0-rc.15", default-features = false }
quick-xml = "0.42.0"
regex = "1.13.1"
reqwest = { version = "0.12.28", default-features = false }
diff --git a/rust/bindings/napi/photos/src/lib.rs b/rust/bindings/napi/photos/src/lib.rs
index 30026c08c7..41cbe570f9 100644
--- a/rust/bindings/napi/photos/src/lib.rs
+++ b/rust/bindings/napi/photos/src/lib.rs
@@ -10,13 +10,11 @@ pub use log::init_logging;
#[napi]
pub fn init_ort(dylib_path: String) -> Result<()> {
- ort::init_from(&dylib_path)
- .map_err(|error| {
- Error::from_reason(format!(
- "Runtime: failed to load ONNX Runtime library from '{dylib_path}': {error}"
- ))
- })?
- .commit();
+ let _ = ort::init_from(&dylib_path).map_err(|error| {
+ Error::from_reason(format!(
+ "Runtime: failed to load ONNX Runtime library from '{dylib_path}': {error}"
+ ))
+ })?;
Ok(())
}
diff --git a/rust/crates/ensu/Cargo.toml b/rust/crates/ensu/Cargo.toml
index 22062eef00..65848f49ac 100644
--- a/rust/crates/ensu/Cargo.toml
+++ b/rust/crates/ensu/Cargo.toml
@@ -7,7 +7,7 @@ ente-assets.workspace = true
ente-core.workspace = true
ente-ensu-crypto.workspace = true
ente-image.workspace = true
-ort = { workspace = true, features = ["std", "api-27", "tracing"], optional = true }
+ort = { workspace = true, features = ["std", "api-31", "tracing"], optional = true }
regex.workspace = true
rubato = { version = "5.0.0", optional = true }
rusqlite = { workspace = true, default-features = true, optional = true }
diff --git a/rust/crates/ensu/src/transcription/mod.rs b/rust/crates/ensu/src/transcription/mod.rs
index d16f78e628..678dcd08e0 100644
--- a/rust/crates/ensu/src/transcription/mod.rs
+++ b/rust/crates/ensu/src/transcription/mod.rs
@@ -74,3 +74,17 @@ fn voice_error(operation: &str, error: impl Into<TranscriptionError>) -> crate::
}
pub type Result<T> = std::result::Result<T, TranscriptionError>;
+
+fn environment() -> Result<ort::environment::Environment> {
+ static ENVIRONMENT: std::sync::Mutex<Option<ort::environment::Environment>> =
+ std::sync::Mutex::new(None);
+ let mut current = ENVIRONMENT
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ if let Some(environment) = current.as_ref() {
+ return Ok(environment.clone());
+ }
+ let environment = ort::init().build()?;
+ *current = Some(environment.clone());
+ Ok(environment)
+}
diff --git a/rust/crates/ensu/src/transcription/parakeet.rs b/rust/crates/ensu/src/transcription/parakeet.rs
index 1fb161212d..97cc8f43c4 100644
--- a/rust/crates/ensu/src/transcription/parakeet.rs
+++ b/rust/crates/ensu/src/transcription/parakeet.rs
@@ -2,7 +2,10 @@ use std::path::Path;
use ort::{
inputs,
- session::{Session, SessionOutputs, builder::GraphOptimizationLevel},
+ session::{
+ Session, SessionOutputs,
+ builder::{AutoDevicePolicy, GraphOptimizationLevel},
+ },
value::{DynValue, TensorRef},
};
use regex::{Captures, regex};
@@ -117,7 +120,9 @@ impl Parakeet {
}
fn load_session(path: &Path) -> Result<Session> {
- Ok(Session::builder()?
+ let environment = super::environment()?;
+ Ok(Session::builder(&environment)?
+ .with_auto_device(AutoDevicePolicy::PreferCPU)?
.with_optimization_level(GraphOptimizationLevel::Level3)?
.with_parallel_execution(true)?
.with_execution_providers([ort::ep::CPU::default().build()])?
diff --git a/rust/crates/ensu/src/transcription/transcriber.rs b/rust/crates/ensu/src/transcription/transcriber.rs
index 3b61d6eadb..108e6b7cf4 100644
--- a/rust/crates/ensu/src/transcription/transcriber.rs
+++ b/rust/crates/ensu/src/transcription/transcriber.rs
@@ -244,15 +244,17 @@ fn ensure_loaded<'a>(
}
fn load_plan(model_dir: &Path, plan: LoadPlan<'_>) -> Result<Parakeet> {
- use ort::session::builder::GraphOptimizationLevel;
+ use ort::session::builder::{AutoDevicePolicy, GraphOptimizationLevel};
let directory = match plan {
LoadPlan::Source { save_to: None } => model_dir,
LoadPlan::Cached { directory } => directory,
LoadPlan::Source {
save_to: Some(directory),
} => {
+ let environment = super::environment()?;
for name in GRAPHS {
- let session = ort::session::Session::builder()?
+ let session = ort::session::Session::builder(&environment)?
+ .with_auto_device(AutoDevicePolicy::PreferCPU)?
.with_optimization_level(GraphOptimizationLevel::Level3)?
.with_optimized_model_path(directory.join(name))?
.with_parallel_execution(true)?
diff --git a/rust/crates/ensu/src/transcription/vad.rs b/rust/crates/ensu/src/transcription/vad.rs
index b0b8b8de19..f47543d47c 100644
--- a/rust/crates/ensu/src/transcription/vad.rs
+++ b/rust/crates/ensu/src/transcription/vad.rs
@@ -1,6 +1,9 @@
use ort::{
inputs,
- session::{Session, builder::GraphOptimizationLevel},
+ session::{
+ Session,
+ builder::{AutoDevicePolicy, GraphOptimizationLevel},
+ },
value::TensorRef,
};
use std::{collections::VecDeque, path::Path};
@@ -135,7 +138,10 @@ fn inference(error: impl std::fmt::Display) -> TranscriptionError {
impl SileroV4Vad {
pub fn new(path: impl AsRef<Path>, threshold: f32) -> Result<Self> {
- let session = Session::builder()
+ let environment = super::environment()?;
+ let session = Session::builder(&environment)
+ .map_err(inference)?
+ .with_auto_device(AutoDevicePolicy::PreferCPU)
.map_err(inference)?
.with_optimization_level(GraphOptimizationLevel::Level3)
.map_err(inference)?
diff --git a/rust/crates/ml/Cargo.toml b/rust/crates/ml/Cargo.toml
index 00afb99b35..22153d71fb 100644
--- a/rust/crates/ml/Cargo.toml
+++ b/rust/crates/ml/Cargo.toml
@@ -31,7 +31,7 @@ ort = { workspace = true, features = [
"ndarray",
"half",
"coreml",
- "api-28",
+ "api-31",
] }
[target.'cfg(target_os = "android")'.dependencies]
@@ -39,7 +39,7 @@ ash = { version = "0.38.0", default-features = false, features = ["loaded"] }
ort = { workspace = true, features = [
"ndarray",
"half",
- "api-28",
+ "api-31",
"load-dynamic",
"copy-dylibs",
"webgpu",
@@ -51,7 +51,7 @@ ort = { workspace = true, features = [
"ndarray",
"half",
"coreml",
- "api-28",
+ "api-31",
"load-dynamic",
"copy-dylibs",
] }
@@ -60,7 +60,7 @@ ort = { workspace = true, features = [
ort = { workspace = true, features = [
"ndarray",
"half",
- "api-28",
+ "api-31",
"load-dynamic",
"copy-dylibs",
"webgpu",
@@ -70,7 +70,7 @@ ort = { workspace = true, features = [
ort = { workspace = true, features = [
"ndarray",
"half",
- "api-28",
+ "api-31",
"load-dynamic",
"copy-dylibs",
] }
diff --git a/rust/crates/ml/src/onnx/providers.rs b/rust/crates/ml/src/onnx/providers.rs
index d1eee6f0cd..bc89e5f7be 100644
--- a/rust/crates/ml/src/onnx/providers.rs
+++ b/rust/crates/ml/src/onnx/providers.rs
@@ -1,8 +1,15 @@
use ort::{
+ environment::Environment,
ep::{CPU, ExecutionProviderDispatch},
- session::{Session, builder::GraphOptimizationLevel},
+ session::{
+ Session,
+ builder::{AutoDevicePolicy, GraphOptimizationLevel},
+ },
+};
+use std::{
+ path::{Path, PathBuf},
+ sync::Mutex,
};
-use std::path::{Path, PathBuf};
#[cfg(target_os = "android")]
use ort::ep::XNNPACK;
@@ -197,8 +204,23 @@ pub(super) fn provider_attempt(
}
}
+fn environment() -> MlResult<Environment> {
+ static ENVIRONMENT: Mutex<Option<Environment>> = Mutex::new(None);
+ let mut current = ENVIRONMENT
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ if let Some(environment) = current.as_ref() {
+ return Ok(environment.clone());
+ }
+ let environment = ort::init().build()?;
+ *current = Some(environment.clone());
+ Ok(environment)
+}
+
pub(super) fn build_session(model_path: &str, attempt: ProviderAttempt) -> MlResult<Session> {
- let mut builder = Session::builder()?
+ let environment = environment()?;
+ let mut builder = Session::builder(&environment)?
+ .with_auto_device(AutoDevicePolicy::PreferCPU)?
.with_optimization_level(GraphOptimizationLevel::All)?
.with_intra_threads(1)?
.with_inter_threads(1)?;
@@ -434,7 +456,7 @@ mod tests {
default
.providers
.iter()
- .any(|dispatch| dispatch.downcast_ref::<ort::ep::CPU>().is_some())
+ .any(|dispatch| dispatch.name() == "CPUExecutionProvider")
);
for subgraphs in [false, true] {
let options = GpuOptions {
diff --git a/rust/crates/ml/tests/support/ml_indexing.rs b/rust/crates/ml/tests/support/ml_indexing.rs
index 3c2f303b35..7e8d0b939d 100644
--- a/rust/crates/ml/tests/support/ml_indexing.rs
+++ b/rust/crates/ml/tests/support/ml_indexing.rs
@@ -558,9 +558,7 @@ pub(crate) fn asset_cache_dir() -> Result<PathBuf> {
async fn init_onnx_runtime(store: &AssetStore, asset_lock: &AssetLock) -> Result<()> {
let onnx_runtime_library =
resolve_onnx_runtime_library(store, &asset_lock.onnx_runtime).await?;
- let _ = ort::init_from(&onnx_runtime_library)
- .context("load ONNX Runtime dynamic library")?
- .commit();
+ let _ = ort::init_from(&onnx_runtime_library).context("load ONNX Runtime dynamic library")?;
Ok(())
}