xinference 1.10.0__py3-none-any.whl → 1.10.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xinference might be problematic. Click here for more details.

Files changed (317) hide show
  1. xinference/_version.py +3 -3
  2. xinference/api/restful_api.py +11 -28
  3. xinference/client/restful/async_restful_client.py +20 -3
  4. xinference/client/restful/restful_client.py +20 -3
  5. xinference/core/supervisor.py +87 -53
  6. xinference/core/worker.py +10 -0
  7. xinference/deploy/cmdline.py +15 -0
  8. xinference/model/audio/core.py +21 -6
  9. xinference/model/audio/indextts2.py +166 -0
  10. xinference/model/audio/model_spec.json +38 -1
  11. xinference/model/image/model_spec.json +69 -0
  12. xinference/model/image/stable_diffusion/core.py +13 -4
  13. xinference/model/llm/__init__.py +4 -0
  14. xinference/model/llm/llm_family.json +464 -2
  15. xinference/model/llm/sglang/core.py +30 -11
  16. xinference/model/llm/tool_parsers/deepseek_r1_tool_parser.py +94 -32
  17. xinference/model/llm/transformers/multimodal/qwen2_vl.py +34 -8
  18. xinference/model/llm/utils.py +12 -9
  19. xinference/model/llm/vllm/core.py +93 -17
  20. xinference/thirdparty/audiotools/__init__.py +10 -0
  21. xinference/thirdparty/audiotools/core/__init__.py +4 -0
  22. xinference/thirdparty/audiotools/core/audio_signal.py +1682 -0
  23. xinference/thirdparty/audiotools/core/display.py +194 -0
  24. xinference/thirdparty/audiotools/core/dsp.py +390 -0
  25. xinference/thirdparty/audiotools/core/effects.py +647 -0
  26. xinference/thirdparty/audiotools/core/ffmpeg.py +211 -0
  27. xinference/thirdparty/audiotools/core/loudness.py +320 -0
  28. xinference/thirdparty/audiotools/core/playback.py +252 -0
  29. xinference/thirdparty/audiotools/core/templates/__init__.py +0 -0
  30. xinference/thirdparty/audiotools/core/templates/headers.html +322 -0
  31. xinference/thirdparty/audiotools/core/templates/pandoc.css +407 -0
  32. xinference/thirdparty/audiotools/core/templates/widget.html +52 -0
  33. xinference/thirdparty/audiotools/core/util.py +671 -0
  34. xinference/thirdparty/audiotools/core/whisper.py +97 -0
  35. xinference/thirdparty/audiotools/data/__init__.py +3 -0
  36. xinference/thirdparty/audiotools/data/datasets.py +517 -0
  37. xinference/thirdparty/audiotools/data/preprocess.py +81 -0
  38. xinference/thirdparty/audiotools/data/transforms.py +1592 -0
  39. xinference/thirdparty/audiotools/metrics/__init__.py +6 -0
  40. xinference/thirdparty/audiotools/metrics/distance.py +131 -0
  41. xinference/thirdparty/audiotools/metrics/quality.py +159 -0
  42. xinference/thirdparty/audiotools/metrics/spectral.py +247 -0
  43. xinference/thirdparty/audiotools/ml/__init__.py +5 -0
  44. xinference/thirdparty/audiotools/ml/accelerator.py +184 -0
  45. xinference/thirdparty/audiotools/ml/decorators.py +440 -0
  46. xinference/thirdparty/audiotools/ml/experiment.py +90 -0
  47. xinference/thirdparty/audiotools/ml/layers/__init__.py +2 -0
  48. xinference/thirdparty/audiotools/ml/layers/base.py +328 -0
  49. xinference/thirdparty/audiotools/ml/layers/spectral_gate.py +127 -0
  50. xinference/thirdparty/audiotools/post.py +140 -0
  51. xinference/thirdparty/audiotools/preference.py +600 -0
  52. xinference/thirdparty/indextts/BigVGAN/ECAPA_TDNN.py +656 -0
  53. xinference/thirdparty/indextts/BigVGAN/__init__.py +0 -0
  54. xinference/thirdparty/indextts/BigVGAN/activations.py +122 -0
  55. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/__init__.py +0 -0
  56. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/.gitignore +1 -0
  57. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/__init__.py +0 -0
  58. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/activation1d.py +76 -0
  59. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/anti_alias_activation.cpp +23 -0
  60. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/anti_alias_activation_cuda.cu +256 -0
  61. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/compat.h +29 -0
  62. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/load.py +121 -0
  63. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/type_shim.h +92 -0
  64. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/torch/__init__.py +6 -0
  65. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/torch/act.py +31 -0
  66. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/torch/filter.py +102 -0
  67. xinference/thirdparty/indextts/BigVGAN/alias_free_activation/torch/resample.py +58 -0
  68. xinference/thirdparty/indextts/BigVGAN/alias_free_torch/__init__.py +6 -0
  69. xinference/thirdparty/indextts/BigVGAN/alias_free_torch/act.py +29 -0
  70. xinference/thirdparty/indextts/BigVGAN/alias_free_torch/filter.py +96 -0
  71. xinference/thirdparty/indextts/BigVGAN/alias_free_torch/resample.py +49 -0
  72. xinference/thirdparty/indextts/BigVGAN/bigvgan.py +534 -0
  73. xinference/thirdparty/indextts/BigVGAN/models.py +451 -0
  74. xinference/thirdparty/indextts/BigVGAN/nnet/CNN.py +546 -0
  75. xinference/thirdparty/indextts/BigVGAN/nnet/__init__.py +0 -0
  76. xinference/thirdparty/indextts/BigVGAN/nnet/linear.py +89 -0
  77. xinference/thirdparty/indextts/BigVGAN/nnet/normalization.py +670 -0
  78. xinference/thirdparty/indextts/BigVGAN/utils.py +101 -0
  79. xinference/thirdparty/indextts/__init__.py +0 -0
  80. xinference/thirdparty/indextts/cli.py +65 -0
  81. xinference/thirdparty/indextts/gpt/__init__.py +0 -0
  82. xinference/thirdparty/indextts/gpt/conformer/__init__.py +0 -0
  83. xinference/thirdparty/indextts/gpt/conformer/attention.py +312 -0
  84. xinference/thirdparty/indextts/gpt/conformer/embedding.py +163 -0
  85. xinference/thirdparty/indextts/gpt/conformer/subsampling.py +348 -0
  86. xinference/thirdparty/indextts/gpt/conformer_encoder.py +520 -0
  87. xinference/thirdparty/indextts/gpt/model.py +713 -0
  88. xinference/thirdparty/indextts/gpt/model_v2.py +747 -0
  89. xinference/thirdparty/indextts/gpt/perceiver.py +317 -0
  90. xinference/thirdparty/indextts/gpt/transformers_beam_search.py +1013 -0
  91. xinference/thirdparty/indextts/gpt/transformers_generation_utils.py +4747 -0
  92. xinference/thirdparty/indextts/gpt/transformers_gpt2.py +1878 -0
  93. xinference/thirdparty/indextts/gpt/transformers_modeling_utils.py +5525 -0
  94. xinference/thirdparty/indextts/infer.py +690 -0
  95. xinference/thirdparty/indextts/infer_v2.py +739 -0
  96. xinference/thirdparty/indextts/s2mel/dac/__init__.py +16 -0
  97. xinference/thirdparty/indextts/s2mel/dac/__main__.py +36 -0
  98. xinference/thirdparty/indextts/s2mel/dac/model/__init__.py +4 -0
  99. xinference/thirdparty/indextts/s2mel/dac/model/base.py +294 -0
  100. xinference/thirdparty/indextts/s2mel/dac/model/dac.py +400 -0
  101. xinference/thirdparty/indextts/s2mel/dac/model/discriminator.py +228 -0
  102. xinference/thirdparty/indextts/s2mel/dac/model/encodec.py +320 -0
  103. xinference/thirdparty/indextts/s2mel/dac/nn/__init__.py +3 -0
  104. xinference/thirdparty/indextts/s2mel/dac/nn/layers.py +33 -0
  105. xinference/thirdparty/indextts/s2mel/dac/nn/loss.py +368 -0
  106. xinference/thirdparty/indextts/s2mel/dac/nn/quantize.py +339 -0
  107. xinference/thirdparty/indextts/s2mel/dac/utils/__init__.py +123 -0
  108. xinference/thirdparty/indextts/s2mel/dac/utils/decode.py +95 -0
  109. xinference/thirdparty/indextts/s2mel/dac/utils/encode.py +94 -0
  110. xinference/thirdparty/indextts/s2mel/hf_utils.py +12 -0
  111. xinference/thirdparty/indextts/s2mel/modules/alias_free_torch/__init__.py +5 -0
  112. xinference/thirdparty/indextts/s2mel/modules/alias_free_torch/act.py +29 -0
  113. xinference/thirdparty/indextts/s2mel/modules/alias_free_torch/filter.py +96 -0
  114. xinference/thirdparty/indextts/s2mel/modules/alias_free_torch/resample.py +57 -0
  115. xinference/thirdparty/indextts/s2mel/modules/audio.py +82 -0
  116. xinference/thirdparty/indextts/s2mel/modules/bigvgan/activations.py +120 -0
  117. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/__init__.py +0 -0
  118. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/activation1d.py +77 -0
  119. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/anti_alias_activation.cpp +23 -0
  120. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/anti_alias_activation_cuda.cu +246 -0
  121. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/compat.h +29 -0
  122. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/load.py +86 -0
  123. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/type_shim.h +92 -0
  124. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/torch/__init__.py +6 -0
  125. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/torch/act.py +30 -0
  126. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/torch/filter.py +101 -0
  127. xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/torch/resample.py +58 -0
  128. xinference/thirdparty/indextts/s2mel/modules/bigvgan/bigvgan.py +492 -0
  129. xinference/thirdparty/indextts/s2mel/modules/bigvgan/config.json +63 -0
  130. xinference/thirdparty/indextts/s2mel/modules/bigvgan/env.py +18 -0
  131. xinference/thirdparty/indextts/s2mel/modules/bigvgan/meldataset.py +354 -0
  132. xinference/thirdparty/indextts/s2mel/modules/bigvgan/utils.py +99 -0
  133. xinference/thirdparty/indextts/s2mel/modules/campplus/DTDNN.py +115 -0
  134. xinference/thirdparty/indextts/s2mel/modules/campplus/classifier.py +70 -0
  135. xinference/thirdparty/indextts/s2mel/modules/campplus/layers.py +253 -0
  136. xinference/thirdparty/indextts/s2mel/modules/commons.py +632 -0
  137. xinference/thirdparty/indextts/s2mel/modules/diffusion_transformer.py +257 -0
  138. xinference/thirdparty/indextts/s2mel/modules/encodec.py +292 -0
  139. xinference/thirdparty/indextts/s2mel/modules/flow_matching.py +171 -0
  140. xinference/thirdparty/indextts/s2mel/modules/gpt_fast/generate.py +436 -0
  141. xinference/thirdparty/indextts/s2mel/modules/gpt_fast/model.py +360 -0
  142. xinference/thirdparty/indextts/s2mel/modules/gpt_fast/quantize.py +622 -0
  143. xinference/thirdparty/indextts/s2mel/modules/hifigan/f0_predictor.py +55 -0
  144. xinference/thirdparty/indextts/s2mel/modules/hifigan/generator.py +454 -0
  145. xinference/thirdparty/indextts/s2mel/modules/layers.py +354 -0
  146. xinference/thirdparty/indextts/s2mel/modules/length_regulator.py +141 -0
  147. xinference/thirdparty/indextts/s2mel/modules/openvoice/__init__.py +0 -0
  148. xinference/thirdparty/indextts/s2mel/modules/openvoice/api.py +186 -0
  149. xinference/thirdparty/indextts/s2mel/modules/openvoice/attentions.py +465 -0
  150. xinference/thirdparty/indextts/s2mel/modules/openvoice/checkpoints_v2/converter/config.json +57 -0
  151. xinference/thirdparty/indextts/s2mel/modules/openvoice/commons.py +160 -0
  152. xinference/thirdparty/indextts/s2mel/modules/openvoice/mel_processing.py +183 -0
  153. xinference/thirdparty/indextts/s2mel/modules/openvoice/models.py +499 -0
  154. xinference/thirdparty/indextts/s2mel/modules/openvoice/modules.py +598 -0
  155. xinference/thirdparty/indextts/s2mel/modules/openvoice/openvoice_app.py +275 -0
  156. xinference/thirdparty/indextts/s2mel/modules/openvoice/se_extractor.py +153 -0
  157. xinference/thirdparty/indextts/s2mel/modules/openvoice/transforms.py +209 -0
  158. xinference/thirdparty/indextts/s2mel/modules/openvoice/utils.py +194 -0
  159. xinference/thirdparty/indextts/s2mel/modules/quantize.py +229 -0
  160. xinference/thirdparty/indextts/s2mel/modules/rmvpe.py +631 -0
  161. xinference/thirdparty/indextts/s2mel/modules/vocos/__init__.py +4 -0
  162. xinference/thirdparty/indextts/s2mel/modules/vocos/heads.py +164 -0
  163. xinference/thirdparty/indextts/s2mel/modules/vocos/helpers.py +71 -0
  164. xinference/thirdparty/indextts/s2mel/modules/vocos/loss.py +114 -0
  165. xinference/thirdparty/indextts/s2mel/modules/vocos/models.py +118 -0
  166. xinference/thirdparty/indextts/s2mel/modules/vocos/modules.py +213 -0
  167. xinference/thirdparty/indextts/s2mel/modules/vocos/pretrained.py +51 -0
  168. xinference/thirdparty/indextts/s2mel/modules/vocos/spectral_ops.py +192 -0
  169. xinference/thirdparty/indextts/s2mel/modules/wavenet.py +174 -0
  170. xinference/thirdparty/indextts/s2mel/optimizers.py +96 -0
  171. xinference/thirdparty/indextts/s2mel/wav2vecbert_extract.py +148 -0
  172. xinference/thirdparty/indextts/utils/__init__.py +0 -0
  173. xinference/thirdparty/indextts/utils/arch_util.py +120 -0
  174. xinference/thirdparty/indextts/utils/checkpoint.py +34 -0
  175. xinference/thirdparty/indextts/utils/common.py +121 -0
  176. xinference/thirdparty/indextts/utils/feature_extractors.py +50 -0
  177. xinference/thirdparty/indextts/utils/front.py +536 -0
  178. xinference/thirdparty/indextts/utils/maskgct/models/codec/__init__.py +0 -0
  179. xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/codec.py +427 -0
  180. xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/quantize/__init__.py +11 -0
  181. xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/quantize/factorized_vector_quantize.py +150 -0
  182. xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/quantize/lookup_free_quantize.py +77 -0
  183. xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/quantize/residual_vq.py +177 -0
  184. xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/quantize/vector_quantize.py +401 -0
  185. xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/vocos.py +881 -0
  186. xinference/thirdparty/indextts/utils/maskgct/models/codec/codec_dataset.py +264 -0
  187. xinference/thirdparty/indextts/utils/maskgct/models/codec/codec_inference.py +515 -0
  188. xinference/thirdparty/indextts/utils/maskgct/models/codec/codec_sampler.py +126 -0
  189. xinference/thirdparty/indextts/utils/maskgct/models/codec/codec_trainer.py +166 -0
  190. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/__init__.py +0 -0
  191. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/alias_free_torch/__init__.py +5 -0
  192. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/alias_free_torch/act.py +29 -0
  193. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/alias_free_torch/filter.py +96 -0
  194. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/alias_free_torch/resample.py +57 -0
  195. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/facodec_dataset.py +98 -0
  196. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/facodec_inference.py +137 -0
  197. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/facodec_trainer.py +776 -0
  198. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/JDC/__init__.py +1 -0
  199. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/JDC/bst.t7 +0 -0
  200. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/JDC/model.py +219 -0
  201. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/attentions.py +437 -0
  202. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/commons.py +331 -0
  203. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/gradient_reversal.py +35 -0
  204. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/layers.py +460 -0
  205. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/quantize.py +741 -0
  206. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/style_encoder.py +110 -0
  207. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/wavenet.py +224 -0
  208. xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/optimizer.py +104 -0
  209. xinference/thirdparty/indextts/utils/maskgct/models/codec/kmeans/repcodec_model.py +210 -0
  210. xinference/thirdparty/indextts/utils/maskgct/models/codec/kmeans/vocos.py +850 -0
  211. xinference/thirdparty/indextts/utils/maskgct/models/codec/melvqgan/melspec.py +108 -0
  212. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/README.md +216 -0
  213. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/__init__.py +6 -0
  214. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/alias_free_torch/__init__.py +5 -0
  215. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/alias_free_torch/act.py +29 -0
  216. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/alias_free_torch/filter.py +96 -0
  217. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/alias_free_torch/resample.py +57 -0
  218. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/facodec.py +1222 -0
  219. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/gradient_reversal.py +35 -0
  220. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/melspec.py +102 -0
  221. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/quantize/__init__.py +7 -0
  222. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/quantize/fvq.py +116 -0
  223. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/quantize/rvq.py +87 -0
  224. xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/transformer.py +234 -0
  225. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/model.py +184 -0
  226. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/__init__.py +27 -0
  227. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/conv.py +346 -0
  228. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/lstm.py +46 -0
  229. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/norm.py +37 -0
  230. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/quantization/__init__.py +14 -0
  231. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/quantization/ac.py +317 -0
  232. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/quantization/core_vq.py +388 -0
  233. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/quantization/distrib.py +135 -0
  234. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/quantization/vq.py +125 -0
  235. xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/seanet.py +414 -0
  236. xinference/thirdparty/indextts/utils/maskgct/models/codec/vevo/vevo_repcodec.py +592 -0
  237. xinference/thirdparty/indextts/utils/maskgct/models/tts/maskgct/ckpt/wav2vec2bert_stats.pt +0 -0
  238. xinference/thirdparty/indextts/utils/maskgct/models/tts/maskgct/llama_nar.py +650 -0
  239. xinference/thirdparty/indextts/utils/maskgct/models/tts/maskgct/maskgct_s2a.py +503 -0
  240. xinference/thirdparty/indextts/utils/maskgct_utils.py +259 -0
  241. xinference/thirdparty/indextts/utils/text_utils.py +41 -0
  242. xinference/thirdparty/indextts/utils/typical_sampling.py +30 -0
  243. xinference/thirdparty/indextts/utils/utils.py +93 -0
  244. xinference/thirdparty/indextts/utils/webui_utils.py +42 -0
  245. xinference/thirdparty/indextts/utils/xtransformers.py +1247 -0
  246. xinference/thirdparty/indextts/vqvae/__init__.py +0 -0
  247. xinference/thirdparty/indextts/vqvae/xtts_dvae.py +395 -0
  248. xinference/ui/gradio/media_interface.py +66 -8
  249. xinference/ui/web/ui/build/asset-manifest.json +6 -6
  250. xinference/ui/web/ui/build/index.html +1 -1
  251. xinference/ui/web/ui/build/static/css/main.5ea97072.css +2 -0
  252. xinference/ui/web/ui/build/static/css/main.5ea97072.css.map +1 -0
  253. xinference/ui/web/ui/build/static/js/main.d192c4f3.js +3 -0
  254. xinference/ui/web/ui/build/static/js/{main.1086c759.js.LICENSE.txt → main.d192c4f3.js.LICENSE.txt} +0 -7
  255. xinference/ui/web/ui/build/static/js/main.d192c4f3.js.map +1 -0
  256. xinference/ui/web/ui/node_modules/.cache/babel-loader/089c38df5f52348d212ed868dda5c518a42e0c2762caed4175487c0405830c35.json +1 -0
  257. xinference/ui/web/ui/node_modules/.cache/babel-loader/2b6e3a5b6eb2c5c5f2d007e68cd46c372721cd52bf63508adcdb21ecf79241d8.json +1 -0
  258. xinference/ui/web/ui/node_modules/.cache/babel-loader/2d887825fd07a56f872eda4420da25fba0b5b62a23bdcc6c6da1a5281887f618.json +1 -0
  259. xinference/ui/web/ui/node_modules/.cache/babel-loader/4001f9c3e64e73a4f2158826650c174a59d5e3f89ddecddf17cbb6bb688cc4ca.json +1 -0
  260. xinference/ui/web/ui/node_modules/.cache/babel-loader/4a7018a69e6b7f90fc313248c2aa86f2a8f1eb1db120df586047a8023549b44b.json +1 -0
  261. xinference/ui/web/ui/node_modules/.cache/babel-loader/64b12aaa1c1d1bf53820ada8a63769067c0ccc5aab46b32348eb1917ae7f2a11.json +1 -0
  262. xinference/ui/web/ui/node_modules/.cache/babel-loader/7275b67c78ec76ce38a686bb8a576d8c9cecf54e1573614c84859d538efb9be5.json +1 -0
  263. xinference/ui/web/ui/node_modules/.cache/babel-loader/a68b6ee3b31eadc051fb95ce8f8ccb9c2e8b52c60f290dbab545a1917e065282.json +1 -0
  264. xinference/ui/web/ui/node_modules/.cache/babel-loader/ae8771cc37693feb160fa8727231312a0c54ef2d1d1ca893be568cd70016ca7e.json +1 -0
  265. xinference/ui/web/ui/node_modules/.cache/babel-loader/bb4e8722d2d41d87f1fce3661bc8937bffe9448e231fc5f0462630849e851592.json +1 -0
  266. xinference/ui/web/ui/node_modules/.cache/babel-loader/be6aada1ee4adc2bbf65dbe56d17db32bb3b5478be05d6b527805a8ba6cfb2b9.json +1 -0
  267. xinference/ui/web/ui/node_modules/.cache/babel-loader/de91c352653c233cf0cb6674e6e04049a44fd0e1156560de65d5c4620521391e.json +1 -0
  268. xinference/ui/web/ui/node_modules/.cache/babel-loader/e85f7002fc325c83b9c9cd8a1619e5b3ebc701d30e811afc284b88e6ae710cb5.json +1 -0
  269. xinference/ui/web/ui/node_modules/.cache/babel-loader/e8b603c78944bf3d213639078bfe155ff5c0dfa4048a93cbb967cad6a4eb4ff3.json +1 -0
  270. xinference/ui/web/ui/node_modules/.cache/babel-loader/f05535160a508b2a312de546a6de234776c613db276479ea4253c0b1bdeeb7d6.json +1 -0
  271. xinference/ui/web/ui/node_modules/.cache/babel-loader/f09ba9e11106bd59a0de10cc85c55084097729dcab575f43dfcf07375961ed87.json +1 -0
  272. xinference/ui/web/ui/node_modules/.cache/babel-loader/f995a2425dfb0822fd07127f66ffe9b026883bc156b402eb8bd0b83d52460a93.json +1 -0
  273. xinference/ui/web/ui/node_modules/.package-lock.json +0 -33
  274. xinference/ui/web/ui/package-lock.json +0 -34
  275. xinference/ui/web/ui/package.json +0 -1
  276. xinference/ui/web/ui/src/locales/en.json +9 -3
  277. xinference/ui/web/ui/src/locales/ja.json +9 -3
  278. xinference/ui/web/ui/src/locales/ko.json +9 -3
  279. xinference/ui/web/ui/src/locales/zh.json +9 -3
  280. {xinference-1.10.0.dist-info → xinference-1.10.1.dist-info}/METADATA +18 -2
  281. {xinference-1.10.0.dist-info → xinference-1.10.1.dist-info}/RECORD +285 -67
  282. xinference/ui/web/ui/build/static/css/main.013f296b.css +0 -2
  283. xinference/ui/web/ui/build/static/css/main.013f296b.css.map +0 -1
  284. xinference/ui/web/ui/build/static/js/main.1086c759.js +0 -3
  285. xinference/ui/web/ui/build/static/js/main.1086c759.js.map +0 -1
  286. xinference/ui/web/ui/node_modules/.cache/babel-loader/0b0f77000cc1b482ca091cfbcae511dfe02f08916971645fad21d0b1234d04a2.json +0 -1
  287. xinference/ui/web/ui/node_modules/.cache/babel-loader/1c5f8ff423a7c9202bea60b15680f04b1e9964b445b0da3f86c6ff70cf24e797.json +0 -1
  288. xinference/ui/web/ui/node_modules/.cache/babel-loader/44ce7993e344980e3ed4f13e8f69237d4a5dfc60e37ca6b54f51f8ee1357bd67.json +0 -1
  289. xinference/ui/web/ui/node_modules/.cache/babel-loader/4aec1cc414ac3ebb3481d3d915e4db597d9127de813291346eacb8554ab170d4.json +0 -1
  290. xinference/ui/web/ui/node_modules/.cache/babel-loader/644cfec52f3c57a6e222ce60f112237a1efefe9835efd9aad857a685f53d8eed.json +0 -1
  291. xinference/ui/web/ui/node_modules/.cache/babel-loader/663436f72af53fe0d72394f56d003fa4e0bba489e5bb4e483fd34b00f84637f7.json +0 -1
  292. xinference/ui/web/ui/node_modules/.cache/babel-loader/69db82ca9bfe27fe417cc6cf2b1716b09be9c6f0cd198530f12bfc60e801bbcf.json +0 -1
  293. xinference/ui/web/ui/node_modules/.cache/babel-loader/85087e27618d740c236bf159f30e0219db443ab55f0997388eed5fde6f9e90cc.json +0 -1
  294. xinference/ui/web/ui/node_modules/.cache/babel-loader/88b07838348864aa86c672be3bbca1e9f58f6f3a2881b32070ec27f4e7b449d1.json +0 -1
  295. xinference/ui/web/ui/node_modules/.cache/babel-loader/8b8cd408ccfbe115acef27ccfa5b233da8597131a2a5712add13e1e4d5d4504b.json +0 -1
  296. xinference/ui/web/ui/node_modules/.cache/babel-loader/a23824fe746b9c6ca5eee9159b5764d1ff1653c1d856288c0f75c742bbb0023b.json +0 -1
  297. xinference/ui/web/ui/node_modules/.cache/babel-loader/a3eb18af328280b139693c9092dff2a0ef8c9a967e6c8956ceee0996611f1984.json +0 -1
  298. xinference/ui/web/ui/node_modules/.cache/babel-loader/bc1aacc65a102db325ca61bcd2f681e1ae22c36a1f1d98a6ff5e4ad49dc7544f.json +0 -1
  299. xinference/ui/web/ui/node_modules/.cache/babel-loader/c682fd521747c19dae437d83ce3235a306ce6b68e24a117bc57c27ebb8d1f1ca.json +0 -1
  300. xinference/ui/web/ui/node_modules/.cache/babel-loader/d5c224be7081f18cba1678b7874a9782eba895df004874ff8f243f94ba79942a.json +0 -1
  301. xinference/ui/web/ui/node_modules/.cache/babel-loader/f7f18bfb539b036a6a342176dd98a85df5057a884a8da978d679f2a0264883d0.json +0 -1
  302. xinference/ui/web/ui/node_modules/clipboard/.babelrc.json +0 -11
  303. xinference/ui/web/ui/node_modules/clipboard/.eslintrc.json +0 -24
  304. xinference/ui/web/ui/node_modules/clipboard/.prettierrc.json +0 -9
  305. xinference/ui/web/ui/node_modules/clipboard/bower.json +0 -18
  306. xinference/ui/web/ui/node_modules/clipboard/composer.json +0 -25
  307. xinference/ui/web/ui/node_modules/clipboard/package.json +0 -63
  308. xinference/ui/web/ui/node_modules/delegate/package.json +0 -31
  309. xinference/ui/web/ui/node_modules/good-listener/bower.json +0 -11
  310. xinference/ui/web/ui/node_modules/good-listener/package.json +0 -35
  311. xinference/ui/web/ui/node_modules/select/bower.json +0 -13
  312. xinference/ui/web/ui/node_modules/select/package.json +0 -29
  313. xinference/ui/web/ui/node_modules/tiny-emitter/package.json +0 -53
  314. {xinference-1.10.0.dist-info → xinference-1.10.1.dist-info}/WHEEL +0 -0
  315. {xinference-1.10.0.dist-info → xinference-1.10.1.dist-info}/entry_points.txt +0 -0
  316. {xinference-1.10.0.dist-info → xinference-1.10.1.dist-info}/licenses/LICENSE +0 -0
  317. {xinference-1.10.0.dist-info → xinference-1.10.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,741 @@
1
+ # Copyright (c) 2023 Amphion.
2
+ #
3
+ # This source code is licensed under the MIT license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ from modules.dac.nn.quantize import ResidualVectorQuantize
7
+ from torch import nn
8
+ from .wavenet import WN
9
+ from .style_encoder import StyleEncoder
10
+ from .gradient_reversal import GradientReversal
11
+ import torch
12
+ import torchaudio
13
+ import torchaudio.functional as audio_F
14
+ import numpy as np
15
+ from ..alias_free_torch import *
16
+ from torch.nn.utils import weight_norm
17
+ from torch import nn, sin, pow
18
+ from einops.layers.torch import Rearrange
19
+ from modules.dac.model.encodec import SConv1d
20
+
21
+
22
+ def init_weights(m):
23
+ if isinstance(m, nn.Conv1d):
24
+ nn.init.trunc_normal_(m.weight, std=0.02)
25
+ nn.init.constant_(m.bias, 0)
26
+
27
+
28
+ def WNConv1d(*args, **kwargs):
29
+ return weight_norm(nn.Conv1d(*args, **kwargs))
30
+
31
+
32
+ def WNConvTranspose1d(*args, **kwargs):
33
+ return weight_norm(nn.ConvTranspose1d(*args, **kwargs))
34
+
35
+
36
+ class SnakeBeta(nn.Module):
37
+ """
38
+ A modified Snake function which uses separate parameters for the magnitude of the periodic components
39
+ Shape:
40
+ - Input: (B, C, T)
41
+ - Output: (B, C, T), same shape as the input
42
+ Parameters:
43
+ - alpha - trainable parameter that controls frequency
44
+ - beta - trainable parameter that controls magnitude
45
+ References:
46
+ - This activation function is a modified version based on this paper by Liu Ziyin, Tilman Hartwig, Masahito Ueda:
47
+ https://arxiv.org/abs/2006.08195
48
+ Examples:
49
+ >>> a1 = snakebeta(256)
50
+ >>> x = torch.randn(256)
51
+ >>> x = a1(x)
52
+ """
53
+
54
+ def __init__(
55
+ self, in_features, alpha=1.0, alpha_trainable=True, alpha_logscale=False
56
+ ):
57
+ """
58
+ Initialization.
59
+ INPUT:
60
+ - in_features: shape of the input
61
+ - alpha - trainable parameter that controls frequency
62
+ - beta - trainable parameter that controls magnitude
63
+ alpha is initialized to 1 by default, higher values = higher-frequency.
64
+ beta is initialized to 1 by default, higher values = higher-magnitude.
65
+ alpha will be trained along with the rest of your model.
66
+ """
67
+ super(SnakeBeta, self).__init__()
68
+ self.in_features = in_features
69
+
70
+ # initialize alpha
71
+ self.alpha_logscale = alpha_logscale
72
+ if self.alpha_logscale: # log scale alphas initialized to zeros
73
+ self.alpha = nn.Parameter(torch.zeros(in_features) * alpha)
74
+ self.beta = nn.Parameter(torch.zeros(in_features) * alpha)
75
+ else: # linear scale alphas initialized to ones
76
+ self.alpha = nn.Parameter(torch.ones(in_features) * alpha)
77
+ self.beta = nn.Parameter(torch.ones(in_features) * alpha)
78
+
79
+ self.alpha.requires_grad = alpha_trainable
80
+ self.beta.requires_grad = alpha_trainable
81
+
82
+ self.no_div_by_zero = 0.000000001
83
+
84
+ def forward(self, x):
85
+ """
86
+ Forward pass of the function.
87
+ Applies the function to the input elementwise.
88
+ SnakeBeta := x + 1/b * sin^2 (xa)
89
+ """
90
+ alpha = self.alpha.unsqueeze(0).unsqueeze(-1) # line up with x to [B, C, T]
91
+ beta = self.beta.unsqueeze(0).unsqueeze(-1)
92
+ if self.alpha_logscale:
93
+ alpha = torch.exp(alpha)
94
+ beta = torch.exp(beta)
95
+ x = x + (1.0 / (beta + self.no_div_by_zero)) * pow(sin(x * alpha), 2)
96
+
97
+ return x
98
+
99
+
100
+ class ResidualUnit(nn.Module):
101
+ def __init__(self, dim: int = 16, dilation: int = 1):
102
+ super().__init__()
103
+ pad = ((7 - 1) * dilation) // 2
104
+ self.block = nn.Sequential(
105
+ Activation1d(activation=SnakeBeta(dim, alpha_logscale=True)),
106
+ WNConv1d(dim, dim, kernel_size=7, dilation=dilation, padding=pad),
107
+ Activation1d(activation=SnakeBeta(dim, alpha_logscale=True)),
108
+ WNConv1d(dim, dim, kernel_size=1),
109
+ )
110
+
111
+ def forward(self, x):
112
+ return x + self.block(x)
113
+
114
+
115
+ class CNNLSTM(nn.Module):
116
+ def __init__(self, indim, outdim, head, global_pred=False):
117
+ super().__init__()
118
+ self.global_pred = global_pred
119
+ self.model = nn.Sequential(
120
+ ResidualUnit(indim, dilation=1),
121
+ ResidualUnit(indim, dilation=2),
122
+ ResidualUnit(indim, dilation=3),
123
+ Activation1d(activation=SnakeBeta(indim, alpha_logscale=True)),
124
+ Rearrange("b c t -> b t c"),
125
+ )
126
+ self.heads = nn.ModuleList([nn.Linear(indim, outdim) for i in range(head)])
127
+
128
+ def forward(self, x):
129
+ # x: [B, C, T]
130
+ x = self.model(x)
131
+ if self.global_pred:
132
+ x = torch.mean(x, dim=1, keepdim=False)
133
+ outs = [head(x) for head in self.heads]
134
+ return outs
135
+
136
+
137
+ def sequence_mask(length, max_length=None):
138
+ if max_length is None:
139
+ max_length = length.max()
140
+ x = torch.arange(max_length, dtype=length.dtype, device=length.device)
141
+ return x.unsqueeze(0) < length.unsqueeze(1)
142
+
143
+
144
+ class MFCC(nn.Module):
145
+ def __init__(self, n_mfcc=40, n_mels=80):
146
+ super(MFCC, self).__init__()
147
+ self.n_mfcc = n_mfcc
148
+ self.n_mels = n_mels
149
+ self.norm = "ortho"
150
+ dct_mat = audio_F.create_dct(self.n_mfcc, self.n_mels, self.norm)
151
+ self.register_buffer("dct_mat", dct_mat)
152
+
153
+ def forward(self, mel_specgram):
154
+ if len(mel_specgram.shape) == 2:
155
+ mel_specgram = mel_specgram.unsqueeze(0)
156
+ unsqueezed = True
157
+ else:
158
+ unsqueezed = False
159
+ # (channel, n_mels, time).tranpose(...) dot (n_mels, n_mfcc)
160
+ # -> (channel, time, n_mfcc).tranpose(...)
161
+ mfcc = torch.matmul(mel_specgram.transpose(1, 2), self.dct_mat).transpose(1, 2)
162
+
163
+ # unpack batch
164
+ if unsqueezed:
165
+ mfcc = mfcc.squeeze(0)
166
+ return mfcc
167
+
168
+
169
+ class FAquantizer(nn.Module):
170
+ def __init__(
171
+ self,
172
+ in_dim=1024,
173
+ n_p_codebooks=1,
174
+ n_c_codebooks=2,
175
+ n_t_codebooks=2,
176
+ n_r_codebooks=3,
177
+ codebook_size=1024,
178
+ codebook_dim=8,
179
+ quantizer_dropout=0.5,
180
+ causal=False,
181
+ separate_prosody_encoder=False,
182
+ timbre_norm=False,
183
+ ):
184
+ super(FAquantizer, self).__init__()
185
+ conv1d_type = SConv1d # if causal else nn.Conv1d
186
+ self.prosody_quantizer = ResidualVectorQuantize(
187
+ input_dim=in_dim,
188
+ n_codebooks=n_p_codebooks,
189
+ codebook_size=codebook_size,
190
+ codebook_dim=codebook_dim,
191
+ quantizer_dropout=quantizer_dropout,
192
+ )
193
+
194
+ self.content_quantizer = ResidualVectorQuantize(
195
+ input_dim=in_dim,
196
+ n_codebooks=n_c_codebooks,
197
+ codebook_size=codebook_size,
198
+ codebook_dim=codebook_dim,
199
+ quantizer_dropout=quantizer_dropout,
200
+ )
201
+
202
+ if not timbre_norm:
203
+ self.timbre_quantizer = ResidualVectorQuantize(
204
+ input_dim=in_dim,
205
+ n_codebooks=n_t_codebooks,
206
+ codebook_size=codebook_size,
207
+ codebook_dim=codebook_dim,
208
+ quantizer_dropout=quantizer_dropout,
209
+ )
210
+ else:
211
+ self.timbre_encoder = StyleEncoder(
212
+ in_dim=80, hidden_dim=512, out_dim=in_dim
213
+ )
214
+ self.timbre_linear = nn.Linear(1024, 1024 * 2)
215
+ self.timbre_linear.bias.data[:1024] = 1
216
+ self.timbre_linear.bias.data[1024:] = 0
217
+ self.timbre_norm = nn.LayerNorm(1024, elementwise_affine=False)
218
+
219
+ self.residual_quantizer = ResidualVectorQuantize(
220
+ input_dim=in_dim,
221
+ n_codebooks=n_r_codebooks,
222
+ codebook_size=codebook_size,
223
+ codebook_dim=codebook_dim,
224
+ quantizer_dropout=quantizer_dropout,
225
+ )
226
+
227
+ if separate_prosody_encoder:
228
+ self.melspec_linear = conv1d_type(
229
+ in_channels=20, out_channels=256, kernel_size=1, causal=causal
230
+ )
231
+ self.melspec_encoder = WN(
232
+ hidden_channels=256,
233
+ kernel_size=5,
234
+ dilation_rate=1,
235
+ n_layers=8,
236
+ gin_channels=0,
237
+ p_dropout=0.2,
238
+ causal=causal,
239
+ )
240
+ self.melspec_linear2 = conv1d_type(
241
+ in_channels=256, out_channels=1024, kernel_size=1, causal=causal
242
+ )
243
+ else:
244
+ pass
245
+ self.separate_prosody_encoder = separate_prosody_encoder
246
+
247
+ self.prob_random_mask_residual = 0.75
248
+
249
+ SPECT_PARAMS = {
250
+ "n_fft": 2048,
251
+ "win_length": 1200,
252
+ "hop_length": 300,
253
+ }
254
+ MEL_PARAMS = {
255
+ "n_mels": 80,
256
+ }
257
+
258
+ self.to_mel = torchaudio.transforms.MelSpectrogram(
259
+ n_mels=MEL_PARAMS["n_mels"], sample_rate=24000, **SPECT_PARAMS
260
+ )
261
+ self.mel_mean, self.mel_std = -4, 4
262
+ self.frame_rate = 24000 / 300
263
+ self.hop_length = 300
264
+
265
+ self.is_timbre_norm = timbre_norm
266
+ if timbre_norm:
267
+ self.forward = self.forward_v2
268
+
269
+ def preprocess(self, wave_tensor, n_bins=20):
270
+ mel_tensor = self.to_mel(wave_tensor.squeeze(1))
271
+ mel_tensor = (torch.log(1e-5 + mel_tensor) - self.mel_mean) / self.mel_std
272
+ return mel_tensor[:, :n_bins, : int(wave_tensor.size(-1) / self.hop_length)]
273
+
274
+ @torch.no_grad()
275
+ def decode(self, codes):
276
+ code_c, code_p, code_t = codes.split([1, 1, 2], dim=1)
277
+
278
+ z_c = self.content_quantizer.from_codes(code_c)[0]
279
+ z_p = self.prosody_quantizer.from_codes(code_p)[0]
280
+ z_t = self.timbre_quantizer.from_codes(code_t)[0]
281
+
282
+ z = z_c + z_p + z_t
283
+
284
+ return z, [z_c, z_p, z_t]
285
+
286
+ @torch.no_grad()
287
+ def encode(self, x, wave_segments, n_c=1):
288
+ outs = 0
289
+ if self.separate_prosody_encoder:
290
+ prosody_feature = self.preprocess(wave_segments)
291
+
292
+ f0_input = prosody_feature # (B, T, 20)
293
+ f0_input = self.melspec_linear(f0_input)
294
+ f0_input = self.melspec_encoder(
295
+ f0_input,
296
+ torch.ones(f0_input.shape[0], 1, f0_input.shape[2])
297
+ .to(f0_input.device)
298
+ .bool(),
299
+ )
300
+ f0_input = self.melspec_linear2(f0_input)
301
+
302
+ common_min_size = min(f0_input.size(2), x.size(2))
303
+ f0_input = f0_input[:, :, :common_min_size]
304
+
305
+ x = x[:, :, :common_min_size]
306
+
307
+ (
308
+ z_p,
309
+ codes_p,
310
+ latents_p,
311
+ commitment_loss_p,
312
+ codebook_loss_p,
313
+ ) = self.prosody_quantizer(f0_input, 1)
314
+ outs += z_p.detach()
315
+ else:
316
+ (
317
+ z_p,
318
+ codes_p,
319
+ latents_p,
320
+ commitment_loss_p,
321
+ codebook_loss_p,
322
+ ) = self.prosody_quantizer(x, 1)
323
+ outs += z_p.detach()
324
+
325
+ (
326
+ z_c,
327
+ codes_c,
328
+ latents_c,
329
+ commitment_loss_c,
330
+ codebook_loss_c,
331
+ ) = self.content_quantizer(x, n_c)
332
+ outs += z_c.detach()
333
+
334
+ timbre_residual_feature = x - z_p.detach() - z_c.detach()
335
+
336
+ (
337
+ z_t,
338
+ codes_t,
339
+ latents_t,
340
+ commitment_loss_t,
341
+ codebook_loss_t,
342
+ ) = self.timbre_quantizer(timbre_residual_feature, 2)
343
+ outs += z_t # we should not detach timbre
344
+
345
+ residual_feature = timbre_residual_feature - z_t
346
+
347
+ (
348
+ z_r,
349
+ codes_r,
350
+ latents_r,
351
+ commitment_loss_r,
352
+ codebook_loss_r,
353
+ ) = self.residual_quantizer(residual_feature, 3)
354
+
355
+ return [codes_c, codes_p, codes_t, codes_r], [z_c, z_p, z_t, z_r]
356
+
357
+ def forward(
358
+ self, x, wave_segments, noise_added_flags, recon_noisy_flags, n_c=2, n_t=2
359
+ ):
360
+ # timbre = self.timbre_encoder(mels, sequence_mask(mel_lens, mels.size(-1)).unsqueeze(1))
361
+ # timbre = self.timbre_encoder(mel_segments, torch.ones(mel_segments.size(0), 1, mel_segments.size(2)).bool().to(mel_segments.device))
362
+ outs = 0
363
+ if self.separate_prosody_encoder:
364
+ prosody_feature = self.preprocess(wave_segments)
365
+
366
+ f0_input = prosody_feature # (B, T, 20)
367
+ f0_input = self.melspec_linear(f0_input)
368
+ f0_input = self.melspec_encoder(
369
+ f0_input,
370
+ torch.ones(f0_input.shape[0], 1, f0_input.shape[2])
371
+ .to(f0_input.device)
372
+ .bool(),
373
+ )
374
+ f0_input = self.melspec_linear2(f0_input)
375
+
376
+ common_min_size = min(f0_input.size(2), x.size(2))
377
+ f0_input = f0_input[:, :, :common_min_size]
378
+
379
+ x = x[:, :, :common_min_size]
380
+
381
+ (
382
+ z_p,
383
+ codes_p,
384
+ latents_p,
385
+ commitment_loss_p,
386
+ codebook_loss_p,
387
+ ) = self.prosody_quantizer(f0_input, 1)
388
+ outs += z_p.detach()
389
+ else:
390
+ (
391
+ z_p,
392
+ codes_p,
393
+ latents_p,
394
+ commitment_loss_p,
395
+ codebook_loss_p,
396
+ ) = self.prosody_quantizer(x, 1)
397
+ outs += z_p.detach()
398
+
399
+ (
400
+ z_c,
401
+ codes_c,
402
+ latents_c,
403
+ commitment_loss_c,
404
+ codebook_loss_c,
405
+ ) = self.content_quantizer(x, n_c)
406
+ outs += z_c.detach()
407
+
408
+ timbre_residual_feature = x - z_p.detach() - z_c.detach()
409
+
410
+ (
411
+ z_t,
412
+ codes_t,
413
+ latents_t,
414
+ commitment_loss_t,
415
+ codebook_loss_t,
416
+ ) = self.timbre_quantizer(timbre_residual_feature, n_t)
417
+ outs += z_t # we should not detach timbre
418
+
419
+ residual_feature = timbre_residual_feature - z_t
420
+
421
+ (
422
+ z_r,
423
+ codes_r,
424
+ latents_r,
425
+ commitment_loss_r,
426
+ codebook_loss_r,
427
+ ) = self.residual_quantizer(residual_feature, 3)
428
+
429
+ bsz = z_r.shape[0]
430
+ res_mask = np.random.choice(
431
+ [0, 1],
432
+ size=bsz,
433
+ p=[
434
+ self.prob_random_mask_residual,
435
+ 1 - self.prob_random_mask_residual,
436
+ ],
437
+ )
438
+ res_mask = torch.from_numpy(res_mask).unsqueeze(1).unsqueeze(1) # (B, 1, 1)
439
+ res_mask = res_mask.to(device=z_r.device, dtype=z_r.dtype)
440
+ noise_must_on = noise_added_flags * recon_noisy_flags
441
+ noise_must_off = noise_added_flags * (~recon_noisy_flags)
442
+ res_mask[noise_must_on] = 1
443
+ res_mask[noise_must_off] = 0
444
+
445
+ outs += z_r * res_mask
446
+
447
+ quantized = [z_p, z_c, z_t, z_r]
448
+ commitment_losses = (
449
+ commitment_loss_p
450
+ + commitment_loss_c
451
+ + commitment_loss_t
452
+ + commitment_loss_r
453
+ )
454
+ codebook_losses = (
455
+ codebook_loss_p + codebook_loss_c + codebook_loss_t + codebook_loss_r
456
+ )
457
+
458
+ return outs, quantized, commitment_losses, codebook_losses
459
+
460
+ def forward_v2(
461
+ self,
462
+ x,
463
+ wave_segments,
464
+ n_c=1,
465
+ n_t=2,
466
+ full_waves=None,
467
+ wave_lens=None,
468
+ return_codes=False,
469
+ ):
470
+ # timbre = self.timbre_encoder(x, sequence_mask(mel_lens, mels.size(-1)).unsqueeze(1))
471
+ if full_waves is None:
472
+ mel = self.preprocess(wave_segments, n_bins=80)
473
+ timbre = self.timbre_encoder(
474
+ mel, torch.ones(mel.size(0), 1, mel.size(2)).bool().to(mel.device)
475
+ )
476
+ else:
477
+ mel = self.preprocess(full_waves, n_bins=80)
478
+ timbre = self.timbre_encoder(
479
+ mel,
480
+ sequence_mask(wave_lens // self.hop_length, mel.size(-1)).unsqueeze(1),
481
+ )
482
+ outs = 0
483
+ if self.separate_prosody_encoder:
484
+ prosody_feature = self.preprocess(wave_segments)
485
+
486
+ f0_input = prosody_feature # (B, T, 20)
487
+ f0_input = self.melspec_linear(f0_input)
488
+ f0_input = self.melspec_encoder(
489
+ f0_input,
490
+ torch.ones(f0_input.shape[0], 1, f0_input.shape[2])
491
+ .to(f0_input.device)
492
+ .bool(),
493
+ )
494
+ f0_input = self.melspec_linear2(f0_input)
495
+
496
+ common_min_size = min(f0_input.size(2), x.size(2))
497
+ f0_input = f0_input[:, :, :common_min_size]
498
+
499
+ x = x[:, :, :common_min_size]
500
+
501
+ (
502
+ z_p,
503
+ codes_p,
504
+ latents_p,
505
+ commitment_loss_p,
506
+ codebook_loss_p,
507
+ ) = self.prosody_quantizer(f0_input, 1)
508
+ outs += z_p.detach()
509
+ else:
510
+ (
511
+ z_p,
512
+ codes_p,
513
+ latents_p,
514
+ commitment_loss_p,
515
+ codebook_loss_p,
516
+ ) = self.prosody_quantizer(x, 1)
517
+ outs += z_p.detach()
518
+
519
+ (
520
+ z_c,
521
+ codes_c,
522
+ latents_c,
523
+ commitment_loss_c,
524
+ codebook_loss_c,
525
+ ) = self.content_quantizer(x, n_c)
526
+ outs += z_c.detach()
527
+
528
+ residual_feature = x - z_p.detach() - z_c.detach()
529
+
530
+ (
531
+ z_r,
532
+ codes_r,
533
+ latents_r,
534
+ commitment_loss_r,
535
+ codebook_loss_r,
536
+ ) = self.residual_quantizer(residual_feature, 3)
537
+
538
+ bsz = z_r.shape[0]
539
+ res_mask = np.random.choice(
540
+ [0, 1],
541
+ size=bsz,
542
+ p=[
543
+ self.prob_random_mask_residual,
544
+ 1 - self.prob_random_mask_residual,
545
+ ],
546
+ )
547
+ res_mask = torch.from_numpy(res_mask).unsqueeze(1).unsqueeze(1) # (B, 1, 1)
548
+ res_mask = res_mask.to(device=z_r.device, dtype=z_r.dtype)
549
+
550
+ if not self.training:
551
+ res_mask = torch.ones_like(res_mask)
552
+ outs += z_r * res_mask
553
+
554
+ quantized = [z_p, z_c, z_r]
555
+ codes = [codes_p, codes_c, codes_r]
556
+ commitment_losses = commitment_loss_p + commitment_loss_c + commitment_loss_r
557
+ codebook_losses = codebook_loss_p + codebook_loss_c + codebook_loss_r
558
+
559
+ style = self.timbre_linear(timbre).unsqueeze(2) # (B, 2d, 1)
560
+ gamma, beta = style.chunk(2, 1) # (B, d, 1)
561
+ outs = outs.transpose(1, 2)
562
+ outs = self.timbre_norm(outs)
563
+ outs = outs.transpose(1, 2)
564
+ outs = outs * gamma + beta
565
+
566
+ if return_codes:
567
+ return outs, quantized, commitment_losses, codebook_losses, timbre, codes
568
+ else:
569
+ return outs, quantized, commitment_losses, codebook_losses, timbre
570
+
571
+ def voice_conversion(self, z, ref_wave):
572
+ ref_mel = self.preprocess(ref_wave, n_bins=80)
573
+ ref_timbre = self.timbre_encoder(
574
+ ref_mel,
575
+ sequence_mask(
576
+ torch.LongTensor([ref_wave.size(-1)]).to(z.device) // self.hop_length,
577
+ ref_mel.size(-1),
578
+ ).unsqueeze(1),
579
+ )
580
+ style = self.timbre_linear(ref_timbre).unsqueeze(2) # (B, 2d, 1)
581
+ gamma, beta = style.chunk(2, 1) # (B, d, 1)
582
+ outs = z.transpose(1, 2)
583
+ outs = self.timbre_norm(outs)
584
+ outs = outs.transpose(1, 2)
585
+ outs = outs * gamma + beta
586
+
587
+ return outs
588
+
589
+
590
+ class FApredictors(nn.Module):
591
+ def __init__(
592
+ self,
593
+ in_dim=1024,
594
+ use_gr_content_f0=False,
595
+ use_gr_prosody_phone=False,
596
+ use_gr_residual_f0=False,
597
+ use_gr_residual_phone=False,
598
+ use_gr_timbre_content=True,
599
+ use_gr_timbre_prosody=True,
600
+ use_gr_x_timbre=False,
601
+ norm_f0=True,
602
+ timbre_norm=False,
603
+ use_gr_content_global_f0=False,
604
+ ):
605
+ super(FApredictors, self).__init__()
606
+ self.f0_predictor = CNNLSTM(in_dim, 1, 2)
607
+ self.phone_predictor = CNNLSTM(in_dim, 1024, 1)
608
+ if timbre_norm:
609
+ self.timbre_predictor = nn.Linear(in_dim, 20000)
610
+ else:
611
+ self.timbre_predictor = CNNLSTM(in_dim, 20000, 1, global_pred=True)
612
+
613
+ self.use_gr_content_f0 = use_gr_content_f0
614
+ self.use_gr_prosody_phone = use_gr_prosody_phone
615
+ self.use_gr_residual_f0 = use_gr_residual_f0
616
+ self.use_gr_residual_phone = use_gr_residual_phone
617
+ self.use_gr_timbre_content = use_gr_timbre_content
618
+ self.use_gr_timbre_prosody = use_gr_timbre_prosody
619
+ self.use_gr_x_timbre = use_gr_x_timbre
620
+
621
+ self.rev_f0_predictor = nn.Sequential(
622
+ GradientReversal(alpha=1.0), CNNLSTM(in_dim, 1, 2)
623
+ )
624
+ self.rev_content_predictor = nn.Sequential(
625
+ GradientReversal(alpha=1.0), CNNLSTM(in_dim, 1024, 1)
626
+ )
627
+ self.rev_timbre_predictor = nn.Sequential(
628
+ GradientReversal(alpha=1.0), CNNLSTM(in_dim, 20000, 1, global_pred=True)
629
+ )
630
+
631
+ self.norm_f0 = norm_f0
632
+ self.timbre_norm = timbre_norm
633
+ if timbre_norm:
634
+ self.forward = self.forward_v2
635
+ self.global_f0_predictor = nn.Linear(in_dim, 1)
636
+
637
+ self.use_gr_content_global_f0 = use_gr_content_global_f0
638
+ if use_gr_content_global_f0:
639
+ self.rev_global_f0_predictor = nn.Sequential(
640
+ GradientReversal(alpha=1.0), CNNLSTM(in_dim, 1, 1, global_pred=True)
641
+ )
642
+
643
+ def forward(self, quantized):
644
+ prosody_latent = quantized[0]
645
+ content_latent = quantized[1]
646
+ timbre_latent = quantized[2]
647
+ residual_latent = quantized[3]
648
+ content_pred = self.phone_predictor(content_latent)[0]
649
+
650
+ if self.norm_f0:
651
+ spk_pred = self.timbre_predictor(timbre_latent)[0]
652
+ f0_pred, uv_pred = self.f0_predictor(prosody_latent)
653
+ else:
654
+ spk_pred = self.timbre_predictor(timbre_latent + prosody_latent)[0]
655
+ f0_pred, uv_pred = self.f0_predictor(prosody_latent + timbre_latent)
656
+
657
+ prosody_rev_latent = torch.zeros_like(quantized[0])
658
+ if self.use_gr_content_f0:
659
+ prosody_rev_latent += quantized[1]
660
+ if self.use_gr_timbre_prosody:
661
+ prosody_rev_latent += quantized[2]
662
+ if self.use_gr_residual_f0:
663
+ prosody_rev_latent += quantized[3]
664
+ rev_f0_pred, rev_uv_pred = self.rev_f0_predictor(prosody_rev_latent)
665
+
666
+ content_rev_latent = torch.zeros_like(quantized[1])
667
+ if self.use_gr_prosody_phone:
668
+ content_rev_latent += quantized[0]
669
+ if self.use_gr_timbre_content:
670
+ content_rev_latent += quantized[2]
671
+ if self.use_gr_residual_phone:
672
+ content_rev_latent += quantized[3]
673
+ rev_content_pred = self.rev_content_predictor(content_rev_latent)[0]
674
+
675
+ if self.norm_f0:
676
+ timbre_rev_latent = quantized[0] + quantized[1] + quantized[3]
677
+ else:
678
+ timbre_rev_latent = quantized[1] + quantized[3]
679
+ if self.use_gr_x_timbre:
680
+ x_spk_pred = self.rev_timbre_predictor(timbre_rev_latent)[0]
681
+ else:
682
+ x_spk_pred = None
683
+
684
+ preds = {
685
+ "f0": f0_pred,
686
+ "uv": uv_pred,
687
+ "content": content_pred,
688
+ "timbre": spk_pred,
689
+ }
690
+
691
+ rev_preds = {
692
+ "rev_f0": rev_f0_pred,
693
+ "rev_uv": rev_uv_pred,
694
+ "rev_content": rev_content_pred,
695
+ "x_timbre": x_spk_pred,
696
+ }
697
+ return preds, rev_preds
698
+
699
+ def forward_v2(self, quantized, timbre):
700
+ prosody_latent = quantized[0]
701
+ content_latent = quantized[1]
702
+ residual_latent = quantized[2]
703
+ content_pred = self.phone_predictor(content_latent)[0]
704
+
705
+ spk_pred = self.timbre_predictor(timbre)
706
+ f0_pred, uv_pred = self.f0_predictor(prosody_latent)
707
+
708
+ prosody_rev_latent = torch.zeros_like(prosody_latent)
709
+ if self.use_gr_content_f0:
710
+ prosody_rev_latent += content_latent
711
+ if self.use_gr_residual_f0:
712
+ prosody_rev_latent += residual_latent
713
+ rev_f0_pred, rev_uv_pred = self.rev_f0_predictor(prosody_rev_latent)
714
+
715
+ content_rev_latent = torch.zeros_like(content_latent)
716
+ if self.use_gr_prosody_phone:
717
+ content_rev_latent += prosody_latent
718
+ if self.use_gr_residual_phone:
719
+ content_rev_latent += residual_latent
720
+ rev_content_pred = self.rev_content_predictor(content_rev_latent)[0]
721
+
722
+ timbre_rev_latent = prosody_latent + content_latent + residual_latent
723
+ if self.use_gr_x_timbre:
724
+ x_spk_pred = self.rev_timbre_predictor(timbre_rev_latent)[0]
725
+ else:
726
+ x_spk_pred = None
727
+
728
+ preds = {
729
+ "f0": f0_pred,
730
+ "uv": uv_pred,
731
+ "content": content_pred,
732
+ "timbre": spk_pred,
733
+ }
734
+
735
+ rev_preds = {
736
+ "rev_f0": rev_f0_pred,
737
+ "rev_uv": rev_uv_pred,
738
+ "rev_content": rev_content_pred,
739
+ "x_timbre": x_spk_pred,
740
+ }
741
+ return preds, rev_preds