configuration_pop2piano.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright 2023 The HuggingFace Inc. 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. """Pop2Piano model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="sweetcocoa/pop2piano")
  19. @strict
  20. class Pop2PianoConfig(PreTrainedConfig):
  21. r"""
  22. composer_vocab_size (`int`, *optional*, defaults to 21):
  23. Denotes the number of composers.
  24. relative_attention_num_buckets (`int`, *optional*, defaults to 32):
  25. The number of buckets to use for each attention layer.
  26. relative_attention_max_distance (`int`, *optional*, defaults to 128):
  27. The maximum distance of the longer sequences for the bucket separation.
  28. feed_forward_proj (`string`, *optional*, defaults to `"gated-gelu"`):
  29. Type of feed forward layer to be used. Should be one of `"relu"` or `"gated-gelu"`.
  30. dense_act_fn (`string`, *optional*, defaults to `"relu"`):
  31. Type of Activation Function to be used in `Pop2PianoDenseActDense` and in `Pop2PianoDenseGatedActDense`.
  32. """
  33. model_type = "pop2piano"
  34. keys_to_ignore_at_inference = ["past_key_values"]
  35. attribute_map = {"num_hidden_layers": "num_layers", "hidden_size": "d_model", "num_attention_heads": "num_heads"}
  36. vocab_size: int = 2400
  37. composer_vocab_size: int = 21
  38. d_model: int = 512
  39. d_kv: int = 64
  40. d_ff: int = 2048
  41. num_layers: int = 6
  42. num_decoder_layers: int | None = None
  43. num_heads: int = 8
  44. relative_attention_num_buckets: int = 32
  45. relative_attention_max_distance: int = 128
  46. dropout_rate: float | int = 0.1
  47. layer_norm_epsilon: float = 1e-6
  48. initializer_factor: float = 1.0
  49. feed_forward_proj: str = "gated-gelu"
  50. is_encoder_decoder: bool = True
  51. use_cache: bool = True
  52. pad_token_id: int | None = 0
  53. eos_token_id: int | list[int] | None = 1
  54. dense_act_fn: str = "relu"
  55. is_decoder: bool = False
  56. tie_word_embeddings: bool = True
  57. def __post_init__(self, **kwargs):
  58. self.num_decoder_layers = self.num_decoder_layers if self.num_decoder_layers is not None else self.num_layers
  59. self.is_gated_act = self.feed_forward_proj.split("-")[0] == "gated"
  60. super().__post_init__(**kwargs)
  61. __all__ = ["Pop2PianoConfig"]