Modern Apps git

← Modern-Apps.git

ml: flip selfie to v2, production path on device

Commit
fa30c1cbe7d08fb327744d532595cbd1a4644dd8
Author
vayun-mathur <[email protected]>
When
2026-09-14 15:48 UTC (2 months ago)
Parents
e78614b

Diff

camera/src/main/assets/selfie_segmentation.maml
diff --git a/camera/src/main/assets/selfie_segmentation.maml b/camera/src/main/assets/selfie_segmentation.mamlindex 3c62b9472d..924e5c5210 100644Binary files a/camera/src/main/assets/selfie_segmentation.maml and b/camera/src/main/assets/selfie_segmentation.maml differ
library/ml/src/main/rust/src/maml2/parity.rs
diff --git a/library/ml/src/main/rust/src/maml2/parity.rs b/library/ml/src/main/rust/src/maml2/parity.rsindex a84dbcd97a..532fffc413 100644--- a/library/ml/src/main/rust/src/maml2/parity.rs+++ b/library/ml/src/main/rust/src/maml2/parity.rs@@ -250,22 +250,6 @@ fn v2_plan_matches_v1_bit_exact() {     ); } -/// True numeric parity for selfie segmentation: the v2-lowered plan against-/// the v1 plan at 256x256.-#[test]-fn v2_selfie_matches_v1_bit_exact() {-    use crate::nets::selfie;-    assert_bit_exact(-        "selfie at 256x256",-        "camera/src/main/assets/selfie_segmentation.maml",-        weights::graph::SELFIE,-        "camera/src/main/assets/selfie_segmentation.maml2",-        0,-        |offsets| selfie::build(offsets),-        spread_inputs(&[(3usize, 256usize, 256usize)], 0.0),-    );-}- /// True numeric parity for U^2-Net portable at 320x320. #[test] fn v2_u2netp_matches_v1_bit_exact() {
library/ml/src/main/rust/src/vulkan/parity_maml2.rs
diff --git a/library/ml/src/main/rust/src/vulkan/parity_maml2.rs b/library/ml/src/main/rust/src/vulkan/parity_maml2.rsindex d0c2dd6229..931096bcca 100644--- a/library/ml/src/main/rust/src/vulkan/parity_maml2.rs+++ b/library/ml/src/main/rust/src/vulkan/parity_maml2.rs@@ -107,7 +107,7 @@ fn v2_selfie_load_path_on_device() {     // is the host fallback (device builds have no checkout to walk to, so a     // missing dir skips rather than panicking on path arithmetic).     let bytes = match std::env::var("MODELRUNNER_ASSETS") {-        Ok(dir) => match std::fs::read(std::path::PathBuf::from(dir).join("selfie_segmentation.maml2")) {+        Ok(dir) => match std::fs::read(std::path::PathBuf::from(dir).join("selfie_segmentation.maml")) {             Ok(bytes) => bytes,             Err(_) => return,         },@@ -119,7 +119,7 @@ fn v2_selfie_load_path_on_device() {             let Some(root) = root else {                 return;             };-            match std::fs::read(root.join("camera/src/main/assets/selfie_segmentation.maml2")) {+            match std::fs::read(root.join("camera/src/main/assets/selfie_segmentation.maml")) {                 Ok(bytes) => bytes,                 Err(_) => return,             }
library/ml/src/main/rust/tests/assets.rs
diff --git a/library/ml/src/main/rust/tests/assets.rs b/library/ml/src/main/rust/tests/assets.rsindex 8c077b532c..119e7a94b8 100644--- a/library/ml/src/main/rust/tests/assets.rs+++ b/library/ml/src/main/rust/tests/assets.rs@@ -14,7 +14,7 @@ use std::path::{Path, PathBuf};  use modelrunner::nets::{-    maia, mobilefacenet, ppocr_det, ppocr_rec, scrfd, selfie, supertonic_duration,+    maia, mobilefacenet, ppocr_det, ppocr_rec, scrfd, supertonic_duration,     supertonic_sampler, supertonic_text, supertonic_vocoder, tinyclip, u2netp, whisper, }; use modelrunner::post::ctc;@@ -45,10 +45,15 @@ fn load(relative: &str, graph_id: u32) -> Weights { }  #[test]-fn the_shipped_selfie_asset_builds_the_selfie_forward_pass() {-    let weights = load("camera/src/main/assets/selfie_segmentation.maml", graph::SELFIE);-    assert_eq!(weights.len(), selfie::TENSORS);-    let plan = selfie::build(&weights).expect("the shipped asset matches nets::selfie");+fn the_shipped_selfie_asset_loads_as_v2() {+    // Flipped to v2: the asset bytes are a `MAM2` file, loaded through the+    // production path (parse + entry 0), not the v1 reader.+    let path = repo_root().join("camera/src/main/assets/selfie_segmentation.maml");+    let bytes = std::fs::read(&path).expect("read the shipped asset");+    let model = modelrunner::maml2::load::Model::parse(bytes).expect("a v2 selfie file");+    let (plan, _blob) = model.load(0).expect("entry 0 loads");+    assert_eq!(plan.inputs.len(), 1);+    assert_eq!(plan.outputs.len(), 1);     assert!(!plan.ops.is_empty()); } @@ -356,9 +361,10 @@ fn the_shipped_whisper_asset_embeds_a_token_on_the_host() { fn neither_asset_will_load_as_the_other_network() {     // The `graph_id` in the header exists for exactly this: the two files are both     // ordered fp16 tensor tables, so without it a swapped asset would parse.-    let selfie = repo_root().join("camera/src/main/assets/selfie_segmentation.maml");-    let bytes = std::fs::read(selfie).expect("the selfie asset");-    assert!(Weights::parse(&bytes, graph::U2NETP).is_err());+    // (Selfie is v2 now and covered by the digest gate instead; u2netp still v1.)+    let u2netp = repo_root().join("photos/src/main/assets/u2netp.maml");+    let bytes = std::fs::read(u2netp).expect("the u2netp asset");+    assert!(Weights::parse(&bytes, graph::SELFIE).is_err()); }  #[test]@@ -366,47 +372,50 @@ fn report_the_device_memory_each_net_needs() {     // Not an assertion so much as the number a reviewer wants to see, printed by     // `cargo test -- --nocapture`. Both are well inside what a phone will give a     // background allocation, which is the point.-    for (name, weights, arena) in [+    for (name, (weight_bytes, arena)) in [         (             "selfie",-            load("camera/src/main/assets/selfie_segmentation.maml", graph::SELFIE),-            selfie::build(&load(-                "camera/src/main/assets/selfie_segmentation.maml",-                graph::SELFIE,-            ))-            .expect("selfie")-            .arena_elems,+            {+                let path = repo_root().join("camera/src/main/assets/selfie_segmentation.maml");+                let bytes = std::fs::read(&path).expect("the selfie asset");+                let model = modelrunner::maml2::load::Model::parse(bytes)+                    .expect("a v2 selfie file");+                let (plan, blob) = model.load(0).expect("entry 0 loads");+                use modelrunner::weights::Blob;+                (blob.data_len() as usize, plan.arena_elems)+            }         ),         (             "u2netp",-            load("photos/src/main/assets/u2netp.maml", graph::U2NETP),-            u2netp::build(&load("photos/src/main/assets/u2netp.maml", graph::U2NETP))-                .expect("u2netp")-                .arena_elems,+            {+                let weights = load("photos/src/main/assets/u2netp.maml", graph::U2NETP);+                let bytes = weights.data().len();+                let arena = u2netp::build(&weights).expect("u2netp").arena_elems;+                (bytes, arena)+            }         ),         (             "mobilefacenet",-            load("photos/src/main/assets/w600k_mbf.maml", graph::MOBILEFACENET),-            mobilefacenet::build(&load(-                "photos/src/main/assets/w600k_mbf.maml",-                graph::MOBILEFACENET,-            ))-            .expect("mobilefacenet")-            .arena_elems,+            {+                let weights = load("photos/src/main/assets/w600k_mbf.maml", graph::MOBILEFACENET);+                let bytes = weights.data().len();+                let arena =+                    mobilefacenet::build(&weights).expect("mobilefacenet").arena_elems;+                (bytes, arena)+            }         ),         (             "scrfd@640",-            load("photos/src/main/assets/scrfd_500m.maml", graph::SCRFD),-            scrfd::build(-                &load("photos/src/main/assets/scrfd_500m.maml", graph::SCRFD),-                scrfd::LONG_SIDE,-                scrfd::LONG_SIDE,-            )-            .expect("scrfd")-            .arena_elems,+            {+                let weights = load("photos/src/main/assets/scrfd_500m.maml", graph::SCRFD);+                let bytes = weights.data().len();+                let arena = scrfd::build(&weights, scrfd::LONG_SIDE, scrfd::LONG_SIDE)+                    .expect("scrfd")+                    .arena_elems;+                (bytes, arena)+            }         ),     ] {-        let weight_bytes = weights.data().len();         let arena_bytes = arena as usize * 2;         println!(             "{name}: {} KiB weights + {} KiB arena = {} KiB",