configuration_musicflamingo.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/musicflamingo/modular_musicflamingo.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_musicflamingo.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2026 NVIDIA CORPORATION and the HuggingFace Inc. team. All rights
  8. # reserved.
  9. #
  10. # Licensed under the Apache License, Version 2.0 (the "License");
  11. # you may not use this file except in compliance with the License.
  12. # You may obtain a copy of the License at
  13. #
  14. # http://www.apache.org/licenses/LICENSE-2.0
  15. #
  16. # Unless required by applicable law or agreed to in writing, software
  17. # distributed under the License is distributed on an "AS IS" BASIS,
  18. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. # See the License for the specific language governing permissions and
  20. # limitations under the License.
  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="nvidia/music-flamingo-2601-hf")
  26. @strict
  27. class MusicFlamingoConfig(PreTrainedConfig):
  28. r"""
  29. audio_bos_token_id (`int`, *optional*, defaults to 151670):
  30. The beginning-of-audio token index used to mark the start of audio spans.
  31. audio_eos_token_id (`int`, *optional*, defaults to 151671):
  32. The end-of-audio token index used to mark the end of audio spans.
  33. audio_frame_step (`float`, *optional*, defaults to 0.01):
  34. Duration in seconds of one input mel frame (trained with hop_length 160 at sampling_rate 16000).
  35. Example:
  36. ```python
  37. >>> from transformers import MusicFlamingoForConditionalGeneration, MusicFlamingoConfig, AudioFlamingo3EncoderConfig, Qwen2Config
  38. >>> # Initializing an MusicFlamingoEncoder config
  39. >>> audio_config = AudioFlamingo3EncoderConfig()
  40. >>> # Initializing a Qwen2 config
  41. >>> text_config = Qwen2Config()
  42. >>> # Initializing an MusicFlamingo configuration
  43. >>> configuration = MusicFlamingoConfig(audio_config, text_config)
  44. >>> # Initializing a model from the musicflamingo style configuration
  45. >>> model = MusicFlamingoForConditionalGeneration(configuration)
  46. >>> # Accessing the model configuration
  47. >>> configuration = model.config
  48. ```"""
  49. model_type = "musicflamingo"
  50. sub_configs = {"audio_config": AutoConfig, "text_config": AutoConfig}
  51. audio_config: dict | PreTrainedConfig | None = None
  52. text_config: dict | PreTrainedConfig | None = None
  53. audio_token_id: int = 151669
  54. projector_hidden_act: str = "gelu"
  55. projector_bias: bool = True
  56. audio_bos_token_id: int = 151670
  57. audio_eos_token_id: int = 151671
  58. audio_frame_step: float = 0.01
  59. rope_parameters: dict | None = None
  60. def __post_init__(self, **kwargs):
  61. if isinstance(self.audio_config, dict):
  62. self.audio_config["model_type"] = self.audio_config.get("model_type", "musicflamingo_encoder")
  63. self.audio_config = CONFIG_MAPPING[self.audio_config["model_type"]](**self.audio_config)
  64. elif self.audio_config is None:
  65. self.audio_config = CONFIG_MAPPING["musicflamingo_encoder"]()
  66. if isinstance(self.text_config, dict):
  67. self.text_config["model_type"] = self.text_config.get("model_type", "qwen2")
  68. self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config)
  69. elif self.text_config is None:
  70. self.text_config = CONFIG_MAPPING["qwen2"]()
  71. super().__post_init__(**kwargs)
  72. if self.rope_parameters is None:
  73. self.rope_parameters = {"rope_type": "default", "rope_theta": 1200, "partial_rotary_factor": 0.2}
  74. self.max_position_embeddings = self.rope_parameters["rope_theta"]
  75. self.head_dim = self.audio_config.hidden_size
  76. __all__ = ["MusicFlamingoConfig"]