# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # This file was automatically generated from src/transformers/models/janus/modular_janus.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_janus.py file directly. One of our CI enforces this. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # Copyright 2025 Deepseek AI and 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, logging from ..auto import CONFIG_MAPPING, AutoConfig logger = logging.get_logger(__name__) @auto_docstring(checkpoint="deepseek-community/Janus-Pro-1B") @strict class JanusVisionConfig(PreTrainedConfig): r""" projection_dropout (`float`, *optional*, defaults to 0.0): Dropout probability for the projection layer. num_image_tokens (`int`, *optional*, defaults to 576): Number of image tokens. """ model_type = "janus_vision_model" base_config_key = "vision_config" hidden_size: int = 1024 num_hidden_layers: int = 24 num_attention_heads: int = 16 num_channels: int = 3 image_size: int | list[int] | tuple[int, int] = 384 patch_size: int | list[int] | tuple[int, int] = 16 hidden_act: str = "gelu" layer_norm_eps: float = 1e-6 attention_dropout: float | int = 0.0 mlp_ratio: float | int = 4.0 attention_bias: bool = True hidden_dropout_rate: float | int = 0.0 projection_dim: int = 2048 projection_dropout: float | int = 0.0 use_qk_norm: bool = False initializer_range: float = 0.02 depth: int = 2 num_image_tokens: int = 576 @auto_docstring(checkpoint="deepseek-community/Janus-Pro-1B") @strict class JanusVQVAEConfig(PreTrainedConfig): r""" base_channels (`int`, *optional*, defaults to 128): Base channel count. channel_multiplier (`list[int]`, *optional*, defaults to `[1, 1, 2, 2, 4]`): Channel multipliers for each resolution. num_res_blocks (`int`, *optional*, defaults to 2): Number of residual blocks. num_patches (`int`, *optional*, defaults to 32): Num of patches the input images can be divided into. out_channels (`int`, *optional*, defaults to 3): Number of out channels. image_token_embed_dim (`int`, *optional*, defaults to 2048): Dimension of image embeddings. It should be same as the dimensionality of text embeddings. """ model_type = "janus_vqgan" base_config_key = "vq_config" embed_dim: int = 8 num_embeddings: int = 16384 double_latent: bool = False latent_channels: int = 256 in_channels: int = 3 base_channels: int = 128 channel_multiplier: list[int] | tuple[int, ...] = (1, 1, 2, 2, 4) num_res_blocks: int = 2 dropout: float | int = 0.0 initializer_range: float = 0.02 num_patches: int = 32 out_channels: int = 3 projection_dim: int = 2048 num_hidden_layers: int = 2 hidden_act: str = "gelu" image_token_embed_dim: int = 2048 @auto_docstring(checkpoint="deepseek-community/Janus-Pro-1B") @strict class JanusConfig(PreTrainedConfig): r""" Example: ```python >>> from transformers import JanusForConditionalGeneration, JanusConfig, JanusVisionConfig, JanusVQVAEConfig, LlamaConfig >>> # Initializing a Janus vision config >>> vision_config = JanusVisionConfig() >>> # Initializing a Llama config >>> text_config = LlamaConfig() >>> # Initializing a VQ config >>> vq_config = JanusVQVAEConfig() >>> # Initializing a Janus Pro 1B style configuration >>> configuration = JanusConfig(vision_config=vision_config, text_config=text_config, vq_config=vq_config) >>> # Initializing a model from the Janus Pro 1B style configuration >>> model = JanusForConditionalGeneration(configuration) >>> # Accessing the model configuration >>> configuration = model.config ```""" model_type = "janus" sub_configs = { "text_config": AutoConfig, "vision_config": JanusVisionConfig, "vq_config": JanusVQVAEConfig, } text_config: dict | PreTrainedConfig | None = None vision_config: dict | PreTrainedConfig | None = None vq_config: dict | PreTrainedConfig | None = None image_token_id: int = 100581 def __post_init__(self, **kwargs): if isinstance(self.text_config, dict): self.text_config["model_type"] = self.text_config.get("model_type", "llama") self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config) elif self.text_config is None: logger.info("`text_config` is None. Initializing with default values") self.text_config = CONFIG_MAPPING["llama"]() if self.vision_config is None: logger.info("`vision_config` is None. Initializing with default JanusVisionConfig values") self.vision_config = JanusVisionConfig() elif isinstance(self.vision_config, dict): self.vision_config = JanusVisionConfig(**self.vision_config) if self.vq_config is None: logger.info("`vq_config` is None. Initializing with default JanusVQVAEConfig values") self.vq_config = JanusVQVAEConfig() elif isinstance(self.vq_config, dict): self.vq_config = JanusVQVAEConfig(**self.vq_config) # This dimension is required when decoding discrete image tokens to continuous input. self.vq_config.num_patches = self.vision_config.image_size // self.vision_config.patch_size super().__post_init__(**kwargs) __all__ = ["JanusVQVAEConfig", "JanusVisionConfig", "JanusConfig"]