mlboydaisuke commited on
Commit
22fd6fc
·
verified ·
1 Parent(s): 1c0fc7c

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +25 -15
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-compatible** required three verbatim
72
- (weights-exact, output corr 1.0) model-side rewrites:
 
 
73
 
74
  1. **Fused-qkv → 4D manual attention** — the fused `qkv` reshape emits a 5D
75
- head-split (`RESHAPE` rank 5) that the GPU delegate rejects; decompose into
76
- separate q/k/v projections so attention stays 4D.
 
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 (slice + neg + concat) with constant cos/sin →
81
- clean `MUL`/`ADD`/`SLICE`/`CONCAT`.
82
- 3. **Attention-pool with constant query → constant-RHS matmul** — the pooling
83
- query is a constant latent, so the `q·kᵀ` batch-matmul is `const @ non-const`,
84
- which the delegate rejects; reorder as `k @ q_constᵀ` (constant RHS the
85
- fully-connected path). Self-attention uses `scaled_dot_product_attention`,
86
- whose lowering keeps the batch-matmul 3D with a materialized transpose
87
- (both required for GPU residency).
88
-
89
- Verified: zero banned ops, zero >4D tensors, TFLite-vs-PyTorch output
90
- correlation = 1.000000 (FP32 and FP16).
 
 
 
 
 
 
 
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