configuration_glm46v.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/glm46v/modular_glm46v.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_glm46v.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2025 the HuggingFace 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
  23. from ..auto import CONFIG_MAPPING, AutoConfig
  24. @auto_docstring(checkpoint="zai-org/GLM-4.1V-9B-Thinking")
  25. @strict
  26. class Glm46VConfig(PreTrainedConfig):
  27. r"""
  28. image_start_token_id (`int`, *optional*, defaults to 151339):
  29. The image start token index to encode the start of image.
  30. image_end_token_id (`int`, *optional*, defaults to 151340):
  31. The image end token index to encode the end of image.
  32. video_start_token_id (`int`, *optional*, defaults to 151361):
  33. The video start token index to encode the start of video.
  34. video_end_token_id (`int`, *optional*, defaults to 151362):
  35. The video end token index to encode the end of video.
  36. ```python
  37. >>> from transformers import Glm46VForConditionalGeneration, Glm46VConfig
  38. >>> # Initializing a GLM-4.6V style configuration
  39. >>> configuration = Glm46VConfig()
  40. >>> # Initializing a model from the GLM-4.6V style configuration
  41. >>> model = Glm4vForConditionalGeneration(configuration)
  42. >>> # Accessing the model configuration
  43. >>> configuration = model.config
  44. ```"""
  45. model_type = "glm46v"
  46. sub_configs = {"text_config": AutoConfig, "vision_config": AutoConfig}
  47. keys_to_ignore_at_inference = ["past_key_values"]
  48. text_config: dict | PreTrainedConfig | None = None
  49. vision_config: dict | PreTrainedConfig | None = None
  50. image_token_id: int = 151343
  51. video_token_id: int = 151344
  52. image_start_token_id: int = 151339
  53. image_end_token_id: int = 151340
  54. video_start_token_id: int = 151361
  55. video_end_token_id: int = 151362
  56. tie_word_embeddings: bool = False
  57. def __post_init__(self, **kwargs):
  58. if isinstance(self.vision_config, dict):
  59. self.vision_config["model_type"] = self.vision_config.get("model_type", "glm4v_vision")
  60. self.vision_config = CONFIG_MAPPING[self.vision_config["model_type"]](**self.vision_config)
  61. elif self.vision_config is None:
  62. self.vision_config = CONFIG_MAPPING["glm4v_vision"]()
  63. if isinstance(self.text_config, dict):
  64. self.text_config["model_type"] = self.text_config.get("model_type", "glm4v_text")
  65. self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config)
  66. elif self.text_config is None:
  67. self.text_config = CONFIG_MAPPING["glm4v_text"]()
  68. super().__post_init__(**kwargs)
  69. __all__ = ["Glm46VConfig"]