smdesai commited on
Commit
b30b0e2
Β·
verified Β·
1 Parent(s): 84c84b6

Add three fixed-size branch entrypoints to the portable decoder

Browse files

decoder.aimodel now also has branch_256x256x4, branch_128x128x16 and branch_1024x512x16 (same weights; answer and prefill outputs bit-identical). The dynamic branch is unreliable on the GPU; the d1 runtime pads multi-question requests up to these. Model card updated.

README.md CHANGED
@@ -64,10 +64,10 @@ of time, which the app downloads instead.
64
 
65
  | File | Size | What |
66
  |---|---:|---|
67
- | `decoder.aimodel` | 2.3 GB | the LFM2 hybrid decoder (30 layers), **8-bit k-means palettized** Linear layers, fp16 math; entrypoints `answer`, `prefill`, `branch` over one copy of the weights |
68
  | `vision.aimodel` | 815 MB | SigLIP2 so400m vision tower + projector, fp16, one image crop per call |
69
- | `h18p/{decoder,vision}.h18p.aimodelc` | 2.3 GB + 815 MB | the same two, compiled for the iPhone 17 Pro / Pro Max GPU (A19 Pro) |
70
- | `h19p/{decoder,vision}.h19p.aimodelc` | 2.3 GB + 815 MB | the same two, compiled for the iPhone 18 Pro / Pro Max GPU (A20 Pro) |
71
  | `embed.f16` | 500 MB | the (tied) token embedding table, 128,000 Γ— 2,048 fp16 β€” looked up on the host, and used for the readout |
72
  | `tokenizer.json` | 17 MB | the original model's tokenizer |
73
  | `meta.json` | | `image_token_id`, hidden size, the graphs' float input type |
@@ -84,9 +84,10 @@ cache (β‰ˆ 3–5 s).
84
  | `answer` | `embeds` (1, L, 2048) fp16, `length` (1,) int32 β†’ `hidden` (1, 2048): the final-norm hidden state at position `length βˆ’ 1` (the answer slot) |
85
  | `prefill` | `embeds` (1, P, 2048), `length` (1,) β†’ `k_cache`, `v_cache` (8, 1, 8, P, 64) for the 8 attention layers (after q/k norms and RoPE) and `conv_tail` (22, 1, 2048, 2), the last two values of BΒ·x for the 22 conv layers |
86
  | `branch` | `embeds` (B, T, 2048), `lengths` (B,), `prefix_len` (1,), the three caches β†’ `hidden` (B, 2048) at each row's last real token; positions continue at `prefix_len + t` |
 
87
  | `vision` (`main`) | `patches` (1, S, 768), `row_w`/`col_w` (1, S, 16), `valid` (1, S), S = 64…1,024 patch slots in 2Γ—2-block order β†’ `tokens` (1, S/4, 2048) |
88
 
89
- All lengths are dynamic: right-pad to a bucket (the runtime uses powers of two, 128…8,192 tokens on the iPhone;
90
  batch 1/4/16). Padding is exact β€” causal attention and convolution never let a pad reach a real token, cache keys
91
  past `prefix_len` are masked, and reads are one-hot.
92
 
@@ -113,9 +114,17 @@ past `prefix_len` are masked, and reads are one-hot.
113
  digit, an option code and its space-prefixed form); each option scores its best form; softmax over the options.
114
  Only those few logits are needed β€” the full-vocabulary log-softmax cancels.
115
 
116
- On the iPhone GPU, keep the number of distinct `prefill`/`branch` shapes per loaded model small: after the 4th distinct
117
- `branch` shape in one process, calls returned wrong (finite) values; reloading the model clears it. Prompts past
118
- 8,192 tokens fail on the iPhone GPU.
 
 
 
 
 
 
 
 
119
 
120
  The reference for every host step is the original model's own code (`prompt.py`, `runner.py` and its LFM2-VL
121
  processor in [LiquidAI/d1-3B](https://huggingface.co/LiquidAI/d1-3B)): a port that reproduces its prompt text, token
 
64
 
65
  | File | Size | What |
66
  |---|---:|---|
67
+ | `decoder.aimodel` | 2.3 GB | the LFM2 hybrid decoder (30 layers), **8-bit k-means palettized** Linear layers, fp16 math; entrypoints `answer`, `prefill`, `branch` and three fixed-size `branch_<P>x<T>x<B>` over one copy of the weights |
68
  | `vision.aimodel` | 815 MB | SigLIP2 so400m vision tower + projector, fp16, one image crop per call |
69
+ | `h18p/{decoder,vision}.h18p.aimodelc` | 2.3 GB + 815 MB | the same two, compiled for the iPhone 17 Pro / Pro Max GPU (A19 Pro); the decoder without the fixed-size entrypoints |
70
+ | `h19p/{decoder,vision}.h19p.aimodelc` | 2.3 GB + 815 MB | the same two, compiled for the iPhone 18 Pro / Pro Max GPU (A20 Pro); the decoder without the fixed-size entrypoints |
71
  | `embed.f16` | 500 MB | the (tied) token embedding table, 128,000 Γ— 2,048 fp16 β€” looked up on the host, and used for the readout |
72
  | `tokenizer.json` | 17 MB | the original model's tokenizer |
73
  | `meta.json` | | `image_token_id`, hidden size, the graphs' float input type |
 
84
  | `answer` | `embeds` (1, L, 2048) fp16, `length` (1,) int32 β†’ `hidden` (1, 2048): the final-norm hidden state at position `length βˆ’ 1` (the answer slot) |
85
  | `prefill` | `embeds` (1, P, 2048), `length` (1,) β†’ `k_cache`, `v_cache` (8, 1, 8, P, 64) for the 8 attention layers (after q/k norms and RoPE) and `conv_tail` (22, 1, 2048, 2), the last two values of BΒ·x for the 22 conv layers |
86
  | `branch` | `embeds` (B, T, 2048), `lengths` (B,), `prefix_len` (1,), the three caches β†’ `hidden` (B, 2048) at each row's last real token; positions continue at `prefix_len + t` |
87
+ | `branch_256x256x4`, `branch_128x128x16`, `branch_1024x512x16` | `branch` with every shape fixed: P = 256 / 128 / 1,024 cache positions, T = 256 / 128 / 512 tokens, B = 4 / 16 / 16 rows |
88
  | `vision` (`main`) | `patches` (1, S, 768), `row_w`/`col_w` (1, S, 16), `valid` (1, S), S = 64…1,024 patch slots in 2Γ—2-block order β†’ `tokens` (1, S/4, 2048) |
89
 
90
+ Lengths are dynamic except in the fixed-size `branch_*`: right-pad to a bucket (the runtime uses powers of two, 128…8,192 tokens on the iPhone;
91
  batch 1/4/16). Padding is exact β€” causal attention and convolution never let a pad reach a real token, cache keys
92
  past `prefix_len` are masked, and reads are one-hot.
93
 
 
114
  digit, an option code and its space-prefixed form); each option scores its best form; softmax over the options.
115
  Only those few logits are needed β€” the full-vocabulary log-softmax cancels.
116
 
117
+ **Prefer the fixed-size `branch_*`.** The dynamic `branch` is unreliable on the GPU: on macOS 27.3 it returns wrong
118
+ (finite) hidden states at many shapes, and on the iPhone, after the 4th distinct shape in one process, or now and then
119
+ with a "command buffer exited with error status" fault, calls return wrong values until the model is reloaded. Pad a
120
+ multi-question request up to the smallest fixed-size entrypoint whose P, T and B are all at least its buckets (the
121
+ padding is exact, as above), and use the dynamic `branch` only when none covers it. Core AI sets up all of a model's
122
+ fixed-size entrypoints together on first use, and their memory adds up, which is why there are only three (about
123
+ 1 GB loaded and 2 GB running; all 84 bucket shapes took 25 GB). On an iPhone Duo (`iPhone19,4`, portable
124
+ `decoder.aimodel`), 13 table-shading requests (163 answers) matched the original model with no decision different
125
+ (max |Ξ”p| 0.019), about three times faster than with the dynamic `branch`. The fixed-size and dynamic entrypoints
126
+ share the weights of the decoder measured below; `answer` and `prefill` are unchanged. Prompts past 8,192 tokens fail
127
+ on the iPhone GPU.
128
 
129
  The reference for every host step is the original model's own code (`prompt.py`, `runner.py` and its LFM2-VL
130
  processor in [LiquidAI/d1-3B](https://huggingface.co/LiquidAI/d1-3B)): a port that reproduces its prompt text, token
decoder.aimodel/main.hash CHANGED
Binary files a/decoder.aimodel/main.hash and b/decoder.aimodel/main.hash differ
 
decoder.aimodel/main.mlirb CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e25433d54cf5eec4dba0318d989e91a9276a00f5a9b76b3621e000dbb08037b6
3
- size 2465851576
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d622a3f6cc053c065a6cddbb306fe68ac6c8fad27eecff57c33754ded307b377
3
+ size 2466947219
decoder.aimodel/metadata.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "producer" : "coreai-core 1.0.0b3",
3
- "creationDate" : "20261008T183710Z",
4
- "assetVersion" : "2.0"
5
  }
 
1
  {
2
+ "creationDate" : "20261112T010956Z",
3
+ "assetVersion" : "2.0",
4
+ "producer" : "coreai-core 1.0.0b3"
5
  }