1
0

class_utils.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright [2023-11-28] <sxc19@mails.tsinghua.edu.cn, Xingchen Song>
  2. # 2024 Alibaba Inc (authors: Xiang Lyu)
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import torch
  16. from cosyvoice.transformer.activation import Swish
  17. from cosyvoice.transformer.subsampling import (
  18. LinearNoSubsampling,
  19. EmbedinigNoSubsampling,
  20. Conv1dSubsampling2,
  21. Conv2dSubsampling4,
  22. Conv2dSubsampling6,
  23. Conv2dSubsampling8,
  24. )
  25. from cosyvoice.transformer.embedding import (PositionalEncoding,
  26. RelPositionalEncoding,
  27. WhisperPositionalEncoding,
  28. LearnablePositionalEncoding,
  29. NoPositionalEncoding)
  30. from cosyvoice.transformer.attention import (MultiHeadedAttention,
  31. RelPositionMultiHeadedAttention)
  32. from cosyvoice.transformer.embedding import EspnetRelPositionalEncoding
  33. from cosyvoice.transformer.subsampling import LegacyLinearNoSubsampling
  34. COSYVOICE_ACTIVATION_CLASSES = {
  35. "hardtanh": torch.nn.Hardtanh,
  36. "tanh": torch.nn.Tanh,
  37. "relu": torch.nn.ReLU,
  38. "selu": torch.nn.SELU,
  39. "swish": getattr(torch.nn, "SiLU", Swish),
  40. "gelu": torch.nn.GELU,
  41. }
  42. COSYVOICE_SUBSAMPLE_CLASSES = {
  43. "linear": LinearNoSubsampling,
  44. "linear_legacy": LegacyLinearNoSubsampling,
  45. "embed": EmbedinigNoSubsampling,
  46. "conv1d2": Conv1dSubsampling2,
  47. "conv2d": Conv2dSubsampling4,
  48. "conv2d6": Conv2dSubsampling6,
  49. "conv2d8": Conv2dSubsampling8,
  50. 'paraformer_dummy': torch.nn.Identity
  51. }
  52. COSYVOICE_EMB_CLASSES = {
  53. "embed": PositionalEncoding,
  54. "abs_pos": PositionalEncoding,
  55. "rel_pos": RelPositionalEncoding,
  56. "rel_pos_espnet": EspnetRelPositionalEncoding,
  57. "no_pos": NoPositionalEncoding,
  58. "abs_pos_whisper": WhisperPositionalEncoding,
  59. "embed_learnable_pe": LearnablePositionalEncoding,
  60. }
  61. COSYVOICE_ATTENTION_CLASSES = {
  62. "selfattn": MultiHeadedAttention,
  63. "rel_selfattn": RelPositionMultiHeadedAttention,
  64. }