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,503 @@
|
|
|
1
|
+
# Copyright (c) 2024 Amphion.
|
|
2
|
+
#
|
|
3
|
+
# This source code is licensed under the MIT license found in the
|
|
4
|
+
# LICENSE file in the root directory of this source tree.
|
|
5
|
+
|
|
6
|
+
import torch
|
|
7
|
+
import numpy as np
|
|
8
|
+
import torch.nn as nn
|
|
9
|
+
import math
|
|
10
|
+
from einops import rearrange
|
|
11
|
+
from indextts.utils.maskgct.models.tts.maskgct.llama_nar import DiffLlama
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def top_k(logits, thres=0.9):
|
|
15
|
+
k = math.ceil((1 - thres) * logits.shape[-1])
|
|
16
|
+
val, ind = logits.topk(k, dim=-1)
|
|
17
|
+
probs = torch.full_like(logits, float("-inf"))
|
|
18
|
+
probs.scatter_(2, ind, val)
|
|
19
|
+
return probs
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def log(t, eps=1e-10):
|
|
23
|
+
return torch.log(t + eps)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def gumbel_noise(t):
|
|
27
|
+
noise = torch.zeros_like(t).uniform_(0, 1)
|
|
28
|
+
return -log(-log(noise))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def gumbel_sample(t, temperature=1.0, dim=-1):
|
|
32
|
+
return ((t / max(temperature, 1e-10)) + gumbel_noise(t)).argmax(dim=dim)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def top_k(logits, thres=0.9):
|
|
36
|
+
k = math.ceil((1 - thres) * logits.shape[-1])
|
|
37
|
+
val, ind = logits.topk(k, dim=-1)
|
|
38
|
+
probs = torch.full_like(logits, float("-inf"))
|
|
39
|
+
probs.scatter_(2, ind, val)
|
|
40
|
+
return probs
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def log(t, eps=1e-10):
|
|
44
|
+
return torch.log(t + eps)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def gumbel_noise(t):
|
|
48
|
+
noise = torch.zeros_like(t).uniform_(0, 1)
|
|
49
|
+
return -log(-log(noise))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def gumbel_sample(t, temperature=1.0, dim=-1):
|
|
53
|
+
return ((t / max(temperature, 1e-10)) + gumbel_noise(t)).argmax(dim=dim)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class MaskGCT_S2A(nn.Module):
|
|
57
|
+
def __init__(
|
|
58
|
+
self,
|
|
59
|
+
num_quantizer=12,
|
|
60
|
+
hidden_size=1024,
|
|
61
|
+
num_layers=16,
|
|
62
|
+
num_heads=16,
|
|
63
|
+
codebook_size=1024,
|
|
64
|
+
cfg_scale=0.15,
|
|
65
|
+
mask_layer_schedule="linear",
|
|
66
|
+
cond_codebook_size=1024,
|
|
67
|
+
cond_dim=1024,
|
|
68
|
+
predict_layer_1=True,
|
|
69
|
+
cfg=None,
|
|
70
|
+
):
|
|
71
|
+
super().__init__()
|
|
72
|
+
|
|
73
|
+
num_quantizer = (
|
|
74
|
+
cfg.num_quantizer
|
|
75
|
+
if cfg is not None and hasattr(cfg, "num_quantizer")
|
|
76
|
+
else num_quantizer
|
|
77
|
+
)
|
|
78
|
+
hidden_size = (
|
|
79
|
+
cfg.hidden_size
|
|
80
|
+
if cfg is not None and hasattr(cfg, "hidden_size")
|
|
81
|
+
else hidden_size
|
|
82
|
+
)
|
|
83
|
+
num_layers = (
|
|
84
|
+
cfg.num_layers
|
|
85
|
+
if cfg is not None and hasattr(cfg, "num_layers")
|
|
86
|
+
else num_layers
|
|
87
|
+
)
|
|
88
|
+
num_heads = (
|
|
89
|
+
cfg.num_heads
|
|
90
|
+
if cfg is not None and hasattr(cfg, "num_heads")
|
|
91
|
+
else num_heads
|
|
92
|
+
)
|
|
93
|
+
codebook_size = (
|
|
94
|
+
cfg.codebook_size
|
|
95
|
+
if cfg is not None and hasattr(cfg, "codebook_size")
|
|
96
|
+
else codebook_size
|
|
97
|
+
)
|
|
98
|
+
cfg_scale = (
|
|
99
|
+
cfg.cfg_scale
|
|
100
|
+
if cfg is not None and hasattr(cfg, "cfg_scale")
|
|
101
|
+
else cfg_scale
|
|
102
|
+
)
|
|
103
|
+
mask_layer_schedule = (
|
|
104
|
+
cfg.mask_layer_schedule
|
|
105
|
+
if cfg is not None and hasattr(cfg, "mask_layer_schedule")
|
|
106
|
+
else mask_layer_schedule
|
|
107
|
+
)
|
|
108
|
+
cond_codebook_size = (
|
|
109
|
+
cfg.cond_codebook_size
|
|
110
|
+
if cfg is not None and hasattr(cfg, "cond_codebook_size")
|
|
111
|
+
else cond_codebook_size
|
|
112
|
+
)
|
|
113
|
+
cond_dim = (
|
|
114
|
+
cfg.cond_dim if cfg is not None and hasattr(cfg, "cond_dim") else cond_dim
|
|
115
|
+
)
|
|
116
|
+
predict_layer_1 = (
|
|
117
|
+
cfg.predict_layer_1
|
|
118
|
+
if cfg is not None and hasattr(cfg, "predict_layer_1")
|
|
119
|
+
else predict_layer_1
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
self.num_quantizer = num_quantizer
|
|
123
|
+
self.hidden_size = hidden_size
|
|
124
|
+
self.codebook_size = codebook_size
|
|
125
|
+
self.num_layers = num_layers
|
|
126
|
+
self.num_heads = num_heads
|
|
127
|
+
self.cfg_scale = cfg_scale
|
|
128
|
+
self.mask_layer_schedule = mask_layer_schedule
|
|
129
|
+
self.cond_codebook_size = cond_codebook_size
|
|
130
|
+
self.cond_dim = cond_dim
|
|
131
|
+
self.predict_layer_1 = predict_layer_1
|
|
132
|
+
|
|
133
|
+
self.layer_emb = nn.Embedding(self.num_quantizer, self.hidden_size)
|
|
134
|
+
self.mask_emb = nn.Embedding(1, self.hidden_size)
|
|
135
|
+
|
|
136
|
+
self.token_emb = torch.nn.ModuleList(
|
|
137
|
+
[
|
|
138
|
+
nn.Embedding(self.codebook_size, self.hidden_size)
|
|
139
|
+
for _ in range(self.num_quantizer)
|
|
140
|
+
]
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
self.to_logits = torch.nn.ModuleList(
|
|
144
|
+
[
|
|
145
|
+
nn.Linear(self.hidden_size, self.codebook_size)
|
|
146
|
+
for _ in range(self.num_quantizer)
|
|
147
|
+
]
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
self.cond_emb = nn.Embedding(cond_codebook_size, self.hidden_size)
|
|
151
|
+
|
|
152
|
+
self.reset_parameters()
|
|
153
|
+
|
|
154
|
+
self.diff_estimator = DiffLlama(
|
|
155
|
+
hidden_size=hidden_size,
|
|
156
|
+
num_heads=self.num_heads,
|
|
157
|
+
num_layers=num_layers,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
def mask_prob(self, t):
|
|
161
|
+
return torch.sin(t * np.pi / 2).to(t.device)
|
|
162
|
+
|
|
163
|
+
def mask_layer(self, t):
|
|
164
|
+
# print(self.predict_layer_1)
|
|
165
|
+
if self.mask_layer_schedule == "uniform":
|
|
166
|
+
if self.predict_layer_1:
|
|
167
|
+
mask_layer = torch.randint(0, self.num_quantizer, (1,)).to(t.device)
|
|
168
|
+
else:
|
|
169
|
+
mask_layer = torch.randint(1, self.num_quantizer, (1,)).to(t.device)
|
|
170
|
+
elif self.mask_layer_schedule == "cosine":
|
|
171
|
+
if self.predict_layer_1:
|
|
172
|
+
weights = torch.tensor(
|
|
173
|
+
[
|
|
174
|
+
np.cos(i / self.num_quantizer * np.pi / 2)
|
|
175
|
+
for i in range(self.num_quantizer)
|
|
176
|
+
]
|
|
177
|
+
)
|
|
178
|
+
else:
|
|
179
|
+
weights = torch.tensor(
|
|
180
|
+
[0]
|
|
181
|
+
+ [
|
|
182
|
+
np.cos((i - 1) / self.num_quantizer * np.pi / 2)
|
|
183
|
+
for i in range(1, self.num_quantizer)
|
|
184
|
+
]
|
|
185
|
+
)
|
|
186
|
+
mask_layer = torch.multinomial(weights, 1).to(t.device)
|
|
187
|
+
elif self.mask_layer_schedule == "linear":
|
|
188
|
+
if self.predict_layer_1:
|
|
189
|
+
weights = torch.tensor(
|
|
190
|
+
[self.num_quantizer - i for i in range(self.num_quantizer)]
|
|
191
|
+
)
|
|
192
|
+
else:
|
|
193
|
+
weights = torch.tensor(
|
|
194
|
+
[0]
|
|
195
|
+
+ [
|
|
196
|
+
self.num_quantizer - (i - 1)
|
|
197
|
+
for i in range(1, self.num_quantizer)
|
|
198
|
+
]
|
|
199
|
+
)
|
|
200
|
+
weights = weights / weights.sum()
|
|
201
|
+
mask_layer = torch.multinomial(weights, 1).to(t.device)
|
|
202
|
+
# print(mask_layer)
|
|
203
|
+
new_t = t
|
|
204
|
+
|
|
205
|
+
return mask_layer, new_t
|
|
206
|
+
|
|
207
|
+
def forward_diffusion(self, x0, t):
|
|
208
|
+
# x0: (B, T, num_quantizer)
|
|
209
|
+
mask_layer, new_t = self.mask_layer(t) # (1,)
|
|
210
|
+
mask_prob = self.mask_prob(new_t) # (B,)
|
|
211
|
+
mask_token = self.mask_emb(torch.zeros_like(mask_layer)) # (1, hidden_size)
|
|
212
|
+
|
|
213
|
+
xt = torch.zeros(x0.shape[0], x0.shape[1], self.hidden_size).to(x0.device)
|
|
214
|
+
|
|
215
|
+
cfg_scale = self.cfg_scale
|
|
216
|
+
|
|
217
|
+
# get prompt len
|
|
218
|
+
if torch.rand(1) > cfg_scale:
|
|
219
|
+
prompt_len = torch.randint(
|
|
220
|
+
min(x0.shape[1] // 4, 5), x0.shape[1] // 2, (x0.shape[0],)
|
|
221
|
+
).to(
|
|
222
|
+
x0.device
|
|
223
|
+
) # (B,)
|
|
224
|
+
else:
|
|
225
|
+
prompt_len = torch.zeros(x0.shape[0]).to(x0) # (B,)
|
|
226
|
+
|
|
227
|
+
# get is prompt
|
|
228
|
+
is_prompt = torch.zeros_like(x0[:, :, 0]) # (B, T)
|
|
229
|
+
col_indices = (
|
|
230
|
+
torch.arange(is_prompt.shape[1])
|
|
231
|
+
.repeat(is_prompt.shape[0], 1)
|
|
232
|
+
.to(prompt_len)
|
|
233
|
+
) # (B, T)
|
|
234
|
+
is_prompt[col_indices < prompt_len.unsqueeze(1)] = 1 # (B, T) 1 if prompt
|
|
235
|
+
|
|
236
|
+
for idx, token_emb_idx in enumerate(self.token_emb):
|
|
237
|
+
if idx < mask_layer:
|
|
238
|
+
xt = xt + token_emb_idx(x0[:, :, idx]) # (B, T, hidden_size)
|
|
239
|
+
|
|
240
|
+
elif idx == mask_layer:
|
|
241
|
+
mask = torch.bernoulli(
|
|
242
|
+
torch.ones_like(x0[:, :, idx]) * mask_prob[..., None]
|
|
243
|
+
) # mask if 1, not mask if 0
|
|
244
|
+
# prompt part don't need to be masked
|
|
245
|
+
mask[is_prompt.bool()] = 0
|
|
246
|
+
# Ensure at least one token is masked
|
|
247
|
+
mask_num = mask[:,].sum(dim=1, keepdim=False)
|
|
248
|
+
all_zero_mask = (mask_num == 0).bool()
|
|
249
|
+
row_indices_to_modify = torch.nonzero(all_zero_mask)
|
|
250
|
+
# mask the first token if all tokens are not masked (may mask pad if random indices)
|
|
251
|
+
mask[row_indices_to_modify, prompt_len[row_indices_to_modify]] = 1
|
|
252
|
+
|
|
253
|
+
mask = mask[..., None] # (B, T, 1)
|
|
254
|
+
xt = (
|
|
255
|
+
xt
|
|
256
|
+
+ mask * mask_token[:, None, :]
|
|
257
|
+
+ (1 - mask) * token_emb_idx(x0[:, :, idx])
|
|
258
|
+
) # (B, T, hidden_size)
|
|
259
|
+
|
|
260
|
+
else:
|
|
261
|
+
# prompt part don't need to be masked
|
|
262
|
+
xt = (
|
|
263
|
+
xt
|
|
264
|
+
+ token_emb_idx(x0[:, :, idx]) * is_prompt[..., None]
|
|
265
|
+
+ mask_token * (1 - is_prompt[..., None])
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
return xt, new_t, mask_layer, mask, prompt_len, mask_prob
|
|
269
|
+
|
|
270
|
+
def loss_t(self, x0, x_mask, t, cond=None):
|
|
271
|
+
xt, new_t, mask_layer, mask, prompt_len, mask_prob = self.forward_diffusion(
|
|
272
|
+
x0, t
|
|
273
|
+
)
|
|
274
|
+
# xt: (B, T, hidden_size)
|
|
275
|
+
# new_t: (B,)
|
|
276
|
+
# mask_layer: (1,)
|
|
277
|
+
# mask: (B, T, 1) mask if 1, not mask if 0
|
|
278
|
+
# prompt_len: (B,)
|
|
279
|
+
# mask_prob: (B,)
|
|
280
|
+
|
|
281
|
+
mask_layer_cond = self.layer_emb(mask_layer).unsqueeze(1) # (1, 1, hidden_size)
|
|
282
|
+
cond = cond + mask_layer_cond # (B, T, hidden_size)
|
|
283
|
+
|
|
284
|
+
embeds = self.diff_estimator(xt, new_t, cond, x_mask) # (B, T, hidden_size)
|
|
285
|
+
|
|
286
|
+
logits = self.to_logits[mask_layer.item()](embeds) # (B, T, codebook_size)
|
|
287
|
+
|
|
288
|
+
# final mask used for loss calculation
|
|
289
|
+
final_mask = mask * x_mask[..., None] # (B, T, 1)
|
|
290
|
+
|
|
291
|
+
return logits, mask_layer, final_mask, x0, prompt_len, mask_prob
|
|
292
|
+
|
|
293
|
+
def compute_loss(self, x0, x_mask, cond=None):
|
|
294
|
+
# x0: (B, T, num_quantizer)
|
|
295
|
+
# x_mask: (B, T) mask is 0 for padding
|
|
296
|
+
t = torch.rand(x0.shape[0], device=x0.device, requires_grad=False)
|
|
297
|
+
t = torch.clamp(t, 1e-5, 1.0)
|
|
298
|
+
return self.loss_t(x0, x_mask, t, cond)
|
|
299
|
+
|
|
300
|
+
def reset_parameters(self):
|
|
301
|
+
def _reset_parameters(m):
|
|
302
|
+
if isinstance(m, nn.MultiheadAttention):
|
|
303
|
+
if m._qkv_same_embed_dim:
|
|
304
|
+
nn.init.normal_(m.in_proj_weight, std=0.02)
|
|
305
|
+
else:
|
|
306
|
+
nn.init.normal_(m.q_proj_weight, std=0.02)
|
|
307
|
+
nn.init.normal_(m.k_proj_weight, std=0.02)
|
|
308
|
+
nn.init.normal_(m.v_proj_weight, std=0.02)
|
|
309
|
+
|
|
310
|
+
if m.in_proj_bias is not None:
|
|
311
|
+
nn.init.constant_(m.in_proj_bias, 0.0)
|
|
312
|
+
nn.init.constant_(m.out_proj.bias, 0.0)
|
|
313
|
+
if m.bias_k is not None:
|
|
314
|
+
nn.init.xavier_normal_(m.bias_k)
|
|
315
|
+
if m.bias_v is not None:
|
|
316
|
+
nn.init.xavier_normal_(m.bias_v)
|
|
317
|
+
|
|
318
|
+
elif (
|
|
319
|
+
isinstance(m, nn.Conv1d)
|
|
320
|
+
or isinstance(m, nn.ConvTranspose1d)
|
|
321
|
+
or isinstance(m, nn.Conv2d)
|
|
322
|
+
or isinstance(m, nn.ConvTranspose2d)
|
|
323
|
+
):
|
|
324
|
+
m.weight.data.normal_(0.0, 0.02)
|
|
325
|
+
|
|
326
|
+
elif isinstance(m, nn.Linear):
|
|
327
|
+
m.weight.data.normal_(mean=0.0, std=0.02)
|
|
328
|
+
if m.bias is not None:
|
|
329
|
+
m.bias.data.zero_()
|
|
330
|
+
|
|
331
|
+
elif isinstance(m, nn.Embedding):
|
|
332
|
+
m.weight.data.normal_(mean=0.0, std=0.02)
|
|
333
|
+
if m.padding_idx is not None:
|
|
334
|
+
m.weight.data[m.padding_idx].zero_()
|
|
335
|
+
|
|
336
|
+
self.apply(_reset_parameters)
|
|
337
|
+
|
|
338
|
+
@torch.no_grad()
|
|
339
|
+
def reverse_diffusion(
|
|
340
|
+
self,
|
|
341
|
+
cond,
|
|
342
|
+
prompt,
|
|
343
|
+
x_mask=None,
|
|
344
|
+
prompt_mask=None,
|
|
345
|
+
temp=1.5,
|
|
346
|
+
filter_thres=0.98,
|
|
347
|
+
max_layer=None,
|
|
348
|
+
gt_code=None,
|
|
349
|
+
n_timesteps=[10, 4, 4, 4, 4, 4, 4, 4],
|
|
350
|
+
cfg=1.0,
|
|
351
|
+
rescale_cfg=1.0,
|
|
352
|
+
):
|
|
353
|
+
|
|
354
|
+
assert (
|
|
355
|
+
len(n_timesteps) == self.num_quantizer
|
|
356
|
+
) # each layer has a number of steps
|
|
357
|
+
|
|
358
|
+
prompt_code = prompt # (B, prompt_len, num_quantizer)
|
|
359
|
+
prompt_len = prompt_code.shape[1]
|
|
360
|
+
target_len = cond.shape[1] - prompt_len
|
|
361
|
+
|
|
362
|
+
if x_mask == None:
|
|
363
|
+
x_mask = torch.ones(cond.shape[0], target_len).to(cond.device) # (B, T)
|
|
364
|
+
if prompt_mask == None:
|
|
365
|
+
prompt_mask = torch.ones(cond.shape[0], prompt_len).to(
|
|
366
|
+
cond.device
|
|
367
|
+
) # (B, prompt_len)
|
|
368
|
+
|
|
369
|
+
cum = torch.zeros(x_mask.shape[0], x_mask.shape[1], self.hidden_size).to(
|
|
370
|
+
x_mask.device
|
|
371
|
+
) # (B, T, hidden_size)
|
|
372
|
+
|
|
373
|
+
bsz, seq_len, _ = cum.shape
|
|
374
|
+
|
|
375
|
+
choice_temp = 1.0
|
|
376
|
+
start_temp = temp # temperature for sampling
|
|
377
|
+
start_choice_temp = choice_temp # temperature for choicing mask tokens
|
|
378
|
+
|
|
379
|
+
if max_layer is None:
|
|
380
|
+
max_layer = self.num_quantizer
|
|
381
|
+
|
|
382
|
+
xt = torch.LongTensor(bsz, seq_len, max_layer).to(x_mask.device)
|
|
383
|
+
|
|
384
|
+
if gt_code is not None:
|
|
385
|
+
gt_layer = gt_code.shape[-1]
|
|
386
|
+
xt[:, :, :gt_layer] = gt_code
|
|
387
|
+
for i in range(gt_layer):
|
|
388
|
+
cum += self.token_emb[i](xt[:, :, i])
|
|
389
|
+
else:
|
|
390
|
+
gt_layer = 0
|
|
391
|
+
|
|
392
|
+
for mask_layer in range(gt_layer, max_layer):
|
|
393
|
+
steps = n_timesteps[mask_layer]
|
|
394
|
+
to_logits = self.to_logits[mask_layer]
|
|
395
|
+
token_emb = self.token_emb[mask_layer]
|
|
396
|
+
mask_layer = torch.tensor(mask_layer).to(x_mask.device).long().unsqueeze(0)
|
|
397
|
+
mask_layer_cond = self.layer_emb(mask_layer).unsqueeze(
|
|
398
|
+
1
|
|
399
|
+
) # (1,) -> (1, 1, hidden_size)
|
|
400
|
+
temp_cond = cond + mask_layer_cond # (B, T, hidden_size)
|
|
401
|
+
|
|
402
|
+
mask_token = self.mask_emb(torch.zeros_like(mask_layer)) # (1, hidden_size)
|
|
403
|
+
mask = torch.full((bsz, seq_len, 1), True).to(x_mask.device) # (B, T, 1)
|
|
404
|
+
seq = torch.full((bsz, seq_len), 0).to(x_mask.device)
|
|
405
|
+
|
|
406
|
+
h = 1.0 / steps
|
|
407
|
+
|
|
408
|
+
# prompt_code: (B, prompt_len, num_quantizer)
|
|
409
|
+
cur_prompt = 0
|
|
410
|
+
for idx, emb in enumerate(self.token_emb):
|
|
411
|
+
cur_prompt = cur_prompt + emb(
|
|
412
|
+
prompt_code[:, :, idx]
|
|
413
|
+
) # (B, prompt_len, hidden_size)
|
|
414
|
+
|
|
415
|
+
t_list = [1.0 - i * h for i in range(steps)]
|
|
416
|
+
t_list.append(0.0)
|
|
417
|
+
for i in range(steps):
|
|
418
|
+
t = t_list[i] * torch.ones(bsz).to(x_mask.device)
|
|
419
|
+
token = token_emb(seq) # (B, T, hidden_size)
|
|
420
|
+
cur = cum + mask * mask_token[:, None, :] + (~mask) * token
|
|
421
|
+
cur = cur + mask_token[:, None, :] * (max_layer - 1 - mask_layer)
|
|
422
|
+
|
|
423
|
+
xt_input = torch.cat([cur_prompt, cur], dim=1) # (B, T, hidden_size)
|
|
424
|
+
xt_mask = torch.cat(
|
|
425
|
+
[prompt_mask, x_mask], dim=1
|
|
426
|
+
) # (B, T), mask is 0 for padding
|
|
427
|
+
|
|
428
|
+
embeds = self.diff_estimator(xt_input, t, temp_cond, xt_mask)
|
|
429
|
+
embeds = embeds[:, prompt_len:, :]
|
|
430
|
+
|
|
431
|
+
# cfg
|
|
432
|
+
if cfg > 0:
|
|
433
|
+
mask_embeds = self.diff_estimator(
|
|
434
|
+
cur, t, temp_cond[:, prompt_len:, :], x_mask
|
|
435
|
+
)
|
|
436
|
+
pos_emb_std = embeds.std() # std(g_cond)
|
|
437
|
+
embeds = embeds + cfg * (embeds - mask_embeds) # g_cfg
|
|
438
|
+
rescale_embeds = embeds * pos_emb_std / embeds.std() # g_final
|
|
439
|
+
embeds = rescale_cfg * rescale_embeds + (1 - rescale_cfg) * embeds
|
|
440
|
+
|
|
441
|
+
logits = to_logits(embeds) # (B, T, codebook_size)
|
|
442
|
+
annealing_scale = t_list[i]
|
|
443
|
+
|
|
444
|
+
choice_temp = start_choice_temp * annealing_scale
|
|
445
|
+
temp = start_temp * annealing_scale
|
|
446
|
+
logits = top_k(logits, filter_thres)
|
|
447
|
+
|
|
448
|
+
if i == steps - 1:
|
|
449
|
+
# greedy
|
|
450
|
+
if steps == 1:
|
|
451
|
+
temp = 0.2
|
|
452
|
+
sampled_ids = gumbel_sample(logits, temperature=max(temp, 1e-3))
|
|
453
|
+
else:
|
|
454
|
+
sampled_ids = logits.argmax(dim=-1)
|
|
455
|
+
|
|
456
|
+
else:
|
|
457
|
+
# sampling
|
|
458
|
+
sampled_ids = gumbel_sample(logits, temperature=max(temp, 1e-3))
|
|
459
|
+
|
|
460
|
+
seq = torch.where(mask.squeeze(-1), sampled_ids, seq)
|
|
461
|
+
|
|
462
|
+
scores = logits.softmax(dim=-1)
|
|
463
|
+
scores = scores.gather(2, rearrange(sampled_ids, "b n -> b n 1"))
|
|
464
|
+
scores = rearrange(scores, "b n 1 -> b n")
|
|
465
|
+
|
|
466
|
+
scores = choice_temp * gumbel_noise(scores) + scores
|
|
467
|
+
scores = 1 - scores
|
|
468
|
+
|
|
469
|
+
next_t = t_list[i + 1] * torch.ones(bsz).to(x_mask.device)
|
|
470
|
+
|
|
471
|
+
next_mask_num = (self.mask_prob(next_t) * seq_len).long()[0].item()
|
|
472
|
+
|
|
473
|
+
if next_mask_num == 0:
|
|
474
|
+
break
|
|
475
|
+
scores = scores.masked_fill(
|
|
476
|
+
~mask.squeeze(-1), -torch.finfo(scores.dtype).max
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
mask_indices = scores.topk(next_mask_num, dim=-1).indices
|
|
480
|
+
mask = torch.zeros_like(scores, dtype=torch.bool).scatter(
|
|
481
|
+
1, mask_indices, True
|
|
482
|
+
)
|
|
483
|
+
seq = seq.masked_fill(mask, 0)
|
|
484
|
+
|
|
485
|
+
mask = mask.unsqueeze(-1)
|
|
486
|
+
|
|
487
|
+
cum = cum + token_emb(seq)
|
|
488
|
+
xt[..., mask_layer.squeeze(0).item()] = seq
|
|
489
|
+
|
|
490
|
+
return xt
|
|
491
|
+
|
|
492
|
+
def forward(self, x0, x_mask, cond_code=None):
|
|
493
|
+
# x0: (B, T, num_quantizer)
|
|
494
|
+
# x_mask: (B, T) mask is 0 for padding
|
|
495
|
+
# cond_code: semantic token (B, T)
|
|
496
|
+
cond = self.cond_emb(cond_code)
|
|
497
|
+
|
|
498
|
+
logits, mask_layer, final_mask, x0, prompt_len, mask_prob = self.compute_loss(
|
|
499
|
+
x0,
|
|
500
|
+
x_mask,
|
|
501
|
+
cond,
|
|
502
|
+
)
|
|
503
|
+
return logits, mask_layer, final_mask, x0, prompt_len, mask_prob
|