Count encoder features and language-model slots before admitting media
Trace modality-specific representation lengths through a declared connector and reserve space for formatting and generation without assuming one universal visual-token count.
On this page
The question for today
What you’ll understand
- Calculate patch features for an explicitly specified image grid.
- Distinguish encoder output length from connector and language-context length.
- Check a prompt-plus-generation budget under a stated architecture contract.
An image is not one token merely because a prompt displays one image marker. A vision encoder may produce hundreds of patch features, a connector may retain or compress them, and a language model may consume those results as positions or attend to them separately. Audio and video introduce their own sample, frame, and temporal budgets. Capacity planning starts by naming each representation boundary. A number quoted for one checkpoint or processor is an example of its contract, not a rule for every multimodal model.
Separate raw media size from encoded length
For a simple nonoverlapping image grid, processed height and width divided by patch size determine the patch count when both are divisible. Padding, cropping, tiling, global thumbnails, class tokens, and feature-selection rules can change the actual output. Raw upload dimensions therefore do not uniquely determine encoded length. A processor may resize first or produce multiple crops. Record the processed shapes and the encoder feature tensor rather than inferring cost from a file's compressed byte size or a single visible placeholder in a chat window.
Other modalities need analogous explicit accounting. A video's sampled frame count and per-frame features matter separately from its duration; an audio encoder's stride determines how waveform samples become feature steps. The learned representation dimension and sequence length are different quantities. Multiplying them estimates tensor values, while the architecture determines how many become language-model positions. A fixed learned-query connector can reduce feature count, but its encoder still processed the original media and its compressed output is not a lossless representation of every detail.
A connector determines the language interface
Architectures make different choices. The original BLIP-2 paper uses a learned-query bottleneck, while LLaVA-style projected visual features and Flamingo's visual resampling with gated cross-attention illustrate different bridges. Their lengths and masks are not interchangeable. A language-context calculation that concatenates visual features applies only when those features occupy that sequence. If media is supplied through separate cross-attention, account for its keys, values, and masking separately instead of pretending its raw feature count is automatically the same number of ordinary text tokens.
For a concatenated-prefix contract, budget text, retained visual positions, formatting tokens, and reserved generation against the allowed sequence length. Some systems allocate generated capacity dynamically, but admission still needs a stated policy. Truncating text without awareness of expanded image positions can remove required markers or break feature alignment. Versioned Transformers 4.57.1 LLaVA documentation explicitly describes processor attributes affecting image-token expansion; use that checkpoint's compatible processor and inspect its output rather than adopting an approximate image-token count as a universal constant.
Validate length at the actual boundary
Test a small image, an extreme aspect ratio, multiple crops, long text, and the maximum supported media count. Compare predicted processed length with the processor's feature shapes and the model's merge requirements. Include special-token and generation settings in the trace. Report quality as well as capacity when reducing resolution or connector output length: a smaller input may remove the text, object, or temporal detail the task needs. The correct budget is an enforceable serving contract backed by these probes, not a promise that every admitted request will have equal cost.
The roofline lab offers a separate arithmetic-versus-byte ceiling. Reset, set both I=4 FLOP/byte and B=100 decimal GB/s, predict 400 GFLOP/s, then Play. Reset and set both I=16 and B=100 for the fixed 1000 GFLOP/s cap. It has no media encoder, tokenization, visual-feature merge, context limit, or generation cache; playback traces a selected synthetic roof. Use the worked representation counts for token admission, and use measured encoder and language-model execution for latency rather than interpreting this diagram as a multimodal capacity simulator.
Work it through
One image fits a hypothetical concatenated-prefix budget
A declared toy architecture processes 336×336 images with 14×14 nonoverlapping patches, retains no extra vision token, and projects every patch into one language-model slot. Text occupies 180 slots, formatting 12, generation reserve 128, and the allowed total is 1024. This is a hypothetical contract, not a promise of multi-image support by any named checkpoint.
Each image has 24×24=576 patch features and, under the stated direct projection contract,576 visual language positions. A connector that resampled to fewer positions would require a different calculation.
One image consumes 180+576+12=768 input positions. Including 128 reserved generation positions gives 896, leaving 1024−896=128 positions under this admission rule.
Two images would consume 180+1152+12+128=1472 total positions, exceeding the allowed 1024 by 448. The one-marker-per-image appearance of a rendered prompt would not reveal this expanded length.
Length admission follows processed features and the chosen bridge. Supporting a different number of images or a compressed connector requires a compatible, separately validated model contract.
The living notebook
Explore the model
Interactive lab · roofline
An arithmetic ceiling is not a media-token budget
Reset, set both I=4 FLOP/byte and B=100 decimal GB/s, predict 400 GFLOP/s, then Play. Reset and re-enter both I=16 and B=100 for the fixed 1000 cap. The model is min(1000,B×I), with no encoder, patch grid, processor, sequence length, or generation cache. It cannot predict admitted media counts or actual multimodal latency.
- Attainable ceiling
- 640 GFLOP/s
- Ridge intensity
- 12.5 FLOP/byte
- Ceiling regime
- Memory-bound ceiling
Synthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forCount each representation boundary explicitly and measure its real execution separately.
Pause & reason
Check your understanding
Your turn
Try it yourself
A toy direct-patch prefix uses 224×224 images and 16-pixel square patches, no extra vision features, text 100, formatting 8, and generation 64. Compute its total reservation and remaining room under a 512-position limit.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compute the 14×14 patch grid before adding the nonvisual positions.
Compare with the solution
The image contributes 196 positions. Total reservation is 196+100+8+64=368, leaving 512−368=144. This assumes the declared direct projection, no tiling, and no extra tokens. A learned resampler or separate cross-attention interface would use a different budget.
Keep the idea
Take it with you
- Raw media, encoder features, connector outputs, and language positions are different counts.
- Budget formatting and generation under the exact compatible architecture and processor.
- Reducing media length changes information and resource use; validate both.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.