huggingface
huggingface
¶
HuggingFace-backed VLM base class.
HuggingFaceGenerativeVLM
¶
HuggingFaceGenerativeVLM(input_keys, pretrained, frozen, model_name, attention_type=value, model_dtype=None, max_text_length=None, lora_config=None)
Bases: GenerativeVLM, ABC
Base class for VLMs loaded through HuggingFace image-text generation APIs.
Load or initialize a HuggingFace VLM component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_keys
|
str | list[str]
|
RGB camera keys consumed by the VLM. |
required |
pretrained
|
bool
|
Whether to load pretrained HuggingFace weights. |
required |
frozen
|
bool
|
Whether to freeze all model weights. |
required |
model_name
|
str
|
HuggingFace model identifier. |
required |
attention_type
|
str
|
HuggingFace attention implementation. |
value
|
model_dtype
|
str | None
|
Optional precision string for model parameter dtype. |
None
|
max_text_length
|
int | None
|
Optional text sequence length. Defaults to the text config maximum position count. |
None
|
lora_config
|
LoRAAdaptation | None
|
Optional LoRA adapter configuration. |
None
|
Source code in src/versatil/models/decoding/generative_language_models/vision_language/huggingface.py
resize_token_embeddings
¶
Resize the HuggingFace VLM token embeddings.
Source code in src/versatil/models/decoding/generative_language_models/vision_language/huggingface.py
forward_language_model
¶
forward_language_model(input_ids=None, inputs_embeds=None, attention_mask=None, past_key_values=None, use_cache=False, cache_position=None, position_ids=None, output_hidden_states=True)
Run the nested language model over token IDs or embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Tensor | None
|
Optional token IDs with shape |
None
|
inputs_embeds
|
Tensor | None
|
Optional token embeddings with shape |
None
|
attention_mask
|
Tensor | None
|
Optional language-model attention mask. |
None
|
past_key_values
|
Cache | tuple[tuple[Tensor, ...], ...] | None
|
Optional cached key/value tensors. |
None
|
use_cache
|
bool
|
Whether to return/update cached key/value tensors. |
False
|
cache_position
|
Tensor | None
|
Optional HuggingFace KV-cache slots for the tokens
in this call. During cached decoding, if the prefix has length
|
None
|
position_ids
|
Tensor | None
|
Optional positions for the language model positional
encoding, with shape |
None
|
output_hidden_states
|
bool
|
Whether to return hidden states. |
True
|
Returns:
| Type | Description |
|---|---|
CausalLanguageModelOutput
|
Causal language-model output with logits shape |