configuration_colqwen2.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright 2025 The HuggingFace Inc. team.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from huggingface_hub.dataclasses import strict
  15. from ...configuration_utils import PreTrainedConfig
  16. from ...utils import auto_docstring, logging
  17. from ..auto import CONFIG_MAPPING
  18. logger = logging.get_logger(__name__)
  19. @auto_docstring(checkpoint="vidore/colqwen2-v1.0-hf")
  20. @strict
  21. class ColQwen2Config(PreTrainedConfig):
  22. r"""
  23. Example:
  24. ```python
  25. from transformers.models.colqwen2 import ColQwen2Config, ColQwen2ForRetrieval
  26. config = ColQwen2Config()
  27. model = ColQwen2ForRetrieval(config)
  28. ```
  29. """
  30. model_type = "colqwen2"
  31. sub_configs = {"vlm_config": PreTrainedConfig}
  32. vlm_config: dict | PreTrainedConfig | None = None
  33. embedding_dim: int = 128
  34. initializer_range: float = 0.02
  35. def __post_init__(self, **kwargs):
  36. if self.vlm_config is None:
  37. self.vlm_config = CONFIG_MAPPING["qwen2_vl"]()
  38. logger.info(
  39. "`vlm_config` is `None`. Initializing `vlm_config` with the `Qwen2VLConfig` with default values."
  40. )
  41. elif isinstance(self.vlm_config, dict):
  42. self.vlm_config = CONFIG_MAPPING[self.vlm_config["model_type"]](**self.vlm_config)
  43. if not hasattr(self.vlm_config, "vocab_size"):
  44. self.vlm_config.vocab_size = self.vlm_config.get_text_config().vocab_size
  45. super().__post_init__(**kwargs)
  46. def get_text_config(self, *args, **kwargs) -> PreTrainedConfig:
  47. return self.vlm_config.get_text_config(*args, **kwargs)
  48. __all__ = ["ColQwen2Config"]