configuration_modernvbert.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/modernvbert/modular_modernvbert.py.
  3. # Do NOT edit this file manually as any edits will be overwritten by the generation of
  4. # the file from the modular. If any change should be done, please apply the change to the
  5. # modular_modernvbert.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2026 Illuin Technology and contributors, and The HuggingFace Inc. team. All rights reserved.
  8. #
  9. # Licensed under the Apache License, Version 2.0 (the "License");
  10. # you may not use this file except in compliance with the License.
  11. # You may obtain a copy of the License at
  12. #
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. #
  15. # Unless required by applicable law or agreed to in writing, software
  16. # distributed under the License is distributed on an "AS IS" BASIS,
  17. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. # See the License for the specific language governing permissions and
  19. # limitations under the License.
  20. from typing import Literal
  21. from huggingface_hub.dataclasses import strict
  22. from ...configuration_utils import PreTrainedConfig
  23. from ...utils import auto_docstring
  24. from ..auto import CONFIG_MAPPING, AutoConfig
  25. @auto_docstring(checkpoint="ModernVBERT/modernvbert")
  26. @strict
  27. class ModernVBertConfig(PreTrainedConfig):
  28. r"""
  29. pixel_shuffle_factor (`int | None`, *optional*, defaults to 4):
  30. Scale factor used by any pixel-shuffle / upsampling operations in the vision head.
  31. initializer_cutoff_factor (`float | None`, *optional*, defaults to 2.0):
  32. The cutoff factor for the truncated_normal_initializer for initializing all weight matrices.
  33. classifier_pooling (`Literal["cls", "mean"]`, *optional*, defaults to `"cls"`):
  34. The pooling strategy to use for classification tasks.
  35. classifier_bias (`bool | None`, *optional*, defaults to `False`):
  36. Whether to add a bias term to the classification head
  37. Example:
  38. ```python
  39. >>> from transformers import ModernVBertConfig
  40. >>> # Initializing configuration
  41. >>> configuration = ModernVBertConfig()
  42. >>> # Initializing a model from the configuration (model class is implemented in
  43. >>> # `modernvbert.modeling_modernvbert`)
  44. >>> from transformers import ModernVBertModel
  45. >>> model = ModernVBertModel(configuration)
  46. >>> # Accessing the model configuration
  47. >>> cfg = model.config
  48. ```"""
  49. model_type = "modernvbert"
  50. sub_configs = {"text_config": AutoConfig, "vision_config": AutoConfig}
  51. text_config: PreTrainedConfig | dict | None = None
  52. vision_config: PreTrainedConfig | dict | None = None
  53. image_token_id: int = 50407
  54. pixel_shuffle_factor: int = 4
  55. initializer_range: float = 0.02
  56. initializer_cutoff_factor: float = 2.0
  57. classifier_pooling: Literal["cls", "mean"] = "cls"
  58. classifier_dropout: float | int = 0.0
  59. classifier_bias: bool = False
  60. tie_word_embeddings: bool = False
  61. def __post_init__(self, **kwargs):
  62. if self.text_config is None:
  63. self.text_config = CONFIG_MAPPING["modernbert"]()
  64. elif isinstance(self.text_config, dict):
  65. self.text_config = CONFIG_MAPPING["modernbert"](**self.text_config)
  66. if self.vision_config is None:
  67. self.vision_config = CONFIG_MAPPING["siglip_vision_model"]()
  68. elif isinstance(self.vision_config, dict):
  69. self.vision_config = CONFIG_MAPPING["siglip_vision_model"](**self.vision_config)
  70. super().__post_init__(**kwargs)
  71. __all__ = ["ModernVBertConfig"]