Image Feature Extraction
LiteRT
LiteRT
PerceptionEncoder
on-device
android
gpu
clip
image-encoder
vit
rope
Instructions to use mlboydaisuke/PE-Core-base-patch16-224-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use mlboydaisuke/PE-Core-base-patch16-224-LiteRT with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- PerceptionEncoder
How to use mlboydaisuke/PE-Core-base-patch16-224-LiteRT with PerceptionEncoder:
# Use PE-Core models as CLIP models import core.vision_encoder.pe as pe model = pe.CLIP.from_config("mlboydaisuke/PE-Core-base-patch16-224-LiteRT", pretrained=True)# Use any PE model as a vision encoder import core.vision_encoder.pe as pe model = pe.VisionTransformer.from_config("mlboydaisuke/PE-Core-base-patch16-224-LiteRT", pretrained=True) - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -68,26 +68,36 @@ text tower offline and take the dot product on device.
|
|
| 68 |
## Conversion notes
|
| 69 |
|
| 70 |
Converted with [litert-torch / ai-edge-torch](https://github.com/google-ai-edge/ai-edge-torch).
|
| 71 |
-
Making a RoPE ViT image tower **fully GPU-
|
| 72 |
-
|
|
|
|
|
|
|
| 73 |
|
| 74 |
1. **Fused-qkv → 4D manual attention** — the fused `qkv` reshape emits a 5D
|
| 75 |
-
head-split
|
| 76 |
-
|
|
|
|
| 77 |
2. **Interleaved 2D-RoPE → rotate-half** — PE-Core's interleaved rotary uses a
|
| 78 |
strided `x[..., ::2]` that lowers to `GATHER_ND` (GPU-banned). Bake an
|
| 79 |
even→odd channel permutation into the q/k weights (preserves q·k exactly) and
|
| 80 |
-
apply the rotate-half form
|
| 81 |
-
|
| 82 |
-
3. **Attention-pool
|
| 83 |
-
query is a constant latent, so
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
## Training data & PII
|
| 93 |
|
|
|
|
| 68 |
## Conversion notes
|
| 69 |
|
| 70 |
Converted with [litert-torch / ai-edge-torch](https://github.com/google-ai-edge/ai-edge-torch).
|
| 71 |
+
Making a RoPE ViT image tower **fully GPU-resident *and* numerically correct** on
|
| 72 |
+
the ML Drift GPU delegate required four verbatim (weights-exact, output
|
| 73 |
+
corr ≈ 1.0) model-side rewrites — the first three for residency, the last for
|
| 74 |
+
on-device numerical correctness:
|
| 75 |
|
| 76 |
1. **Fused-qkv → 4D manual attention** — the fused `qkv` reshape emits a 5D
|
| 77 |
+
head-split the GPU delegate rejects; decompose into separate q/k/v projections.
|
| 78 |
+
Self-attention uses `scaled_dot_product_attention`, whose lowering keeps the
|
| 79 |
+
batch-matmul 3D with a materialized transpose (both required for residency).
|
| 80 |
2. **Interleaved 2D-RoPE → rotate-half** — PE-Core's interleaved rotary uses a
|
| 81 |
strided `x[..., ::2]` that lowers to `GATHER_ND` (GPU-banned). Bake an
|
| 82 |
even→odd channel permutation into the q/k weights (preserves q·k exactly) and
|
| 83 |
+
apply the rotate-half form with constant cos/sin → clean
|
| 84 |
+
`MUL`/`ADD`/`SLICE`/`CONCAT`.
|
| 85 |
+
3. **Attention-pool single-query attention → broadcast-multiply + reduce-sum** —
|
| 86 |
+
the pooling query is a constant latent, so a batch-matmul there is
|
| 87 |
+
`const @ non-const` (rejected at compile, and the reordered `const-RHS` form is
|
| 88 |
+
mis-computed on device); expressing it as `(q·k).sum` + softmax + `(attn·v).sum`
|
| 89 |
+
is exact and GPU-correct.
|
| 90 |
+
4. **Overflow-safe LayerNorm** — the delegate computes the LayerNorm variance
|
| 91 |
+
reduction in **fp16 even for an fp32 graph**; deep-ViT "massive activations"
|
| 92 |
+
(|x|~50+) make `sum((x-mean)²)` exceed fp16 max (65504), so the normalization
|
| 93 |
+
is wrong and the error compounds with depth (output correlation collapses to
|
| 94 |
+
~0.28 over 12 blocks while *still reporting full GPU residency*). Scaling by
|
| 95 |
+
1/32 before squaring (undone after) keeps the running sum in range —
|
| 96 |
+
mathematically identical to `nn.LayerNorm`.
|
| 97 |
+
|
| 98 |
+
Verified **on a Pixel 8a GPU**: zero banned ops, zero >4D tensors, full residency,
|
| 99 |
+
and TFLite(GPU)-vs-PyTorch output correlation = 1.0 (the on-device GPU result —
|
| 100 |
+
not just the host CPU result — matches the reference).
|
| 101 |
|
| 102 |
## Training data & PII
|
| 103 |
|