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,451 @@
|
|
|
1
|
+
# Copyright (c) 2022 NVIDIA CORPORATION.
|
|
2
|
+
# Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
# Adapted from https://github.com/jik876/hifi-gan under the MIT license.
|
|
5
|
+
# LICENSE is in incl_licenses directory.
|
|
6
|
+
import torch
|
|
7
|
+
import torch.nn as nn
|
|
8
|
+
import torch.nn.functional as F
|
|
9
|
+
from torch.nn import Conv1d, Conv2d, ConvTranspose1d
|
|
10
|
+
from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm
|
|
11
|
+
|
|
12
|
+
import indextts.BigVGAN.activations as activations
|
|
13
|
+
|
|
14
|
+
from indextts.BigVGAN.ECAPA_TDNN import ECAPA_TDNN
|
|
15
|
+
from indextts.BigVGAN.utils import get_padding, init_weights
|
|
16
|
+
|
|
17
|
+
LRELU_SLOPE = 0.1
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AMPBlock1(torch.nn.Module):
|
|
21
|
+
def __init__(self, h, channels, kernel_size=3, dilation=(1, 3, 5), activation=None):
|
|
22
|
+
super(AMPBlock1, self).__init__()
|
|
23
|
+
self.h = h
|
|
24
|
+
|
|
25
|
+
self.convs1 = nn.ModuleList([
|
|
26
|
+
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=dilation[0],
|
|
27
|
+
padding=get_padding(kernel_size, dilation[0]))),
|
|
28
|
+
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=dilation[1],
|
|
29
|
+
padding=get_padding(kernel_size, dilation[1]))),
|
|
30
|
+
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=dilation[2],
|
|
31
|
+
padding=get_padding(kernel_size, dilation[2])))
|
|
32
|
+
])
|
|
33
|
+
self.convs1.apply(init_weights)
|
|
34
|
+
|
|
35
|
+
self.convs2 = nn.ModuleList([
|
|
36
|
+
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=1,
|
|
37
|
+
padding=get_padding(kernel_size, 1))),
|
|
38
|
+
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=1,
|
|
39
|
+
padding=get_padding(kernel_size, 1))),
|
|
40
|
+
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=1,
|
|
41
|
+
padding=get_padding(kernel_size, 1)))
|
|
42
|
+
])
|
|
43
|
+
self.convs2.apply(init_weights)
|
|
44
|
+
|
|
45
|
+
self.num_layers = len(self.convs1) + len(self.convs2) # total number of conv layers
|
|
46
|
+
if self.h.get("use_cuda_kernel", False):
|
|
47
|
+
from indextts.BigVGAN.alias_free_activation.cuda.activation1d import Activation1d
|
|
48
|
+
else:
|
|
49
|
+
from indextts.BigVGAN.alias_free_torch import Activation1d
|
|
50
|
+
if activation == 'snake': # periodic nonlinearity with snake function and anti-aliasing
|
|
51
|
+
self.activations = nn.ModuleList([
|
|
52
|
+
Activation1d(
|
|
53
|
+
activation=activations.Snake(channels, alpha_logscale=h.snake_logscale))
|
|
54
|
+
for _ in range(self.num_layers)
|
|
55
|
+
])
|
|
56
|
+
elif activation == 'snakebeta': # periodic nonlinearity with snakebeta function and anti-aliasing
|
|
57
|
+
self.activations = nn.ModuleList([
|
|
58
|
+
Activation1d(
|
|
59
|
+
activation=activations.SnakeBeta(channels, alpha_logscale=h.snake_logscale))
|
|
60
|
+
for _ in range(self.num_layers)
|
|
61
|
+
])
|
|
62
|
+
else:
|
|
63
|
+
raise NotImplementedError("activation incorrectly specified. check the config file and look for 'activation'.")
|
|
64
|
+
|
|
65
|
+
def forward(self, x):
|
|
66
|
+
acts1, acts2 = self.activations[::2], self.activations[1::2]
|
|
67
|
+
for c1, c2, a1, a2 in zip(self.convs1, self.convs2, acts1, acts2):
|
|
68
|
+
xt = a1(x)
|
|
69
|
+
xt = c1(xt)
|
|
70
|
+
xt = a2(xt)
|
|
71
|
+
xt = c2(xt)
|
|
72
|
+
x = xt + x
|
|
73
|
+
|
|
74
|
+
return x
|
|
75
|
+
|
|
76
|
+
def remove_weight_norm(self):
|
|
77
|
+
for l in self.convs1:
|
|
78
|
+
remove_weight_norm(l)
|
|
79
|
+
for l in self.convs2:
|
|
80
|
+
remove_weight_norm(l)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class AMPBlock2(torch.nn.Module):
|
|
84
|
+
def __init__(self, h, channels, kernel_size=3, dilation=(1, 3), activation=None):
|
|
85
|
+
super(AMPBlock2, self).__init__()
|
|
86
|
+
self.h = h
|
|
87
|
+
|
|
88
|
+
self.convs = nn.ModuleList([
|
|
89
|
+
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=dilation[0],
|
|
90
|
+
padding=get_padding(kernel_size, dilation[0]))),
|
|
91
|
+
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=dilation[1],
|
|
92
|
+
padding=get_padding(kernel_size, dilation[1])))
|
|
93
|
+
])
|
|
94
|
+
self.convs.apply(init_weights)
|
|
95
|
+
|
|
96
|
+
self.num_layers = len(self.convs) # total number of conv layers
|
|
97
|
+
if self.h.get("use_cuda_kernel", False):
|
|
98
|
+
from indextts.BigVGAN.alias_free_activation.cuda.activation1d import Activation1d
|
|
99
|
+
else:
|
|
100
|
+
from indextts.BigVGAN.alias_free_torch import Activation1d
|
|
101
|
+
|
|
102
|
+
if activation == 'snake': # periodic nonlinearity with snake function and anti-aliasing
|
|
103
|
+
self.activations = nn.ModuleList([
|
|
104
|
+
Activation1d(
|
|
105
|
+
activation=activations.Snake(channels, alpha_logscale=h.snake_logscale))
|
|
106
|
+
for _ in range(self.num_layers)
|
|
107
|
+
])
|
|
108
|
+
elif activation == 'snakebeta': # periodic nonlinearity with snakebeta function and anti-aliasing
|
|
109
|
+
self.activations = nn.ModuleList([
|
|
110
|
+
Activation1d(
|
|
111
|
+
activation=activations.SnakeBeta(channels, alpha_logscale=h.snake_logscale))
|
|
112
|
+
for _ in range(self.num_layers)
|
|
113
|
+
])
|
|
114
|
+
else:
|
|
115
|
+
raise NotImplementedError("activation incorrectly specified. check the config file and look for 'activation'.")
|
|
116
|
+
|
|
117
|
+
def forward(self, x):
|
|
118
|
+
for c, a in zip(self.convs, self.activations):
|
|
119
|
+
xt = a(x)
|
|
120
|
+
xt = c(xt)
|
|
121
|
+
x = xt + x
|
|
122
|
+
|
|
123
|
+
return x
|
|
124
|
+
|
|
125
|
+
def remove_weight_norm(self):
|
|
126
|
+
for l in self.convs:
|
|
127
|
+
remove_weight_norm(l)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class BigVGAN(torch.nn.Module):
|
|
131
|
+
# this is our main BigVGAN model. Applies anti-aliased periodic activation for resblocks.
|
|
132
|
+
def __init__(self, h, use_cuda_kernel=False):
|
|
133
|
+
"""
|
|
134
|
+
Args:
|
|
135
|
+
h (dict)
|
|
136
|
+
use_cuda_kernel (bool): whether to use custom cuda kernel for anti-aliased activation
|
|
137
|
+
"""
|
|
138
|
+
super(BigVGAN, self).__init__()
|
|
139
|
+
self.h = h
|
|
140
|
+
self.h["use_cuda_kernel"] = use_cuda_kernel
|
|
141
|
+
|
|
142
|
+
self.num_kernels = len(h.resblock_kernel_sizes)
|
|
143
|
+
self.num_upsamples = len(h.upsample_rates)
|
|
144
|
+
|
|
145
|
+
self.feat_upsample = h.feat_upsample
|
|
146
|
+
self.cond_in_each_up_layer = h.cond_d_vector_in_each_upsampling_layer
|
|
147
|
+
|
|
148
|
+
# pre conv
|
|
149
|
+
self.conv_pre = weight_norm(Conv1d(h.gpt_dim, h.upsample_initial_channel, 7, 1, padding=3))
|
|
150
|
+
|
|
151
|
+
# define which AMPBlock to use. BigVGAN uses AMPBlock1 as default
|
|
152
|
+
resblock = AMPBlock1 if h.resblock == "1" else AMPBlock2
|
|
153
|
+
|
|
154
|
+
# transposed conv-based upsamplers. does not apply anti-aliasing
|
|
155
|
+
self.ups = nn.ModuleList()
|
|
156
|
+
for i, (u, k) in enumerate(zip(h.upsample_rates, h.upsample_kernel_sizes)):
|
|
157
|
+
self.ups.append(nn.ModuleList([
|
|
158
|
+
weight_norm(ConvTranspose1d(h.upsample_initial_channel // (2 ** i),
|
|
159
|
+
h.upsample_initial_channel // (2 ** (i + 1)),
|
|
160
|
+
k, u, padding=(k - u) // 2))
|
|
161
|
+
]))
|
|
162
|
+
|
|
163
|
+
# residual blocks using anti-aliased multi-periodicity composition modules (AMP)
|
|
164
|
+
self.resblocks = nn.ModuleList()
|
|
165
|
+
for i in range(len(self.ups)):
|
|
166
|
+
ch = h.upsample_initial_channel // (2 ** (i + 1))
|
|
167
|
+
for j, (k, d) in enumerate(zip(h.resblock_kernel_sizes, h.resblock_dilation_sizes)):
|
|
168
|
+
self.resblocks.append(resblock(self.h, ch, k, d, activation=h.activation))
|
|
169
|
+
if use_cuda_kernel:
|
|
170
|
+
from indextts.BigVGAN.alias_free_activation.cuda.activation1d import Activation1d
|
|
171
|
+
else:
|
|
172
|
+
from indextts.BigVGAN.alias_free_torch import Activation1d
|
|
173
|
+
|
|
174
|
+
# post conv
|
|
175
|
+
if h.activation == "snake": # periodic nonlinearity with snake function and anti-aliasing
|
|
176
|
+
activation_post = activations.Snake(ch, alpha_logscale=h.snake_logscale)
|
|
177
|
+
self.activation_post = Activation1d(activation=activation_post)
|
|
178
|
+
elif h.activation == "snakebeta": # periodic nonlinearity with snakebeta function and anti-aliasing
|
|
179
|
+
activation_post = activations.SnakeBeta(ch, alpha_logscale=h.snake_logscale)
|
|
180
|
+
self.activation_post = Activation1d(activation=activation_post)
|
|
181
|
+
else:
|
|
182
|
+
raise NotImplementedError("activation incorrectly specified. check the config file and look for 'activation'.")
|
|
183
|
+
|
|
184
|
+
self.conv_post = weight_norm(Conv1d(ch, 1, 7, 1, padding=3))
|
|
185
|
+
|
|
186
|
+
# weight initialization
|
|
187
|
+
for i in range(len(self.ups)):
|
|
188
|
+
self.ups[i].apply(init_weights)
|
|
189
|
+
self.conv_post.apply(init_weights)
|
|
190
|
+
|
|
191
|
+
self.speaker_encoder = ECAPA_TDNN(h.num_mels, lin_neurons=h.speaker_embedding_dim)
|
|
192
|
+
self.cond_layer = nn.Conv1d(h.speaker_embedding_dim, h.upsample_initial_channel, 1)
|
|
193
|
+
if self.cond_in_each_up_layer:
|
|
194
|
+
self.conds = nn.ModuleList()
|
|
195
|
+
for i in range(len(self.ups)):
|
|
196
|
+
ch = h.upsample_initial_channel // (2 ** (i + 1))
|
|
197
|
+
self.conds.append(nn.Conv1d(h.speaker_embedding_dim, ch, 1))
|
|
198
|
+
|
|
199
|
+
# self.logit_scale = nn.Parameter(torch.ones([]) * np.log(1 / 0.07))
|
|
200
|
+
|
|
201
|
+
def forward(self, x, mel_ref, lens=None):
|
|
202
|
+
speaker_embedding = self.speaker_encoder(mel_ref, lens)
|
|
203
|
+
n_batch = x.size(0)
|
|
204
|
+
contrastive_loss = None
|
|
205
|
+
if n_batch * 2 == speaker_embedding.size(0):
|
|
206
|
+
spe_emb_chunk1, spe_emb_chunk2 = speaker_embedding[:n_batch, :, :], speaker_embedding[n_batch:, :, :]
|
|
207
|
+
contrastive_loss = self.cal_clip_loss(spe_emb_chunk1.squeeze(1), spe_emb_chunk2.squeeze(1), self.logit_scale.exp())
|
|
208
|
+
|
|
209
|
+
speaker_embedding = speaker_embedding[:n_batch, :, :]
|
|
210
|
+
speaker_embedding = speaker_embedding.transpose(1, 2)
|
|
211
|
+
|
|
212
|
+
# upsample feat
|
|
213
|
+
if self.feat_upsample:
|
|
214
|
+
x = torch.nn.functional.interpolate(
|
|
215
|
+
x.transpose(1, 2),
|
|
216
|
+
scale_factor=[4],
|
|
217
|
+
mode="linear",
|
|
218
|
+
).squeeze(1)
|
|
219
|
+
else:
|
|
220
|
+
x = x.transpose(1, 2)
|
|
221
|
+
|
|
222
|
+
### bigVGAN ###
|
|
223
|
+
# pre conv
|
|
224
|
+
x = self.conv_pre(x)
|
|
225
|
+
|
|
226
|
+
x = x + self.cond_layer(speaker_embedding)
|
|
227
|
+
|
|
228
|
+
for i in range(self.num_upsamples):
|
|
229
|
+
# upsampling
|
|
230
|
+
for i_up in range(len(self.ups[i])):
|
|
231
|
+
x = self.ups[i][i_up](x)
|
|
232
|
+
|
|
233
|
+
if self.cond_in_each_up_layer:
|
|
234
|
+
x = x + self.conds[i](speaker_embedding)
|
|
235
|
+
|
|
236
|
+
# AMP blocks
|
|
237
|
+
xs = None
|
|
238
|
+
for j in range(self.num_kernels):
|
|
239
|
+
if xs is None:
|
|
240
|
+
xs = self.resblocks[i * self.num_kernels + j](x)
|
|
241
|
+
else:
|
|
242
|
+
xs += self.resblocks[i * self.num_kernels + j](x)
|
|
243
|
+
x = xs / self.num_kernels
|
|
244
|
+
|
|
245
|
+
# post conv
|
|
246
|
+
x = self.activation_post(x)
|
|
247
|
+
x = self.conv_post(x)
|
|
248
|
+
x = torch.tanh(x)
|
|
249
|
+
|
|
250
|
+
return x, contrastive_loss
|
|
251
|
+
|
|
252
|
+
def remove_weight_norm(self):
|
|
253
|
+
print('Removing weight norm...')
|
|
254
|
+
for l in self.ups:
|
|
255
|
+
for l_i in l:
|
|
256
|
+
remove_weight_norm(l_i)
|
|
257
|
+
for l in self.resblocks:
|
|
258
|
+
l.remove_weight_norm()
|
|
259
|
+
remove_weight_norm(self.conv_pre)
|
|
260
|
+
remove_weight_norm(self.conv_post)
|
|
261
|
+
|
|
262
|
+
def cal_clip_loss(self, image_features, text_features, logit_scale):
|
|
263
|
+
device = image_features.device
|
|
264
|
+
logits_per_image, logits_per_text = self.get_logits(image_features, text_features, logit_scale)
|
|
265
|
+
labels = torch.arange(logits_per_image.shape[0], device=device, dtype=torch.long)
|
|
266
|
+
total_loss = (
|
|
267
|
+
F.cross_entropy(logits_per_image, labels) +
|
|
268
|
+
F.cross_entropy(logits_per_text, labels)
|
|
269
|
+
) / 2
|
|
270
|
+
return total_loss
|
|
271
|
+
|
|
272
|
+
def get_logits(self, image_features, text_features, logit_scale):
|
|
273
|
+
logits_per_image = logit_scale * image_features @ text_features.T
|
|
274
|
+
logits_per_text = logit_scale * text_features @ image_features.T
|
|
275
|
+
return logits_per_image, logits_per_text
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
class DiscriminatorP(torch.nn.Module):
|
|
279
|
+
def __init__(self, h, period, kernel_size=5, stride=3, use_spectral_norm=False):
|
|
280
|
+
super(DiscriminatorP, self).__init__()
|
|
281
|
+
self.period = period
|
|
282
|
+
self.d_mult = h.discriminator_channel_mult
|
|
283
|
+
norm_f = weight_norm if use_spectral_norm == False else spectral_norm
|
|
284
|
+
self.convs = nn.ModuleList([
|
|
285
|
+
norm_f(Conv2d(1, int(32 * self.d_mult), (kernel_size, 1), (stride, 1), padding=(get_padding(5, 1), 0))),
|
|
286
|
+
norm_f(Conv2d(int(32 * self.d_mult), int(128 * self.d_mult), (kernel_size, 1), (stride, 1), padding=(get_padding(5, 1), 0))),
|
|
287
|
+
norm_f(Conv2d(int(128 * self.d_mult), int(512 * self.d_mult), (kernel_size, 1), (stride, 1), padding=(get_padding(5, 1), 0))),
|
|
288
|
+
norm_f(Conv2d(int(512 * self.d_mult), int(1024 * self.d_mult), (kernel_size, 1), (stride, 1), padding=(get_padding(5, 1), 0))),
|
|
289
|
+
norm_f(Conv2d(int(1024 * self.d_mult), int(1024 * self.d_mult), (kernel_size, 1), 1, padding=(2, 0))),
|
|
290
|
+
])
|
|
291
|
+
self.conv_post = norm_f(Conv2d(int(1024 * self.d_mult), 1, (3, 1), 1, padding=(1, 0)))
|
|
292
|
+
|
|
293
|
+
def forward(self, x):
|
|
294
|
+
fmap = []
|
|
295
|
+
|
|
296
|
+
# 1d to 2d
|
|
297
|
+
b, c, t = x.shape
|
|
298
|
+
if t % self.period != 0: # pad first
|
|
299
|
+
n_pad = self.period - (t % self.period)
|
|
300
|
+
x = F.pad(x, (0, n_pad), "reflect")
|
|
301
|
+
t = t + n_pad
|
|
302
|
+
x = x.view(b, c, t // self.period, self.period)
|
|
303
|
+
|
|
304
|
+
for l in self.convs:
|
|
305
|
+
x = l(x)
|
|
306
|
+
x = F.leaky_relu(x, LRELU_SLOPE)
|
|
307
|
+
fmap.append(x)
|
|
308
|
+
x = self.conv_post(x)
|
|
309
|
+
fmap.append(x)
|
|
310
|
+
x = torch.flatten(x, 1, -1)
|
|
311
|
+
|
|
312
|
+
return x, fmap
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
class MultiPeriodDiscriminator(torch.nn.Module):
|
|
316
|
+
def __init__(self, h):
|
|
317
|
+
super(MultiPeriodDiscriminator, self).__init__()
|
|
318
|
+
self.mpd_reshapes = h.mpd_reshapes
|
|
319
|
+
print("mpd_reshapes: {}".format(self.mpd_reshapes))
|
|
320
|
+
discriminators = [DiscriminatorP(h, rs, use_spectral_norm=h.use_spectral_norm) for rs in self.mpd_reshapes]
|
|
321
|
+
self.discriminators = nn.ModuleList(discriminators)
|
|
322
|
+
|
|
323
|
+
def forward(self, y, y_hat):
|
|
324
|
+
y_d_rs = []
|
|
325
|
+
y_d_gs = []
|
|
326
|
+
fmap_rs = []
|
|
327
|
+
fmap_gs = []
|
|
328
|
+
for i, d in enumerate(self.discriminators):
|
|
329
|
+
y_d_r, fmap_r = d(y)
|
|
330
|
+
y_d_g, fmap_g = d(y_hat)
|
|
331
|
+
y_d_rs.append(y_d_r)
|
|
332
|
+
fmap_rs.append(fmap_r)
|
|
333
|
+
y_d_gs.append(y_d_g)
|
|
334
|
+
fmap_gs.append(fmap_g)
|
|
335
|
+
|
|
336
|
+
return y_d_rs, y_d_gs, fmap_rs, fmap_gs
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
class DiscriminatorR(nn.Module):
|
|
340
|
+
def __init__(self, cfg, resolution):
|
|
341
|
+
super().__init__()
|
|
342
|
+
|
|
343
|
+
self.resolution = resolution
|
|
344
|
+
assert len(self.resolution) == 3, \
|
|
345
|
+
"MRD layer requires list with len=3, got {}".format(self.resolution)
|
|
346
|
+
self.lrelu_slope = LRELU_SLOPE
|
|
347
|
+
|
|
348
|
+
norm_f = weight_norm if cfg.use_spectral_norm == False else spectral_norm
|
|
349
|
+
if hasattr(cfg, "mrd_use_spectral_norm"):
|
|
350
|
+
print("INFO: overriding MRD use_spectral_norm as {}".format(cfg.mrd_use_spectral_norm))
|
|
351
|
+
norm_f = weight_norm if cfg.mrd_use_spectral_norm == False else spectral_norm
|
|
352
|
+
self.d_mult = cfg.discriminator_channel_mult
|
|
353
|
+
if hasattr(cfg, "mrd_channel_mult"):
|
|
354
|
+
print("INFO: overriding mrd channel multiplier as {}".format(cfg.mrd_channel_mult))
|
|
355
|
+
self.d_mult = cfg.mrd_channel_mult
|
|
356
|
+
|
|
357
|
+
self.convs = nn.ModuleList([
|
|
358
|
+
norm_f(nn.Conv2d(1, int(32 * self.d_mult), (3, 9), padding=(1, 4))),
|
|
359
|
+
norm_f(nn.Conv2d(int(32 * self.d_mult), int(32 * self.d_mult), (3, 9), stride=(1, 2), padding=(1, 4))),
|
|
360
|
+
norm_f(nn.Conv2d(int(32 * self.d_mult), int(32 * self.d_mult), (3, 9), stride=(1, 2), padding=(1, 4))),
|
|
361
|
+
norm_f(nn.Conv2d(int(32 * self.d_mult), int(32 * self.d_mult), (3, 9), stride=(1, 2), padding=(1, 4))),
|
|
362
|
+
norm_f(nn.Conv2d(int(32 * self.d_mult), int(32 * self.d_mult), (3, 3), padding=(1, 1))),
|
|
363
|
+
])
|
|
364
|
+
self.conv_post = norm_f(nn.Conv2d(int(32 * self.d_mult), 1, (3, 3), padding=(1, 1)))
|
|
365
|
+
|
|
366
|
+
def forward(self, x):
|
|
367
|
+
fmap = []
|
|
368
|
+
|
|
369
|
+
x = self.spectrogram(x)
|
|
370
|
+
x = x.unsqueeze(1)
|
|
371
|
+
for l in self.convs:
|
|
372
|
+
x = l(x)
|
|
373
|
+
x = F.leaky_relu(x, self.lrelu_slope)
|
|
374
|
+
fmap.append(x)
|
|
375
|
+
x = self.conv_post(x)
|
|
376
|
+
fmap.append(x)
|
|
377
|
+
x = torch.flatten(x, 1, -1)
|
|
378
|
+
|
|
379
|
+
return x, fmap
|
|
380
|
+
|
|
381
|
+
def spectrogram(self, x):
|
|
382
|
+
n_fft, hop_length, win_length = self.resolution
|
|
383
|
+
x = F.pad(x, (int((n_fft - hop_length) / 2), int((n_fft - hop_length) / 2)), mode='reflect')
|
|
384
|
+
x = x.squeeze(1)
|
|
385
|
+
x = torch.stft(x, n_fft=n_fft, hop_length=hop_length, win_length=win_length, center=False, return_complex=True)
|
|
386
|
+
x = torch.view_as_real(x) # [B, F, TT, 2]
|
|
387
|
+
mag = torch.norm(x, p=2, dim=-1) # [B, F, TT]
|
|
388
|
+
|
|
389
|
+
return mag
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
class MultiResolutionDiscriminator(nn.Module):
|
|
393
|
+
def __init__(self, cfg, debug=False):
|
|
394
|
+
super().__init__()
|
|
395
|
+
self.resolutions = cfg.resolutions
|
|
396
|
+
assert len(self.resolutions) == 3, \
|
|
397
|
+
"MRD requires list of list with len=3, each element having a list with len=3. got {}".\
|
|
398
|
+
format(self.resolutions)
|
|
399
|
+
self.discriminators = nn.ModuleList(
|
|
400
|
+
[DiscriminatorR(cfg, resolution) for resolution in self.resolutions]
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
def forward(self, y, y_hat):
|
|
404
|
+
y_d_rs = []
|
|
405
|
+
y_d_gs = []
|
|
406
|
+
fmap_rs = []
|
|
407
|
+
fmap_gs = []
|
|
408
|
+
|
|
409
|
+
for i, d in enumerate(self.discriminators):
|
|
410
|
+
y_d_r, fmap_r = d(x=y)
|
|
411
|
+
y_d_g, fmap_g = d(x=y_hat)
|
|
412
|
+
y_d_rs.append(y_d_r)
|
|
413
|
+
fmap_rs.append(fmap_r)
|
|
414
|
+
y_d_gs.append(y_d_g)
|
|
415
|
+
fmap_gs.append(fmap_g)
|
|
416
|
+
|
|
417
|
+
return y_d_rs, y_d_gs, fmap_rs, fmap_gs
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def feature_loss(fmap_r, fmap_g):
|
|
421
|
+
loss = 0
|
|
422
|
+
for dr, dg in zip(fmap_r, fmap_g):
|
|
423
|
+
for rl, gl in zip(dr, dg):
|
|
424
|
+
loss += torch.mean(torch.abs(rl - gl))
|
|
425
|
+
|
|
426
|
+
return loss * 2
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
def discriminator_loss(disc_real_outputs, disc_generated_outputs):
|
|
430
|
+
loss = 0
|
|
431
|
+
r_losses = []
|
|
432
|
+
g_losses = []
|
|
433
|
+
for dr, dg in zip(disc_real_outputs, disc_generated_outputs):
|
|
434
|
+
r_loss = torch.mean((1 - dr)**2)
|
|
435
|
+
g_loss = torch.mean(dg**2)
|
|
436
|
+
loss += (r_loss + g_loss)
|
|
437
|
+
r_losses.append(r_loss.item())
|
|
438
|
+
g_losses.append(g_loss.item())
|
|
439
|
+
|
|
440
|
+
return loss, r_losses, g_losses
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def generator_loss(disc_outputs):
|
|
444
|
+
loss = 0
|
|
445
|
+
gen_losses = []
|
|
446
|
+
for dg in disc_outputs:
|
|
447
|
+
l = torch.mean((1 - dg)**2)
|
|
448
|
+
gen_losses.append(l)
|
|
449
|
+
loss += l
|
|
450
|
+
|
|
451
|
+
return loss, gen_losses
|