DL0135 Dynamic High-Resolution ViT

How do Dynamic High-Resolution ViT slicing architectures handle non-standard aspect ratios and high-resolution images without spatial distortion?

Answer

A pretrained vision tower expects one fixed square input, usually 336 \times 336 or 448 \times 448, with exactly one learned position embedding per patch. Squashing a 1500 \times 500 receipt or slide into that square applies anisotropic scaling (0.30x horizontally against 0.90x vertically), which shears glyphs and bar charts before the encoder sees a single pixel, while interpolating the position-embedding grid up to native resolution is both off-distribution and quadratically expensive in attention. Dynamic high-resolution slicing, the AnyRes family used by LLaVA-NeXT, UReader, Monkey, MiniCPM-V and InternVL 1.5, avoids both by never changing the encoder’s input size: it picks a tile grid whose aspect ratio best matches the image, resizes the image to exactly n_w S \times n_h S, cuts it into n_h n_w native-resolution tiles that are encoded independently, and appends a downsampled full-image thumbnail to restore the global layout that slicing destroys. Because the target width and height are both integer multiples of the same tile size chosen to match the input ratio, the horizontal and vertical scale factors are (nearly) equal, so the resize is isotropic and no geometry is distorted. What remains is a budgeting problem: the token count grows linearly in tiles, so token compression and a cap N_{\max} on the tile product decide how much resolution you can actually afford.

(1) Aspect-Ratio Matched Grid: enumerate all grids with n_h n_w \leq N_{\max} and pick the one minimizing the log-ratio mismatch against W/H, which is exactly the quantity that becomes anisotropic shear if you get it wrong.
(2) Tiles Stay At Native Resolution: every tile is precisely S \times S, so the frozen CLIP or SigLIP tower runs at its pretraining resolution with no position-embedding interpolation and no distribution shift.
(3) Thumbnail Carries Global Context: tiles are encoded independently, so no attention crosses a seam; a low-resolution whole-image view is concatenated to supply page layout and object-scale cues.
(4) Linear Instead Of Quadratic Attention: encoding K tiles of M patches costs K \cdot O(M^2) rather than O(K^2M^2) for one giant grid, a K-fold saving that is why slicing scales to 4K pages.
(5) Token Compression Is Mandatory: a pixel-unshuffle of stride 2 folds each 2 \times 2 patch neighborhood into one embedding, cutting 1024 patches per 448 tile to 256 tokens; without it a 12-tile page costs over 13k tokens.
(6) The LLM Must Be Told The Layout: the flattened tile sequence is ambiguous, so implementations insert row separator tokens or 2D tile indices, otherwise a 3 \times 1 and a 1 \times 3 arrangement look identical downstream.

Two-panel diagram of a 1500 by 500 panoramic input containing a reference circle. The left panel resizes it into a single 448 by 448 square, where the circle becomes a narrow vertical ellipse because horizontal scale is 0.30x and vertical scale is 0.90x. The right panel matches a 3 by 1 tile grid, resizes to 1344 by 448 with both axes at 0.90x so the circle stays circular, cuts it into three native-resolution 448 tiles, and adds a low-resolution global thumbnail.

Figure 1: The reference circle is the whole story. A single square resize applies different scale factors per axis, so the circle becomes an ellipse and every glyph shears; the aspect-ratio-matched grid scales both axes by 0.90x, keeps each tile at the encoder’s native 448 \times 448, and pays for the lost cross-tile view with one global thumbnail.

Two details separate a correct implementation from a leaky one. First, the resize to n_w^\ast S \times n_h^\ast S is only exactly isotropic when the chosen grid ratio equals the image ratio; otherwise a residual anisotropy survives, equal to the log mismatch, and it is bounded by how fine your candidate set is. With N_{\max} = 6 a 4:3 photo still carries 0.29 of residual log-anisotropy because the exact 3 \times 4 grid needs 12 tiles, which is why InternVL 1.5 raises N_{\max} to 12 and InternLM-XComposer2-4KHD pushes to 55 tiles, and why some systems pad to the grid instead of stretching. Second, slicing changes what the encoder can see: a table row spanning a vertical seam is split across two independently encoded tiles, so the fusion must happen inside the language model rather than in the vision tower, and this is the main reason answers to fine-grained OCR questions degrade near tile boundaries. Token cost is the binding constraint in production: LLaVA-NeXT at S=336 with at most 4 tiles plus a base view spends 5 \times 576 = 2880 tokens per image, and InternVL 1.5 with 12 tiles plus a thumbnail spends 13 \times 256 = 3328 only because pixel shuffle compresses each tile fourfold.

Mathematical Formulation:
\mathcal{G} = \{(n_h, n_w) : n_h n_w \leq N_{\max}\}
(n_h^\ast, n_w^\ast) = \arg\min_{\mathcal{G}} \left| \log \frac{n_w}{n_h} - \log \frac{W}{H} \right|
s_x = \frac{n_w^\ast S}{W}
s_y = \frac{n_h^\ast S}{H}
D = \left| \log \frac{s_x}{s_y} \right|
T = (n_h^\ast n_w^\ast + 1) \frac{S^2}{p^2 r^2}

Where:

  • (n_h^\ast, n_w^\ast) is the selected tile grid, and \mathcal{G} the candidate set of grids whose tile product stays within the budget N_{\max}.
  • W and H are the original image width and height, and S is the encoder’s native side length (336 for LLaVA-NeXT, 448 for InternVL 1.5).
  • s_x and s_y are the per-axis scale factors of the resize, and D is the residual anisotropy: D = 0 means the resize is isotropic and geometry is preserved exactly.
  • T is the vision-token count fed to the LLM, with the +1 accounting for the global thumbnail.
  • p is the patch size (typically 14) and r the pixel-shuffle stride, so S=448, p=14, r=2 gives 1024/4 = 256 tokens per tile.
  • The objective is stated in log space because minimizing |\log(n_w/n_h) - \log(W/H)| is identical to minimizing D, which makes aspect matching and distortion control the same problem.
Two charts. Left: residual log-anisotropy versus the maximum tile product for images of aspect ratio 4:3, 3:1, 5:1 and 8:1, showing step decreases to zero when an exactly matching grid enters the candidate set, with the 4:3 curve stuck at 0.29 until twelve tiles are allowed. Right: vision-token count versus tile count for pixel-shuffle stride 1 and stride 2, with a horizontal 4096-token image budget line that stride 1 crosses at three tiles while stride 2 stays under it through twelve tiles.

Figure 2: The two knobs pull against each other. Raising N_{\max} is what drives residual anisotropy to zero for awkward ratios (left), but each extra tile buys a fixed block of tokens, so only pixel-shuffle compression keeps a 12-tile page inside a realistic per-image token budget (right).

PropertySquare resize + PE interpolationDynamic tiling (AnyRes)Native dynamic resolution
Aspect handlingAnisotropic stretch, or padding that wastes most of the input areaIsotropic up to grid quantization; residual anisotropy shrinks as N_max growsExact: the patch grid itself takes the image’s shape, no quantization
Encoder reuseFrozen tower reused, but interpolated position embeddings go off-distributionFrozen tower reused unchanged at its exact pretraining resolutionRequires training or adapting the tower with 2D RoPE and variable-length packing
Attention costQuadratic in total patches once resolution is raisedLinear in tiles: K independent O(M squared) passes, easy to batchQuadratic over the full image unless windowed or block-diagonal attention is used
Global contextComplete but low detail; small text is unrecoverableBroken at seams; restored approximately by the thumbnail and separator tokensIntact, every patch can attend to every other patch in the image
Representative systemsOriginal LLaVA, BLIP-2, early CLIP-based VLMsUReader, Monkey, LLaVA-NeXT, MiniCPM-V, InternVL 1.5 and 2.5NaViT, Idefics2, Qwen2-VL and Qwen2.5-VL, Pixtral

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *