Skip to content

vllm.model_executor.models.deepseek_ocr

Inference-only Deepseek-OCR model compatible with HuggingFace weights.

Classes:

DeepseekOCRForCausalLM

Bases: Module, SupportsMultiModal, SupportsPP, SupportsLoRA, SupportsEncoderCudaGraph

Methods:

Attributes:

global_image_output_token property

Tokens per global image (grid + one newline per row).

image_side property

Number of output grid cells per spatial dim for a global image.

patch_side property

Number of output grid cells per spatial dim for a local patch.

single_patch_output_token property

Tokens per local patch (square grid, no newlines).

_assemble_patch_grid(features, crop_shape)

Assemble projected patches into a 2-D tile grid with newline columns.

_batched_encoder_forward_global_path(pixel_values)

Encode batched global images with newline tokens inserted. Output shape: [B * 272, n_embed].

_batched_encoder_forward_local_path(images_crop)

Encode local patches without newline insertion (newlines are added later in postprocess_encoder_output via _assemble_patch_grid). Output shape: [P * 100, n_embed].

_get_num_input_output_tokens(image_spatial_crop=None)

Return (num_input_tokens, num_output_tokens, global_output_token, local_output_token) for a single image described by image_spatial_crop.

encoder_eager_forward(mm_kwargs, path='default')

Eager encoder forward with optional per-path execution.

path="default": full forward (global + local + assembly). path="global": global-only batched forward with newlines. path="local": local-only batched forward without newlines.

get_mm_mapping()

Get the module prefix in multimodal models.

postprocess_encoder_output(outputs, indices, per_item_out_tokens, dest, clone=False, batch_mm_kwargs=None)

Assemble per-image embeddings from global and local encoder outputs.

output['global'] contains global-image features with newlines already inserted (from CUDA graph replay or eager fallback): [B * 272, n_embed].

output['local'] contains local-patch features without newlines (from CUDA graph replay or eager fallback): [P * 100, n_embed]. May be None if no patches in batch.

This method: 1. Splits output['global'] into per-image global portions. 2. Splits output['local'] into per-image patch groups. 3. For each image: assembles patch grid with newlines via _assemble_patch_grid, then concatenates [local_tiled, global, view_seperator].

DeepseekOCRImagePixelInputs

Bases: TensorSchema

Dimensions: - b: Batch size - n: Number of images - p: Number of patches - base_size: Base size of the processor - image_size: Image size of the processor