configuration_colmodernvbert.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/colmodernvbert/modular_colmodernvbert.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_colmodernvbert.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 huggingface_hub.dataclasses import strict
  21. from ...configuration_utils import PreTrainedConfig
  22. from ...utils import auto_docstring, logging
  23. from ..auto import CONFIG_MAPPING
  24. logger = logging.get_logger(__name__)
  25. @auto_docstring(checkpoint="ModernVBERT/colmodernvbert-merged")
  26. @strict
  27. class ColModernVBertConfig(PreTrainedConfig):
  28. r"""
  29. Example:
  30. ```python
  31. from transformers import ColModernVBertConfig, ColModernVBertForRetrieval
  32. config = ColModernVBertConfig()
  33. model = ColModernVBertForRetrieval(config)
  34. ```
  35. """
  36. model_type = "colmodernvbert"
  37. sub_configs = {"vlm_config": PreTrainedConfig}
  38. vlm_config: dict | PreTrainedConfig | None = None
  39. embedding_dim: int = 128
  40. initializer_range: float = 0.02
  41. def __post_init__(self, **kwargs):
  42. if self.vlm_config is None:
  43. self.vlm_config = CONFIG_MAPPING["modernvbert"]()
  44. logger.info(
  45. "`vlm_config` is `None`. Initializing `vlm_config` with the `ModernVBertConfig` with default values."
  46. )
  47. elif isinstance(self.vlm_config, dict):
  48. self.vlm_config = CONFIG_MAPPING[self.vlm_config["model_type"]](**self.vlm_config)
  49. if not hasattr(self.vlm_config, "vocab_size"):
  50. self.vlm_config.vocab_size = self.vlm_config.get_text_config().vocab_size
  51. if self.vlm_config is None:
  52. self.vlm_config = CONFIG_MAPPING["qwen2_vl"]()
  53. logger.info(
  54. "`vlm_config` is `None`. Initializing `vlm_config` with the `Qwen2VLConfig` with default values."
  55. )
  56. elif isinstance(self.vlm_config, dict):
  57. self.vlm_config = CONFIG_MAPPING[self.vlm_config["model_type"]](**self.vlm_config)
  58. if not hasattr(self.vlm_config, "vocab_size"):
  59. self.vlm_config.vocab_size = self.vlm_config.get_text_config().vocab_size
  60. super().__post_init__(**kwargs)
  61. def get_text_config(self, *args, **kwargs) -> PreTrainedConfig:
  62. return self.vlm_config.get_text_config(*args, **kwargs)
  63. __all__ = ["ColModernVBertConfig"]