configuration_univnet.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # Copyright 2023 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. """UnivNetModel model configuration"""
  15. from ...configuration_utils import PretrainedConfig
  16. from ...utils import logging
  17. logger = logging.get_logger(__name__)
  18. class UnivNetConfig(PretrainedConfig):
  19. r"""
  20. This is the configuration class to store the configuration of a [`UnivNetModel`]. It is used to instantiate a
  21. UnivNet vocoder model according to the specified arguments, defining the model architecture. Instantiating a
  22. configuration with the defaults will yield a similar configuration to that of the UnivNet
  23. [dg845/univnet-dev](https://huggingface.co/dg845/univnet-dev) architecture, which corresponds to the 'c32'
  24. architecture in [maum-ai/univnet](https://github.com/maum-ai/univnet/blob/master/config/default_c32.yaml).
  25. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
  26. documentation from [`PretrainedConfig`] for more information.
  27. Args:
  28. model_in_channels (`int`, *optional*, defaults to 64):
  29. The number of input channels for the UnivNet residual network. This should correspond to
  30. `noise_sequence.shape[1]` and the value used in the [`UnivNetFeatureExtractor`] class.
  31. model_hidden_channels (`int`, *optional*, defaults to 32):
  32. The number of hidden channels of each residual block in the UnivNet residual network.
  33. num_mel_bins (`int`, *optional*, defaults to 100):
  34. The number of frequency bins in the conditioning log-mel spectrogram. This should correspond to the value
  35. used in the [`UnivNetFeatureExtractor`] class.
  36. resblock_kernel_sizes (`tuple[int]` or `list[int]`, *optional*, defaults to `[3, 3, 3]`):
  37. A tuple of integers defining the kernel sizes of the 1D convolutional layers in the UnivNet residual
  38. network. The length of `resblock_kernel_sizes` defines the number of resnet blocks and should match that of
  39. `resblock_stride_sizes` and `resblock_dilation_sizes`.
  40. resblock_stride_sizes (`tuple[int]` or `list[int]`, *optional*, defaults to `[8, 8, 4]`):
  41. A tuple of integers defining the stride sizes of the 1D convolutional layers in the UnivNet residual
  42. network. The length of `resblock_stride_sizes` should match that of `resblock_kernel_sizes` and
  43. `resblock_dilation_sizes`.
  44. resblock_dilation_sizes (`tuple[tuple[int]]` or `list[list[int]]`, *optional*, defaults to `[[1, 3, 9, 27], [1, 3, 9, 27], [1, 3, 9, 27]]`):
  45. A nested tuple of integers defining the dilation rates of the dilated 1D convolutional layers in the
  46. UnivNet residual network. The length of `resblock_dilation_sizes` should match that of
  47. `resblock_kernel_sizes` and `resblock_stride_sizes`. The length of each nested list in
  48. `resblock_dilation_sizes` defines the number of convolutional layers per resnet block.
  49. kernel_predictor_num_blocks (`int`, *optional*, defaults to 3):
  50. The number of residual blocks in the kernel predictor network, which calculates the kernel and bias for
  51. each location variable convolution layer in the UnivNet residual network.
  52. kernel_predictor_hidden_channels (`int`, *optional*, defaults to 64):
  53. The number of hidden channels for each residual block in the kernel predictor network.
  54. kernel_predictor_conv_size (`int`, *optional*, defaults to 3):
  55. The kernel size of each 1D convolutional layer in the kernel predictor network.
  56. kernel_predictor_dropout (`float`, *optional*, defaults to 0.0):
  57. The dropout probability for each residual block in the kernel predictor network.
  58. initializer_range (`float`, *optional*, defaults to 0.01):
  59. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
  60. leaky_relu_slope (`float`, *optional*, defaults to 0.2):
  61. The angle of the negative slope used by the leaky ReLU activation.
  62. Example:
  63. ```python
  64. >>> from transformers import UnivNetModel, UnivNetConfig
  65. >>> # Initializing a Tortoise TTS style configuration
  66. >>> configuration = UnivNetConfig()
  67. >>> # Initializing a model (with random weights) from the Tortoise TTS style configuration
  68. >>> model = UnivNetModel(configuration)
  69. >>> # Accessing the model configuration
  70. >>> configuration = model.config
  71. ```
  72. """
  73. model_type = "univnet"
  74. def __init__(
  75. self,
  76. model_in_channels=64,
  77. model_hidden_channels=32,
  78. num_mel_bins=100,
  79. resblock_kernel_sizes=[3, 3, 3],
  80. resblock_stride_sizes=[8, 8, 4],
  81. resblock_dilation_sizes=[[1, 3, 9, 27], [1, 3, 9, 27], [1, 3, 9, 27]],
  82. kernel_predictor_num_blocks=3,
  83. kernel_predictor_hidden_channels=64,
  84. kernel_predictor_conv_size=3,
  85. kernel_predictor_dropout=0.0,
  86. initializer_range=0.01,
  87. leaky_relu_slope=0.2,
  88. **kwargs,
  89. ):
  90. if not (len(resblock_kernel_sizes) == len(resblock_stride_sizes) == len(resblock_dilation_sizes)):
  91. raise ValueError(
  92. "`resblock_kernel_sizes`, `resblock_stride_sizes`, and `resblock_dilation_sizes` must all have the"
  93. " same length (which will be the number of resnet blocks in the model)."
  94. )
  95. self.model_in_channels = model_in_channels
  96. self.model_hidden_channels = model_hidden_channels
  97. self.num_mel_bins = num_mel_bins
  98. self.resblock_kernel_sizes = resblock_kernel_sizes
  99. self.resblock_stride_sizes = resblock_stride_sizes
  100. self.resblock_dilation_sizes = resblock_dilation_sizes
  101. self.kernel_predictor_num_blocks = kernel_predictor_num_blocks
  102. self.kernel_predictor_hidden_channels = kernel_predictor_hidden_channels
  103. self.kernel_predictor_conv_size = kernel_predictor_conv_size
  104. self.kernel_predictor_dropout = kernel_predictor_dropout
  105. self.initializer_range = initializer_range
  106. self.leaky_relu_slope = leaky_relu_slope
  107. super().__init__(**kwargs)
  108. __all__ = ["UnivNetConfig"]