Views
No views yet
CompiledModel API (ML Drift / LITERT_CL delegate).
The whole graph is GPU-resident — no CPU/XNNPACK fallback ops.| Task | Image encoder for promptable segmentation (SAM 2 image path) |
| Backbone | Hiera-Tiny (hierarchical ViT, window + global attention) + FPN neck |
| Input | [1, 3, 1024, 1024] NCHW float32, ImageNet-normalized |
| Outputs | 3 FPN feature maps: [1,256,256,256], [1,256,128,128], [1,256,64,64] |
| Precision / size | FP16, 80 MB |
| Device | Pixel 8a, LiteRT GPU (Accelerator.GPU), ~7 ms / image |
| Residency | Replacing 862 out of 862 node(s) with delegate (LITERT_CL) (full, single partition) |
resize to 1024x1024 (bilinear) -> x/255 -> (x - mean) / std
mean = [0.485, 0.456, 0.406], std = [0.229, 0.224, 0.225] # ImageNet, RGB, NCHWlitert-torch. SAM 2's Hiera encoder is not GPU-clean out of the box; these exact,
weights-faithful rewrites were applied (model-side only — no converter patch):window_partition / window_unpartition: the 6-D view+permute window reshape rejected by the
GPU delegate (>4-D) is re-expressed as a sequence of ≤4-D reshape/transpose ops (numerically
exact, verified vs the original).Sam2MultiScaleAttention: the 5-D fused-QKV reshape is decomposed into separate q/k/v, and
attention runs as a 3-D batched SDPA ([B*heads, N, d]). A 4-D SDPA makes the delegate emit a
[C,C]->[nW,ws,C,C] BROADCAST_TO on every windowed block; the 3-D form removes all 9.pos_embed is
baked to a buffer (add only) — removes a runtime interpolate of a constant.BROADCAST_TO ops.banned ops = NONE, >4-D tensors = 0, full GPU residency.cos = 1.000, mae = 0). On-device GPU output vs the
CPU reference, per FPN level:| Output | cosine |
|---|---|
FPN-0 256x256 (high-res, drives mask detail) | 0.99998 |
FPN-1 128x128 | 0.99994 |
FPN-2 64x64 (coarse image embedding) | 0.99253 |
1val model = CompiledModel.create(context.assets, "sam2_tiny_image_encoder_fp16.tflite",
2 CompiledModel.Options(Accelerator.GPU), null)
3// input: [1,3,1024,1024] NCHW, ImageNet-normalized
4// outputs: 3 FPN feature maps -> feed to the SAM 2 prompt encoder + mask decoderfacebook/sam2.1-hiera-tiny checkpoint. Because the
source data is real-world imagery, it may incidentally contain people, faces, vehicles, signage and
other PII; no PII was deliberately collected and this conversion adds none. Apply your own content/PII
filtering as appropriate. See the SAM 2 release and
paper for full dataset details.