vllm.model_executor.models.llava
¶
Classes:
-
LlavaForConditionalGeneration– -
LlavaImageEmbeddingInputs–Dimensions:
-
LlavaImagePixelInputs–Dimensions:
-
PixtralHFImagePixelInputs–Dimensions:
Attributes:
-
LlavaImageInputs(TypeAlias) –Alias for supported LLaVA image input types.
LlavaImageInputs = LlavaImagePixelInputs | PixtralHFImagePixelInputs | LlavaImageEmbeddingInputs
module-attribute
¶
Alias for supported LLaVA image input types.
LlavaForConditionalGeneration
¶
Bases: Module, SupportsLoRA, SupportsMultiModal, SupportsPP, SupportsEagle, SupportsEagle3
Methods:
-
forward–Run forward pass for LLaVA-1.5.
-
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-1.5.
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:
"USER: <image>\nWhat's the content of the image?\nASSISTANT:".
Tokenizer outputs:
[1, 3148, 1001, 29901, 29871, 32000, 29871, 13, 5618, 29915, 29879,
278, 2793, 310, 278, 1967, 29973, 13, 22933, 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, 3148, 1001, 29901, 29871, 32000, ..., 32000, 29871, 13, 5618,
29915, 29879, 278, 2793, 310, 278, 1967, 29973, 13, 22933, 9047, 13566,
29901].
We insert 575 tokens so that including the original image token in the input, there are a total of 576 (24 * 24) image tokens, which corresponds to the number of image tokens inputted to the language model, i.e. the number of image tokens outputted by the visual encoder.
This way, the positions and attn_metadata are consistent
with the input_ids.
Parameters:
-
(input_ids¶Tensor | None) –Flattened (concatenated) input_ids corresponding to a batch.
-
(positions¶Tensor) –Position indices for the input tokens.
-
(intermediate_tensors¶IntermediateTensors | None, default:None) –Intermediate tensors from prior forward pass.
-
(inputs_embeds¶Tensor | None, default:None) –Optional tensor of input embeddings.
-
(**kwargs¶object, default:{}) –Multimodal inputs for this batch, forwarded to the multimodal embedding path.
Info
get_mm_mapping()
¶
Get the module prefix in multimodal models.
LlavaImageEmbeddingInputs
¶
Bases: TensorSchema
Dimensions: - bn: Batch size * number of images - ifs: Image feature size - hs: Hidden size (must match language model backbone)
LlavaImagePixelInputs
¶
Bases: TensorSchema
Dimensions
- bn: Batch size * number of images
- c: Number of channels (3)
- h: Height
- w: Width
Note that height or width may be different per batch and image,
in which case the data is passed as a list instead of a batched tensor.
PixtralHFImagePixelInputs
¶
Bases: TensorSchema
Dimensions
- bn: Batch size * number of images
- c: Number of channels
- h: Height
- w: Width
Note that height or width may be different per batch and image,
in which case the data is passed as a list instead of a batched tensor.