in input_ids (1, N) · attention_mask (1, N) · media_features (1, M, 512)
1
Embed and fuse media
Look up 512-dim token embeddings, then drop vision/audio soft tokens into their placeholder slots.
Core ML changeNumber the media placeholders with cumsum, pick their vectors with gather, and insert them with where. Text-only calls provide a dummy zero row.
→ (1, N, 512)
2
Per-layer embeddings
Project to one 512-dim slice per layer, used later to gate each of the 24 layers.
Core ML changeUse a fixed reshape(1, -1, 24, 512) so tracing avoids an unsupported aten::Int operation.
→ (1, N, 24, 512)
3
Positions and masks
Positions 0…N−1 for RoPE, plus a full mask and a sliding-window mask (|q − k| ≤ 512).
Core ML changeCreate positions with a fixed arange and a runtime zero. Use −30000 to block attention in the masks.
→ pos (N) · two (N × N) masks
4
24 encoder layers
Attention, then MLP, then the per-layer gate. Five sliding-window layers, then one full-attention layer, four times over.
Sliding window · 2 KV heads · head_dim 256
Full attention · 1 KV head · head_dim 512
→ (1, N, 512)
5
Pool, project, normalize
Average over real tokens only, project 512 → 768, scale to unit length.
Core ML changeAverage the tokens before projecting. Because the projection is linear and has no bias, this gives the same result with one projection instead of one per token.
out (1, 768)