configuration_glmasr.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # Copyright 2025 the HuggingFace Team. All rights reserved.
  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
  17. from ..auto import CONFIG_MAPPING, AutoConfig
  18. @auto_docstring(checkpoint="zai-org/GLM-ASR-Nano-2512")
  19. @strict
  20. class GlmAsrEncoderConfig(PreTrainedConfig):
  21. r"""
  22. Example:
  23. ```python
  24. >>> from transformers import GlmAsrEncoderConfig, GlmAsrEncoder
  25. >>> # Initializing a GlmAsrEncoderConfig
  26. >>> configuration = GlmAsrEncoderConfig()
  27. >>> # Initializing a GlmAsrEncoder (with random weights)
  28. >>> model = GlmAsrEncoder(configuration)
  29. >>> # Accessing the model configuration
  30. >>> configuration = model.config
  31. ```"""
  32. model_type = "glmasr_encoder"
  33. hidden_size: int = 1280
  34. intermediate_size: int = 5120
  35. num_hidden_layers: int = 32
  36. num_attention_heads: int = 20
  37. num_key_value_heads: int | None = None
  38. hidden_act: str = "gelu"
  39. max_position_embeddings: int = 1500
  40. initializer_range: float = 0.02
  41. rope_parameters: dict | None = None
  42. attention_dropout: float | int = 0.0
  43. num_mel_bins: int = 128
  44. def __post_init__(self, **kwargs):
  45. if self.num_key_value_heads is None:
  46. self.num_key_value_heads = self.num_attention_heads
  47. kwargs.setdefault("partial_rotary_factor", 0.5)
  48. super().__post_init__(**kwargs)
  49. @auto_docstring(checkpoint="zai-org/GLM-ASR-Nano-2512")
  50. @strict
  51. class GlmAsrConfig(PreTrainedConfig):
  52. r"""
  53. Example:
  54. ```python
  55. >>> from transformers import GlmAsrForConditionalGeneration, GlmAsrConfig
  56. >>> # Initializing a glmasr configuration
  57. >>> configuration = GlmAsrConfig()
  58. >>> # Initializing a GLM-ASR-Nano-2512 model with random weights
  59. >>> model = GlmAsrForConditionalGeneration(configuration)
  60. >>> # Accessing the model configuration
  61. >>> configuration = model.config
  62. ```"""
  63. model_type = "glmasr"
  64. sub_configs = {"text_config": AutoConfig, "audio_config": AutoConfig}
  65. _default_text_config_kwargs = {
  66. "vocab_size": 59264,
  67. "hidden_size": 2048,
  68. "intermediate_size": 6144,
  69. "num_hidden_layers": 28,
  70. "num_attention_heads": 16,
  71. "num_key_value_heads": 4,
  72. "max_position_embeddings": 8192,
  73. "rms_norm_eps": 1e-05,
  74. "use_cache": True,
  75. "eos_token_id": [59246, 59253, 59255],
  76. "rope_parameters": {"rope_theta": 10000.0, "rope_type": "default"},
  77. }
  78. audio_config: dict | PreTrainedConfig | None = None
  79. text_config: dict | PreTrainedConfig | None = None
  80. audio_token_id: int = 59260
  81. projector_hidden_act: str = "gelu"
  82. def __post_init__(self, **kwargs):
  83. if isinstance(self.audio_config, dict):
  84. self.audio_config["model_type"] = self.audio_config.get("model_type", "glmasr_encoder")
  85. self.audio_config = CONFIG_MAPPING[self.audio_config["model_type"]](**self.audio_config)
  86. elif self.audio_config is None:
  87. self.audio_config = CONFIG_MAPPING["glmasr_encoder"]()
  88. if isinstance(self.text_config, dict):
  89. self.text_config["model_type"] = self.text_config.get("model_type", "llama")
  90. self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](
  91. **{**self._default_text_config_kwargs, **self.text_config}
  92. )
  93. elif self.text_config is None:
  94. self.text_config = CONFIG_MAPPING["llama"](**self._default_text_config_kwargs)
  95. super().__post_init__(**kwargs)
  96. __all__ = ["GlmAsrEncoderConfig", "GlmAsrConfig"]