Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Use CPU for Rust OCR inference

laurensprieme269f21d29c5
diff --git a/rust/crates/ml/src/ocr/classify.rs b/rust/crates/ml/src/ocr/classify.rs
index 6c8ec05d81..de07e72444 100644
--- a/rust/crates/ml/src/ocr/classify.rs
+++ b/rust/crates/ml/src/ocr/classify.rs
@@ -38,10 +38,11 @@ pub(crate) struct AngleClassifier {
impl AngleClassifier {
pub(crate) fn new(model_path: &str) -> Self {
Self {
- session: Mutex::new(
- OnnxSession::new(model_path, MODEL_NAMESPACE, ExecutionMode::CpuAccelerated)
- .with_unvalidated_acceleration(),
- ),
+ session: Mutex::new(OnnxSession::new(
+ model_path,
+ MODEL_NAMESPACE,
+ ExecutionMode::CpuOnly,
+ )),
}
}
diff --git a/rust/crates/ml/src/ocr/detect.rs b/rust/crates/ml/src/ocr/detect.rs
index 0c8bfda640..10f1216234 100644
--- a/rust/crates/ml/src/ocr/detect.rs
+++ b/rust/crates/ml/src/ocr/detect.rs
@@ -46,10 +46,11 @@ pub(crate) struct TextDetector {
impl TextDetector {
pub(crate) fn new(model_path: &str) -> Self {
Self {
- session: Mutex::new(
- OnnxSession::new(model_path, MODEL_NAMESPACE, ExecutionMode::CpuAccelerated)
- .with_unvalidated_acceleration(),
- ),
+ session: Mutex::new(OnnxSession::new(
+ model_path,
+ MODEL_NAMESPACE,
+ ExecutionMode::CpuOnly,
+ )),
}
}
diff --git a/rust/crates/ml/src/ocr/recognize.rs b/rust/crates/ml/src/ocr/recognize.rs
index a9f7591b2f..33ff2ae47d 100644
--- a/rust/crates/ml/src/ocr/recognize.rs
+++ b/rust/crates/ml/src/ocr/recognize.rs
@@ -63,10 +63,11 @@ pub(crate) struct TextRecognizer {
impl TextRecognizer {
pub(crate) fn new(model_path: &str, dictionary_path: &str) -> Self {
Self {
- session: Mutex::new(
- OnnxSession::new(model_path, MODEL_NAMESPACE, ExecutionMode::CpuAccelerated)
- .with_unvalidated_acceleration(),
- ),
+ session: Mutex::new(OnnxSession::new(
+ model_path,
+ MODEL_NAMESPACE,
+ ExecutionMode::CpuOnly,
+ )),
dictionary: LazyDictionary::new(dictionary_path),
}
}
diff --git a/rust/crates/ml/src/onnx/providers.rs b/rust/crates/ml/src/onnx/providers.rs
index c6434c6429..96a4536afd 100644
--- a/rust/crates/ml/src/onnx/providers.rs
+++ b/rust/crates/ml/src/onnx/providers.rs
@@ -48,7 +48,6 @@ const ENABLE_PERSISTENT_COREML_CACHE: bool = true;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum ExecutionMode {
PlatformDefault,
- CpuAccelerated,
CpuOnly,
}
@@ -78,7 +77,6 @@ impl ProviderPlan {
) -> Self {
let providers = match mode {
ExecutionMode::PlatformDefault => platform_default_providers(model_path, validation),
- ExecutionMode::CpuAccelerated => cpu_accelerated_providers(),
ExecutionMode::CpuOnly => vec![ExecutionProvider::Cpu],
};
Self::from_providers(providers)
@@ -273,16 +271,6 @@ fn platform_default_providers(
vec![ExecutionProvider::Cpu]
}
-#[cfg(target_os = "android")]
-fn cpu_accelerated_providers() -> Vec<ExecutionProvider> {
- vec![ExecutionProvider::Xnnpack, ExecutionProvider::Cpu]
-}
-
-#[cfg(not(target_os = "android"))]
-fn cpu_accelerated_providers() -> Vec<ExecutionProvider> {
- vec![ExecutionProvider::Cpu]
-}
-
// Missing goldens fail closed, usually indicating they were not regenerated
// after an update.
#[cfg(any(
@@ -490,21 +478,6 @@ mod tests {
assert!(!plan.has_fallback());
}
- #[test]
- fn cpu_accelerated_plan_ends_with_cpu_and_never_uses_gpu_providers() {
- let plan = ProviderPlan::new(
- ExecutionMode::CpuAccelerated,
- "model.onnx",
- AccelerationValidation::Unvalidated,
- );
-
- assert_eq!(plan.providers.last(), Some(&ExecutionProvider::Cpu));
- assert!(!plan.providers.iter().any(|provider| matches!(
- provider,
- ExecutionProvider::WebGpu | ExecutionProvider::CoreMl
- )));
- }
-
fn accelerated_provider_plan() -> ProviderPlan {
ProviderPlan::from_providers(vec![
ExecutionProvider::WebGpu,