Python module
max.pipelines.architectures.idefics3
Idefics3 vision-language architecture for multimodal text generation.
Idefics3Config
class max.pipelines.architectures.idefics3.Idefics3Config(*, devices, scale_factor, image_token_id, vision_config, text_config)
Bases: ArchConfigWithKVCache
Configuration for Idefics3 models.
-
Parameters:
-
- devices (list[DeviceRef])
- scale_factor (int)
- image_token_id (int)
- vision_config (Idefics3VisionConfig)
- text_config (Llama3Config)
calculate_max_seq_len()
static calculate_max_seq_len(pipeline_config, huggingface_config)
Calculate maximum sequence length for Idefics3.
-
Parameters:
-
- pipeline_config (PipelineConfig)
- huggingface_config (AutoConfig)
-
Return type:
construct_kv_params()
static construct_kv_params(huggingface_config, pipeline_config, devices, kv_cache_config, cache_dtype)
Get KV cache parameters for the language model.
-
Parameters:
-
- huggingface_config (AutoConfig)
- pipeline_config (PipelineConfig)
- devices (list[DeviceRef])
- kv_cache_config (KVCacheConfig)
- cache_dtype (DType)
-
Return type:
devices
Devices that the Idefics3 model is parallelized over.
finalize()
finalize(huggingface_config, llm_state_dict, return_logits, norm_method='rms_norm')
Finalize the Idefics3Config instance with state_dict dependent fields.
-
Parameters:
-
- huggingface_config (AutoConfig) – HuggingFace model configuration.
- llm_state_dict (dict[str, WeightData]) – Language model weights dictionary.
- dtype – Data type for model parameters.
- return_logits (ReturnLogits) – Return logits configuration.
- norm_method (Literal['rms_norm', 'layer_norm']) – Normalization method.
-
Return type:
-
None
get_kv_params()
get_kv_params()
Returns the KV cache parameters from the embedded text config.
-
Return type:
get_max_seq_len()
get_max_seq_len()
Returns the maximum sequence length from the embedded text config.
-
Return type:
get_num_layers()
static get_num_layers(huggingface_config)
Get number of layers in the language model.
-
Parameters:
-
huggingface_config (AutoConfig)
-
Return type:
image_seq_len
property image_seq_len: int
Calculate the number of image tokens after connector processing.
image_token_id
image_token_id: int
Token ID used to represent image tokens in the text sequence.
initialize()
classmethod initialize(pipeline_config, model_config=None)
Initializes an Idefics3Config instance from pipeline configuration.
-
Parameters:
-
- pipeline_config (PipelineConfig) – The MAX Engine pipeline configuration.
- model_config (MAXModelConfig | None)
-
Returns:
-
An Idefics3Config instance with fields initialized from config.
-
Return type:
scale_factor
scale_factor: int
Scale factor for pixel shuffle operation in the connector.
text_config
text_config: Llama3Config
Text model configuration (Llama3-based).
vision_config
vision_config: Idefics3VisionConfig
Vision encoder configuration (SigLIP-based).
Idefics3Model
class max.pipelines.architectures.idefics3.Idefics3Model(pipeline_config, session, devices, kv_cache_config, weights, adapter=None, return_logits=ReturnLogits.LAST_TOKEN)
Bases: PipelineModelWithKVCache[TextAndVisionContext]
An Idefics3 pipeline model for multimodal text generation.
-
Parameters:
-
- pipeline_config (PipelineConfig)
- session (InferenceSession)
- devices (list[Device])
- kv_cache_config (KVCacheConfig)
- weights (Weights)
- adapter (WeightsAdapter | None)
- return_logits (ReturnLogits)
calculate_max_seq_len()
static calculate_max_seq_len(pipeline_config, huggingface_config)
Calculates the maximum sequence length for the Idefics3 model.
-
Parameters:
-
- pipeline_config (PipelineConfig)
- huggingface_config (AutoConfig)
-
Return type:
execute()
execute(model_inputs)
Executes the Idefics3 model with the prepared inputs.
-
Parameters:
-
model_inputs (ModelInputs)
-
Return type:
get_kv_params()
classmethod get_kv_params(huggingface_config, pipeline_config, devices, kv_cache_config, cache_dtype)
Gets the parameters required to configure the KV cache for Idefics3.
-
Parameters:
-
- huggingface_config (AutoConfig)
- pipeline_config (PipelineConfig)
- devices (list[DeviceRef])
- kv_cache_config (KVCacheConfig)
- cache_dtype (DType)
-
Return type:
language_model
language_model: Model
The compiled language model for text generation.
load_model()
load_model(session)
Loads the compiled Idefics3 models into the MAX Engine session.
-
Returns:
-
A tuple of (vision_model, language_model).
-
Parameters:
-
session (InferenceSession)
-
Return type:
prepare_initial_token_inputs()
prepare_initial_token_inputs(replica_batches, kv_cache_inputs=None, return_n_logits=1)
Prepares the initial inputs for the first execution pass of the Idefics3 model.
-
Parameters:
-
- replica_batches (Sequence[Sequence[TextAndVisionContext]])
- kv_cache_inputs (KVCacheInputs[Buffer, Buffer] | None)
- return_n_logits (int)
-
Return type:
prepare_next_token_inputs()
prepare_next_token_inputs(next_tokens, prev_model_inputs)
Prepares the secondary inputs to be passed to execute().
While prepare_initial_token_inputs is responsible for managing the initial inputs.
This function is responsible for updating the inputs, for each step in a multi-step execution pattern.
-
Parameters:
-
- next_tokens (Buffer)
- prev_model_inputs (ModelInputs)
-
Return type:
-
Idefics3Inputs
vision_model
vision_model: Model
The compiled vision model for processing images.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!