vllm.model_executor.models.llava_next
¶
Classes:
-
LlavaNextForConditionalGeneration– -
LlavaNextImageEmbeddingInputs–Dimensions:
-
LlavaNextImagePixelInputs–Dimensions:
-
LlavaNextProcessingInfo–
Attributes:
-
LlavaNextImageInputs(TypeAlias) –Alias for supported LLaVA-NeXT image input types.
LlavaNextImageInputs = LlavaNextImagePixelInputs | LlavaNextImageEmbeddingInputs
module-attribute
¶
Alias for supported LLaVA-NeXT image input types.
LlavaNextForConditionalGeneration
¶
Bases: Module, SupportsLoRA, SupportsMultiModal, SupportsPP
Methods:
-
forward–Run forward pass for LlaVA-NeXT.
-
get_mm_mapping–Get the module prefix in multimodal models
forward(input_ids, positions, intermediate_tensors=None, inputs_embeds=None, **kwargs)
¶
Run forward pass for LlaVA-NeXT.
One key thing to understand is the `input_ids` already accounts for the
positions of the to-be-inserted image embeddings.
Concretely, consider a text prompt:
`"A chat between a curious human and an artificial intelligence
assistant. The assistant gives helpful, detailed, and polite answers to
the human's questions.
USER: <image>\nWhat is shown in this image? ASSISTANT:"`.
Tokenizer outputs:
`[1, 319, 13563, 1546, 263, 12758, 5199, 322, 385, 23116, 21082, 20255,
29889, 450, 20255, 4076, 8444, 29892, 13173, 29892, 322, 1248, 568,
6089, 304, 278, 5199, 29915, 29879, 5155, 29889, 3148, 1001, 29901,
29871, 32000, 13, 5618, 338, 4318, 297, 445, 1967, 29973, 319, 1799,
9047, 13566, 29901]`.
To reserve space in KV cache, we have to insert placeholder tokens
before they are inputted to the model, so the input processor prepends
additional image tokens (denoted as `32000`), resulting in:
`[1, 319, 13563, 1546, 263, 12758, 5199, 322, 385, 23116, 21082, 20255,
29889, 450, 20255, 4076, 8444, 29892, 13173, 29892, 322, 1248, 568,
6089, 304, 278, 5199, 29915, 29879, 5155, 29889, 3148, 1001, 29901,
29871, 32000, ..., 32000, 13, 5618, 338, 4318, 297, 445, 1967, 29973,
319, 1799, 9047, 13566, 29901]`.
Unlike in LLaVA-1.5, the number of image tokens inputted to the language
model depends on the original size of the input image. Including the
original image token in the input, the required number of image tokens
is given by [`LlavaNextProcessingInfo.get_num_image_tokens`][vllm.\
model_executor.models.llava_next.LlavaNextProcessingInfo.get_num_image_tokens].
This way, the `positions` and `attn_metadata` are consistent
with the `input_ids`.
Args:
input_ids: Flattened (concatenated) input_ids corresponding to a
batch.
positions: Position indices for the input tokens.
intermediate_tensors: Intermediate tensors from prior forward pass.
inputs_embeds: Optional tensor of input embeddings.
**kwargs: Multimodal inputs for this batch, forwarded to the
multimodal embedding path.
Info:
[`LlavaNextImageInputs`][vllm.model_executor.models.llava_next.LlavaNextImageInputs]
get_mm_mapping()
¶
Get the module prefix in multimodal models
LlavaNextImageEmbeddingInputs
¶
Bases: TensorSchema
Dimensions: - bn: Batch size * number of images - ifs: Image feature size - hs: Hidden size (must match language model backbone)
LlavaNextImagePixelInputs
¶
Bases: TensorSchema
Dimensions
- bn: Batch size * number of images
- np: Number of patches + 1
- c: Number of channels (3)
- h: Height
- w: Width
Note that num_patches may be different per batch and image,
in which case the data is passed as a list instead of a batched tensor.
LlavaNextProcessingInfo
¶
Bases: BaseLlavaProcessingInfo
Methods:
-
get_num_image_tokens–Get the number of image tokens for the given image dimensions.
get_num_image_tokens(*, image_width, image_height)
¶
Get the number of image tokens for the given image dimensions.