configuration_univnet.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="dg845/univnet-dev")
  19. @strict
  20. class UnivNetConfig(PreTrainedConfig):
  21. r"""
  22. model_in_channels (`int`, *optional*, defaults to 64):
  23. The number of input channels for the UnivNet residual network. This should correspond to
  24. `noise_sequence.shape[1]` and the value used in the [`UnivNetFeatureExtractor`] class.
  25. model_hidden_channels (`int`, *optional*, defaults to 32):
  26. The number of hidden channels of each residual block in the UnivNet residual network.
  27. num_mel_bins (`int`, *optional*, defaults to 100):
  28. The number of frequency bins in the conditioning log-mel spectrogram. This should correspond to the value
  29. used in the [`UnivNetFeatureExtractor`] class.
  30. resblock_kernel_sizes (`tuple[int]` or `list[int]`, *optional*, defaults to `[3, 3, 3]`):
  31. A tuple of integers defining the kernel sizes of the 1D convolutional layers in the UnivNet residual
  32. network. The length of `resblock_kernel_sizes` defines the number of resnet blocks and should match that of
  33. `resblock_stride_sizes` and `resblock_dilation_sizes`.
  34. resblock_stride_sizes (`tuple[int]` or `list[int]`, *optional*, defaults to `[8, 8, 4]`):
  35. A tuple of integers defining the stride sizes of the 1D convolutional layers in the UnivNet residual
  36. network. The length of `resblock_stride_sizes` should match that of `resblock_kernel_sizes` and
  37. `resblock_dilation_sizes`.
  38. 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]]`):
  39. A nested tuple of integers defining the dilation rates of the dilated 1D convolutional layers in the
  40. UnivNet residual network. The length of `resblock_dilation_sizes` should match that of
  41. `resblock_kernel_sizes` and `resblock_stride_sizes`. The length of each nested list in
  42. `resblock_dilation_sizes` defines the number of convolutional layers per resnet block.
  43. kernel_predictor_num_blocks (`int`, *optional*, defaults to 3):
  44. The number of residual blocks in the kernel predictor network, which calculates the kernel and bias for
  45. each location variable convolution layer in the UnivNet residual network.
  46. kernel_predictor_hidden_channels (`int`, *optional*, defaults to 64):
  47. The number of hidden channels for each residual block in the kernel predictor network.
  48. kernel_predictor_conv_size (`int`, *optional*, defaults to 3):
  49. The kernel size of each 1D convolutional layer in the kernel predictor network.
  50. kernel_predictor_dropout (`float`, *optional*, defaults to 0.0):
  51. The dropout probability for each residual block in the kernel predictor network.
  52. leaky_relu_slope (`float`, *optional*, defaults to 0.2):
  53. The angle of the negative slope used by the leaky ReLU activation.
  54. Example:
  55. ```python
  56. >>> from transformers import UnivNetModel, UnivNetConfig
  57. >>> # Initializing a Tortoise TTS style configuration
  58. >>> configuration = UnivNetConfig()
  59. >>> # Initializing a model (with random weights) from the Tortoise TTS style configuration
  60. >>> model = UnivNetModel(configuration)
  61. >>> # Accessing the model configuration
  62. >>> configuration = model.config
  63. ```
  64. """
  65. model_type = "univnet"
  66. model_in_channels: int = 64
  67. model_hidden_channels: int = 32
  68. num_mel_bins: int = 100
  69. resblock_kernel_sizes: list[int] | tuple[int, ...] = (3, 3, 3)
  70. resblock_stride_sizes: list[int] | tuple[int, ...] = (8, 8, 4)
  71. resblock_dilation_sizes: list | tuple = ((1, 3, 9, 27), (1, 3, 9, 27), (1, 3, 9, 27))
  72. kernel_predictor_num_blocks: int = 3
  73. kernel_predictor_hidden_channels: int = 64
  74. kernel_predictor_conv_size: int = 3
  75. kernel_predictor_dropout: float | int = 0.0
  76. initializer_range: float = 0.01
  77. leaky_relu_slope: float = 0.2
  78. def validate_architecture(self):
  79. """Part of `@strict`-powered validation. Validates the architecture of the config."""
  80. if not (
  81. len(self.resblock_kernel_sizes) == len(self.resblock_stride_sizes) == len(self.resblock_dilation_sizes)
  82. ):
  83. raise ValueError(
  84. "`resblock_kernel_sizes`, `resblock_stride_sizes`, and `resblock_dilation_sizes` must all have the"
  85. " same length (which will be the number of resnet blocks in the model)."
  86. )
  87. __all__ = ["UnivNetConfig"]