# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # This file was automatically generated from src/transformers/models/fast_vlm/modular_fast_vlm.py. # Do NOT edit this file manually as any edits will be overwritten by the generation of # the file from the modular. If any change should be done, please apply the change to the # modular_fast_vlm.py file directly. One of our CI enforces this. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # Copyright 2025 The HuggingFace Team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from huggingface_hub.dataclasses import strict from ...configuration_utils import PreTrainedConfig from ...utils import auto_docstring from ..auto import CONFIG_MAPPING, AutoConfig @auto_docstring(checkpoint="KamilaMila/FastVLM-7B") @strict class FastVlmConfig(PreTrainedConfig): r""" Example: ```python >>> from transformers import FastVlmForConditionalGeneration, FastVlmConfig >>> # Initializing a FastVLM-7B style configuration >>> configuration = FastVlmConfig() >>> # Initializing a model from the FastVLM-7B style configuration >>> model = FastVlmForConditionalGeneration(configuration) >>> # Accessing the model configuration >>> configuration = model.config ```""" model_type = "fast_vlm" attribute_map = { "image_token_id": "image_token_index", } sub_configs = {"text_config": AutoConfig, "vision_config": AutoConfig} vision_config: dict | PreTrainedConfig | None = None text_config: dict | PreTrainedConfig | None = None image_token_index: int = 151646 image_seq_length: int = 576 projector_hidden_act: str = "gelu" vision_feature_select_strategy: str = "full" vision_feature_layer: int | list[int] = -1 multimodal_projector_bias: bool = True tie_word_embeddings: bool = False def __post_init__(self, **kwargs): if isinstance(self.vision_config, dict): self.vision_config["model_type"] = self.vision_config.get("model_type", "timm_wrapper") self.vision_config = CONFIG_MAPPING[self.vision_config["model_type"]](**self.vision_config) elif self.vision_config is None: self.vision_config = CONFIG_MAPPING["timm_wrapper"]( architecture="fastvit_mci3", do_pooling=True, global_pool="avg", hidden_size=3072, initializer_range=0.02, model_args={"inference_mode": True}, ) if isinstance(self.text_config, dict): self.text_config["model_type"] = self.text_config.get("model_type", "qwen2") self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config) elif self.text_config is None: self.text_config = CONFIG_MAPPING["qwen2"]( hidden_size=3584, vocab_size=152128, intermediate_size=18944, num_attention_heads=28, num_key_value_heads=4, num_hidden_layers=28, ) # The default value is `False` but this config is used with many model types # Attr `tie_word_embeddings` was saved in text config for those models, so we # need an ugly workaround and forward-pass the attr from text config if not self.tie_word_embeddings and self.text_config.tie_word_embeddings: self.tie_word_embeddings = self.text_config.tie_word_embeddings super().__post_init__(**kwargs) def validate_architecture(self): """Part of `@strict`-powered validation. Validates the architecture of the config.""" if self.vision_feature_select_strategy != "full": raise ValueError( f"Unexpected select feature strategy: {self.vision_feature_select_strategy}. Only 'full' is supported in FastVLM." ) if self.vision_feature_layer != -1: raise ValueError( f"Unexpected vision feature layer: {self.vision_feature_layer}. Only -1 is supported in FastVLM." ) __all__ = ["FastVlmConfig"]