Skip to content

armgit / ente

Public Imported from GitHub
0

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

Update ort to pinned ONNX Runtime 1.27 revision

laurenspriem24006694bb56
diff --git a/infra/ml/test/ml_indexing/assets.json b/infra/ml/test/ml_indexing/assets.json
index 893854cf3c..191b2b1318 100644
--- a/infra/ml/test/ml_indexing/assets.json
+++ b/infra/ml/test/ml_indexing/assets.json
@@ -13,31 +13,25 @@
"sha256": "2def6506e098234abc2e6e10febd820b8e3e66d6ad4c9525cb4f1cec3418f9b6"
},
"onnx_runtime": {
- "version": "1.18.1",
+ "version": "1.27.0",
"archives": {
"aarch64-apple-darwin": {
- "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.18.1/onnxruntime-osx-arm64-1.18.1.tgz",
- "sha256": "f3356203e9b6f5023168a12db74b1060ab397f8f3ce8f5cb2c2bd9e7f1195b01",
- "library_path": "onnxruntime-osx-arm64-1.18.1/lib/libonnxruntime.1.18.1.dylib",
- "library_sha256": "cf0c4da3d0ccae9b71cc854333e716d162869a3c42f9017b142408542fcec9b7"
- },
- "x86_64-apple-darwin": {
- "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.18.1/onnxruntime-osx-x86_64-1.18.1.tgz",
- "sha256": "938198521ecccd6fca4cadd627a57966de092feb6ea9ecb579437898d04ebad8",
- "library_path": "onnxruntime-osx-x86_64-1.18.1/lib/libonnxruntime.1.18.1.dylib",
- "library_sha256": "b25f77bf7c58ef0fbcdd5fb090301df4e80f82cf0000ceed1042418729b6594d"
+ "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.27.0/onnxruntime-osx-arm64-1.27.0.tgz",
+ "sha256": "545e81c58152353acb0d1e8bd6ce4b62f830c0961f5b3acfedc790ffd76e477a",
+ "library_path": "./onnxruntime-osx-arm64-1.27.0/lib/libonnxruntime.dylib",
+ "library_sha256": "2ebb057c654ef6422b28bc84bfcc69591b4eccea7814a3bd84677607c36096de"
},
"x86_64-unknown-linux-gnu": {
- "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.18.1/onnxruntime-linux-x64-1.18.1.tgz",
- "sha256": "a0994512ec1e1debc00c18bfc7a5f16249f6ebd6a6128ff2034464cc380ea211",
- "library_path": "onnxruntime-linux-x64-1.18.1/lib/libonnxruntime.so.1.18.1",
- "library_sha256": "1147caa734d19f7549f90a659aa9ca444366eeb80a596900d19d242145a9f4c9"
+ "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.27.0/onnxruntime-linux-x64-1.27.0.tgz",
+ "sha256": "547e40a48f1fe73e3f812d7c88a948612c23f896b91e4e2ee1e232d7b468246f",
+ "library_path": "onnxruntime-linux-x64-1.27.0/lib/libonnxruntime.so.1.27.0",
+ "library_sha256": "4061866361d9a8d2872f5f419c5515ce35a830a0c5c77ce1723320ac0dbabfc7"
},
"aarch64-unknown-linux-gnu": {
- "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.18.1/onnxruntime-linux-aarch64-1.18.1.tgz",
- "sha256": "c1dcd8ab29e8d227d886b6ee415c08aea893956acf98f0758a42a84f27c02851",
- "library_path": "onnxruntime-linux-aarch64-1.18.1/lib/libonnxruntime.so.1.18.1",
- "library_sha256": "006437cc7da2dd9a8a116e3fb0c96fe9c4ec8645fccbb731f3b02082a6fbf70e"
+ "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.27.0/onnxruntime-linux-aarch64-1.27.0.tgz",
+ "sha256": "3e4d83ac06924a32a07b6d7f91ce6f852876153fc0bbdf931bf517a140bfbe48",
+ "library_path": "onnxruntime-linux-aarch64-1.27.0/lib/libonnxruntime.so.1.27.0",
+ "library_sha256": "c36bc200e7e6c093b8abb0b34590fbdd8c52fd3fb5e33795b9523ffdde2fce0f"
}
}
},
diff --git a/mobile/apps/photos/rust_builder/cargokit/build_pod.sh b/mobile/apps/photos/rust_builder/cargokit/build_pod.sh
index 2ff02b1583..bb057239b7 100755
--- a/mobile/apps/photos/rust_builder/cargokit/build_pod.sh
+++ b/mobile/apps/photos/rust_builder/cargokit/build_pod.sh
@@ -41,9 +41,9 @@ if [[ -n "$PODS_ROOT" ]] && [[ -d "$PODS_ROOT/onnxruntime-c/onnxruntime.xcframew
ORT_XCFWK_LOCATION="$PODS_ROOT/onnxruntime-c/onnxruntime.xcframework"
export ORT_IOS_XCFWK_LOCATION="$ORT_XCFWK_LOCATION"
- # ort-sys 2.0.0-rc.4 (used in this repo) only respects ORT_LIB_LOCATION.
- # Build a per-target static archive named libonnxruntime.a so it can link
- # against ONNX Runtime from the CocoaPods xcframework.
+ # Keep ORT_LIB_LOCATION as a fallback for targets that ort-sys cannot link
+ # directly from the xcframework (for example, an x86_64 iOS simulator).
+ # Build a per-target static archive named libonnxruntime.a for that path.
ORT_ARCHIVE_SOURCE=""
ORT_ARCHIVE_ARCH=""
if [[ "$CARGOKIT_DARWIN_PLATFORM_NAME" == "iphoneos" ]]; then
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index a6ce5faa9b..e7d7eba24d 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -2379,7 +2379,7 @@ dependencies = [
"flate2",
"futures-util",
"llama-cpp-2",
- "ort 2.0.0-rc.12",
+ "ort",
"parking_lot",
"regex",
"reqwest 0.12.28",
@@ -2434,7 +2434,7 @@ dependencies = [
"imageproc",
"nalgebra 0.33.3",
"once_cell",
- "ort 2.0.0-rc.4",
+ "ort",
"plsfix",
"quick-xml",
"regex",
@@ -5519,19 +5519,6 @@ dependencies = [
"tempfile",
]
-[[package]]
-name = "ndarray"
-version = "0.15.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "adb12d4e967ec485a5f71c6311fe28158e9d6f4bc4a447b474184d0f91a8fa32"
-dependencies = [
- "matrixmultiply",
- "num-complex",
- "num-integer",
- "num-traits",
- "rawpointer",
-]
-
[[package]]
name = "ndarray"
version = "0.17.2"
@@ -6101,48 +6088,24 @@ dependencies = [
"pin-project-lite",
]
-[[package]]
-name = "ort"
-version = "2.0.0-rc.4"
-source = "git+https://github.com/pykeio/ort.git?tag=v2.0.0-rc.4#04da381f4da0127ce26e2f6ccab1e7e5a8cd1985"
-dependencies = [
- "half",
- "js-sys",
- "libloading 0.8.9",
- "ndarray 0.15.6",
- "ort-sys 2.0.0-rc.4",
- "thiserror 1.0.69",
- "tracing",
- "web-sys",
-]
-
[[package]]
name = "ort"
version = "2.0.0-rc.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d7de3af33d24a745ffb8fab904b13478438d1cd52868e6f17735ef6e1f8bf133"
+source = "git+https://github.com/pykeio/ort.git?rev=31c8f1443bb579bfddb82705288347697e468fb3#31c8f1443bb579bfddb82705288347697e468fb3"
dependencies = [
+ "half",
"libloading 0.9.0",
- "ndarray 0.17.2",
- "ort-sys 2.0.0-rc.12",
+ "ndarray",
+ "ort-sys",
"smallvec",
"tracing",
"ureq",
]
-[[package]]
-name = "ort-sys"
-version = "2.0.0-rc.4"
-source = "git+https://github.com/pykeio/ort.git?tag=v2.0.0-rc.4#04da381f4da0127ce26e2f6ccab1e7e5a8cd1985"
-dependencies = [
- "pkg-config",
-]
-
[[package]]
name = "ort-sys"
version = "2.0.0-rc.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d7b497d21a8b6fbb4b5a544f8fadb77e801a09ae0add9e411d31c6f89e3c1e90"
+source = "git+https://github.com/pykeio/ort.git?rev=31c8f1443bb579bfddb82705288347697e468fb3#31c8f1443bb579bfddb82705288347697e468fb3"
dependencies = [
"hmac-sha256",
"lzma-rust2",
@@ -9430,9 +9393,9 @@ dependencies = [
"env_logger 0.10.2",
"hound",
"log",
- "ndarray 0.17.2",
+ "ndarray",
"once_cell",
- "ort 2.0.0-rc.12",
+ "ort",
"regex",
"rustfft",
"serde",
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 837bb0edff..06e57b0b16 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -33,3 +33,9 @@ serde = { version = "1.0.228", features = ["derive"] }
thiserror = "2.0.18"
uniffi = { version = "0.31.0" }
wasm-bindgen = "0.2.125"
+
+# Keep transitive ORT users (notably transcribe-rs) on the same upstream
+# revision as the workspace's direct ORT dependencies.
+[patch.crates-io]
+ort = { git = "https://github.com/pykeio/ort.git", rev = "31c8f1443bb579bfddb82705288347697e468fb3" }
+ort-sys = { git = "https://github.com/pykeio/ort.git", rev = "31c8f1443bb579bfddb82705288347697e468fb3" }
diff --git a/rust/crates/ensu/Cargo.toml b/rust/crates/ensu/Cargo.toml
index 4ced215648..8e70edf501 100644
--- a/rust/crates/ensu/Cargo.toml
+++ b/rust/crates/ensu/Cargo.toml
@@ -43,7 +43,7 @@ llama-cpp-2 = { version = "=0.1.144", default-features = false, features = ["mtm
llama-cpp-2 = { version = "=0.1.144", features = ["mtmd"] }
[target.'cfg(target_os = "android")'.dependencies]
-ort = { version = "=2.0.0-rc.12", default-features = false, features = ["load-dynamic"], optional = true }
+ort = { git = "https://github.com/pykeio/ort.git", rev = "31c8f1443bb579bfddb82705288347697e468fb3", default-features = false, features = ["load-dynamic"], optional = true }
[features]
default = ["sqlite"]
diff --git a/rust/crates/photos/Cargo.toml b/rust/crates/photos/Cargo.toml
index 70a2e8a921..f59fa61706 100644
--- a/rust/crates/photos/Cargo.toml
+++ b/rust/crates/photos/Cargo.toml
@@ -23,11 +23,11 @@ html-escape = "0.2.13"
plsfix = "0.1.8"
thiserror.workspace = true
-# Photos stays on ORT rc.4 while Ensu transcription uses rc.12. Cargo cannot
-# resolve both prereleases from crates.io in one workspace, so Photos pins rc.4
-# from the upstream tag as a distinct source.
+# Pin ORT to the workspace-wide upstream revision. The crates.io patch in the
+# workspace manifest also keeps transitive ORT users on this same commit.
[target.'cfg(target_os = "ios")'.dependencies]
-ort = { git = "https://github.com/pykeio/ort.git", tag = "v2.0.0-rc.4", default-features = false, features = [
+ort = { git = "https://github.com/pykeio/ort.git", rev = "31c8f1443bb579bfddb82705288347697e468fb3", default-features = false, features = [
+ "std",
"ndarray",
"half",
# Temporarily disabled to avoid iOS duplicate ObjC class collisions
@@ -38,7 +38,7 @@ ort = { git = "https://github.com/pykeio/ort.git", tag = "v2.0.0-rc.4", default-
] }
[target.'cfg(not(target_os = "ios"))'.dependencies]
-ort = { git = "https://github.com/pykeio/ort.git", tag = "v2.0.0-rc.4", default-features = false, features = [
+ort = { git = "https://github.com/pykeio/ort.git", rev = "31c8f1443bb579bfddb82705288347697e468fb3", default-features = false, features = [
"ndarray",
"half",
"load-dynamic",
diff --git a/rust/crates/photos/src/ml/clip/image.rs b/rust/crates/photos/src/ml/clip/image.rs
index 0362ff2dc1..150cae192d 100644
--- a/rust/crates/photos/src/ml/clip/image.rs
+++ b/rust/crates/photos/src/ml/clip/image.rs
@@ -7,8 +7,8 @@ use crate::ml::{
pub fn run_clip_image(runtime: &MlRuntimeView<'_>, decoded: &DecodedImage) -> MlResult<ClipResult> {
let input = preprocess::preprocess_clip(decoded)?;
- let clip_image = runtime.clip_image_session()?;
- let (shape, output) = onnx::run_f32(&clip_image, input, [1, 3, 256, 256])?;
+ let mut clip_image = runtime.clip_image_session()?;
+ let (shape, output) = onnx::run_f32(&mut clip_image, input, [1, 3, 256, 256])?;
let mut embedding = if shape.len() == 2 {
if shape[0] != 1 {
diff --git a/rust/crates/photos/src/ml/clip/text.rs b/rust/crates/photos/src/ml/clip/text.rs
index 3dbee31a97..95b4bf29cf 100644
--- a/rust/crates/photos/src/ml/clip/text.rs
+++ b/rust/crates/photos/src/ml/clip/text.rs
@@ -16,9 +16,9 @@ pub fn run_clip_text(runtime: &MlRuntimeView<'_>, token_ids: &[i32]) -> MlResult
)));
}
- let clip_text = runtime.clip_text_session()?;
+ let mut clip_text = runtime.clip_text_session()?;
let (shape, output) = onnx::run_i32_f32(
- &clip_text,
+ &mut clip_text,
token_ids.to_vec(),
[1, CLIP_TEXT_TOKEN_COUNT as i64],
)?;
diff --git a/rust/crates/photos/src/ml/error.rs b/rust/crates/photos/src/ml/error.rs
index f988ef0234..afb3dcdf44 100644
--- a/rust/crates/photos/src/ml/error.rs
+++ b/rust/crates/photos/src/ml/error.rs
@@ -20,8 +20,8 @@ pub enum MlError {
Runtime(String),
}
-impl From<ort::Error> for MlError {
- fn from(value: ort::Error) -> Self {
+impl<R> From<ort::Error<R>> for MlError {
+ fn from(value: ort::Error<R>) -> Self {
MlError::Ort(value.to_string())
}
}
diff --git a/rust/crates/photos/src/ml/face/detect.rs b/rust/crates/photos/src/ml/face/detect.rs
index e666bdb490..c7cd00e61a 100644
--- a/rust/crates/photos/src/ml/face/detect.rs
+++ b/rust/crates/photos/src/ml/face/detect.rs
@@ -16,9 +16,9 @@ pub fn run_face_detection(
) -> MlResult<Vec<FaceDetection>> {
let (input, scaled_width, scaled_height, pad_left, pad_top) =
preprocess::preprocess_yolo(decoded)?;
- let face_detection = runtime.face_detection_session()?;
+ let mut face_detection = runtime.face_detection_session()?;
let output_data = onnx::run_f32_data(
- &face_detection,
+ &mut face_detection,
input,
[1, 3, INPUT_HEIGHT as i64, INPUT_WIDTH as i64],
)?;
diff --git a/rust/crates/photos/src/ml/face/embed.rs b/rust/crates/photos/src/ml/face/embed.rs
index ccab739ead..0785c45423 100644
--- a/rust/crates/photos/src/ml/face/embed.rs
+++ b/rust/crates/photos/src/ml/face/embed.rs
@@ -38,9 +38,9 @@ pub fn run_face_embedding(
input.extend_from_slice(aligned);
}
- let face_embedding = runtime.face_embedding_session()?;
+ let mut face_embedding = runtime.face_embedding_session()?;
let (shape, output) = onnx::run_f32(
- &face_embedding,
+ &mut face_embedding,
input,
[
aligned_faces.len() as i64,
diff --git a/rust/crates/photos/src/ml/onnx.rs b/rust/crates/photos/src/ml/onnx.rs
index 75cbd324a3..848bc1c625 100644
--- a/rust/crates/photos/src/ml/onnx.rs
+++ b/rust/crates/photos/src/ml/onnx.rs
@@ -1,15 +1,16 @@
use ort::{
- CPUExecutionProvider, ExecutionProviderDispatch, GraphOptimizationLevel, Session, Tensor,
- TensorElementType, ValueType, XNNPACKExecutionProvider,
+ ep::{CPU, ExecutionProviderDispatch, XNNPACK},
+ session::{Session, builder::GraphOptimizationLevel},
+ value::{Tensor, TensorElementType, ValueType},
};
// Temporarily disabled on Rust side to avoid iOS duplicate ObjC class collisions
// (`CoreMLExecution`) while Dart ONNXRuntime is still linked in production.
// Re-enable once iOS uses a single shared ORT runtime.
// #[cfg(target_vendor = "apple")]
-// use ort::CoreMLExecutionProvider;
+// use ort::ep::CoreML;
#[cfg(target_os = "android")]
-use ort::NNAPIExecutionProvider;
+use ort::ep::NNAPI;
use crate::ml::{
error::{MlError, MlResult},
@@ -82,24 +83,20 @@ fn providers_for_policy(
// Temporarily disabled on Rust side. Keep this block for easy re-enable.
// #[cfg(target_vendor = "apple")]
// if policy.prefer_coreml {
- // providers.push(CoreMLExecutionProvider::default().build());
+ // providers.push(CoreML::default().build());
// }
#[cfg(target_os = "android")]
if policy.prefer_nnapi {
// Prefer NNAPI accelerators and let ORT handle CPU fallback via the added CPU EP.
- providers.push(NNAPIExecutionProvider::default().with_disable_cpu().build());
+ providers.push(NNAPI::default().with_disable_cpu(true).build());
}
if policy.allow_cpu_fallback {
if include_xnnpack && policy.prefer_xnnpack {
- providers.push(XNNPACKExecutionProvider::default().build());
+ providers.push(XNNPACK::default().build());
}
- providers.push(
- CPUExecutionProvider::default()
- .with_arena_allocator()
- .build(),
- );
+ providers.push(CPU::default().with_arena_allocator(true).build());
}
providers
@@ -110,7 +107,7 @@ fn build_session_with_providers(
providers: Vec<ExecutionProviderDispatch>,
) -> MlResult<Session> {
let mut builder = Session::builder()?
- .with_optimization_level(GraphOptimizationLevel::Level3)?
+ .with_optimization_level(GraphOptimizationLevel::All)?
.with_intra_threads(1)?
.with_inter_threads(1)?;
@@ -123,9 +120,9 @@ fn build_session_with_providers(
/// Returns true if the session's first input expects FP16 tensors.
fn session_expects_f16(session: &Session) -> bool {
session
- .inputs
+ .inputs()
.first()
- .and_then(|i| match &i.input_type {
+ .and_then(|i| match i.dtype() {
ValueType::Tensor { ty, .. } => Some(*ty == TensorElementType::Float16),
_ => None,
})
@@ -135,33 +132,33 @@ fn session_expects_f16(session: &Session) -> bool {
/// Run inference accepting f32 data and returning f32 results.
/// Automatically converts inputs/outputs for FP16 models.
pub fn run_f32<const N: usize>(
- session: &Session,
+ session: &mut Session,
input: Vec<f32>,
input_shape: [i64; N],
) -> MlResult<(Vec<i64>, Vec<f32>)> {
let outputs = if session_expects_f16(session) {
let f16_input: Vec<half::f16> = input.into_iter().map(half::f16::from_f32).collect();
let input_tensor = Tensor::<half::f16>::from_array((input_shape, f16_input))?;
- session.run(ort::inputs![input_tensor]?)?
+ session.run(ort::inputs![input_tensor])?
} else {
let input_tensor = Tensor::<f32>::from_array((input_shape, input))?;
- session.run(ort::inputs![input_tensor]?)?
+ session.run(ort::inputs![input_tensor])?
};
- if outputs.is_empty() {
+ if outputs.len() == 0 {
return Err(MlError::Ort("missing first output tensor".to_string()));
}
let output = &outputs[0];
// Extract output: try f32 first, fall back to f16 with conversion.
- if let Ok(tensor) = output.try_extract_tensor::<f32>() {
- let shape = tensor.shape().iter().map(|d| *d as i64).collect::<Vec<_>>();
- let data = tensor.iter().copied().collect::<Vec<_>>();
+ if let Ok((tensor_shape, tensor_data)) = output.try_extract_tensor::<f32>() {
+ let shape = tensor_shape.iter().copied().collect::<Vec<_>>();
+ let data = tensor_data.to_vec();
Ok((shape, data))
} else {
- let tensor = output.try_extract_tensor::<half::f16>()?;
- let shape = tensor.shape().iter().map(|d| *d as i64).collect::<Vec<_>>();
- let data = tensor
+ let (tensor_shape, tensor_data) = output.try_extract_tensor::<half::f16>()?;
+ let shape = tensor_shape.iter().copied().collect::<Vec<_>>();
+ let data = tensor_data
.iter()
.map(|v: &half::f16| v.to_f32())
.collect::<Vec<_>>();
@@ -170,27 +167,27 @@ pub fn run_f32<const N: usize>(
}
pub fn run_f32_data<const N: usize>(
- session: &Session,
+ session: &mut Session,
input: Vec<f32>,
input_shape: [i64; N],
) -> MlResult<Vec<f32>> {
let outputs = if session_expects_f16(session) {
let f16_input: Vec<half::f16> = input.into_iter().map(half::f16::from_f32).collect();
let input_tensor = Tensor::<half::f16>::from_array((input_shape, f16_input))?;
- session.run(ort::inputs![input_tensor]?)?
+ session.run(ort::inputs![input_tensor])?
} else {
let input_tensor = Tensor::<f32>::from_array((input_shape, input))?;
- session.run(ort::inputs![input_tensor]?)?
+ session.run(ort::inputs![input_tensor])?
};
- if outputs.is_empty() {
+ if outputs.len() == 0 {
return Err(MlError::Ort("missing first output tensor".to_string()));
}
let output = &outputs[0];
- if let Ok(tensor) = output.try_extract_tensor::<f32>() {
- Ok(tensor.iter().copied().collect::<Vec<_>>())
+ if let Ok((_tensor_shape, tensor_data)) = output.try_extract_tensor::<f32>() {
+ Ok(tensor_data.to_vec())
} else {
- let tensor = output.try_extract_tensor::<half::f16>()?;
- Ok(tensor
+ let (_tensor_shape, tensor_data) = output.try_extract_tensor::<half::f16>()?;
+ Ok(tensor_data
.iter()
.map(|v: &half::f16| v.to_f32())
.collect::<Vec<_>>())
@@ -198,19 +195,19 @@ pub fn run_f32_data<const N: usize>(
}
pub fn run_i32_f32<const N: usize>(
- session: &Session,
+ session: &mut Session,
input: Vec<i32>,
input_shape: [i64; N],
) -> MlResult<(Vec<i64>, Vec<f32>)> {
let input_tensor = Tensor::<i32>::from_array((input_shape, input))?;
- let outputs = session.run(ort::inputs![input_tensor]?)?;
- if outputs.is_empty() {
+ let outputs = session.run(ort::inputs![input_tensor])?;
+ if outputs.len() == 0 {
return Err(MlError::Ort("missing first output tensor".to_string()));
}
let output = &outputs[0];
- let tensor = output.try_extract_tensor::<f32>()?;
- let shape = tensor.shape().iter().map(|d| *d as i64).collect::<Vec<_>>();
- let data = tensor.iter().copied().collect::<Vec<_>>();
+ let (tensor_shape, tensor_data) = output.try_extract_tensor::<f32>()?;
+ let shape = tensor_shape.iter().copied().collect::<Vec<_>>();
+ let data = tensor_data.to_vec();
Ok((shape, data))
}
diff --git a/rust/crates/photos/src/ml/pet/detect.rs b/rust/crates/photos/src/ml/pet/detect.rs
index 817ecbd9c6..463a93a47f 100644
--- a/rust/crates/photos/src/ml/pet/detect.rs
+++ b/rust/crates/photos/src/ml/pet/detect.rs
@@ -38,9 +38,9 @@ pub fn run_pet_face_detection(
let (input, scaled_width, scaled_height, pad_left, pad_top) =
preprocess::preprocess_yolo(decoded)?;
- let pet_face_detection = runtime.pet_face_detection_session()?;
+ let mut pet_face_detection = runtime.pet_face_detection_session()?;
let (output_shape, output_data) = onnx::run_f32(
- &pet_face_detection,
+ &mut pet_face_detection,
input,
[1, 3, INPUT_HEIGHT as i64, INPUT_WIDTH as i64],
)?;
@@ -162,9 +162,9 @@ pub fn run_pet_body_detection(
let (input, scaled_width, scaled_height, pad_left, pad_top) =
preprocess::preprocess_yolo(decoded)?;
- let body_detection = runtime.pet_body_detection_session()?;
+ let mut body_detection = runtime.pet_body_detection_session()?;
let (_output_shape, output_data) = onnx::run_f32(
- &body_detection,
+ &mut body_detection,
input,
[1, 3, INPUT_HEIGHT as i64, INPUT_WIDTH as i64],
)?;
diff --git a/rust/crates/photos/src/ml/pet/embed.rs b/rust/crates/photos/src/ml/pet/embed.rs
index f640f56f5c..5c4b020bf5 100644
--- a/rust/crates/photos/src/ml/pet/embed.rs
+++ b/rust/crates/photos/src/ml/pet/embed.rs
@@ -73,14 +73,14 @@ pub fn run_pet_face_embedding(
input.extend_from_slice(aligned);
}
- let session = if species == 0 {
+ let mut session = if species == 0 {
runtime.pet_face_embedding_dog_session()?
} else {
runtime.pet_face_embedding_cat_session()?
};
let (shape, output) = onnx::run_f32(
- &session,
+ &mut session,
input,
[
indices.len() as i64,
@@ -177,14 +177,14 @@ pub fn run_pet_body_embedding(
input.extend_from_slice(preprocessed[idx].as_ref().unwrap());
}
- let session = if is_cat {
+ let mut session = if is_cat {
runtime.pet_body_embedding_cat_session()?
} else {
runtime.pet_body_embedding_dog_session()?
};
let (shape, output) = onnx::run_f32(
- &session,
+ &mut session,
input,
[
indices.len() as i64,
diff --git a/rust/crates/photos/src/ml/runtime.rs b/rust/crates/photos/src/ml/runtime.rs
index 7421fe40a1..9db603eea2 100644
--- a/rust/crates/photos/src/ml/runtime.rs
+++ b/rust/crates/photos/src/ml/runtime.rs
@@ -1,10 +1,10 @@
use std::{
- ops::Deref,
+ ops::{Deref, DerefMut},
sync::{Mutex, MutexGuard},
};
use once_cell::sync::Lazy;
-use ort::Session;
+use ort::session::Session;
use crate::ml::{
error::{MlError, MlResult},
@@ -108,6 +108,15 @@ impl Deref for ModelSessionGuard<'_> {
}
}
+impl DerefMut for ModelSessionGuard<'_> {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ self.state
+ .session
+ .as_mut()
+ .expect("session must be loaded before creating ModelSessionGuard")
+ }
+}
+
impl ModelSlot {
fn new() -> Self {
Self {
diff --git a/rust/crates/photos/tests/support/ml_indexing.rs b/rust/crates/photos/tests/support/ml_indexing.rs
index 847e222b35..0a30230bb6 100644
--- a/rust/crates/photos/tests/support/ml_indexing.rs
+++ b/rust/crates/photos/tests/support/ml_indexing.rs
@@ -197,9 +197,9 @@ impl MlIndexingTestContext {
let onnx_runtime_library =
resolve_onnx_runtime_library(&client, &cache_dir, &asset_lock.onnx_runtime)?;
- ort::init_from(onnx_runtime_library.to_string_lossy())
- .commit()
- .context("initialize ONNX Runtime dynamic library")?;
+ let _ = ort::init_from(&onnx_runtime_library)
+ .context("load ONNX Runtime dynamic library")?
+ .commit();
let runtime_config = MlRuntimeConfig {
model_paths: resolve_model_paths(&client, &cache_dir, &asset_lock.models)?,