← notes Architectures

OneVision-Encoder: spend video tokens only on surprise

A video codec already marks the patches that the previous frame cannot predict. OneVision-Encoder keeps only those patches, from 64 frames, and gives them to a plain ViT at the token cost of 8 frames.

20 min read 7 interactive

Eight frames miss the fast part

A typical video encoder (CLIP, SigLIP2, DINOv3 used frame by frame) samples 8 or 16 frames and encodes every patch of each. Most of those tokens show a wall, a sky or a floor that did not change. An event that falls between two sampled frames is lost.

Take a 15-second dive at 30 fps: 450 frames. Eight evenly spaced frames are 2.1 s apart. A full twist lasts well under a second, so the encoder sees at most one pose per phase of the dive. Sixty-four frames are 0.23 s apart, but 64 dense frames at 224 px are 16,384 patches, and the attention cost grows with the square of that.

OV-Encoder (arXiv 2602.08683) keeps the 64-frame time axis and drops most of the patches. It does not learn which patches to drop. It reads the choice from the compressed video file, where the codec has already measured, for every block of every frame, how much of the block the past cannot predict. The paper calls this the “surprise”.

The pipeline has five steps, one section each below: read the codec signals, score and select patches, pack them with their positions, run a ViT with 3D RoPE, and train it with a cluster-classification loss. This note follows the paper and the released code. Where the two disagree, the note says so.

What the codec already knows

A codec stores a few frames in full and the rest as differences:

  • An I-frame (key frame) is a full picture. It does not depend on other frames.
  • A P-frame (predicted frame) is stored as notes against the previous frame. For each block of pixels, the encoder searches the previous frame for the best copy source. The shift is the motion vector (MV). What is still wrong after the copy is the residual.
  • A GOP (group of pictures) is one I-frame plus the P-frames that follow it.

In formula form, a P-frame is a copy with the motion vectors dtd_t, plus the residual RtR_t:

Ft=P(Ft−1,dt)+Rt.F_t = \mathcal{P}(F_{t-1}, d_t) + R_t .

The block search picks the shift ss with the smallest sum of absolute differences:

SAD(s)=∑i∣Ft[i]−Ft−1[i+s]∣.\mathrm{SAD}(s) = \sum_i |F_t[i] - F_{t-1}[i+s]| .

A block of static background costs nothing. A block that moved costs a motion vector. A block with new content costs a residual.

playground

A codec writes notes only where the row changes

Click any pixel to change its value (20 → 90 → 200). Press Copy previous to make the frames equal.

copy source (motion vector) residual pixel (correction)
blocks with no notes
move notes
corrected pixels
This is the walkthrough's 12-pixel example: the bright object moves 2 pixels right, and a grey pixel appears at position 10. Block 0 needs no notes, block 1 needs a move, block 2 needs a move and one corrected pixel. The notes mark exactly where the row changes.

The two kinds of note detect different things. Motion vectors find movement: a hand, a ball, a camera pan. The residual finds new appearance: a light that switches on, an object that enters. Together they are a change map that the decoder computes anyway.

The map has limits. The codec chooses notes to save bits, not to describe the world, so a flat wall can get random small motion vectors. A camera pan gives every block a motion vector. A still scene gives no signal at all.

For training, the authors re-encode every clip with libx265: no B-frames, one reference frame, CRF 23, and a fixed GOP. The paper says GOP 32. The released script defaults to GOP 16. Benchmark videos keep their original bitstream, so motion statistics at test time can differ from those in training.

Score every patch, keep the global top K

The paper describes the score only in words. The released code (the step3 preprocessing script) gives the exact rule. For each frame tt with motion field (mvx,mvy)(\mathrm{mv}_x, \mathrm{mv}_y) in quarter-pixel units and luma residual YtresY^{\mathrm{res}}_t (zero stored as 128):

m^t=clip(14mvx2+mvy2max⁡(P95, 10−6),0,1)e^t=clip(∣Ytres−128∣max⁡(P95, 1),0,1)st=12(m^t+e^t)\begin{aligned} \hat m_t &= \mathrm{clip}\Big(\frac{\tfrac14\sqrt{\mathrm{mv}_x^2+\mathrm{mv}_y^2}}{\max(\mathrm{P}_{95},\,10^{-6})},0,1\Big) \\ \hat e_t &= \mathrm{clip}\Big(\frac{|Y^{\mathrm{res}}_t-128|}{\max(\mathrm{P}_{95},\,1)},0,1\Big) \\ s_t &= \tfrac12(\hat m_t + \hat e_t) \end{aligned}

P95\mathrm{P}_{95} is the 95th percentile over the pixels of that frame. The patch score S(t,h,w)S(t,h,w) is the sum of sts_t over the 14×1414 \times 14 pixels of the patch. The selection Ω\Omega is the top KK of all T⋅256T \cdot 256 patch scores, over the whole clip at once. Frame 0 is treated as the I-frame and gets score 0.

The per-frame division by P95\mathrm{P}_{95} does two jobs. It puts pixels of motion and grey levels of residual on one [0,1][0, 1] scale, so the two cues can be averaged. It also stretches every frame to the same range. The authors explain (GitHub issue #116) that this stops one dramatic frame from taking the whole budget. The walkthrough points out the cost: a frame with almost no change also gets a full range, so its codec noise competes equally with real motion in other frames.

playground

Codec saliency on a 16-frame toy clip

Press Play or drag across the bar chart to scrub time. Switch Normalise to Fixed, then try Pan and Pan−med.

Normalise
Camera
Show
kept patch motion vector / fused score frame where an object changes

kept K / L
reduction γ
frame equivalents
kept on quiet frames
Simulated clip (toy numbers): 16 frames of 8×8 patches, block-matched in your browser, with a ball that flies in frames 3–10 and a light that switches on at frame 12. With per-frame normalisation, about 40% of the default budget lands on frames where no object changes. A fixed scale halves that share. A pan gives every block a motion vector; subtracting the median vector (the LMM tool's fix) removes most of it.

The budget sets the sparsity. With L=16,384L = 16{,}384 patches per clip:

KKkept K/LK/Lreduction γ\gammaframe equivalentsused for
5123.1%96.9%2smallest budget (Table 5)
10246.25%93.75%4Table 5
204812.5%87.5%8training default; 8-frame probe
409625%75%1616-frame probe

Two more facts about selection. Over 200,000 training clips, central patches are chosen about 1.5× as often as corners (0.62% vs 0.42%, against a uniform 0.39%). The authors attribute this to camera framing and balance it with full-frame training inputs. The LMM version of the selector also subtracts the median motion vector of each frame, so a pure pan gives almost no motion score. The training tool does not.

Pack the survivors into eight fake frames

Every patch of the clip has one flat index on a fixed “virtual” grid of 64 frames:

idx(t,h,w)=t⋅256+h⋅16+w,t∈[0,63],  h,w∈[0,15].\mathrm{idx}(t,h,w) = t \cdot 256 + h \cdot 16 + w, \qquad t \in [0, 63],\; h, w \in [0, 15].

For example, index 5000 is frame 19, row 8, column 8. The K=2048K = 2048 selected patches are gathered in index order and written into the slots of a tensor of shape [B,3,8,224,224][B, 3, 8, 224, 224]: a fake 8-frame video. A patch lands in slot jj, next to random other patches.

This is exact, not an approximation, for two reasons. The patch embedding is a Conv2d with kernel = stride = 14, so each token depends only on its own pixels. And the model has no absolute position embedding: the only position signal is the RoPE angle, computed from the true (t,h,w)(t, h, w) of each slot (visible_indices). The canvas layout carries no information. The token list is a set of (embedding, true position) pairs, and bidirectional attention does not care about their order.

animation

Kept patches move to the canvas with their labels

Press Play. Then switch the mode to Frames or Tiling and play it again.

Input mode

tokens packed
frames covered
real tensor
Toy grid: 8 frames of 4×4 patches, 32 kept patches. The codec mode packs patches from most frames; the frame mode spends the same 32 slots on 2 whole frames. In tiling, frames are stacked into one tall image, so the time gap becomes a row gap and t is always 0.

One set of weights is trained on several input layouts. Batch shares are from paper Table 9, and the 128-GPU training script reproduces them (8 : 6 : 2 clips per GPU):

ModeTensorTokensPosition of a tokenShare
Codec[B,3,8,224,224][B,3,8,224,224]2048true t∈[0,63]t \in [0,63] and (h,w)(h,w)50%
Frame sampling[B,3,8,224,224][B,3,8,224,224]2048one frame per bin of 8; all 256 (h,w)(h,w)37.5%
Tiling[B,3,1792,224][B,3,1792,224]2048t=0t=0, h∈[0,127]h \in [0,127]12.5%
Single image[B,3,448,448][B,3,448,448]1024t=0t=0, h,w∈[0,31]h,w \in [0,31]image heads

Frame sampling covers the frame border, which the codec mode under-samples, and it is the fallback when no codec data exist. Tiling teaches the “storyboard” images that are common in LMM data. The paper defines the chunk-wise time offset by chunk number. The code uses the frame number on the 64-frame grid, so frames 3 and 60 are 57 steps apart, not 7.

3D RoPE gives each token its true place

RoPE splits a head vector of dh=64d_h = 64 channels into 32 pairs and rotates pair jj by the angle ϕjp\phi_j p, where pp is the position. Because R(α)⊤R(β)=R(β−α)R(\alpha)^\top R(\beta) = R(\beta - \alpha), the query–key score depends only on the offset pk−pqp_k - p_q. A token does not need its neighbours to be present. This is the property that sparse input needs.

OV-Encoder gives each pair one axis: 8 pairs for time, 12 for rows, 12 for columns (the 4:6:6 split). Each axis gets its own geometric list of frequencies, from 1 down to almost 10−410^{-4} (base 10410^4): ϕk=10−4k/8\phi_k = 10^{-4k/8} for time and 10−4k/1210^{-4k/12} for rows and columns. Positions in training are short (64 frames, 16 patches), so the slow pairs hardly turn. Over the whole clip, the last 3 time pairs turn by at most 0.2 rad, and the last 6 row pairs and 6 column pairs by at most 0.15 rad. Thus 15 of the 32 pairs act almost like content channels with no position. The paper does not ablate the base or the split.

playground

One offset, many absolute positions

Change the offset. Watch the dials (one per pair) and the two score curves. Press New q, k for other random vectors.

ideal RoPE (half-split rotation) released code (interleaved rotation) pair turns < 0.2 rad over the whole clip
ideal score
released mean ± std
released min … max
Simulated with random 64-d query and key vectors and the real frequency tables. The ideal curve is flat: only the offset matters. The released curve moves as the pair slides across the clip, at the same offset. The dashed dials turn less than 0.2 rad over the whole clip.

The shuffle control in the results (below) relies on positions. Because the released RoPE mixes relative and absolute signals, a shuffle disturbs both.

A plain ViT at the price of eight frames

The network is a standard pre-norm ViT-L/14: 24 layers, width 1024, 16 heads of 64 channels, MLP 1024 → 4096 → 1024. It has no [CLS] token, no register tokens and no absolute position embedding. A pooling head (one learned query with 16-head attention, then an MLP) gives a 1024-d embedding. The walkthrough counts about 315M parameters, pooling head included. Every sample has exactly KK tokens, so attention needs no padding mask. There are no temporal tubelets: a tubelet would need the same patch in two frames, and selection keeps patches per frame.

The walkthrough estimates the FLOPs of one forward pass as 2N(12d2)⋅242N(12d^2) \cdot 24 for the linear layers and 4N2d⋅244N^2 d \cdot 24 for attention. At N=2048N = 2048 the total is 1.65 TFLOP; all 64 frames dense (N=16,384N = 16{,}384) cost 36.3 TFLOP, 22× more. The linear part grows 8×, the attention part 64×.

calculator

Tokens and compute for one clip

Switch between the probe setting (224 px) and the LMM setting (504 px). Change the number of frames and the budget.

Setting
patches per frame P₀
dense clip L = T·P₀
kept tokens K
kept K / L
dense / codec FLOPs
linear layers attention (grows with N²)
The encoder cost of the codec input equals that of the same number of dense frames: K = 8 frame equivalents costs what 8 frames cost. Decoding 64 frames and reading motion vectors is not in these numbers, and the paper does not report that cost.

In the LMM setting, frames are 504×504504 \times 504, so each has 36×36=129636 \times 36 = 1296 patches. Dense 64 frames are 82,944 patches. The codec budget of 8 frame equivalents is 10,368 patches. The projector has no merge step, so each patch becomes one LLM token: exactly the count of 8 dense frames. The LLM gets the same number of tokens. Only their spread over time differs.

Training without captions: cluster discrimination

The encoder never sees captions in pre-training. Its labels come from one offline kk-means run on features of a frozen teacher, MetaCLIP-H/14:

  • Image head: 2,000,000 clusters of LAION and COYO image features. Each image gets its 10 nearest centres as labels.
  • Video head: 400,000 clusters. The clip feature is “L2-normalise each frame → concatenate → L2-normalise”, so frame order is part of the vector. Each clip gets 10 labels.
  • OCR head: each word of a 365,187-word vocabulary (count from the code) is a class; a document image gets 100 tags.

The encoder must classify each sample into its clusters. The paper writes the objective as a logistic loss per (sample, centre) pair (Eq. 9). The released code does something else: Partial FC with a CosFace margin. Each step keeps 8 of a sample’s labels. For each kept label yjy_j there is one softmax over a candidate set Nj\mathcal N_j of sampled negative centres:

L=18∑j=18−log⁡es(cos⁡θyj−m)es(cos⁡θyj−m)+∑k∈Njes cos⁡~θk,cos⁡~θk={0,cos⁡θk>0.75cos⁡θk,else\mathcal L = \frac18 \sum_{j=1}^{8} -\log \frac{e^{s(\cos\theta_{y_j} - m)}}{e^{s(\cos\theta_{y_j} - m)} + \sum_{k \in \mathcal N_j} e^{s\,\widetilde{\cos}\theta_k}}, \qquad \widetilde{\cos}\theta_k = \begin{cases} 0, & \cos\theta_k > 0.75 \\ \cos\theta_k, & \text{else} \end{cases}

with scale s=64s = 64 and margin m=0.3m = 0.3. The margin forces the target to beat every negative by a cosine gap of 0.3. The filter sets very close “negatives” to 0. Such negatives are often another true label of the same sample, or a near-duplicate cluster, and pushing the embedding away from them would hurt.

playground

Margin and filter on one label slot

Drag the dots along their lanes. Turn the filter off. Set the margin to 0.

Filter at 0.75
target centre (hollow: cos − m) sampled negative centre (hollow: filtered to 0)
target logit s(cos − m)
p(target)
loss −log p
Default values are the walkthrough's example: the loss is 0.25 with margin and filter. Without the filter, the 0.80 negative takes the softmax and the loss jumps to 24.3. Without the margin, the target wins easily and the loss is small, but the gradient stops pushing for a gap.

A full classifier over 2M classes in 1024-d is 8.19 GB of fp32 weights. Partial FC splits the centres over the 128 GPUs (15,625 each) and samples 10% of them per step, so one softmax sees about 200,000 centres. The normaliser is computed with two all-reduces (max, then sum), without gathering logits.

Training has two stages. Stage 1 uses only images at 224 px, 13B samples, AdamW at lr 10−310^{-3}. Stage 2 adds OCR and video (64 frames at 224 px, with the 50 / 37.5 / 12.5 mode mix) and 448 px images, for 4B samples at lr 10−410^{-4}. The released Stage-2 shell uses lr 5×10−55 \times 10^{-5} and 3.2×1083.2 \times 10^8 samples; it may be one of several runs.

What the results show

The cleanest test is the attentive probe: the backbone is frozen, and a new pooling head plus a linear classifier are trained on top. The same OV-Encoder weights can be fed codec-selected patches or dense frames at the same budget, so the gap between the two rows isolates the input layout.

playground

Attentive-probe results

Switch tables. In Probe, pick Diving48 and then CharadesEgo. In Controls, pick SSV2 and then Diving48.

Table
Block

Values from paper Tables 4, 5 and 6. OV (Codec) and OV (Frame) are the same weights. The biggest gains are on motion-heavy Diving48; DINOv3 leads on CharadesEgo in both blocks.

What the tables support:

  • Average. OV-Encoder (Codec) has the best average in both blocks: 60.2 (8 frames, 2048 patches) and 61.5 (16 frames, 4096 patches), against DINOv3 at 58.0 and 59.1.
  • Diving48. Codec 67.2 vs Frame 57.6 with the same weights: +9.6 points from the layout alone (+6.2 at 16 frames). The abstract’s “+17.1 over SigLIP2 and +8.1 over DINOv3” mixes the two blocks (67.2 − 50.1 at 8 frames, 69.4 − 61.3 at 16 frames).
  • Budget. Codec at 1024 patches (average 56.2) beats SigLIP2 at 4096 patches (55.7).
  • Controls. Shuffling patch positions costs 13.4 average points, the largest drop in every column. Replacing 50% of the selected patches with non-motion patches costs 6.1; with motion patches from another video, 6.6. The paper says the second drop is “even larger” on fine-grained benchmarks, but on Diving48 it is smaller (12.2 vs 14.0), and the 0.5-point average gap has no error bars.
  • Not best everywhere. DINOv3 leads on CharadesEgo in both blocks and on Epic-Verb at 8 frames.

In the LMM probe (Qwen3-4B, about 1.5M SFT samples), the language-aligned OV-Encoder-Lang averages 52.1 on 7 video benchmarks against 48.0 for Qwen3-ViT, the abstract’s +4.1. The paper also claims wins “on all 16 benchmarks”. Table 2 does not support this:

Comparison (paper Table 2)Rows where OV-Encoder is not ahead
OV-Encoder (Codec) vs SigLIP27 of 16: MLVU, TOMATO, AI2D, MMBench, OCRBench, MMStar, RealWorldQA
OV-Encoder-Lang vs Qwen3-ViT4 of 16: TOMATO, DocVQA, OCRBench, MMStar (tie)