xinference 1.9.1__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.
- xinference/_version.py +3 -3
- xinference/api/restful_api.py +400 -3
- xinference/client/restful/async_restful_client.py +20 -3
- xinference/client/restful/restful_client.py +20 -3
- xinference/constants.py +2 -0
- xinference/core/supervisor.py +111 -49
- xinference/core/worker.py +10 -0
- xinference/deploy/cmdline.py +15 -0
- xinference/model/audio/core.py +26 -6
- xinference/model/audio/indextts2.py +166 -0
- xinference/model/audio/kokoro.py +1 -1
- xinference/model/audio/kokoro_zh.py +124 -0
- xinference/model/audio/model_spec.json +58 -1
- xinference/model/embedding/sentence_transformers/core.py +4 -4
- xinference/model/embedding/vllm/core.py +7 -1
- xinference/model/image/model_spec.json +71 -3
- xinference/model/image/stable_diffusion/core.py +13 -4
- xinference/model/llm/__init__.py +4 -0
- xinference/model/llm/core.py +10 -0
- xinference/model/llm/llama_cpp/core.py +1 -0
- xinference/model/llm/llm_family.json +503 -21
- xinference/model/llm/llm_family.py +1 -0
- xinference/model/llm/mlx/core.py +52 -33
- xinference/model/llm/sglang/core.py +32 -55
- xinference/model/llm/tool_parsers/__init__.py +58 -0
- xinference/model/llm/tool_parsers/abstract_tool_parser.py +33 -0
- xinference/model/llm/tool_parsers/deepseek_r1_tool_parser.py +190 -0
- xinference/model/llm/tool_parsers/deepseek_v3_tool_parser.py +145 -0
- xinference/model/llm/tool_parsers/glm4_tool_parser.py +123 -0
- xinference/model/llm/tool_parsers/llama3_tool_parser.py +77 -0
- xinference/model/llm/tool_parsers/qwen_tool_parser.py +320 -0
- xinference/model/llm/transformers/core.py +1 -1
- xinference/model/llm/transformers/multimodal/qwen2_vl.py +34 -8
- xinference/model/llm/utils.py +138 -53
- xinference/model/llm/vllm/core.py +95 -78
- 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/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/types.py +105 -2
- 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.d192c4f3.js +3 -0
- xinference/ui/web/ui/build/static/js/{main.1086c759.js.LICENSE.txt → main.d192c4f3.js.LICENSE.txt} +0 -7
- xinference/ui/web/ui/build/static/js/main.d192c4f3.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/f05535160a508b2a312de546a6de234776c613db276479ea4253c0b1bdeeb7d6.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/f09ba9e11106bd59a0de10cc85c55084097729dcab575f43dfcf07375961ed87.json +1 -0
- xinference/ui/web/ui/node_modules/.cache/babel-loader/f995a2425dfb0822fd07127f66ffe9b026883bc156b402eb8bd0b83d52460a93.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.9.1.dist-info → xinference-1.10.1.dist-info}/METADATA +24 -4
- {xinference-1.9.1.dist-info → xinference-1.10.1.dist-info}/RECORD +302 -76
- 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.9.1.dist-info → xinference-1.10.1.dist-info}/WHEEL +0 -0
- {xinference-1.9.1.dist-info → xinference-1.10.1.dist-info}/entry_points.txt +0 -0
- {xinference-1.9.1.dist-info → xinference-1.10.1.dist-info}/licenses/LICENSE +0 -0
- {xinference-1.9.1.dist-info → xinference-1.10.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import torch
|
|
3
|
+
from torch import nn
|
|
4
|
+
from typing import Optional, Any
|
|
5
|
+
from torch import Tensor
|
|
6
|
+
import torch.nn.functional as F
|
|
7
|
+
import torchaudio
|
|
8
|
+
import torchaudio.functional as audio_F
|
|
9
|
+
|
|
10
|
+
import random
|
|
11
|
+
random.seed(0)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _get_activation_fn(activ):
|
|
15
|
+
if activ == 'relu':
|
|
16
|
+
return nn.ReLU()
|
|
17
|
+
elif activ == 'lrelu':
|
|
18
|
+
return nn.LeakyReLU(0.2)
|
|
19
|
+
elif activ == 'swish':
|
|
20
|
+
return lambda x: x*torch.sigmoid(x)
|
|
21
|
+
else:
|
|
22
|
+
raise RuntimeError('Unexpected activ type %s, expected [relu, lrelu, swish]' % activ)
|
|
23
|
+
|
|
24
|
+
class LinearNorm(torch.nn.Module):
|
|
25
|
+
def __init__(self, in_dim, out_dim, bias=True, w_init_gain='linear'):
|
|
26
|
+
super(LinearNorm, self).__init__()
|
|
27
|
+
self.linear_layer = torch.nn.Linear(in_dim, out_dim, bias=bias)
|
|
28
|
+
|
|
29
|
+
torch.nn.init.xavier_uniform_(
|
|
30
|
+
self.linear_layer.weight,
|
|
31
|
+
gain=torch.nn.init.calculate_gain(w_init_gain))
|
|
32
|
+
|
|
33
|
+
def forward(self, x):
|
|
34
|
+
return self.linear_layer(x)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ConvNorm(torch.nn.Module):
|
|
38
|
+
def __init__(self, in_channels, out_channels, kernel_size=1, stride=1,
|
|
39
|
+
padding=None, dilation=1, bias=True, w_init_gain='linear', param=None):
|
|
40
|
+
super(ConvNorm, self).__init__()
|
|
41
|
+
if padding is None:
|
|
42
|
+
assert(kernel_size % 2 == 1)
|
|
43
|
+
padding = int(dilation * (kernel_size - 1) / 2)
|
|
44
|
+
|
|
45
|
+
self.conv = torch.nn.Conv1d(in_channels, out_channels,
|
|
46
|
+
kernel_size=kernel_size, stride=stride,
|
|
47
|
+
padding=padding, dilation=dilation,
|
|
48
|
+
bias=bias)
|
|
49
|
+
|
|
50
|
+
torch.nn.init.xavier_uniform_(
|
|
51
|
+
self.conv.weight, gain=torch.nn.init.calculate_gain(w_init_gain, param=param))
|
|
52
|
+
|
|
53
|
+
def forward(self, signal):
|
|
54
|
+
conv_signal = self.conv(signal)
|
|
55
|
+
return conv_signal
|
|
56
|
+
|
|
57
|
+
class CausualConv(nn.Module):
|
|
58
|
+
def __init__(self, in_channels, out_channels, kernel_size=1, stride=1, padding=1, dilation=1, bias=True, w_init_gain='linear', param=None):
|
|
59
|
+
super(CausualConv, self).__init__()
|
|
60
|
+
if padding is None:
|
|
61
|
+
assert(kernel_size % 2 == 1)
|
|
62
|
+
padding = int(dilation * (kernel_size - 1) / 2) * 2
|
|
63
|
+
else:
|
|
64
|
+
self.padding = padding * 2
|
|
65
|
+
self.conv = nn.Conv1d(in_channels, out_channels,
|
|
66
|
+
kernel_size=kernel_size, stride=stride,
|
|
67
|
+
padding=self.padding,
|
|
68
|
+
dilation=dilation,
|
|
69
|
+
bias=bias)
|
|
70
|
+
|
|
71
|
+
torch.nn.init.xavier_uniform_(
|
|
72
|
+
self.conv.weight, gain=torch.nn.init.calculate_gain(w_init_gain, param=param))
|
|
73
|
+
|
|
74
|
+
def forward(self, x):
|
|
75
|
+
x = self.conv(x)
|
|
76
|
+
x = x[:, :, :-self.padding]
|
|
77
|
+
return x
|
|
78
|
+
|
|
79
|
+
class CausualBlock(nn.Module):
|
|
80
|
+
def __init__(self, hidden_dim, n_conv=3, dropout_p=0.2, activ='lrelu'):
|
|
81
|
+
super(CausualBlock, self).__init__()
|
|
82
|
+
self.blocks = nn.ModuleList([
|
|
83
|
+
self._get_conv(hidden_dim, dilation=3**i, activ=activ, dropout_p=dropout_p)
|
|
84
|
+
for i in range(n_conv)])
|
|
85
|
+
|
|
86
|
+
def forward(self, x):
|
|
87
|
+
for block in self.blocks:
|
|
88
|
+
res = x
|
|
89
|
+
x = block(x)
|
|
90
|
+
x += res
|
|
91
|
+
return x
|
|
92
|
+
|
|
93
|
+
def _get_conv(self, hidden_dim, dilation, activ='lrelu', dropout_p=0.2):
|
|
94
|
+
layers = [
|
|
95
|
+
CausualConv(hidden_dim, hidden_dim, kernel_size=3, padding=dilation, dilation=dilation),
|
|
96
|
+
_get_activation_fn(activ),
|
|
97
|
+
nn.BatchNorm1d(hidden_dim),
|
|
98
|
+
nn.Dropout(p=dropout_p),
|
|
99
|
+
CausualConv(hidden_dim, hidden_dim, kernel_size=3, padding=1, dilation=1),
|
|
100
|
+
_get_activation_fn(activ),
|
|
101
|
+
nn.Dropout(p=dropout_p)
|
|
102
|
+
]
|
|
103
|
+
return nn.Sequential(*layers)
|
|
104
|
+
|
|
105
|
+
class ConvBlock(nn.Module):
|
|
106
|
+
def __init__(self, hidden_dim, n_conv=3, dropout_p=0.2, activ='relu'):
|
|
107
|
+
super().__init__()
|
|
108
|
+
self._n_groups = 8
|
|
109
|
+
self.blocks = nn.ModuleList([
|
|
110
|
+
self._get_conv(hidden_dim, dilation=3**i, activ=activ, dropout_p=dropout_p)
|
|
111
|
+
for i in range(n_conv)])
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def forward(self, x):
|
|
115
|
+
for block in self.blocks:
|
|
116
|
+
res = x
|
|
117
|
+
x = block(x)
|
|
118
|
+
x += res
|
|
119
|
+
return x
|
|
120
|
+
|
|
121
|
+
def _get_conv(self, hidden_dim, dilation, activ='relu', dropout_p=0.2):
|
|
122
|
+
layers = [
|
|
123
|
+
ConvNorm(hidden_dim, hidden_dim, kernel_size=3, padding=dilation, dilation=dilation),
|
|
124
|
+
_get_activation_fn(activ),
|
|
125
|
+
nn.GroupNorm(num_groups=self._n_groups, num_channels=hidden_dim),
|
|
126
|
+
nn.Dropout(p=dropout_p),
|
|
127
|
+
ConvNorm(hidden_dim, hidden_dim, kernel_size=3, padding=1, dilation=1),
|
|
128
|
+
_get_activation_fn(activ),
|
|
129
|
+
nn.Dropout(p=dropout_p)
|
|
130
|
+
]
|
|
131
|
+
return nn.Sequential(*layers)
|
|
132
|
+
|
|
133
|
+
class LocationLayer(nn.Module):
|
|
134
|
+
def __init__(self, attention_n_filters, attention_kernel_size,
|
|
135
|
+
attention_dim):
|
|
136
|
+
super(LocationLayer, self).__init__()
|
|
137
|
+
padding = int((attention_kernel_size - 1) / 2)
|
|
138
|
+
self.location_conv = ConvNorm(2, attention_n_filters,
|
|
139
|
+
kernel_size=attention_kernel_size,
|
|
140
|
+
padding=padding, bias=False, stride=1,
|
|
141
|
+
dilation=1)
|
|
142
|
+
self.location_dense = LinearNorm(attention_n_filters, attention_dim,
|
|
143
|
+
bias=False, w_init_gain='tanh')
|
|
144
|
+
|
|
145
|
+
def forward(self, attention_weights_cat):
|
|
146
|
+
processed_attention = self.location_conv(attention_weights_cat)
|
|
147
|
+
processed_attention = processed_attention.transpose(1, 2)
|
|
148
|
+
processed_attention = self.location_dense(processed_attention)
|
|
149
|
+
return processed_attention
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class Attention(nn.Module):
|
|
153
|
+
def __init__(self, attention_rnn_dim, embedding_dim, attention_dim,
|
|
154
|
+
attention_location_n_filters, attention_location_kernel_size):
|
|
155
|
+
super(Attention, self).__init__()
|
|
156
|
+
self.query_layer = LinearNorm(attention_rnn_dim, attention_dim,
|
|
157
|
+
bias=False, w_init_gain='tanh')
|
|
158
|
+
self.memory_layer = LinearNorm(embedding_dim, attention_dim, bias=False,
|
|
159
|
+
w_init_gain='tanh')
|
|
160
|
+
self.v = LinearNorm(attention_dim, 1, bias=False)
|
|
161
|
+
self.location_layer = LocationLayer(attention_location_n_filters,
|
|
162
|
+
attention_location_kernel_size,
|
|
163
|
+
attention_dim)
|
|
164
|
+
self.score_mask_value = -float("inf")
|
|
165
|
+
|
|
166
|
+
def get_alignment_energies(self, query, processed_memory,
|
|
167
|
+
attention_weights_cat):
|
|
168
|
+
"""
|
|
169
|
+
PARAMS
|
|
170
|
+
------
|
|
171
|
+
query: decoder output (batch, n_mel_channels * n_frames_per_step)
|
|
172
|
+
processed_memory: processed encoder outputs (B, T_in, attention_dim)
|
|
173
|
+
attention_weights_cat: cumulative and prev. att weights (B, 2, max_time)
|
|
174
|
+
RETURNS
|
|
175
|
+
-------
|
|
176
|
+
alignment (batch, max_time)
|
|
177
|
+
"""
|
|
178
|
+
|
|
179
|
+
processed_query = self.query_layer(query.unsqueeze(1))
|
|
180
|
+
processed_attention_weights = self.location_layer(attention_weights_cat)
|
|
181
|
+
energies = self.v(torch.tanh(
|
|
182
|
+
processed_query + processed_attention_weights + processed_memory))
|
|
183
|
+
|
|
184
|
+
energies = energies.squeeze(-1)
|
|
185
|
+
return energies
|
|
186
|
+
|
|
187
|
+
def forward(self, attention_hidden_state, memory, processed_memory,
|
|
188
|
+
attention_weights_cat, mask):
|
|
189
|
+
"""
|
|
190
|
+
PARAMS
|
|
191
|
+
------
|
|
192
|
+
attention_hidden_state: attention rnn last output
|
|
193
|
+
memory: encoder outputs
|
|
194
|
+
processed_memory: processed encoder outputs
|
|
195
|
+
attention_weights_cat: previous and cummulative attention weights
|
|
196
|
+
mask: binary mask for padded data
|
|
197
|
+
"""
|
|
198
|
+
alignment = self.get_alignment_energies(
|
|
199
|
+
attention_hidden_state, processed_memory, attention_weights_cat)
|
|
200
|
+
|
|
201
|
+
if mask is not None:
|
|
202
|
+
alignment.data.masked_fill_(mask, self.score_mask_value)
|
|
203
|
+
|
|
204
|
+
attention_weights = F.softmax(alignment, dim=1)
|
|
205
|
+
attention_context = torch.bmm(attention_weights.unsqueeze(1), memory)
|
|
206
|
+
attention_context = attention_context.squeeze(1)
|
|
207
|
+
|
|
208
|
+
return attention_context, attention_weights
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
class ForwardAttentionV2(nn.Module):
|
|
212
|
+
def __init__(self, attention_rnn_dim, embedding_dim, attention_dim,
|
|
213
|
+
attention_location_n_filters, attention_location_kernel_size):
|
|
214
|
+
super(ForwardAttentionV2, self).__init__()
|
|
215
|
+
self.query_layer = LinearNorm(attention_rnn_dim, attention_dim,
|
|
216
|
+
bias=False, w_init_gain='tanh')
|
|
217
|
+
self.memory_layer = LinearNorm(embedding_dim, attention_dim, bias=False,
|
|
218
|
+
w_init_gain='tanh')
|
|
219
|
+
self.v = LinearNorm(attention_dim, 1, bias=False)
|
|
220
|
+
self.location_layer = LocationLayer(attention_location_n_filters,
|
|
221
|
+
attention_location_kernel_size,
|
|
222
|
+
attention_dim)
|
|
223
|
+
self.score_mask_value = -float(1e20)
|
|
224
|
+
|
|
225
|
+
def get_alignment_energies(self, query, processed_memory,
|
|
226
|
+
attention_weights_cat):
|
|
227
|
+
"""
|
|
228
|
+
PARAMS
|
|
229
|
+
------
|
|
230
|
+
query: decoder output (batch, n_mel_channels * n_frames_per_step)
|
|
231
|
+
processed_memory: processed encoder outputs (B, T_in, attention_dim)
|
|
232
|
+
attention_weights_cat: prev. and cumulative att weights (B, 2, max_time)
|
|
233
|
+
RETURNS
|
|
234
|
+
-------
|
|
235
|
+
alignment (batch, max_time)
|
|
236
|
+
"""
|
|
237
|
+
|
|
238
|
+
processed_query = self.query_layer(query.unsqueeze(1))
|
|
239
|
+
processed_attention_weights = self.location_layer(attention_weights_cat)
|
|
240
|
+
energies = self.v(torch.tanh(
|
|
241
|
+
processed_query + processed_attention_weights + processed_memory))
|
|
242
|
+
|
|
243
|
+
energies = energies.squeeze(-1)
|
|
244
|
+
return energies
|
|
245
|
+
|
|
246
|
+
def forward(self, attention_hidden_state, memory, processed_memory,
|
|
247
|
+
attention_weights_cat, mask, log_alpha):
|
|
248
|
+
"""
|
|
249
|
+
PARAMS
|
|
250
|
+
------
|
|
251
|
+
attention_hidden_state: attention rnn last output
|
|
252
|
+
memory: encoder outputs
|
|
253
|
+
processed_memory: processed encoder outputs
|
|
254
|
+
attention_weights_cat: previous and cummulative attention weights
|
|
255
|
+
mask: binary mask for padded data
|
|
256
|
+
"""
|
|
257
|
+
log_energy = self.get_alignment_energies(
|
|
258
|
+
attention_hidden_state, processed_memory, attention_weights_cat)
|
|
259
|
+
|
|
260
|
+
#log_energy =
|
|
261
|
+
|
|
262
|
+
if mask is not None:
|
|
263
|
+
log_energy.data.masked_fill_(mask, self.score_mask_value)
|
|
264
|
+
|
|
265
|
+
#attention_weights = F.softmax(alignment, dim=1)
|
|
266
|
+
|
|
267
|
+
#content_score = log_energy.unsqueeze(1) #[B, MAX_TIME] -> [B, 1, MAX_TIME]
|
|
268
|
+
#log_alpha = log_alpha.unsqueeze(2) #[B, MAX_TIME] -> [B, MAX_TIME, 1]
|
|
269
|
+
|
|
270
|
+
#log_total_score = log_alpha + content_score
|
|
271
|
+
|
|
272
|
+
#previous_attention_weights = attention_weights_cat[:,0,:]
|
|
273
|
+
|
|
274
|
+
log_alpha_shift_padded = []
|
|
275
|
+
max_time = log_energy.size(1)
|
|
276
|
+
for sft in range(2):
|
|
277
|
+
shifted = log_alpha[:,:max_time-sft]
|
|
278
|
+
shift_padded = F.pad(shifted, (sft,0), 'constant', self.score_mask_value)
|
|
279
|
+
log_alpha_shift_padded.append(shift_padded.unsqueeze(2))
|
|
280
|
+
|
|
281
|
+
biased = torch.logsumexp(torch.cat(log_alpha_shift_padded,2), 2)
|
|
282
|
+
|
|
283
|
+
log_alpha_new = biased + log_energy
|
|
284
|
+
|
|
285
|
+
attention_weights = F.softmax(log_alpha_new, dim=1)
|
|
286
|
+
|
|
287
|
+
attention_context = torch.bmm(attention_weights.unsqueeze(1), memory)
|
|
288
|
+
attention_context = attention_context.squeeze(1)
|
|
289
|
+
|
|
290
|
+
return attention_context, attention_weights, log_alpha_new
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
class PhaseShuffle2d(nn.Module):
|
|
294
|
+
def __init__(self, n=2):
|
|
295
|
+
super(PhaseShuffle2d, self).__init__()
|
|
296
|
+
self.n = n
|
|
297
|
+
self.random = random.Random(1)
|
|
298
|
+
|
|
299
|
+
def forward(self, x, move=None):
|
|
300
|
+
# x.size = (B, C, M, L)
|
|
301
|
+
if move is None:
|
|
302
|
+
move = self.random.randint(-self.n, self.n)
|
|
303
|
+
|
|
304
|
+
if move == 0:
|
|
305
|
+
return x
|
|
306
|
+
else:
|
|
307
|
+
left = x[:, :, :, :move]
|
|
308
|
+
right = x[:, :, :, move:]
|
|
309
|
+
shuffled = torch.cat([right, left], dim=3)
|
|
310
|
+
return shuffled
|
|
311
|
+
|
|
312
|
+
class PhaseShuffle1d(nn.Module):
|
|
313
|
+
def __init__(self, n=2):
|
|
314
|
+
super(PhaseShuffle1d, self).__init__()
|
|
315
|
+
self.n = n
|
|
316
|
+
self.random = random.Random(1)
|
|
317
|
+
|
|
318
|
+
def forward(self, x, move=None):
|
|
319
|
+
# x.size = (B, C, M, L)
|
|
320
|
+
if move is None:
|
|
321
|
+
move = self.random.randint(-self.n, self.n)
|
|
322
|
+
|
|
323
|
+
if move == 0:
|
|
324
|
+
return x
|
|
325
|
+
else:
|
|
326
|
+
left = x[:, :, :move]
|
|
327
|
+
right = x[:, :, move:]
|
|
328
|
+
shuffled = torch.cat([right, left], dim=2)
|
|
329
|
+
|
|
330
|
+
return shuffled
|
|
331
|
+
|
|
332
|
+
class MFCC(nn.Module):
|
|
333
|
+
def __init__(self, n_mfcc=40, n_mels=80):
|
|
334
|
+
super(MFCC, self).__init__()
|
|
335
|
+
self.n_mfcc = n_mfcc
|
|
336
|
+
self.n_mels = n_mels
|
|
337
|
+
self.norm = 'ortho'
|
|
338
|
+
dct_mat = audio_F.create_dct(self.n_mfcc, self.n_mels, self.norm)
|
|
339
|
+
self.register_buffer('dct_mat', dct_mat)
|
|
340
|
+
|
|
341
|
+
def forward(self, mel_specgram):
|
|
342
|
+
if len(mel_specgram.shape) == 2:
|
|
343
|
+
mel_specgram = mel_specgram.unsqueeze(0)
|
|
344
|
+
unsqueezed = True
|
|
345
|
+
else:
|
|
346
|
+
unsqueezed = False
|
|
347
|
+
# (channel, n_mels, time).tranpose(...) dot (n_mels, n_mfcc)
|
|
348
|
+
# -> (channel, time, n_mfcc).tranpose(...)
|
|
349
|
+
mfcc = torch.matmul(mel_specgram.transpose(1, 2), self.dct_mat).transpose(1, 2)
|
|
350
|
+
|
|
351
|
+
# unpack batch
|
|
352
|
+
if unsqueezed:
|
|
353
|
+
mfcc = mfcc.squeeze(0)
|
|
354
|
+
return mfcc
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
from typing import Tuple
|
|
2
|
+
import torch
|
|
3
|
+
import torch.nn as nn
|
|
4
|
+
from torch.nn import functional as F
|
|
5
|
+
from indextts.s2mel.modules.commons import sequence_mask
|
|
6
|
+
import numpy as np
|
|
7
|
+
from indextts.s2mel.dac.nn.quantize import VectorQuantize
|
|
8
|
+
|
|
9
|
+
# f0_bin = 256
|
|
10
|
+
f0_max = 1100.0
|
|
11
|
+
f0_min = 50.0
|
|
12
|
+
f0_mel_min = 1127 * np.log(1 + f0_min / 700)
|
|
13
|
+
f0_mel_max = 1127 * np.log(1 + f0_max / 700)
|
|
14
|
+
|
|
15
|
+
def f0_to_coarse(f0, f0_bin):
|
|
16
|
+
f0_mel = 1127 * (1 + f0 / 700).log()
|
|
17
|
+
a = (f0_bin - 2) / (f0_mel_max - f0_mel_min)
|
|
18
|
+
b = f0_mel_min * a - 1.
|
|
19
|
+
f0_mel = torch.where(f0_mel > 0, f0_mel * a - b, f0_mel)
|
|
20
|
+
# torch.clip_(f0_mel, min=1., max=float(f0_bin - 1))
|
|
21
|
+
f0_coarse = torch.round(f0_mel).long()
|
|
22
|
+
f0_coarse = f0_coarse * (f0_coarse > 0)
|
|
23
|
+
f0_coarse = f0_coarse + ((f0_coarse < 1) * 1)
|
|
24
|
+
f0_coarse = f0_coarse * (f0_coarse < f0_bin)
|
|
25
|
+
f0_coarse = f0_coarse + ((f0_coarse >= f0_bin) * (f0_bin - 1))
|
|
26
|
+
return f0_coarse
|
|
27
|
+
|
|
28
|
+
class InterpolateRegulator(nn.Module):
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
channels: int,
|
|
32
|
+
sampling_ratios: Tuple,
|
|
33
|
+
is_discrete: bool = False,
|
|
34
|
+
in_channels: int = None, # only applies to continuous input
|
|
35
|
+
vector_quantize: bool = False, # whether to use vector quantization, only applies to continuous input
|
|
36
|
+
codebook_size: int = 1024, # for discrete only
|
|
37
|
+
out_channels: int = None,
|
|
38
|
+
groups: int = 1,
|
|
39
|
+
n_codebooks: int = 1, # number of codebooks
|
|
40
|
+
quantizer_dropout: float = 0.0, # dropout for quantizer
|
|
41
|
+
f0_condition: bool = False,
|
|
42
|
+
n_f0_bins: int = 512,
|
|
43
|
+
):
|
|
44
|
+
super().__init__()
|
|
45
|
+
self.sampling_ratios = sampling_ratios
|
|
46
|
+
out_channels = out_channels or channels
|
|
47
|
+
model = nn.ModuleList([])
|
|
48
|
+
if len(sampling_ratios) > 0:
|
|
49
|
+
self.interpolate = True
|
|
50
|
+
for _ in sampling_ratios:
|
|
51
|
+
module = nn.Conv1d(channels, channels, 3, 1, 1)
|
|
52
|
+
norm = nn.GroupNorm(groups, channels)
|
|
53
|
+
act = nn.Mish()
|
|
54
|
+
model.extend([module, norm, act])
|
|
55
|
+
else:
|
|
56
|
+
self.interpolate = False
|
|
57
|
+
model.append(
|
|
58
|
+
nn.Conv1d(channels, out_channels, 1, 1)
|
|
59
|
+
)
|
|
60
|
+
self.model = nn.Sequential(*model)
|
|
61
|
+
self.embedding = nn.Embedding(codebook_size, channels)
|
|
62
|
+
self.is_discrete = is_discrete
|
|
63
|
+
|
|
64
|
+
self.mask_token = nn.Parameter(torch.zeros(1, channels))
|
|
65
|
+
|
|
66
|
+
self.n_codebooks = n_codebooks
|
|
67
|
+
if n_codebooks > 1:
|
|
68
|
+
self.extra_codebooks = nn.ModuleList([
|
|
69
|
+
nn.Embedding(codebook_size, channels) for _ in range(n_codebooks - 1)
|
|
70
|
+
])
|
|
71
|
+
self.extra_codebook_mask_tokens = nn.ParameterList([
|
|
72
|
+
nn.Parameter(torch.zeros(1, channels)) for _ in range(n_codebooks - 1)
|
|
73
|
+
])
|
|
74
|
+
self.quantizer_dropout = quantizer_dropout
|
|
75
|
+
|
|
76
|
+
if f0_condition:
|
|
77
|
+
self.f0_embedding = nn.Embedding(n_f0_bins, channels)
|
|
78
|
+
self.f0_condition = f0_condition
|
|
79
|
+
self.n_f0_bins = n_f0_bins
|
|
80
|
+
self.f0_bins = torch.arange(2, 1024, 1024 // n_f0_bins)
|
|
81
|
+
self.f0_mask = nn.Parameter(torch.zeros(1, channels))
|
|
82
|
+
else:
|
|
83
|
+
self.f0_condition = False
|
|
84
|
+
|
|
85
|
+
if not is_discrete:
|
|
86
|
+
self.content_in_proj = nn.Linear(in_channels, channels)
|
|
87
|
+
if vector_quantize:
|
|
88
|
+
self.vq = VectorQuantize(channels, codebook_size, 8)
|
|
89
|
+
|
|
90
|
+
def forward(self, x, ylens=None, n_quantizers=None, f0=None):
|
|
91
|
+
# apply token drop
|
|
92
|
+
if self.training:
|
|
93
|
+
n_quantizers = torch.ones((x.shape[0],)) * self.n_codebooks
|
|
94
|
+
dropout = torch.randint(1, self.n_codebooks + 1, (x.shape[0],))
|
|
95
|
+
n_dropout = int(x.shape[0] * self.quantizer_dropout)
|
|
96
|
+
n_quantizers[:n_dropout] = dropout[:n_dropout]
|
|
97
|
+
n_quantizers = n_quantizers.to(x.device)
|
|
98
|
+
# decide whether to drop for each sample in batch
|
|
99
|
+
else:
|
|
100
|
+
n_quantizers = torch.ones((x.shape[0],), device=x.device) * (self.n_codebooks if n_quantizers is None else n_quantizers)
|
|
101
|
+
if self.is_discrete:
|
|
102
|
+
if self.n_codebooks > 1:
|
|
103
|
+
assert len(x.size()) == 3
|
|
104
|
+
x_emb = self.embedding(x[:, 0])
|
|
105
|
+
for i, emb in enumerate(self.extra_codebooks):
|
|
106
|
+
x_emb = x_emb + (n_quantizers > i+1)[..., None, None] * emb(x[:, i+1])
|
|
107
|
+
# add mask token if not using this codebook
|
|
108
|
+
# x_emb = x_emb + (n_quantizers <= i+1)[..., None, None] * self.extra_codebook_mask_tokens[i]
|
|
109
|
+
x = x_emb
|
|
110
|
+
elif self.n_codebooks == 1:
|
|
111
|
+
if len(x.size()) == 2:
|
|
112
|
+
x = self.embedding(x)
|
|
113
|
+
else:
|
|
114
|
+
x = self.embedding(x[:, 0])
|
|
115
|
+
else:
|
|
116
|
+
x = self.content_in_proj(x)
|
|
117
|
+
# x in (B, T, D)
|
|
118
|
+
mask = sequence_mask(ylens).unsqueeze(-1)
|
|
119
|
+
if self.interpolate:
|
|
120
|
+
x = F.interpolate(x.transpose(1, 2).contiguous(), size=ylens.max(), mode='nearest')
|
|
121
|
+
else:
|
|
122
|
+
x = x.transpose(1, 2).contiguous()
|
|
123
|
+
mask = mask[:, :x.size(2), :]
|
|
124
|
+
ylens = ylens.clamp(max=x.size(2)).long()
|
|
125
|
+
if self.f0_condition:
|
|
126
|
+
if f0 is None:
|
|
127
|
+
x = x + self.f0_mask.unsqueeze(-1)
|
|
128
|
+
else:
|
|
129
|
+
#quantized_f0 = torch.bucketize(f0, self.f0_bins.to(f0.device)) # (N, T)
|
|
130
|
+
quantized_f0 = f0_to_coarse(f0, self.n_f0_bins)
|
|
131
|
+
quantized_f0 = quantized_f0.clamp(0, self.n_f0_bins - 1).long()
|
|
132
|
+
f0_emb = self.f0_embedding(quantized_f0)
|
|
133
|
+
f0_emb = F.interpolate(f0_emb.transpose(1, 2).contiguous(), size=ylens.max(), mode='nearest')
|
|
134
|
+
x = x + f0_emb
|
|
135
|
+
out = self.model(x).transpose(1, 2).contiguous()
|
|
136
|
+
if hasattr(self, 'vq'):
|
|
137
|
+
out_q, commitment_loss, codebook_loss, codes, out, = self.vq(out.transpose(1, 2))
|
|
138
|
+
out_q = out_q.transpose(1, 2)
|
|
139
|
+
return out_q * mask, ylens, codes, commitment_loss, codebook_loss
|
|
140
|
+
olens = ylens
|
|
141
|
+
return out * mask, olens, None, None, None
|
|
File without changes
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
import numpy as np
|
|
3
|
+
import re
|
|
4
|
+
import soundfile
|
|
5
|
+
from . import utils
|
|
6
|
+
from . import commons
|
|
7
|
+
import os
|
|
8
|
+
import librosa
|
|
9
|
+
# from openvoice.text import text_to_sequence
|
|
10
|
+
from .mel_processing import spectrogram_torch
|
|
11
|
+
from .models import SynthesizerTrn
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class OpenVoiceBaseClass(object):
|
|
15
|
+
def __init__(self,
|
|
16
|
+
config_path,
|
|
17
|
+
device='cuda:0'):
|
|
18
|
+
if 'cuda' in device:
|
|
19
|
+
assert torch.cuda.is_available()
|
|
20
|
+
|
|
21
|
+
hps = utils.get_hparams_from_file(config_path)
|
|
22
|
+
|
|
23
|
+
model = SynthesizerTrn(
|
|
24
|
+
len(getattr(hps, 'symbols', [])),
|
|
25
|
+
hps.data.filter_length // 2 + 1,
|
|
26
|
+
n_speakers=hps.data.n_speakers,
|
|
27
|
+
**hps.model,
|
|
28
|
+
).to(device)
|
|
29
|
+
|
|
30
|
+
model.eval()
|
|
31
|
+
self.model = model
|
|
32
|
+
self.hps = hps
|
|
33
|
+
self.device = device
|
|
34
|
+
|
|
35
|
+
def load_ckpt(self, ckpt_path):
|
|
36
|
+
checkpoint_dict = torch.load(ckpt_path, map_location=torch.device(self.device))
|
|
37
|
+
a, b = self.model.load_state_dict(checkpoint_dict['model'], strict=False)
|
|
38
|
+
print("Loaded checkpoint '{}'".format(ckpt_path))
|
|
39
|
+
print('missing/unexpected keys:', a, b)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class BaseSpeakerTTS(OpenVoiceBaseClass):
|
|
43
|
+
language_marks = {
|
|
44
|
+
"english": "EN",
|
|
45
|
+
"chinese": "ZH",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
def get_text(text, hps, is_symbol):
|
|
50
|
+
text_norm = text_to_sequence(text, hps.symbols, [] if is_symbol else hps.data.text_cleaners)
|
|
51
|
+
if hps.data.add_blank:
|
|
52
|
+
text_norm = commons.intersperse(text_norm, 0)
|
|
53
|
+
text_norm = torch.LongTensor(text_norm)
|
|
54
|
+
return text_norm
|
|
55
|
+
|
|
56
|
+
@staticmethod
|
|
57
|
+
def audio_numpy_concat(segment_data_list, sr, speed=1.):
|
|
58
|
+
audio_segments = []
|
|
59
|
+
for segment_data in segment_data_list:
|
|
60
|
+
audio_segments += segment_data.reshape(-1).tolist()
|
|
61
|
+
audio_segments += [0] * int((sr * 0.05)/speed)
|
|
62
|
+
audio_segments = np.array(audio_segments).astype(np.float32)
|
|
63
|
+
return audio_segments
|
|
64
|
+
|
|
65
|
+
@staticmethod
|
|
66
|
+
def split_segments_into_pieces(text, language_str):
|
|
67
|
+
texts = utils.split_segment(text, language_str=language_str)
|
|
68
|
+
print(" > Text split into segments.")
|
|
69
|
+
print('\n'.join(texts))
|
|
70
|
+
print(" > ===========================")
|
|
71
|
+
return texts
|
|
72
|
+
|
|
73
|
+
def tts(self, text, output_path, speaker, language='English', speed=1.0):
|
|
74
|
+
mark = self.language_marks.get(language.lower(), None)
|
|
75
|
+
assert mark is not None, f"language {language} is not supported"
|
|
76
|
+
|
|
77
|
+
texts = self.split_segments_into_pieces(text, mark)
|
|
78
|
+
|
|
79
|
+
audio_list = []
|
|
80
|
+
for t in texts:
|
|
81
|
+
t = re.sub(r'([a-z])([A-Z])', r'\1 \2', t)
|
|
82
|
+
t = f'[{mark}]{t}[{mark}]'
|
|
83
|
+
stn_tst = self.get_text(t, self.hps, False)
|
|
84
|
+
device = self.device
|
|
85
|
+
speaker_id = self.hps.speakers[speaker]
|
|
86
|
+
with torch.no_grad():
|
|
87
|
+
x_tst = stn_tst.unsqueeze(0).to(device)
|
|
88
|
+
x_tst_lengths = torch.LongTensor([stn_tst.size(0)]).to(device)
|
|
89
|
+
sid = torch.LongTensor([speaker_id]).to(device)
|
|
90
|
+
audio = self.model.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=0.667, noise_scale_w=0.6,
|
|
91
|
+
length_scale=1.0 / speed)[0][0, 0].data.cpu().float().numpy()
|
|
92
|
+
audio_list.append(audio)
|
|
93
|
+
audio = self.audio_numpy_concat(audio_list, sr=self.hps.data.sampling_rate, speed=speed)
|
|
94
|
+
|
|
95
|
+
if output_path is None:
|
|
96
|
+
return audio
|
|
97
|
+
else:
|
|
98
|
+
soundfile.write(output_path, audio, self.hps.data.sampling_rate)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class ToneColorConverter(OpenVoiceBaseClass):
|
|
102
|
+
def __init__(self, *args, **kwargs):
|
|
103
|
+
super().__init__(*args, **kwargs)
|
|
104
|
+
|
|
105
|
+
# if kwargs.get('enable_watermark', True):
|
|
106
|
+
# import wavmark
|
|
107
|
+
# self.watermark_model = wavmark.load_model().to(self.device)
|
|
108
|
+
# else:
|
|
109
|
+
# self.watermark_model = None
|
|
110
|
+
self.version = getattr(self.hps, '_version_', "v1")
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def extract_se(self, waves, wave_lengths):
|
|
115
|
+
|
|
116
|
+
device = self.device
|
|
117
|
+
hps = self.hps
|
|
118
|
+
gs = []
|
|
119
|
+
|
|
120
|
+
for wav_tensor, wav_len in zip(waves, wave_lengths):
|
|
121
|
+
y = wav_tensor[:wav_len]
|
|
122
|
+
y = y[None, :]
|
|
123
|
+
y = spectrogram_torch(y, hps.data.filter_length,
|
|
124
|
+
hps.data.sampling_rate, hps.data.hop_length, hps.data.win_length,
|
|
125
|
+
center=False).to(device)
|
|
126
|
+
with torch.no_grad():
|
|
127
|
+
g = self.model.ref_enc(y.transpose(1, 2)).unsqueeze(-1)
|
|
128
|
+
gs.append(g.detach())
|
|
129
|
+
gs = torch.stack(gs)
|
|
130
|
+
gs = gs.squeeze(1).squeeze(-1)
|
|
131
|
+
return gs
|
|
132
|
+
|
|
133
|
+
def convert(self, src_waves, src_wave_lengths, src_se, tgt_se, tau=0.3, message="default"):
|
|
134
|
+
hps = self.hps
|
|
135
|
+
# load audio
|
|
136
|
+
with torch.no_grad():
|
|
137
|
+
y = src_waves
|
|
138
|
+
spec = spectrogram_torch(y, hps.data.filter_length,
|
|
139
|
+
hps.data.sampling_rate, hps.data.hop_length, hps.data.win_length,
|
|
140
|
+
center=False).to(self.device)
|
|
141
|
+
spec_lengths = src_wave_lengths // hps.data.hop_length
|
|
142
|
+
spec_lengths = spec_lengths.clamp(min=1, max=spec.size(2))
|
|
143
|
+
audio = self.model.voice_conversion(spec, spec_lengths, sid_src=src_se.unsqueeze(-1), sid_tgt=tgt_se.unsqueeze(-1), tau=tau)[0]
|
|
144
|
+
return audio
|
|
145
|
+
|
|
146
|
+
def add_watermark(self, audio, message):
|
|
147
|
+
# if self.watermark_model is None:
|
|
148
|
+
return audio
|
|
149
|
+
device = self.device
|
|
150
|
+
bits = utils.string_to_bits(message).reshape(-1)
|
|
151
|
+
n_repeat = len(bits) // 32
|
|
152
|
+
|
|
153
|
+
K = 16000
|
|
154
|
+
coeff = 2
|
|
155
|
+
for n in range(n_repeat):
|
|
156
|
+
trunck = audio[(coeff * n) * K: (coeff * n + 1) * K]
|
|
157
|
+
if len(trunck) != K:
|
|
158
|
+
print('Audio too short, fail to add watermark')
|
|
159
|
+
break
|
|
160
|
+
message_npy = bits[n * 32: (n + 1) * 32]
|
|
161
|
+
|
|
162
|
+
with torch.no_grad():
|
|
163
|
+
signal = torch.FloatTensor(trunck).to(device)[None]
|
|
164
|
+
message_tensor = torch.FloatTensor(message_npy).to(device)[None]
|
|
165
|
+
signal_wmd_tensor = self.watermark_model.encode(signal, message_tensor)
|
|
166
|
+
signal_wmd_npy = signal_wmd_tensor.detach().cpu().squeeze()
|
|
167
|
+
audio[(coeff * n) * K: (coeff * n + 1) * K] = signal_wmd_npy
|
|
168
|
+
return audio
|
|
169
|
+
|
|
170
|
+
def detect_watermark(self, audio, n_repeat):
|
|
171
|
+
bits = []
|
|
172
|
+
K = 16000
|
|
173
|
+
coeff = 2
|
|
174
|
+
for n in range(n_repeat):
|
|
175
|
+
trunck = audio[(coeff * n) * K: (coeff * n + 1) * K]
|
|
176
|
+
if len(trunck) != K:
|
|
177
|
+
print('Audio too short, fail to detect watermark')
|
|
178
|
+
return 'Fail'
|
|
179
|
+
with torch.no_grad():
|
|
180
|
+
signal = torch.FloatTensor(trunck).to(self.device).unsqueeze(0)
|
|
181
|
+
message_decoded_npy = (self.watermark_model.decode(signal) >= 0.5).int().detach().cpu().numpy().squeeze()
|
|
182
|
+
bits.append(message_decoded_npy)
|
|
183
|
+
bits = np.stack(bits).reshape(-1, 8)
|
|
184
|
+
message = utils.bits_to_string(bits)
|
|
185
|
+
return message
|
|
186
|
+
|