xinference 1.10.0__py3-none-any.whl → 1.11.0__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.
- xinference/_version.py +3 -3
- xinference/api/restful_api.py +473 -31
- xinference/client/restful/async_restful_client.py +178 -8
- xinference/client/restful/restful_client.py +151 -3
- xinference/core/supervisor.py +99 -53
- xinference/core/worker.py +10 -0
- xinference/deploy/cmdline.py +15 -0
- xinference/model/audio/core.py +21 -6
- xinference/model/audio/indextts2.py +166 -0
- xinference/model/audio/model_spec.json +58 -21
- xinference/model/image/model_spec.json +159 -90
- xinference/model/image/stable_diffusion/core.py +13 -4
- xinference/model/llm/__init__.py +6 -2
- xinference/model/llm/llm_family.json +1299 -174
- xinference/model/llm/mlx/distributed_models/core.py +41 -0
- xinference/model/llm/mlx/distributed_models/qwen2.py +1 -2
- xinference/model/llm/sglang/core.py +44 -11
- xinference/model/llm/tool_parsers/deepseek_r1_tool_parser.py +94 -32
- xinference/model/llm/tool_parsers/qwen_tool_parser.py +29 -4
- xinference/model/llm/transformers/chatglm.py +3 -0
- xinference/model/llm/transformers/core.py +129 -36
- xinference/model/llm/transformers/multimodal/minicpmv45.py +340 -0
- xinference/model/llm/transformers/multimodal/qwen2_vl.py +34 -8
- xinference/model/llm/transformers/utils.py +23 -0
- xinference/model/llm/utils.py +48 -32
- xinference/model/llm/vllm/core.py +207 -72
- xinference/model/utils.py +74 -31
- xinference/thirdparty/audiotools/__init__.py +10 -0
- xinference/thirdparty/audiotools/core/__init__.py +4 -0
- xinference/thirdparty/audiotools/core/audio_signal.py +1682 -0
- xinference/thirdparty/audiotools/core/display.py +194 -0
- xinference/thirdparty/audiotools/core/dsp.py +390 -0
- xinference/thirdparty/audiotools/core/effects.py +647 -0
- xinference/thirdparty/audiotools/core/ffmpeg.py +211 -0
- xinference/thirdparty/audiotools/core/loudness.py +320 -0
- xinference/thirdparty/audiotools/core/playback.py +252 -0
- xinference/thirdparty/audiotools/core/templates/__init__.py +0 -0
- xinference/thirdparty/audiotools/core/templates/headers.html +322 -0
- xinference/thirdparty/audiotools/core/templates/pandoc.css +407 -0
- xinference/thirdparty/audiotools/core/templates/widget.html +52 -0
- xinference/thirdparty/audiotools/core/util.py +671 -0
- xinference/thirdparty/audiotools/core/whisper.py +97 -0
- xinference/thirdparty/audiotools/data/__init__.py +3 -0
- xinference/thirdparty/audiotools/data/datasets.py +517 -0
- xinference/thirdparty/audiotools/data/preprocess.py +81 -0
- xinference/thirdparty/audiotools/data/transforms.py +1592 -0
- xinference/thirdparty/audiotools/metrics/__init__.py +6 -0
- xinference/thirdparty/audiotools/metrics/distance.py +131 -0
- xinference/thirdparty/audiotools/metrics/quality.py +159 -0
- xinference/thirdparty/audiotools/metrics/spectral.py +247 -0
- xinference/thirdparty/audiotools/ml/__init__.py +5 -0
- xinference/thirdparty/audiotools/ml/accelerator.py +184 -0
- xinference/thirdparty/audiotools/ml/decorators.py +440 -0
- xinference/thirdparty/audiotools/ml/experiment.py +90 -0
- xinference/thirdparty/audiotools/ml/layers/__init__.py +2 -0
- xinference/thirdparty/audiotools/ml/layers/base.py +328 -0
- xinference/thirdparty/audiotools/ml/layers/spectral_gate.py +127 -0
- xinference/thirdparty/audiotools/post.py +140 -0
- xinference/thirdparty/audiotools/preference.py +600 -0
- xinference/thirdparty/fish_speech/fish_speech/text/chn_text_norm/text.py +1 -1
- xinference/thirdparty/indextts/BigVGAN/ECAPA_TDNN.py +656 -0
- xinference/thirdparty/indextts/BigVGAN/__init__.py +0 -0
- xinference/thirdparty/indextts/BigVGAN/activations.py +122 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/__init__.py +0 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/.gitignore +1 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/__init__.py +0 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/activation1d.py +76 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/anti_alias_activation.cpp +23 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/anti_alias_activation_cuda.cu +256 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/compat.h +29 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/load.py +121 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/cuda/type_shim.h +92 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/torch/__init__.py +6 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/torch/act.py +31 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/torch/filter.py +102 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_activation/torch/resample.py +58 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_torch/__init__.py +6 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_torch/act.py +29 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_torch/filter.py +96 -0
- xinference/thirdparty/indextts/BigVGAN/alias_free_torch/resample.py +49 -0
- xinference/thirdparty/indextts/BigVGAN/bigvgan.py +534 -0
- xinference/thirdparty/indextts/BigVGAN/models.py +451 -0
- xinference/thirdparty/indextts/BigVGAN/nnet/CNN.py +546 -0
- xinference/thirdparty/indextts/BigVGAN/nnet/__init__.py +0 -0
- xinference/thirdparty/indextts/BigVGAN/nnet/linear.py +89 -0
- xinference/thirdparty/indextts/BigVGAN/nnet/normalization.py +670 -0
- xinference/thirdparty/indextts/BigVGAN/utils.py +101 -0
- xinference/thirdparty/indextts/__init__.py +0 -0
- xinference/thirdparty/indextts/cli.py +65 -0
- xinference/thirdparty/indextts/gpt/__init__.py +0 -0
- xinference/thirdparty/indextts/gpt/conformer/__init__.py +0 -0
- xinference/thirdparty/indextts/gpt/conformer/attention.py +312 -0
- xinference/thirdparty/indextts/gpt/conformer/embedding.py +163 -0
- xinference/thirdparty/indextts/gpt/conformer/subsampling.py +348 -0
- xinference/thirdparty/indextts/gpt/conformer_encoder.py +520 -0
- xinference/thirdparty/indextts/gpt/model.py +713 -0
- xinference/thirdparty/indextts/gpt/model_v2.py +747 -0
- xinference/thirdparty/indextts/gpt/perceiver.py +317 -0
- xinference/thirdparty/indextts/gpt/transformers_beam_search.py +1013 -0
- xinference/thirdparty/indextts/gpt/transformers_generation_utils.py +4747 -0
- xinference/thirdparty/indextts/gpt/transformers_gpt2.py +1878 -0
- xinference/thirdparty/indextts/gpt/transformers_modeling_utils.py +5525 -0
- xinference/thirdparty/indextts/infer.py +690 -0
- xinference/thirdparty/indextts/infer_v2.py +739 -0
- xinference/thirdparty/indextts/s2mel/dac/__init__.py +16 -0
- xinference/thirdparty/indextts/s2mel/dac/__main__.py +36 -0
- xinference/thirdparty/indextts/s2mel/dac/model/__init__.py +4 -0
- xinference/thirdparty/indextts/s2mel/dac/model/base.py +294 -0
- xinference/thirdparty/indextts/s2mel/dac/model/dac.py +400 -0
- xinference/thirdparty/indextts/s2mel/dac/model/discriminator.py +228 -0
- xinference/thirdparty/indextts/s2mel/dac/model/encodec.py +320 -0
- xinference/thirdparty/indextts/s2mel/dac/nn/__init__.py +3 -0
- xinference/thirdparty/indextts/s2mel/dac/nn/layers.py +33 -0
- xinference/thirdparty/indextts/s2mel/dac/nn/loss.py +368 -0
- xinference/thirdparty/indextts/s2mel/dac/nn/quantize.py +339 -0
- xinference/thirdparty/indextts/s2mel/dac/utils/__init__.py +123 -0
- xinference/thirdparty/indextts/s2mel/dac/utils/decode.py +95 -0
- xinference/thirdparty/indextts/s2mel/dac/utils/encode.py +94 -0
- xinference/thirdparty/indextts/s2mel/hf_utils.py +12 -0
- xinference/thirdparty/indextts/s2mel/modules/alias_free_torch/__init__.py +5 -0
- xinference/thirdparty/indextts/s2mel/modules/alias_free_torch/act.py +29 -0
- xinference/thirdparty/indextts/s2mel/modules/alias_free_torch/filter.py +96 -0
- xinference/thirdparty/indextts/s2mel/modules/alias_free_torch/resample.py +57 -0
- xinference/thirdparty/indextts/s2mel/modules/audio.py +82 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/activations.py +120 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/__init__.py +0 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/activation1d.py +77 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/anti_alias_activation.cpp +23 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/anti_alias_activation_cuda.cu +246 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/compat.h +29 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/load.py +86 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/cuda/type_shim.h +92 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/torch/__init__.py +6 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/torch/act.py +30 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/torch/filter.py +101 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/alias_free_activation/torch/resample.py +58 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/bigvgan.py +492 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/config.json +63 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/env.py +18 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/meldataset.py +354 -0
- xinference/thirdparty/indextts/s2mel/modules/bigvgan/utils.py +99 -0
- xinference/thirdparty/indextts/s2mel/modules/campplus/DTDNN.py +115 -0
- xinference/thirdparty/indextts/s2mel/modules/campplus/classifier.py +70 -0
- xinference/thirdparty/indextts/s2mel/modules/campplus/layers.py +253 -0
- xinference/thirdparty/indextts/s2mel/modules/commons.py +632 -0
- xinference/thirdparty/indextts/s2mel/modules/diffusion_transformer.py +257 -0
- xinference/thirdparty/indextts/s2mel/modules/encodec.py +292 -0
- xinference/thirdparty/indextts/s2mel/modules/flow_matching.py +171 -0
- xinference/thirdparty/indextts/s2mel/modules/gpt_fast/generate.py +436 -0
- xinference/thirdparty/indextts/s2mel/modules/gpt_fast/model.py +360 -0
- xinference/thirdparty/indextts/s2mel/modules/gpt_fast/quantize.py +622 -0
- xinference/thirdparty/indextts/s2mel/modules/hifigan/f0_predictor.py +55 -0
- xinference/thirdparty/indextts/s2mel/modules/hifigan/generator.py +454 -0
- xinference/thirdparty/indextts/s2mel/modules/layers.py +354 -0
- xinference/thirdparty/indextts/s2mel/modules/length_regulator.py +141 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/__init__.py +0 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/api.py +186 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/attentions.py +465 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/checkpoints_v2/converter/config.json +57 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/commons.py +160 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/mel_processing.py +183 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/models.py +499 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/modules.py +598 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/openvoice_app.py +275 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/se_extractor.py +153 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/transforms.py +209 -0
- xinference/thirdparty/indextts/s2mel/modules/openvoice/utils.py +194 -0
- xinference/thirdparty/indextts/s2mel/modules/quantize.py +229 -0
- xinference/thirdparty/indextts/s2mel/modules/rmvpe.py +631 -0
- xinference/thirdparty/indextts/s2mel/modules/vocos/__init__.py +4 -0
- xinference/thirdparty/indextts/s2mel/modules/vocos/heads.py +164 -0
- xinference/thirdparty/indextts/s2mel/modules/vocos/helpers.py +71 -0
- xinference/thirdparty/indextts/s2mel/modules/vocos/loss.py +114 -0
- xinference/thirdparty/indextts/s2mel/modules/vocos/models.py +118 -0
- xinference/thirdparty/indextts/s2mel/modules/vocos/modules.py +213 -0
- xinference/thirdparty/indextts/s2mel/modules/vocos/pretrained.py +51 -0
- xinference/thirdparty/indextts/s2mel/modules/vocos/spectral_ops.py +192 -0
- xinference/thirdparty/indextts/s2mel/modules/wavenet.py +174 -0
- xinference/thirdparty/indextts/s2mel/optimizers.py +96 -0
- xinference/thirdparty/indextts/s2mel/wav2vecbert_extract.py +148 -0
- xinference/thirdparty/indextts/utils/__init__.py +0 -0
- xinference/thirdparty/indextts/utils/arch_util.py +120 -0
- xinference/thirdparty/indextts/utils/checkpoint.py +34 -0
- xinference/thirdparty/indextts/utils/common.py +121 -0
- xinference/thirdparty/indextts/utils/feature_extractors.py +50 -0
- xinference/thirdparty/indextts/utils/front.py +536 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/__init__.py +0 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/codec.py +427 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/quantize/__init__.py +11 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/quantize/factorized_vector_quantize.py +150 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/quantize/lookup_free_quantize.py +77 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/quantize/residual_vq.py +177 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/quantize/vector_quantize.py +401 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/amphion_codec/vocos.py +881 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/codec_dataset.py +264 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/codec_inference.py +515 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/codec_sampler.py +126 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/codec_trainer.py +166 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/__init__.py +0 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/alias_free_torch/__init__.py +5 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/alias_free_torch/act.py +29 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/alias_free_torch/filter.py +96 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/alias_free_torch/resample.py +57 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/facodec_dataset.py +98 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/facodec_inference.py +137 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/facodec_trainer.py +776 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/JDC/__init__.py +1 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/JDC/bst.t7 +0 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/JDC/model.py +219 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/attentions.py +437 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/commons.py +331 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/gradient_reversal.py +35 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/layers.py +460 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/quantize.py +741 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/style_encoder.py +110 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/modules/wavenet.py +224 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/facodec/optimizer.py +104 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/kmeans/repcodec_model.py +210 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/kmeans/vocos.py +850 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/melvqgan/melspec.py +108 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/README.md +216 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/__init__.py +6 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/alias_free_torch/__init__.py +5 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/alias_free_torch/act.py +29 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/alias_free_torch/filter.py +96 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/alias_free_torch/resample.py +57 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/facodec.py +1222 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/gradient_reversal.py +35 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/melspec.py +102 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/quantize/__init__.py +7 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/quantize/fvq.py +116 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/quantize/rvq.py +87 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/ns3_codec/transformer.py +234 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/model.py +184 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/__init__.py +27 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/conv.py +346 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/lstm.py +46 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/norm.py +37 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/quantization/__init__.py +14 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/quantization/ac.py +317 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/quantization/core_vq.py +388 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/quantization/distrib.py +135 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/quantization/vq.py +125 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/speechtokenizer/modules/seanet.py +414 -0
- xinference/thirdparty/indextts/utils/maskgct/models/codec/vevo/vevo_repcodec.py +592 -0
- xinference/thirdparty/indextts/utils/maskgct/models/tts/maskgct/ckpt/wav2vec2bert_stats.pt +0 -0
- xinference/thirdparty/indextts/utils/maskgct/models/tts/maskgct/llama_nar.py +650 -0
- xinference/thirdparty/indextts/utils/maskgct/models/tts/maskgct/maskgct_s2a.py +503 -0
- xinference/thirdparty/indextts/utils/maskgct_utils.py +259 -0
- xinference/thirdparty/indextts/utils/text_utils.py +41 -0
- xinference/thirdparty/indextts/utils/typical_sampling.py +30 -0
- xinference/thirdparty/indextts/utils/utils.py +93 -0
- xinference/thirdparty/indextts/utils/webui_utils.py +42 -0
- xinference/thirdparty/indextts/utils/xtransformers.py +1247 -0
- xinference/thirdparty/indextts/vqvae/__init__.py +0 -0
- xinference/thirdparty/indextts/vqvae/xtts_dvae.py +395 -0
- xinference/thirdparty/melo/text/chinese_mix.py +2 -2
- xinference/types.py +9 -0
- xinference/ui/gradio/media_interface.py +66 -8
- xinference/ui/web/ui/build/asset-manifest.json +6 -6
- xinference/ui/web/ui/build/index.html +1 -1
- xinference/ui/web/ui/build/static/css/main.5ea97072.css +2 -0
- xinference/ui/web/ui/build/static/css/main.5ea97072.css.map +1 -0
- xinference/ui/web/ui/build/static/js/main.45e78536.js +3 -0
- xinference/ui/web/ui/build/static/js/{main.1086c759.js.LICENSE.txt → main.45e78536.js.LICENSE.txt} +0 -7
- xinference/ui/web/ui/build/static/js/main.45e78536.js.map +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/089c38df5f52348d212ed868dda5c518a42e0c2762caed4175487c0405830c35.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/2b6e3a5b6eb2c5c5f2d007e68cd46c372721cd52bf63508adcdb21ecf79241d8.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/2d887825fd07a56f872eda4420da25fba0b5b62a23bdcc6c6da1a5281887f618.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/4001f9c3e64e73a4f2158826650c174a59d5e3f89ddecddf17cbb6bb688cc4ca.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/4a7018a69e6b7f90fc313248c2aa86f2a8f1eb1db120df586047a8023549b44b.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/64b12aaa1c1d1bf53820ada8a63769067c0ccc5aab46b32348eb1917ae7f2a11.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/7275b67c78ec76ce38a686bb8a576d8c9cecf54e1573614c84859d538efb9be5.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/a68b6ee3b31eadc051fb95ce8f8ccb9c2e8b52c60f290dbab545a1917e065282.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/ae8771cc37693feb160fa8727231312a0c54ef2d1d1ca893be568cd70016ca7e.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/bb4e8722d2d41d87f1fce3661bc8937bffe9448e231fc5f0462630849e851592.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/be6aada1ee4adc2bbf65dbe56d17db32bb3b5478be05d6b527805a8ba6cfb2b9.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/de91c352653c233cf0cb6674e6e04049a44fd0e1156560de65d5c4620521391e.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/e85f7002fc325c83b9c9cd8a1619e5b3ebc701d30e811afc284b88e6ae710cb5.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/e8b603c78944bf3d213639078bfe155ff5c0dfa4048a93cbb967cad6a4eb4ff3.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/ea2a26361204e70cf1018d6990fb6354bed82b3ac69690391e0f100385e7abb7.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/f05535160a508b2a312de546a6de234776c613db276479ea4253c0b1bdeeb7d6.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/f09ba9e11106bd59a0de10cc85c55084097729dcab575f43dfcf07375961ed87.json +1 -0
- xinference/ui/web/ui/node_modules/.package-lock.json +0 -33
- xinference/ui/web/ui/package-lock.json +0 -34
- xinference/ui/web/ui/package.json +0 -1
- xinference/ui/web/ui/src/locales/en.json +9 -3
- xinference/ui/web/ui/src/locales/ja.json +9 -3
- xinference/ui/web/ui/src/locales/ko.json +9 -3
- xinference/ui/web/ui/src/locales/zh.json +9 -3
- {xinference-1.10.0.dist-info → xinference-1.11.0.dist-info}/METADATA +24 -6
- {xinference-1.10.0.dist-info → xinference-1.11.0.dist-info}/RECORD +296 -77
- xinference/ui/web/ui/build/static/css/main.013f296b.css +0 -2
- xinference/ui/web/ui/build/static/css/main.013f296b.css.map +0 -1
- xinference/ui/web/ui/build/static/js/main.1086c759.js +0 -3
- xinference/ui/web/ui/build/static/js/main.1086c759.js.map +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/0b0f77000cc1b482ca091cfbcae511dfe02f08916971645fad21d0b1234d04a2.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/1c5f8ff423a7c9202bea60b15680f04b1e9964b445b0da3f86c6ff70cf24e797.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/44ce7993e344980e3ed4f13e8f69237d4a5dfc60e37ca6b54f51f8ee1357bd67.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/4aec1cc414ac3ebb3481d3d915e4db597d9127de813291346eacb8554ab170d4.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/644cfec52f3c57a6e222ce60f112237a1efefe9835efd9aad857a685f53d8eed.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/663436f72af53fe0d72394f56d003fa4e0bba489e5bb4e483fd34b00f84637f7.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/69db82ca9bfe27fe417cc6cf2b1716b09be9c6f0cd198530f12bfc60e801bbcf.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/85087e27618d740c236bf159f30e0219db443ab55f0997388eed5fde6f9e90cc.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/88b07838348864aa86c672be3bbca1e9f58f6f3a2881b32070ec27f4e7b449d1.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/8b8cd408ccfbe115acef27ccfa5b233da8597131a2a5712add13e1e4d5d4504b.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/a23824fe746b9c6ca5eee9159b5764d1ff1653c1d856288c0f75c742bbb0023b.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/a3eb18af328280b139693c9092dff2a0ef8c9a967e6c8956ceee0996611f1984.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/bc1aacc65a102db325ca61bcd2f681e1ae22c36a1f1d98a6ff5e4ad49dc7544f.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/c682fd521747c19dae437d83ce3235a306ce6b68e24a117bc57c27ebb8d1f1ca.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/d5c224be7081f18cba1678b7874a9782eba895df004874ff8f243f94ba79942a.json +0 -1
- xinference/ui/web/ui/node_modules/.cache/babel-loader/f7f18bfb539b036a6a342176dd98a85df5057a884a8da978d679f2a0264883d0.json +0 -1
- xinference/ui/web/ui/node_modules/clipboard/.babelrc.json +0 -11
- xinference/ui/web/ui/node_modules/clipboard/.eslintrc.json +0 -24
- xinference/ui/web/ui/node_modules/clipboard/.prettierrc.json +0 -9
- xinference/ui/web/ui/node_modules/clipboard/bower.json +0 -18
- xinference/ui/web/ui/node_modules/clipboard/composer.json +0 -25
- xinference/ui/web/ui/node_modules/clipboard/package.json +0 -63
- xinference/ui/web/ui/node_modules/delegate/package.json +0 -31
- xinference/ui/web/ui/node_modules/good-listener/bower.json +0 -11
- xinference/ui/web/ui/node_modules/good-listener/package.json +0 -35
- xinference/ui/web/ui/node_modules/select/bower.json +0 -13
- xinference/ui/web/ui/node_modules/select/package.json +0 -29
- xinference/ui/web/ui/node_modules/tiny-emitter/package.json +0 -53
- {xinference-1.10.0.dist-info → xinference-1.11.0.dist-info}/WHEEL +0 -0
- {xinference-1.10.0.dist-info → xinference-1.11.0.dist-info}/entry_points.txt +0 -0
- {xinference-1.10.0.dist-info → xinference-1.11.0.dist-info}/licenses/LICENSE +0 -0
- {xinference-1.10.0.dist-info → xinference-1.11.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
Binary file
|
|
@@ -0,0 +1,219 @@
|
|
|
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
|
+
# This code is borrowed from https://github.com/yl4579/PitchExtractor/blob/main/model.py
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
Implementation of model from:
|
|
10
|
+
Kum et al. - "Joint Detection and Classification of Singing Voice Melody Using
|
|
11
|
+
Convolutional Recurrent Neural Networks" (2019)
|
|
12
|
+
Link: https://www.semanticscholar.org/paper/Joint-Detection-and-Classification-of-Singing-Voice-Kum-Nam/60a2ad4c7db43bace75805054603747fcd062c0d
|
|
13
|
+
"""
|
|
14
|
+
import torch
|
|
15
|
+
from torch import nn
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class JDCNet(nn.Module):
|
|
19
|
+
"""
|
|
20
|
+
Joint Detection and Classification Network model for singing voice melody.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, num_class=722, seq_len=31, leaky_relu_slope=0.01):
|
|
24
|
+
super().__init__()
|
|
25
|
+
self.num_class = num_class
|
|
26
|
+
|
|
27
|
+
# input = (b, 1, 31, 513), b = batch size
|
|
28
|
+
self.conv_block = nn.Sequential(
|
|
29
|
+
nn.Conv2d(
|
|
30
|
+
in_channels=1, out_channels=64, kernel_size=3, padding=1, bias=False
|
|
31
|
+
), # out: (b, 64, 31, 513)
|
|
32
|
+
nn.BatchNorm2d(num_features=64),
|
|
33
|
+
nn.LeakyReLU(leaky_relu_slope, inplace=True),
|
|
34
|
+
nn.Conv2d(64, 64, 3, padding=1, bias=False), # (b, 64, 31, 513)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# res blocks
|
|
38
|
+
self.res_block1 = ResBlock(
|
|
39
|
+
in_channels=64, out_channels=128
|
|
40
|
+
) # (b, 128, 31, 128)
|
|
41
|
+
self.res_block2 = ResBlock(
|
|
42
|
+
in_channels=128, out_channels=192
|
|
43
|
+
) # (b, 192, 31, 32)
|
|
44
|
+
self.res_block3 = ResBlock(in_channels=192, out_channels=256) # (b, 256, 31, 8)
|
|
45
|
+
|
|
46
|
+
# pool block
|
|
47
|
+
self.pool_block = nn.Sequential(
|
|
48
|
+
nn.BatchNorm2d(num_features=256),
|
|
49
|
+
nn.LeakyReLU(leaky_relu_slope, inplace=True),
|
|
50
|
+
nn.MaxPool2d(kernel_size=(1, 4)), # (b, 256, 31, 2)
|
|
51
|
+
nn.Dropout(p=0.2),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# maxpool layers (for auxiliary network inputs)
|
|
55
|
+
# in = (b, 128, 31, 513) from conv_block, out = (b, 128, 31, 2)
|
|
56
|
+
self.maxpool1 = nn.MaxPool2d(kernel_size=(1, 40))
|
|
57
|
+
# in = (b, 128, 31, 128) from res_block1, out = (b, 128, 31, 2)
|
|
58
|
+
self.maxpool2 = nn.MaxPool2d(kernel_size=(1, 20))
|
|
59
|
+
# in = (b, 128, 31, 32) from res_block2, out = (b, 128, 31, 2)
|
|
60
|
+
self.maxpool3 = nn.MaxPool2d(kernel_size=(1, 10))
|
|
61
|
+
|
|
62
|
+
# in = (b, 640, 31, 2), out = (b, 256, 31, 2)
|
|
63
|
+
self.detector_conv = nn.Sequential(
|
|
64
|
+
nn.Conv2d(640, 256, 1, bias=False),
|
|
65
|
+
nn.BatchNorm2d(256),
|
|
66
|
+
nn.LeakyReLU(leaky_relu_slope, inplace=True),
|
|
67
|
+
nn.Dropout(p=0.2),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# input: (b, 31, 512) - resized from (b, 256, 31, 2)
|
|
71
|
+
self.bilstm_classifier = nn.LSTM(
|
|
72
|
+
input_size=512, hidden_size=256, batch_first=True, bidirectional=True
|
|
73
|
+
) # (b, 31, 512)
|
|
74
|
+
|
|
75
|
+
# input: (b, 31, 512) - resized from (b, 256, 31, 2)
|
|
76
|
+
self.bilstm_detector = nn.LSTM(
|
|
77
|
+
input_size=512, hidden_size=256, batch_first=True, bidirectional=True
|
|
78
|
+
) # (b, 31, 512)
|
|
79
|
+
|
|
80
|
+
# input: (b * 31, 512)
|
|
81
|
+
self.classifier = nn.Linear(
|
|
82
|
+
in_features=512, out_features=self.num_class
|
|
83
|
+
) # (b * 31, num_class)
|
|
84
|
+
|
|
85
|
+
# input: (b * 31, 512)
|
|
86
|
+
self.detector = nn.Linear(
|
|
87
|
+
in_features=512, out_features=2
|
|
88
|
+
) # (b * 31, 2) - binary classifier
|
|
89
|
+
|
|
90
|
+
# initialize weights
|
|
91
|
+
self.apply(self.init_weights)
|
|
92
|
+
|
|
93
|
+
def get_feature_GAN(self, x):
|
|
94
|
+
seq_len = x.shape[-2]
|
|
95
|
+
x = x.float().transpose(-1, -2)
|
|
96
|
+
|
|
97
|
+
convblock_out = self.conv_block(x)
|
|
98
|
+
|
|
99
|
+
resblock1_out = self.res_block1(convblock_out)
|
|
100
|
+
resblock2_out = self.res_block2(resblock1_out)
|
|
101
|
+
resblock3_out = self.res_block3(resblock2_out)
|
|
102
|
+
poolblock_out = self.pool_block[0](resblock3_out)
|
|
103
|
+
poolblock_out = self.pool_block[1](poolblock_out)
|
|
104
|
+
|
|
105
|
+
return poolblock_out.transpose(-1, -2)
|
|
106
|
+
|
|
107
|
+
def get_feature(self, x):
|
|
108
|
+
seq_len = x.shape[-2]
|
|
109
|
+
x = x.float().transpose(-1, -2)
|
|
110
|
+
|
|
111
|
+
convblock_out = self.conv_block(x)
|
|
112
|
+
|
|
113
|
+
resblock1_out = self.res_block1(convblock_out)
|
|
114
|
+
resblock2_out = self.res_block2(resblock1_out)
|
|
115
|
+
resblock3_out = self.res_block3(resblock2_out)
|
|
116
|
+
poolblock_out = self.pool_block[0](resblock3_out)
|
|
117
|
+
poolblock_out = self.pool_block[1](poolblock_out)
|
|
118
|
+
|
|
119
|
+
return self.pool_block[2](poolblock_out)
|
|
120
|
+
|
|
121
|
+
def forward(self, x):
|
|
122
|
+
"""
|
|
123
|
+
Returns:
|
|
124
|
+
classification_prediction, detection_prediction
|
|
125
|
+
sizes: (b, 31, 722), (b, 31, 2)
|
|
126
|
+
"""
|
|
127
|
+
###############################
|
|
128
|
+
# forward pass for classifier #
|
|
129
|
+
###############################
|
|
130
|
+
seq_len = x.shape[-1]
|
|
131
|
+
x = x.float().transpose(-1, -2)
|
|
132
|
+
|
|
133
|
+
convblock_out = self.conv_block(x)
|
|
134
|
+
|
|
135
|
+
resblock1_out = self.res_block1(convblock_out)
|
|
136
|
+
resblock2_out = self.res_block2(resblock1_out)
|
|
137
|
+
resblock3_out = self.res_block3(resblock2_out)
|
|
138
|
+
|
|
139
|
+
poolblock_out = self.pool_block[0](resblock3_out)
|
|
140
|
+
poolblock_out = self.pool_block[1](poolblock_out)
|
|
141
|
+
GAN_feature = poolblock_out.transpose(-1, -2)
|
|
142
|
+
poolblock_out = self.pool_block[2](poolblock_out)
|
|
143
|
+
|
|
144
|
+
# (b, 256, 31, 2) => (b, 31, 256, 2) => (b, 31, 512)
|
|
145
|
+
classifier_out = (
|
|
146
|
+
poolblock_out.permute(0, 2, 1, 3).contiguous().view((-1, seq_len, 512))
|
|
147
|
+
)
|
|
148
|
+
classifier_out, _ = self.bilstm_classifier(
|
|
149
|
+
classifier_out
|
|
150
|
+
) # ignore the hidden states
|
|
151
|
+
|
|
152
|
+
classifier_out = classifier_out.contiguous().view((-1, 512)) # (b * 31, 512)
|
|
153
|
+
classifier_out = self.classifier(classifier_out)
|
|
154
|
+
classifier_out = classifier_out.view(
|
|
155
|
+
(-1, seq_len, self.num_class)
|
|
156
|
+
) # (b, 31, num_class)
|
|
157
|
+
|
|
158
|
+
# sizes: (b, 31, 722), (b, 31, 2)
|
|
159
|
+
# classifier output consists of predicted pitch classes per frame
|
|
160
|
+
# detector output consists of: (isvoice, notvoice) estimates per frame
|
|
161
|
+
return torch.abs(classifier_out.squeeze(-1)), GAN_feature, poolblock_out
|
|
162
|
+
|
|
163
|
+
@staticmethod
|
|
164
|
+
def init_weights(m):
|
|
165
|
+
if isinstance(m, nn.Linear):
|
|
166
|
+
nn.init.kaiming_uniform_(m.weight)
|
|
167
|
+
if m.bias is not None:
|
|
168
|
+
nn.init.constant_(m.bias, 0)
|
|
169
|
+
elif isinstance(m, nn.Conv2d):
|
|
170
|
+
nn.init.xavier_normal_(m.weight)
|
|
171
|
+
elif isinstance(m, nn.LSTM) or isinstance(m, nn.LSTMCell):
|
|
172
|
+
for p in m.parameters():
|
|
173
|
+
if p.data is None:
|
|
174
|
+
continue
|
|
175
|
+
|
|
176
|
+
if len(p.shape) >= 2:
|
|
177
|
+
nn.init.orthogonal_(p.data)
|
|
178
|
+
else:
|
|
179
|
+
nn.init.normal_(p.data)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
class ResBlock(nn.Module):
|
|
183
|
+
def __init__(self, in_channels: int, out_channels: int, leaky_relu_slope=0.01):
|
|
184
|
+
super().__init__()
|
|
185
|
+
self.downsample = in_channels != out_channels
|
|
186
|
+
|
|
187
|
+
# BN / LReLU / MaxPool layer before the conv layer - see Figure 1b in the paper
|
|
188
|
+
self.pre_conv = nn.Sequential(
|
|
189
|
+
nn.BatchNorm2d(num_features=in_channels),
|
|
190
|
+
nn.LeakyReLU(leaky_relu_slope, inplace=True),
|
|
191
|
+
nn.MaxPool2d(kernel_size=(1, 2)), # apply downsampling on the y axis only
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
# conv layers
|
|
195
|
+
self.conv = nn.Sequential(
|
|
196
|
+
nn.Conv2d(
|
|
197
|
+
in_channels=in_channels,
|
|
198
|
+
out_channels=out_channels,
|
|
199
|
+
kernel_size=3,
|
|
200
|
+
padding=1,
|
|
201
|
+
bias=False,
|
|
202
|
+
),
|
|
203
|
+
nn.BatchNorm2d(out_channels),
|
|
204
|
+
nn.LeakyReLU(leaky_relu_slope, inplace=True),
|
|
205
|
+
nn.Conv2d(out_channels, out_channels, 3, padding=1, bias=False),
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
# 1 x 1 convolution layer to match the feature dimensions
|
|
209
|
+
self.conv1by1 = None
|
|
210
|
+
if self.downsample:
|
|
211
|
+
self.conv1by1 = nn.Conv2d(in_channels, out_channels, 1, bias=False)
|
|
212
|
+
|
|
213
|
+
def forward(self, x):
|
|
214
|
+
x = self.pre_conv(x)
|
|
215
|
+
if self.downsample:
|
|
216
|
+
x = self.conv(x) + self.conv1by1(x)
|
|
217
|
+
else:
|
|
218
|
+
x = self.conv(x) + x
|
|
219
|
+
return x
|
|
@@ -0,0 +1,437 @@
|
|
|
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
|
+
# This code is modified from https://github.com/sh-lee-prml/HierSpeechpp/blob/main/ttv_v1/attentions.py
|
|
7
|
+
|
|
8
|
+
import copy
|
|
9
|
+
import math
|
|
10
|
+
import numpy as np
|
|
11
|
+
import torch
|
|
12
|
+
from torch import nn
|
|
13
|
+
from torch.nn import functional as F
|
|
14
|
+
|
|
15
|
+
from . import commons
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class LayerNorm(nn.Module):
|
|
19
|
+
def __init__(self, channels, eps=1e-5):
|
|
20
|
+
super().__init__()
|
|
21
|
+
self.channels = channels
|
|
22
|
+
self.eps = eps
|
|
23
|
+
|
|
24
|
+
self.gamma = nn.Parameter(torch.ones(channels))
|
|
25
|
+
self.beta = nn.Parameter(torch.zeros(channels))
|
|
26
|
+
|
|
27
|
+
def forward(self, x):
|
|
28
|
+
x = x.transpose(1, -1)
|
|
29
|
+
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
|
|
30
|
+
return x.transpose(1, -1)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Encoder(nn.Module):
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
hidden_channels,
|
|
37
|
+
filter_channels,
|
|
38
|
+
n_heads,
|
|
39
|
+
n_layers,
|
|
40
|
+
kernel_size=1,
|
|
41
|
+
p_dropout=0.0,
|
|
42
|
+
window_size=4,
|
|
43
|
+
**kwargs
|
|
44
|
+
):
|
|
45
|
+
super().__init__()
|
|
46
|
+
self.hidden_channels = hidden_channels
|
|
47
|
+
self.filter_channels = filter_channels
|
|
48
|
+
self.n_heads = n_heads
|
|
49
|
+
self.n_layers = n_layers
|
|
50
|
+
self.kernel_size = kernel_size
|
|
51
|
+
self.p_dropout = p_dropout
|
|
52
|
+
self.window_size = window_size
|
|
53
|
+
|
|
54
|
+
self.drop = nn.Dropout(p_dropout)
|
|
55
|
+
self.attn_layers = nn.ModuleList()
|
|
56
|
+
self.norm_layers_1 = nn.ModuleList()
|
|
57
|
+
self.ffn_layers = nn.ModuleList()
|
|
58
|
+
self.norm_layers_2 = nn.ModuleList()
|
|
59
|
+
for i in range(self.n_layers):
|
|
60
|
+
self.attn_layers.append(
|
|
61
|
+
MultiHeadAttention(
|
|
62
|
+
hidden_channels,
|
|
63
|
+
hidden_channels,
|
|
64
|
+
n_heads,
|
|
65
|
+
p_dropout=p_dropout,
|
|
66
|
+
window_size=window_size,
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
|
70
|
+
self.ffn_layers.append(
|
|
71
|
+
FFN(
|
|
72
|
+
hidden_channels,
|
|
73
|
+
hidden_channels,
|
|
74
|
+
filter_channels,
|
|
75
|
+
kernel_size,
|
|
76
|
+
p_dropout=p_dropout,
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
|
80
|
+
|
|
81
|
+
def forward(self, x, x_mask):
|
|
82
|
+
attn_mask = x_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
|
83
|
+
x = x * x_mask
|
|
84
|
+
for i in range(self.n_layers):
|
|
85
|
+
y = self.attn_layers[i](x, x, attn_mask)
|
|
86
|
+
y = self.drop(y)
|
|
87
|
+
x = self.norm_layers_1[i](x + y)
|
|
88
|
+
|
|
89
|
+
y = self.ffn_layers[i](x, x_mask)
|
|
90
|
+
y = self.drop(y)
|
|
91
|
+
x = self.norm_layers_2[i](x + y)
|
|
92
|
+
x = x * x_mask
|
|
93
|
+
return x
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class Decoder(nn.Module):
|
|
97
|
+
def __init__(
|
|
98
|
+
self,
|
|
99
|
+
hidden_channels,
|
|
100
|
+
filter_channels,
|
|
101
|
+
n_heads,
|
|
102
|
+
n_layers,
|
|
103
|
+
kernel_size=1,
|
|
104
|
+
p_dropout=0.0,
|
|
105
|
+
proximal_bias=False,
|
|
106
|
+
proximal_init=True,
|
|
107
|
+
**kwargs
|
|
108
|
+
):
|
|
109
|
+
super().__init__()
|
|
110
|
+
self.hidden_channels = hidden_channels
|
|
111
|
+
self.filter_channels = filter_channels
|
|
112
|
+
self.n_heads = n_heads
|
|
113
|
+
self.n_layers = n_layers
|
|
114
|
+
self.kernel_size = kernel_size
|
|
115
|
+
self.p_dropout = p_dropout
|
|
116
|
+
self.proximal_bias = proximal_bias
|
|
117
|
+
self.proximal_init = proximal_init
|
|
118
|
+
|
|
119
|
+
self.drop = nn.Dropout(p_dropout)
|
|
120
|
+
self.self_attn_layers = nn.ModuleList()
|
|
121
|
+
self.norm_layers_0 = nn.ModuleList()
|
|
122
|
+
self.encdec_attn_layers = nn.ModuleList()
|
|
123
|
+
self.norm_layers_1 = nn.ModuleList()
|
|
124
|
+
self.ffn_layers = nn.ModuleList()
|
|
125
|
+
self.norm_layers_2 = nn.ModuleList()
|
|
126
|
+
for i in range(self.n_layers):
|
|
127
|
+
self.self_attn_layers.append(
|
|
128
|
+
MultiHeadAttention(
|
|
129
|
+
hidden_channels,
|
|
130
|
+
hidden_channels,
|
|
131
|
+
n_heads,
|
|
132
|
+
p_dropout=p_dropout,
|
|
133
|
+
proximal_bias=proximal_bias,
|
|
134
|
+
proximal_init=proximal_init,
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
self.norm_layers_0.append(LayerNorm(hidden_channels))
|
|
138
|
+
self.encdec_attn_layers.append(
|
|
139
|
+
MultiHeadAttention(
|
|
140
|
+
hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
|
144
|
+
self.ffn_layers.append(
|
|
145
|
+
FFN(
|
|
146
|
+
hidden_channels,
|
|
147
|
+
hidden_channels,
|
|
148
|
+
filter_channels,
|
|
149
|
+
kernel_size,
|
|
150
|
+
p_dropout=p_dropout,
|
|
151
|
+
causal=True,
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
|
155
|
+
|
|
156
|
+
def forward(self, x, x_mask, h, h_mask):
|
|
157
|
+
"""
|
|
158
|
+
x: decoder input
|
|
159
|
+
h: encoder output
|
|
160
|
+
"""
|
|
161
|
+
self_attn_mask = commons.subsequent_mask(x_mask.size(2)).to(
|
|
162
|
+
device=x.device, dtype=x.dtype
|
|
163
|
+
)
|
|
164
|
+
encdec_attn_mask = h_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
|
165
|
+
x = x * x_mask
|
|
166
|
+
for i in range(self.n_layers):
|
|
167
|
+
y = self.self_attn_layers[i](x, x, self_attn_mask)
|
|
168
|
+
y = self.drop(y)
|
|
169
|
+
x = self.norm_layers_0[i](x + y)
|
|
170
|
+
|
|
171
|
+
y = self.encdec_attn_layers[i](x, h, encdec_attn_mask)
|
|
172
|
+
y = self.drop(y)
|
|
173
|
+
x = self.norm_layers_1[i](x + y)
|
|
174
|
+
|
|
175
|
+
y = self.ffn_layers[i](x, x_mask)
|
|
176
|
+
y = self.drop(y)
|
|
177
|
+
x = self.norm_layers_2[i](x + y)
|
|
178
|
+
x = x * x_mask
|
|
179
|
+
return x
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
class MultiHeadAttention(nn.Module):
|
|
183
|
+
def __init__(
|
|
184
|
+
self,
|
|
185
|
+
channels,
|
|
186
|
+
out_channels,
|
|
187
|
+
n_heads,
|
|
188
|
+
p_dropout=0.0,
|
|
189
|
+
window_size=None,
|
|
190
|
+
heads_share=True,
|
|
191
|
+
block_length=None,
|
|
192
|
+
proximal_bias=False,
|
|
193
|
+
proximal_init=False,
|
|
194
|
+
):
|
|
195
|
+
super().__init__()
|
|
196
|
+
assert channels % n_heads == 0
|
|
197
|
+
|
|
198
|
+
self.channels = channels
|
|
199
|
+
self.out_channels = out_channels
|
|
200
|
+
self.n_heads = n_heads
|
|
201
|
+
self.p_dropout = p_dropout
|
|
202
|
+
self.window_size = window_size
|
|
203
|
+
self.heads_share = heads_share
|
|
204
|
+
self.block_length = block_length
|
|
205
|
+
self.proximal_bias = proximal_bias
|
|
206
|
+
self.proximal_init = proximal_init
|
|
207
|
+
self.attn = None
|
|
208
|
+
|
|
209
|
+
self.k_channels = channels // n_heads
|
|
210
|
+
self.conv_q = nn.Conv1d(channels, channels, 1)
|
|
211
|
+
self.conv_k = nn.Conv1d(channels, channels, 1)
|
|
212
|
+
self.conv_v = nn.Conv1d(channels, channels, 1)
|
|
213
|
+
self.conv_o = nn.Conv1d(channels, out_channels, 1)
|
|
214
|
+
self.drop = nn.Dropout(p_dropout)
|
|
215
|
+
|
|
216
|
+
if window_size is not None:
|
|
217
|
+
n_heads_rel = 1 if heads_share else n_heads
|
|
218
|
+
rel_stddev = self.k_channels**-0.5
|
|
219
|
+
self.emb_rel_k = nn.Parameter(
|
|
220
|
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
|
221
|
+
* rel_stddev
|
|
222
|
+
)
|
|
223
|
+
self.emb_rel_v = nn.Parameter(
|
|
224
|
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
|
225
|
+
* rel_stddev
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
nn.init.xavier_uniform_(self.conv_q.weight)
|
|
229
|
+
nn.init.xavier_uniform_(self.conv_k.weight)
|
|
230
|
+
nn.init.xavier_uniform_(self.conv_v.weight)
|
|
231
|
+
if proximal_init:
|
|
232
|
+
with torch.no_grad():
|
|
233
|
+
self.conv_k.weight.copy_(self.conv_q.weight)
|
|
234
|
+
self.conv_k.bias.copy_(self.conv_q.bias)
|
|
235
|
+
|
|
236
|
+
def forward(self, x, c, attn_mask=None):
|
|
237
|
+
q = self.conv_q(x)
|
|
238
|
+
k = self.conv_k(c)
|
|
239
|
+
v = self.conv_v(c)
|
|
240
|
+
|
|
241
|
+
x, self.attn = self.attention(q, k, v, mask=attn_mask)
|
|
242
|
+
|
|
243
|
+
x = self.conv_o(x)
|
|
244
|
+
return x
|
|
245
|
+
|
|
246
|
+
def attention(self, query, key, value, mask=None):
|
|
247
|
+
# reshape [b, d, t] -> [b, n_h, t, d_k]
|
|
248
|
+
b, d, t_s, t_t = (*key.size(), query.size(2))
|
|
249
|
+
query = query.view(b, self.n_heads, self.k_channels, t_t).transpose(2, 3)
|
|
250
|
+
key = key.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
|
251
|
+
value = value.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
|
252
|
+
|
|
253
|
+
scores = torch.matmul(query / math.sqrt(self.k_channels), key.transpose(-2, -1))
|
|
254
|
+
if self.window_size is not None:
|
|
255
|
+
assert (
|
|
256
|
+
t_s == t_t
|
|
257
|
+
), "Relative attention is only available for self-attention."
|
|
258
|
+
key_relative_embeddings = self._get_relative_embeddings(self.emb_rel_k, t_s)
|
|
259
|
+
rel_logits = self._matmul_with_relative_keys(
|
|
260
|
+
query / math.sqrt(self.k_channels), key_relative_embeddings
|
|
261
|
+
)
|
|
262
|
+
scores_local = self._relative_position_to_absolute_position(rel_logits)
|
|
263
|
+
scores = scores + scores_local
|
|
264
|
+
if self.proximal_bias:
|
|
265
|
+
assert t_s == t_t, "Proximal bias is only available for self-attention."
|
|
266
|
+
scores = scores + self._attention_bias_proximal(t_s).to(
|
|
267
|
+
device=scores.device, dtype=scores.dtype
|
|
268
|
+
)
|
|
269
|
+
if mask is not None:
|
|
270
|
+
scores = scores.masked_fill(mask == 0, -1e4)
|
|
271
|
+
if self.block_length is not None:
|
|
272
|
+
assert (
|
|
273
|
+
t_s == t_t
|
|
274
|
+
), "Local attention is only available for self-attention."
|
|
275
|
+
block_mask = (
|
|
276
|
+
torch.ones_like(scores)
|
|
277
|
+
.triu(-self.block_length)
|
|
278
|
+
.tril(self.block_length)
|
|
279
|
+
)
|
|
280
|
+
scores = scores.masked_fill(block_mask == 0, -1e4)
|
|
281
|
+
p_attn = F.softmax(scores, dim=-1) # [b, n_h, t_t, t_s]
|
|
282
|
+
p_attn = self.drop(p_attn)
|
|
283
|
+
output = torch.matmul(p_attn, value)
|
|
284
|
+
if self.window_size is not None:
|
|
285
|
+
relative_weights = self._absolute_position_to_relative_position(p_attn)
|
|
286
|
+
value_relative_embeddings = self._get_relative_embeddings(
|
|
287
|
+
self.emb_rel_v, t_s
|
|
288
|
+
)
|
|
289
|
+
output = output + self._matmul_with_relative_values(
|
|
290
|
+
relative_weights, value_relative_embeddings
|
|
291
|
+
)
|
|
292
|
+
output = (
|
|
293
|
+
output.transpose(2, 3).contiguous().view(b, d, t_t)
|
|
294
|
+
) # [b, n_h, t_t, d_k] -> [b, d, t_t]
|
|
295
|
+
return output, p_attn
|
|
296
|
+
|
|
297
|
+
def _matmul_with_relative_values(self, x, y):
|
|
298
|
+
"""
|
|
299
|
+
x: [b, h, l, m]
|
|
300
|
+
y: [h or 1, m, d]
|
|
301
|
+
ret: [b, h, l, d]
|
|
302
|
+
"""
|
|
303
|
+
ret = torch.matmul(x, y.unsqueeze(0))
|
|
304
|
+
return ret
|
|
305
|
+
|
|
306
|
+
def _matmul_with_relative_keys(self, x, y):
|
|
307
|
+
"""
|
|
308
|
+
x: [b, h, l, d]
|
|
309
|
+
y: [h or 1, m, d]
|
|
310
|
+
ret: [b, h, l, m]
|
|
311
|
+
"""
|
|
312
|
+
ret = torch.matmul(x, y.unsqueeze(0).transpose(-2, -1))
|
|
313
|
+
return ret
|
|
314
|
+
|
|
315
|
+
def _get_relative_embeddings(self, relative_embeddings, length):
|
|
316
|
+
max_relative_position = 2 * self.window_size + 1
|
|
317
|
+
# Pad first before slice to avoid using cond ops.
|
|
318
|
+
pad_length = max(length - (self.window_size + 1), 0)
|
|
319
|
+
slice_start_position = max((self.window_size + 1) - length, 0)
|
|
320
|
+
slice_end_position = slice_start_position + 2 * length - 1
|
|
321
|
+
if pad_length > 0:
|
|
322
|
+
padded_relative_embeddings = F.pad(
|
|
323
|
+
relative_embeddings,
|
|
324
|
+
commons.convert_pad_shape([[0, 0], [pad_length, pad_length], [0, 0]]),
|
|
325
|
+
)
|
|
326
|
+
else:
|
|
327
|
+
padded_relative_embeddings = relative_embeddings
|
|
328
|
+
used_relative_embeddings = padded_relative_embeddings[
|
|
329
|
+
:, slice_start_position:slice_end_position
|
|
330
|
+
]
|
|
331
|
+
return used_relative_embeddings
|
|
332
|
+
|
|
333
|
+
def _relative_position_to_absolute_position(self, x):
|
|
334
|
+
"""
|
|
335
|
+
x: [b, h, l, 2*l-1]
|
|
336
|
+
ret: [b, h, l, l]
|
|
337
|
+
"""
|
|
338
|
+
batch, heads, length, _ = x.size()
|
|
339
|
+
# Concat columns of pad to shift from relative to absolute indexing.
|
|
340
|
+
x = F.pad(x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, 1]]))
|
|
341
|
+
|
|
342
|
+
# Concat extra elements so to add up to shape (len+1, 2*len-1).
|
|
343
|
+
x_flat = x.view([batch, heads, length * 2 * length])
|
|
344
|
+
x_flat = F.pad(
|
|
345
|
+
x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [0, length - 1]])
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
# Reshape and slice out the padded elements.
|
|
349
|
+
x_final = x_flat.view([batch, heads, length + 1, 2 * length - 1])[
|
|
350
|
+
:, :, :length, length - 1 :
|
|
351
|
+
]
|
|
352
|
+
return x_final
|
|
353
|
+
|
|
354
|
+
def _absolute_position_to_relative_position(self, x):
|
|
355
|
+
"""
|
|
356
|
+
x: [b, h, l, l]
|
|
357
|
+
ret: [b, h, l, 2*l-1]
|
|
358
|
+
"""
|
|
359
|
+
batch, heads, length, _ = x.size()
|
|
360
|
+
# padd along column
|
|
361
|
+
x = F.pad(
|
|
362
|
+
x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, length - 1]])
|
|
363
|
+
)
|
|
364
|
+
x_flat = x.view([batch, heads, length**2 + length * (length - 1)])
|
|
365
|
+
# add 0's in the beginning that will skew the elements after reshape
|
|
366
|
+
x_flat = F.pad(x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [length, 0]]))
|
|
367
|
+
x_final = x_flat.view([batch, heads, length, 2 * length])[:, :, :, 1:]
|
|
368
|
+
return x_final
|
|
369
|
+
|
|
370
|
+
def _attention_bias_proximal(self, length):
|
|
371
|
+
"""Bias for self-attention to encourage attention to close positions.
|
|
372
|
+
Args:
|
|
373
|
+
length: an integer scalar.
|
|
374
|
+
Returns:
|
|
375
|
+
a Tensor with shape [1, 1, length, length]
|
|
376
|
+
"""
|
|
377
|
+
r = torch.arange(length, dtype=torch.float32)
|
|
378
|
+
diff = torch.unsqueeze(r, 0) - torch.unsqueeze(r, 1)
|
|
379
|
+
return torch.unsqueeze(torch.unsqueeze(-torch.log1p(torch.abs(diff)), 0), 0)
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
class FFN(nn.Module):
|
|
383
|
+
def __init__(
|
|
384
|
+
self,
|
|
385
|
+
in_channels,
|
|
386
|
+
out_channels,
|
|
387
|
+
filter_channels,
|
|
388
|
+
kernel_size,
|
|
389
|
+
p_dropout=0.0,
|
|
390
|
+
activation=None,
|
|
391
|
+
causal=False,
|
|
392
|
+
):
|
|
393
|
+
super().__init__()
|
|
394
|
+
self.in_channels = in_channels
|
|
395
|
+
self.out_channels = out_channels
|
|
396
|
+
self.filter_channels = filter_channels
|
|
397
|
+
self.kernel_size = kernel_size
|
|
398
|
+
self.p_dropout = p_dropout
|
|
399
|
+
self.activation = activation
|
|
400
|
+
self.causal = causal
|
|
401
|
+
|
|
402
|
+
if causal:
|
|
403
|
+
self.padding = self._causal_padding
|
|
404
|
+
else:
|
|
405
|
+
self.padding = self._same_padding
|
|
406
|
+
|
|
407
|
+
self.conv_1 = nn.Conv1d(in_channels, filter_channels, kernel_size)
|
|
408
|
+
self.conv_2 = nn.Conv1d(filter_channels, out_channels, kernel_size)
|
|
409
|
+
self.drop = nn.Dropout(p_dropout)
|
|
410
|
+
|
|
411
|
+
def forward(self, x, x_mask):
|
|
412
|
+
x = self.conv_1(self.padding(x * x_mask))
|
|
413
|
+
if self.activation == "gelu":
|
|
414
|
+
x = x * torch.sigmoid(1.702 * x)
|
|
415
|
+
else:
|
|
416
|
+
x = torch.relu(x)
|
|
417
|
+
x = self.drop(x)
|
|
418
|
+
x = self.conv_2(self.padding(x * x_mask))
|
|
419
|
+
return x * x_mask
|
|
420
|
+
|
|
421
|
+
def _causal_padding(self, x):
|
|
422
|
+
if self.kernel_size == 1:
|
|
423
|
+
return x
|
|
424
|
+
pad_l = self.kernel_size - 1
|
|
425
|
+
pad_r = 0
|
|
426
|
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
|
427
|
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
|
428
|
+
return x
|
|
429
|
+
|
|
430
|
+
def _same_padding(self, x):
|
|
431
|
+
if self.kernel_size == 1:
|
|
432
|
+
return x
|
|
433
|
+
pad_l = (self.kernel_size - 1) // 2
|
|
434
|
+
pad_r = self.kernel_size // 2
|
|
435
|
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
|
436
|
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
|
437
|
+
return x
|