xinference 0.16.3__py3-none-any.whl → 1.2.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/_compat.py +24 -2
- xinference/_version.py +3 -3
- xinference/api/restful_api.py +219 -77
- xinference/client/restful/restful_client.py +47 -2
- xinference/constants.py +1 -0
- xinference/core/chat_interface.py +6 -1
- xinference/core/model.py +124 -34
- xinference/core/supervisor.py +180 -12
- xinference/core/utils.py +73 -4
- xinference/core/worker.py +102 -4
- xinference/deploy/cmdline.py +3 -1
- xinference/deploy/test/test_cmdline.py +56 -0
- xinference/isolation.py +24 -0
- xinference/model/audio/__init__.py +12 -0
- xinference/model/audio/core.py +37 -4
- xinference/model/audio/cosyvoice.py +39 -6
- xinference/model/audio/f5tts.py +200 -0
- xinference/model/audio/f5tts_mlx.py +260 -0
- xinference/model/audio/fish_speech.py +70 -110
- xinference/model/audio/melotts.py +110 -0
- xinference/model/audio/model_spec.json +179 -3
- xinference/model/audio/model_spec_modelscope.json +27 -0
- xinference/model/audio/utils.py +32 -0
- xinference/model/audio/whisper.py +35 -10
- xinference/model/audio/whisper_mlx.py +208 -0
- xinference/model/embedding/core.py +322 -6
- xinference/model/embedding/model_spec.json +8 -1
- xinference/model/embedding/model_spec_modelscope.json +9 -1
- xinference/model/image/core.py +69 -1
- xinference/model/image/model_spec.json +145 -4
- xinference/model/image/model_spec_modelscope.json +150 -4
- xinference/model/image/stable_diffusion/core.py +50 -15
- xinference/model/llm/__init__.py +6 -2
- xinference/model/llm/llm_family.json +1055 -93
- xinference/model/llm/llm_family.py +15 -36
- xinference/model/llm/llm_family_modelscope.json +1031 -78
- xinference/model/llm/memory.py +1 -1
- xinference/model/llm/mlx/core.py +285 -47
- xinference/model/llm/sglang/core.py +2 -0
- xinference/model/llm/transformers/chatglm.py +9 -5
- xinference/model/llm/transformers/cogagent.py +272 -0
- xinference/model/llm/transformers/core.py +3 -0
- xinference/model/llm/transformers/glm_edge_v.py +230 -0
- xinference/model/llm/transformers/qwen2_vl.py +12 -1
- xinference/model/llm/transformers/utils.py +16 -8
- xinference/model/llm/utils.py +55 -4
- xinference/model/llm/vllm/core.py +137 -12
- xinference/model/llm/vllm/xavier/__init__.py +13 -0
- xinference/model/llm/vllm/xavier/allocator.py +74 -0
- xinference/model/llm/vllm/xavier/block.py +111 -0
- xinference/model/llm/vllm/xavier/block_manager.py +71 -0
- xinference/model/llm/vllm/xavier/block_tracker.py +129 -0
- xinference/model/llm/vllm/xavier/collective.py +74 -0
- xinference/model/llm/vllm/xavier/collective_manager.py +147 -0
- xinference/model/llm/vllm/xavier/engine.py +247 -0
- xinference/model/llm/vllm/xavier/executor.py +134 -0
- xinference/model/llm/vllm/xavier/scheduler.py +438 -0
- xinference/model/llm/vllm/xavier/test/__init__.py +13 -0
- xinference/model/llm/vllm/xavier/test/test_xavier.py +147 -0
- xinference/model/llm/vllm/xavier/transfer.py +319 -0
- xinference/model/rerank/core.py +11 -4
- xinference/model/video/diffusers.py +14 -0
- xinference/model/video/model_spec.json +15 -0
- xinference/model/video/model_spec_modelscope.json +16 -0
- xinference/thirdparty/cosyvoice/bin/average_model.py +92 -0
- xinference/thirdparty/cosyvoice/bin/export_jit.py +12 -2
- xinference/thirdparty/cosyvoice/bin/export_onnx.py +112 -0
- xinference/thirdparty/cosyvoice/bin/export_trt.sh +9 -0
- xinference/thirdparty/cosyvoice/bin/inference.py +5 -7
- xinference/thirdparty/cosyvoice/bin/spk2info.pt +0 -0
- xinference/thirdparty/cosyvoice/bin/train.py +42 -8
- xinference/thirdparty/cosyvoice/cli/cosyvoice.py +96 -25
- xinference/thirdparty/cosyvoice/cli/frontend.py +77 -30
- xinference/thirdparty/cosyvoice/cli/model.py +330 -80
- xinference/thirdparty/cosyvoice/dataset/dataset.py +6 -2
- xinference/thirdparty/cosyvoice/dataset/processor.py +76 -14
- xinference/thirdparty/cosyvoice/flow/decoder.py +92 -13
- xinference/thirdparty/cosyvoice/flow/flow.py +99 -9
- xinference/thirdparty/cosyvoice/flow/flow_matching.py +110 -13
- xinference/thirdparty/cosyvoice/flow/length_regulator.py +5 -4
- xinference/thirdparty/cosyvoice/hifigan/discriminator.py +140 -0
- xinference/thirdparty/cosyvoice/hifigan/generator.py +58 -42
- xinference/thirdparty/cosyvoice/hifigan/hifigan.py +67 -0
- xinference/thirdparty/cosyvoice/llm/llm.py +139 -6
- xinference/thirdparty/cosyvoice/tokenizer/assets/multilingual_zh_ja_yue_char_del.tiktoken +58836 -0
- xinference/thirdparty/cosyvoice/tokenizer/tokenizer.py +279 -0
- xinference/thirdparty/cosyvoice/transformer/embedding.py +2 -2
- xinference/thirdparty/cosyvoice/transformer/encoder_layer.py +7 -7
- xinference/thirdparty/cosyvoice/transformer/upsample_encoder.py +318 -0
- xinference/thirdparty/cosyvoice/utils/common.py +28 -1
- xinference/thirdparty/cosyvoice/utils/executor.py +69 -7
- xinference/thirdparty/cosyvoice/utils/file_utils.py +2 -12
- xinference/thirdparty/cosyvoice/utils/frontend_utils.py +9 -5
- xinference/thirdparty/cosyvoice/utils/losses.py +20 -0
- xinference/thirdparty/cosyvoice/utils/scheduler.py +1 -2
- xinference/thirdparty/cosyvoice/utils/train_utils.py +101 -45
- xinference/thirdparty/f5_tts/api.py +166 -0
- xinference/thirdparty/f5_tts/configs/E2TTS_Base_train.yaml +44 -0
- xinference/thirdparty/f5_tts/configs/E2TTS_Small_train.yaml +44 -0
- xinference/thirdparty/f5_tts/configs/F5TTS_Base_train.yaml +46 -0
- xinference/thirdparty/f5_tts/configs/F5TTS_Small_train.yaml +46 -0
- xinference/thirdparty/f5_tts/eval/README.md +49 -0
- xinference/thirdparty/f5_tts/eval/ecapa_tdnn.py +330 -0
- xinference/thirdparty/f5_tts/eval/eval_infer_batch.py +207 -0
- xinference/thirdparty/f5_tts/eval/eval_infer_batch.sh +13 -0
- xinference/thirdparty/f5_tts/eval/eval_librispeech_test_clean.py +84 -0
- xinference/thirdparty/f5_tts/eval/eval_seedtts_testset.py +84 -0
- xinference/thirdparty/f5_tts/eval/utils_eval.py +405 -0
- xinference/thirdparty/f5_tts/infer/README.md +191 -0
- xinference/thirdparty/f5_tts/infer/SHARED.md +74 -0
- xinference/thirdparty/f5_tts/infer/examples/basic/basic.toml +11 -0
- xinference/thirdparty/f5_tts/infer/examples/basic/basic_ref_en.wav +0 -0
- xinference/thirdparty/f5_tts/infer/examples/basic/basic_ref_zh.wav +0 -0
- xinference/thirdparty/f5_tts/infer/examples/multi/country.flac +0 -0
- xinference/thirdparty/f5_tts/infer/examples/multi/main.flac +0 -0
- xinference/thirdparty/f5_tts/infer/examples/multi/story.toml +19 -0
- xinference/thirdparty/f5_tts/infer/examples/multi/story.txt +1 -0
- xinference/thirdparty/f5_tts/infer/examples/multi/town.flac +0 -0
- xinference/thirdparty/f5_tts/infer/examples/vocab.txt +2545 -0
- xinference/thirdparty/f5_tts/infer/infer_cli.py +226 -0
- xinference/thirdparty/f5_tts/infer/infer_gradio.py +851 -0
- xinference/thirdparty/f5_tts/infer/speech_edit.py +193 -0
- xinference/thirdparty/f5_tts/infer/utils_infer.py +538 -0
- xinference/thirdparty/f5_tts/model/__init__.py +10 -0
- xinference/thirdparty/f5_tts/model/backbones/README.md +20 -0
- xinference/thirdparty/f5_tts/model/backbones/dit.py +163 -0
- xinference/thirdparty/f5_tts/model/backbones/mmdit.py +146 -0
- xinference/thirdparty/f5_tts/model/backbones/unett.py +219 -0
- xinference/thirdparty/f5_tts/model/cfm.py +285 -0
- xinference/thirdparty/f5_tts/model/dataset.py +319 -0
- xinference/thirdparty/f5_tts/model/modules.py +658 -0
- xinference/thirdparty/f5_tts/model/trainer.py +366 -0
- xinference/thirdparty/f5_tts/model/utils.py +185 -0
- xinference/thirdparty/f5_tts/scripts/count_max_epoch.py +33 -0
- xinference/thirdparty/f5_tts/scripts/count_params_gflops.py +39 -0
- xinference/thirdparty/f5_tts/socket_server.py +159 -0
- xinference/thirdparty/f5_tts/train/README.md +77 -0
- xinference/thirdparty/f5_tts/train/datasets/prepare_csv_wavs.py +139 -0
- xinference/thirdparty/f5_tts/train/datasets/prepare_emilia.py +230 -0
- xinference/thirdparty/f5_tts/train/datasets/prepare_libritts.py +92 -0
- xinference/thirdparty/f5_tts/train/datasets/prepare_ljspeech.py +65 -0
- xinference/thirdparty/f5_tts/train/datasets/prepare_wenetspeech4tts.py +125 -0
- xinference/thirdparty/f5_tts/train/finetune_cli.py +174 -0
- xinference/thirdparty/f5_tts/train/finetune_gradio.py +1846 -0
- xinference/thirdparty/f5_tts/train/train.py +75 -0
- xinference/thirdparty/fish_speech/fish_speech/conversation.py +266 -1
- xinference/thirdparty/fish_speech/fish_speech/i18n/locale/en_US.json +2 -1
- xinference/thirdparty/fish_speech/fish_speech/i18n/locale/es_ES.json +2 -1
- xinference/thirdparty/fish_speech/fish_speech/i18n/locale/ja_JP.json +2 -2
- xinference/thirdparty/fish_speech/fish_speech/i18n/locale/ko_KR.json +123 -0
- xinference/thirdparty/fish_speech/fish_speech/i18n/locale/zh_CN.json +2 -1
- xinference/thirdparty/fish_speech/fish_speech/models/text2semantic/llama.py +137 -29
- xinference/thirdparty/fish_speech/fish_speech/models/vqgan/modules/firefly.py +9 -9
- xinference/thirdparty/fish_speech/fish_speech/models/vqgan/modules/fsq.py +1 -1
- xinference/thirdparty/fish_speech/fish_speech/text/clean.py +17 -11
- xinference/thirdparty/fish_speech/fish_speech/text/spliter.py +1 -1
- xinference/thirdparty/fish_speech/fish_speech/tokenizer.py +152 -0
- xinference/thirdparty/fish_speech/fish_speech/train.py +2 -2
- xinference/thirdparty/fish_speech/fish_speech/utils/__init__.py +2 -1
- xinference/thirdparty/fish_speech/fish_speech/utils/utils.py +22 -0
- xinference/thirdparty/fish_speech/fish_speech/webui/launch_utils.py +1 -1
- xinference/thirdparty/fish_speech/fish_speech/webui/manage.py +2 -2
- xinference/thirdparty/fish_speech/tools/{post_api.py → api_client.py} +34 -18
- xinference/thirdparty/fish_speech/tools/api_server.py +98 -0
- xinference/thirdparty/fish_speech/tools/download_models.py +5 -5
- xinference/thirdparty/fish_speech/tools/e2e_webui.py +232 -0
- xinference/thirdparty/fish_speech/tools/fish_e2e.py +298 -0
- xinference/thirdparty/fish_speech/tools/inference_engine/__init__.py +192 -0
- xinference/thirdparty/fish_speech/tools/inference_engine/reference_loader.py +125 -0
- xinference/thirdparty/fish_speech/tools/inference_engine/utils.py +39 -0
- xinference/thirdparty/fish_speech/tools/inference_engine/vq_manager.py +57 -0
- xinference/thirdparty/fish_speech/tools/llama/eval_in_context.py +2 -2
- xinference/thirdparty/fish_speech/tools/llama/generate.py +484 -72
- xinference/thirdparty/fish_speech/tools/run_webui.py +104 -0
- xinference/thirdparty/fish_speech/tools/schema.py +170 -0
- xinference/thirdparty/fish_speech/tools/server/agent/__init__.py +57 -0
- xinference/thirdparty/fish_speech/tools/server/agent/generate.py +119 -0
- xinference/thirdparty/fish_speech/tools/server/agent/generation_utils.py +122 -0
- xinference/thirdparty/fish_speech/tools/server/agent/pre_generation_utils.py +72 -0
- xinference/thirdparty/fish_speech/tools/server/api_utils.py +75 -0
- xinference/thirdparty/fish_speech/tools/server/exception_handler.py +27 -0
- xinference/thirdparty/fish_speech/tools/server/inference.py +45 -0
- xinference/thirdparty/fish_speech/tools/server/model_manager.py +122 -0
- xinference/thirdparty/fish_speech/tools/server/model_utils.py +129 -0
- xinference/thirdparty/fish_speech/tools/server/views.py +246 -0
- xinference/thirdparty/fish_speech/tools/vqgan/extract_vq.py +7 -1
- xinference/thirdparty/fish_speech/tools/vqgan/inference.py +2 -3
- xinference/thirdparty/fish_speech/tools/webui/__init__.py +173 -0
- xinference/thirdparty/fish_speech/tools/webui/inference.py +91 -0
- xinference/thirdparty/fish_speech/tools/webui/variables.py +14 -0
- xinference/thirdparty/matcha/utils/utils.py +2 -2
- xinference/thirdparty/melo/api.py +135 -0
- xinference/thirdparty/melo/app.py +61 -0
- xinference/thirdparty/melo/attentions.py +459 -0
- xinference/thirdparty/melo/commons.py +160 -0
- xinference/thirdparty/melo/configs/config.json +94 -0
- xinference/thirdparty/melo/data/example/metadata.list +20 -0
- xinference/thirdparty/melo/data_utils.py +413 -0
- xinference/thirdparty/melo/download_utils.py +67 -0
- xinference/thirdparty/melo/infer.py +25 -0
- xinference/thirdparty/melo/init_downloads.py +14 -0
- xinference/thirdparty/melo/losses.py +58 -0
- xinference/thirdparty/melo/main.py +36 -0
- xinference/thirdparty/melo/mel_processing.py +174 -0
- xinference/thirdparty/melo/models.py +1030 -0
- xinference/thirdparty/melo/modules.py +598 -0
- xinference/thirdparty/melo/monotonic_align/__init__.py +16 -0
- xinference/thirdparty/melo/monotonic_align/core.py +46 -0
- xinference/thirdparty/melo/preprocess_text.py +135 -0
- xinference/thirdparty/melo/split_utils.py +174 -0
- xinference/thirdparty/melo/text/__init__.py +35 -0
- xinference/thirdparty/melo/text/chinese.py +199 -0
- xinference/thirdparty/melo/text/chinese_bert.py +107 -0
- xinference/thirdparty/melo/text/chinese_mix.py +253 -0
- xinference/thirdparty/melo/text/cleaner.py +36 -0
- xinference/thirdparty/melo/text/cleaner_multiling.py +110 -0
- xinference/thirdparty/melo/text/cmudict.rep +129530 -0
- xinference/thirdparty/melo/text/cmudict_cache.pickle +0 -0
- xinference/thirdparty/melo/text/english.py +284 -0
- xinference/thirdparty/melo/text/english_bert.py +39 -0
- xinference/thirdparty/melo/text/english_utils/abbreviations.py +35 -0
- xinference/thirdparty/melo/text/english_utils/number_norm.py +97 -0
- xinference/thirdparty/melo/text/english_utils/time_norm.py +47 -0
- xinference/thirdparty/melo/text/es_phonemizer/base.py +140 -0
- xinference/thirdparty/melo/text/es_phonemizer/cleaner.py +109 -0
- xinference/thirdparty/melo/text/es_phonemizer/es_symbols.json +79 -0
- xinference/thirdparty/melo/text/es_phonemizer/es_symbols.txt +1 -0
- xinference/thirdparty/melo/text/es_phonemizer/es_symbols_v2.json +83 -0
- xinference/thirdparty/melo/text/es_phonemizer/es_to_ipa.py +12 -0
- xinference/thirdparty/melo/text/es_phonemizer/example_ipa.txt +400 -0
- xinference/thirdparty/melo/text/es_phonemizer/gruut_wrapper.py +253 -0
- xinference/thirdparty/melo/text/es_phonemizer/punctuation.py +174 -0
- xinference/thirdparty/melo/text/es_phonemizer/spanish_symbols.txt +1 -0
- xinference/thirdparty/melo/text/es_phonemizer/test.ipynb +124 -0
- xinference/thirdparty/melo/text/fr_phonemizer/base.py +140 -0
- xinference/thirdparty/melo/text/fr_phonemizer/cleaner.py +122 -0
- xinference/thirdparty/melo/text/fr_phonemizer/en_symbols.json +78 -0
- xinference/thirdparty/melo/text/fr_phonemizer/example_ipa.txt +1 -0
- xinference/thirdparty/melo/text/fr_phonemizer/fr_symbols.json +89 -0
- xinference/thirdparty/melo/text/fr_phonemizer/fr_to_ipa.py +30 -0
- xinference/thirdparty/melo/text/fr_phonemizer/french_abbreviations.py +48 -0
- xinference/thirdparty/melo/text/fr_phonemizer/french_symbols.txt +1 -0
- xinference/thirdparty/melo/text/fr_phonemizer/gruut_wrapper.py +258 -0
- xinference/thirdparty/melo/text/fr_phonemizer/punctuation.py +172 -0
- xinference/thirdparty/melo/text/french.py +94 -0
- xinference/thirdparty/melo/text/french_bert.py +39 -0
- xinference/thirdparty/melo/text/japanese.py +647 -0
- xinference/thirdparty/melo/text/japanese_bert.py +49 -0
- xinference/thirdparty/melo/text/ko_dictionary.py +44 -0
- xinference/thirdparty/melo/text/korean.py +192 -0
- xinference/thirdparty/melo/text/opencpop-strict.txt +429 -0
- xinference/thirdparty/melo/text/spanish.py +122 -0
- xinference/thirdparty/melo/text/spanish_bert.py +39 -0
- xinference/thirdparty/melo/text/symbols.py +290 -0
- xinference/thirdparty/melo/text/tone_sandhi.py +769 -0
- xinference/thirdparty/melo/train.py +635 -0
- xinference/thirdparty/melo/train.sh +19 -0
- xinference/thirdparty/melo/transforms.py +209 -0
- xinference/thirdparty/melo/utils.py +424 -0
- xinference/types.py +17 -1
- xinference/web/ui/build/asset-manifest.json +6 -6
- xinference/web/ui/build/index.html +1 -1
- xinference/web/ui/build/static/css/main.51a587ff.css +2 -0
- xinference/web/ui/build/static/css/main.51a587ff.css.map +1 -0
- xinference/web/ui/build/static/js/main.b0936c54.js +3 -0
- xinference/web/ui/build/static/js/main.b0936c54.js.map +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/03c4052f1b91f6ba0c5389bdcf49c43319b4076c08e4b8585dab312538ae290a.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/1786b83003b8e9605a0f5f855a185d4d16e38fc893dfb326a2a9cca206b4240a.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/17cbc181dd674b9150b80c73ed6a82656de0082d857f6e5f66d9716129ac0b38.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/185ceb8872d562e032b47e79df6a45670e06345b8ed70aad1a131e0476783c5c.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/26b8c9f34b0bed789b3a833767672e39302d1e0c09b4276f4d58d1df7b6bd93b.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/2b484da66c724d0d56a40849c109327408796a668b1381511b6e9e03baa48658.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/2cbbbce9b84df73330d4c42b82436ed881b3847628f2fbc346aa62e2859fd88c.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/2ec9b14431ed33ce6901bf9f27007be4e6e472709c99d6e22b50ce528e4b78ee.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/3b966db018f96be4a055d6ca205f0990d4d0b370e2980c17d8bca2c9a021819c.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/3eefb411b24c2b3ce053570ef50daccf154022f0e168be5ed0fec21394baf9f4.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/522b229e3cac219123f0d69673f5570e191c2d2a505dc65b312d336eae2279c0.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/52e45f17ba300580ea3fcc9f9228ccba194bb092b76f25e9255af311f8b05aab.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/5a0bc4631f936459afc1a3b1d3ec2420118b1f00e11f60ccac3e08088f3f27a8.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/611fa2c6c53b66039991d06dfb0473b5ab37fc63b4564e0f6e1718523768a045.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/6329bc76c406fe5eb305412383fbde5950f847bb5e43261f73f37622c365acb4.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/63c8e07687ea53a4f8a910ee5e42e0eb26cd1acbfbe820f3e3248a786ee51401.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/69b2d5001684174ec9da57e07914eed3eac4960018bceb6cbfa801d861301d7c.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/710c1acda69e561e30a933b98c6a56d50197868b15c21e2aad55ab6d46649eb6.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/720deca1fce5a1dc5056048fa8258fd138a82ea855f350b6613f104a73fb761f.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/76a23b92d26a499c57e61eea2b895fbc9771bd0849a72e66f8e633192017978b.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/858063f23b34dfe600254eb5afd85518b0002ec4b30b7386616c45600826e3b2.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/920b82c1c89124cf217109eeedbfcd3aae3b917be50c9dfb6bbb4ce26bdfd2e7.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/94d8b7aeb0076f2ce07db598cea0e87b13bc8d5614eb530b8d6e696c2daf6f88.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/9e917fe7022d01b2ccbe5cc0ce73d70bb72bee584ff293bad71bdff6695dee28.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/9f28fdb8399f1d0474f0aca86f1658dc94f5bf0c90f6146352de150692de8862.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/a0dfafa06b2bb7cba8cad41c482503f61944f759f4318139362602ef5cc47ccb.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/a3ff866acddf34917a7ee399e0e571a4dfd8ba66d5057db885f243e16a6eb17d.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/afb8084f539534cd594755ea2205ecd5bd1f62dddcfdf75a2eace59a28131278.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/b57b1438b77294c1f3f6cfce12ac487d8106c6f016975ba0aec94d98997e2e1e.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/b9917b0bf8e4d55ccbac1c334aa04d6ff3c5b6ed9e5d38b9ea2c687fa7d3f5a9.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/bbcc94b0149963d1d6f267ee1f4f03d3925b758392ce2f516c3fe8af0e0169fc.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/bdee44abeadc4abc17d41c52eb49c6e19a4b1a267b6e16876ce91bdeeebfc52d.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/beb112b70f4a56db95920a9e20efb6c97c37b68450716730217a9ee1a9ae92be.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/c88db97be0cdf440193b3995996e83510a04cb00048135485fc0e26d197e80b5.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/d49e5314d34310a62d01a03067ce1bec5da00abce84c5196aa9c6842fa79a430.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/d7664d18c4ddbad9c3a6a31b91f7c00fb0dde804608674a9860ee50f33e54708.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/d9072c318b819b7c90a0f7e9cc0b6413b4dbeb8e9859898e53d75ea882fcde99.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/db16a983bc08a05f0439cc61ca0840e49e1d8400eef678909f16c032a418a3d6.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/dc249829767b8abcbc3677e0b07b6d3ecbfdfe6d08cfe23a665eb33373a9aa9d.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/e242c583c2dbc2784f0fcf513523975f7d5df447e106c1c17e49e8578a6fc3ed.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/eac5f1296513e69e4b96f750ddccd4d0264e2bae4e4c449144e83274a48698d9.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/ed57202cb79649bb716400436590245547df241988fc7c8e1d85d132299542d2.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/f125bf72e773a14cdaebd0c343e80adb909d12e317ee5c00cd4a57442fbe2c62.json +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/f91af913d7f91c410719ab13136aaed3aaf0f8dda06652f25c42cb5231587398.json +1 -0
- xinference/web/ui/node_modules/.package-lock.json +67 -3
- xinference/web/ui/node_modules/@babel/runtime/package.json +592 -538
- xinference/web/ui/node_modules/html-parse-stringify/package.json +50 -0
- xinference/web/ui/node_modules/i18next/dist/esm/package.json +1 -0
- xinference/web/ui/node_modules/i18next/package.json +129 -0
- xinference/web/ui/node_modules/react-i18next/.eslintrc.json +74 -0
- xinference/web/ui/node_modules/react-i18next/dist/es/package.json +1 -0
- xinference/web/ui/node_modules/react-i18next/package.json +162 -0
- xinference/web/ui/node_modules/void-elements/package.json +34 -0
- xinference/web/ui/package-lock.json +69 -3
- xinference/web/ui/package.json +2 -0
- xinference/web/ui/src/locales/en.json +186 -0
- xinference/web/ui/src/locales/zh.json +186 -0
- {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/METADATA +96 -36
- {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/RECORD +335 -146
- {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/WHEEL +1 -1
- xinference/thirdparty/cosyvoice/bin/export_trt.py +0 -8
- xinference/thirdparty/fish_speech/fish_speech/configs/lora/__init__.py +0 -0
- xinference/thirdparty/fish_speech/fish_speech/datasets/__init__.py +0 -0
- xinference/thirdparty/fish_speech/fish_speech/datasets/protos/__init__.py +0 -0
- xinference/thirdparty/fish_speech/fish_speech/i18n/locale/__init__.py +0 -0
- xinference/thirdparty/fish_speech/fish_speech/models/__init__.py +0 -0
- xinference/thirdparty/fish_speech/fish_speech/models/vqgan/modules/__init__.py +0 -0
- xinference/thirdparty/fish_speech/fish_speech/webui/__init__.py +0 -0
- xinference/thirdparty/fish_speech/tools/__init__.py +0 -0
- xinference/thirdparty/fish_speech/tools/api.py +0 -440
- xinference/thirdparty/fish_speech/tools/commons.py +0 -35
- xinference/thirdparty/fish_speech/tools/llama/__init__.py +0 -0
- xinference/thirdparty/fish_speech/tools/msgpack_api.py +0 -34
- xinference/thirdparty/fish_speech/tools/vqgan/__init__.py +0 -0
- xinference/thirdparty/fish_speech/tools/webui.py +0 -485
- xinference/web/ui/build/static/css/main.5061c4c3.css +0 -2
- xinference/web/ui/build/static/css/main.5061c4c3.css.map +0 -1
- xinference/web/ui/build/static/js/main.2f269bb3.js +0 -3
- xinference/web/ui/build/static/js/main.2f269bb3.js.map +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/07ce9e632e6aff24d7aa3ad8e48224433bbfeb0d633fca723453f1fcae0c9f1c.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/1130403f9e46f5738a23b45ac59b57de8f360c908c713e2c0670c2cce9bd367a.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/131091b25d26b17cdca187d7542a21475c211138d900cf667682260e76ef9463.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/1f269fb2a368363c1cb2237825f1dba093b6bdd8c44cc05954fd19ec2c1fff03.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/331312668fa8bd3d7401818f4a25fa98135d7f61371cd6bfff78b18cf4fbdd92.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/40f17338fc75ae095de7d2b4d8eae0d5ca0193a7e2bcece4ee745b22a7a2f4b7.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/4de9a6942c5f1749d6cbfdd54279699975f16016b182848bc253886f52ec2ec3.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/822586ed1077201b64b954f12f25e3f9b45678c1acbabe53d8af3ca82ca71f33.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/8d33354bd2100c8602afc3341f131a88cc36aaeecd5a4b365ed038514708e350.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/9375a35b05d56989b2755bf72161fa707c92f28569d33765a75f91a568fda6e9.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/a158a9ffa0c9b169aee53dd4a0c44501a596755b4e4f6ede7746d65a72e2a71f.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/bd6ad8159341315a1764c397621a560809f7eb7219ab5174c801fca7e969d943.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/c7bf40bab396765f67d0fed627ed3665890608b2d0edaa3e8cb7cfc96310db45.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/d6c643278a0b28320e6f33a60f5fb64c053997cbdc39a60e53ccc574688ade9e.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/e42b72d4cc1ea412ebecbb8d040dc6c6bfee462c33903c2f1f3facb602ad742e.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/e64b7e8cedcf43d4c95deba60ec1341855c887705805bb62431693118b870c69.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/f5039ddbeb815c51491a1989532006b96fc3ae49c6c60e3c097f875b4ae915ae.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/f72f011744c4649fabddca6f7a9327861ac0a315a89b1a2e62a39774e7863845.json +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/feabb04b4aa507102da0a64398a40818e878fd1df9b75dda8461b3e1e7ff3f11.json +0 -1
- /xinference/thirdparty/{cosyvoice/bin → f5_tts}/__init__.py +0 -0
- /xinference/thirdparty/{cosyvoice/flow → melo}/__init__.py +0 -0
- /xinference/thirdparty/{cosyvoice/hifigan → melo/text/english_utils}/__init__.py +0 -0
- /xinference/thirdparty/{cosyvoice/llm → melo/text/es_phonemizer}/__init__.py +0 -0
- /xinference/thirdparty/{fish_speech/fish_speech/configs → melo/text/fr_phonemizer}/__init__.py +0 -0
- /xinference/web/ui/build/static/js/{main.2f269bb3.js.LICENSE.txt → main.b0936c54.js.LICENSE.txt} +0 -0
- {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/LICENSE +0 -0
- {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/entry_points.txt +0 -0
- {xinference-0.16.3.dist-info → xinference-1.2.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ein notation:
|
|
3
|
+
b - batch
|
|
4
|
+
n - sequence
|
|
5
|
+
nt - text sequence
|
|
6
|
+
nw - raw wave length
|
|
7
|
+
d - dimension
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import math
|
|
13
|
+
from typing import Optional
|
|
14
|
+
|
|
15
|
+
import torch
|
|
16
|
+
import torch.nn.functional as F
|
|
17
|
+
import torchaudio
|
|
18
|
+
from librosa.filters import mel as librosa_mel_fn
|
|
19
|
+
from torch import nn
|
|
20
|
+
from x_transformers.x_transformers import apply_rotary_pos_emb
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# raw wav to mel spec
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
mel_basis_cache = {}
|
|
27
|
+
hann_window_cache = {}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_bigvgan_mel_spectrogram(
|
|
31
|
+
waveform,
|
|
32
|
+
n_fft=1024,
|
|
33
|
+
n_mel_channels=100,
|
|
34
|
+
target_sample_rate=24000,
|
|
35
|
+
hop_length=256,
|
|
36
|
+
win_length=1024,
|
|
37
|
+
fmin=0,
|
|
38
|
+
fmax=None,
|
|
39
|
+
center=False,
|
|
40
|
+
): # Copy from https://github.com/NVIDIA/BigVGAN/tree/main
|
|
41
|
+
device = waveform.device
|
|
42
|
+
key = f"{n_fft}_{n_mel_channels}_{target_sample_rate}_{hop_length}_{win_length}_{fmin}_{fmax}_{device}"
|
|
43
|
+
|
|
44
|
+
if key not in mel_basis_cache:
|
|
45
|
+
mel = librosa_mel_fn(sr=target_sample_rate, n_fft=n_fft, n_mels=n_mel_channels, fmin=fmin, fmax=fmax)
|
|
46
|
+
mel_basis_cache[key] = torch.from_numpy(mel).float().to(device) # TODO: why they need .float()?
|
|
47
|
+
hann_window_cache[key] = torch.hann_window(win_length).to(device)
|
|
48
|
+
|
|
49
|
+
mel_basis = mel_basis_cache[key]
|
|
50
|
+
hann_window = hann_window_cache[key]
|
|
51
|
+
|
|
52
|
+
padding = (n_fft - hop_length) // 2
|
|
53
|
+
waveform = torch.nn.functional.pad(waveform.unsqueeze(1), (padding, padding), mode="reflect").squeeze(1)
|
|
54
|
+
|
|
55
|
+
spec = torch.stft(
|
|
56
|
+
waveform,
|
|
57
|
+
n_fft,
|
|
58
|
+
hop_length=hop_length,
|
|
59
|
+
win_length=win_length,
|
|
60
|
+
window=hann_window,
|
|
61
|
+
center=center,
|
|
62
|
+
pad_mode="reflect",
|
|
63
|
+
normalized=False,
|
|
64
|
+
onesided=True,
|
|
65
|
+
return_complex=True,
|
|
66
|
+
)
|
|
67
|
+
spec = torch.sqrt(torch.view_as_real(spec).pow(2).sum(-1) + 1e-9)
|
|
68
|
+
|
|
69
|
+
mel_spec = torch.matmul(mel_basis, spec)
|
|
70
|
+
mel_spec = torch.log(torch.clamp(mel_spec, min=1e-5))
|
|
71
|
+
|
|
72
|
+
return mel_spec
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def get_vocos_mel_spectrogram(
|
|
76
|
+
waveform,
|
|
77
|
+
n_fft=1024,
|
|
78
|
+
n_mel_channels=100,
|
|
79
|
+
target_sample_rate=24000,
|
|
80
|
+
hop_length=256,
|
|
81
|
+
win_length=1024,
|
|
82
|
+
):
|
|
83
|
+
mel_stft = torchaudio.transforms.MelSpectrogram(
|
|
84
|
+
sample_rate=target_sample_rate,
|
|
85
|
+
n_fft=n_fft,
|
|
86
|
+
win_length=win_length,
|
|
87
|
+
hop_length=hop_length,
|
|
88
|
+
n_mels=n_mel_channels,
|
|
89
|
+
power=1,
|
|
90
|
+
center=True,
|
|
91
|
+
normalized=False,
|
|
92
|
+
norm=None,
|
|
93
|
+
).to(waveform.device)
|
|
94
|
+
if len(waveform.shape) == 3:
|
|
95
|
+
waveform = waveform.squeeze(1) # 'b 1 nw -> b nw'
|
|
96
|
+
|
|
97
|
+
assert len(waveform.shape) == 2
|
|
98
|
+
|
|
99
|
+
mel = mel_stft(waveform)
|
|
100
|
+
mel = mel.clamp(min=1e-5).log()
|
|
101
|
+
return mel
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class MelSpec(nn.Module):
|
|
105
|
+
def __init__(
|
|
106
|
+
self,
|
|
107
|
+
n_fft=1024,
|
|
108
|
+
hop_length=256,
|
|
109
|
+
win_length=1024,
|
|
110
|
+
n_mel_channels=100,
|
|
111
|
+
target_sample_rate=24_000,
|
|
112
|
+
mel_spec_type="vocos",
|
|
113
|
+
):
|
|
114
|
+
super().__init__()
|
|
115
|
+
assert mel_spec_type in ["vocos", "bigvgan"], print("We only support two extract mel backend: vocos or bigvgan")
|
|
116
|
+
|
|
117
|
+
self.n_fft = n_fft
|
|
118
|
+
self.hop_length = hop_length
|
|
119
|
+
self.win_length = win_length
|
|
120
|
+
self.n_mel_channels = n_mel_channels
|
|
121
|
+
self.target_sample_rate = target_sample_rate
|
|
122
|
+
|
|
123
|
+
if mel_spec_type == "vocos":
|
|
124
|
+
self.extractor = get_vocos_mel_spectrogram
|
|
125
|
+
elif mel_spec_type == "bigvgan":
|
|
126
|
+
self.extractor = get_bigvgan_mel_spectrogram
|
|
127
|
+
|
|
128
|
+
self.register_buffer("dummy", torch.tensor(0), persistent=False)
|
|
129
|
+
|
|
130
|
+
def forward(self, wav):
|
|
131
|
+
if self.dummy.device != wav.device:
|
|
132
|
+
self.to(wav.device)
|
|
133
|
+
|
|
134
|
+
mel = self.extractor(
|
|
135
|
+
waveform=wav,
|
|
136
|
+
n_fft=self.n_fft,
|
|
137
|
+
n_mel_channels=self.n_mel_channels,
|
|
138
|
+
target_sample_rate=self.target_sample_rate,
|
|
139
|
+
hop_length=self.hop_length,
|
|
140
|
+
win_length=self.win_length,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
return mel
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
# sinusoidal position embedding
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class SinusPositionEmbedding(nn.Module):
|
|
150
|
+
def __init__(self, dim):
|
|
151
|
+
super().__init__()
|
|
152
|
+
self.dim = dim
|
|
153
|
+
|
|
154
|
+
def forward(self, x, scale=1000):
|
|
155
|
+
device = x.device
|
|
156
|
+
half_dim = self.dim // 2
|
|
157
|
+
emb = math.log(10000) / (half_dim - 1)
|
|
158
|
+
emb = torch.exp(torch.arange(half_dim, device=device).float() * -emb)
|
|
159
|
+
emb = scale * x.unsqueeze(1) * emb.unsqueeze(0)
|
|
160
|
+
emb = torch.cat((emb.sin(), emb.cos()), dim=-1)
|
|
161
|
+
return emb
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# convolutional position embedding
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class ConvPositionEmbedding(nn.Module):
|
|
168
|
+
def __init__(self, dim, kernel_size=31, groups=16):
|
|
169
|
+
super().__init__()
|
|
170
|
+
assert kernel_size % 2 != 0
|
|
171
|
+
self.conv1d = nn.Sequential(
|
|
172
|
+
nn.Conv1d(dim, dim, kernel_size, groups=groups, padding=kernel_size // 2),
|
|
173
|
+
nn.Mish(),
|
|
174
|
+
nn.Conv1d(dim, dim, kernel_size, groups=groups, padding=kernel_size // 2),
|
|
175
|
+
nn.Mish(),
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
def forward(self, x: float["b n d"], mask: bool["b n"] | None = None): # noqa: F722
|
|
179
|
+
if mask is not None:
|
|
180
|
+
mask = mask[..., None]
|
|
181
|
+
x = x.masked_fill(~mask, 0.0)
|
|
182
|
+
|
|
183
|
+
x = x.permute(0, 2, 1)
|
|
184
|
+
x = self.conv1d(x)
|
|
185
|
+
out = x.permute(0, 2, 1)
|
|
186
|
+
|
|
187
|
+
if mask is not None:
|
|
188
|
+
out = out.masked_fill(~mask, 0.0)
|
|
189
|
+
|
|
190
|
+
return out
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
# rotary positional embedding related
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def precompute_freqs_cis(dim: int, end: int, theta: float = 10000.0, theta_rescale_factor=1.0):
|
|
197
|
+
# proposed by reddit user bloc97, to rescale rotary embeddings to longer sequence length without fine-tuning
|
|
198
|
+
# has some connection to NTK literature
|
|
199
|
+
# https://www.reddit.com/r/LocalLLaMA/comments/14lz7j5/ntkaware_scaled_rope_allows_llama_models_to_have/
|
|
200
|
+
# https://github.com/lucidrains/rotary-embedding-torch/blob/main/rotary_embedding_torch/rotary_embedding_torch.py
|
|
201
|
+
theta *= theta_rescale_factor ** (dim / (dim - 2))
|
|
202
|
+
freqs = 1.0 / (theta ** (torch.arange(0, dim, 2)[: (dim // 2)].float() / dim))
|
|
203
|
+
t = torch.arange(end, device=freqs.device) # type: ignore
|
|
204
|
+
freqs = torch.outer(t, freqs).float() # type: ignore
|
|
205
|
+
freqs_cos = torch.cos(freqs) # real part
|
|
206
|
+
freqs_sin = torch.sin(freqs) # imaginary part
|
|
207
|
+
return torch.cat([freqs_cos, freqs_sin], dim=-1)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def get_pos_embed_indices(start, length, max_pos, scale=1.0):
|
|
211
|
+
# length = length if isinstance(length, int) else length.max()
|
|
212
|
+
scale = scale * torch.ones_like(start, dtype=torch.float32) # in case scale is a scalar
|
|
213
|
+
pos = (
|
|
214
|
+
start.unsqueeze(1)
|
|
215
|
+
+ (torch.arange(length, device=start.device, dtype=torch.float32).unsqueeze(0) * scale.unsqueeze(1)).long()
|
|
216
|
+
)
|
|
217
|
+
# avoid extra long error.
|
|
218
|
+
pos = torch.where(pos < max_pos, pos, max_pos - 1)
|
|
219
|
+
return pos
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# Global Response Normalization layer (Instance Normalization ?)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
class GRN(nn.Module):
|
|
226
|
+
def __init__(self, dim):
|
|
227
|
+
super().__init__()
|
|
228
|
+
self.gamma = nn.Parameter(torch.zeros(1, 1, dim))
|
|
229
|
+
self.beta = nn.Parameter(torch.zeros(1, 1, dim))
|
|
230
|
+
|
|
231
|
+
def forward(self, x):
|
|
232
|
+
Gx = torch.norm(x, p=2, dim=1, keepdim=True)
|
|
233
|
+
Nx = Gx / (Gx.mean(dim=-1, keepdim=True) + 1e-6)
|
|
234
|
+
return self.gamma * (x * Nx) + self.beta + x
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
# ConvNeXt-V2 Block https://github.com/facebookresearch/ConvNeXt-V2/blob/main/models/convnextv2.py
|
|
238
|
+
# ref: https://github.com/bfs18/e2_tts/blob/main/rfwave/modules.py#L108
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class ConvNeXtV2Block(nn.Module):
|
|
242
|
+
def __init__(
|
|
243
|
+
self,
|
|
244
|
+
dim: int,
|
|
245
|
+
intermediate_dim: int,
|
|
246
|
+
dilation: int = 1,
|
|
247
|
+
):
|
|
248
|
+
super().__init__()
|
|
249
|
+
padding = (dilation * (7 - 1)) // 2
|
|
250
|
+
self.dwconv = nn.Conv1d(
|
|
251
|
+
dim, dim, kernel_size=7, padding=padding, groups=dim, dilation=dilation
|
|
252
|
+
) # depthwise conv
|
|
253
|
+
self.norm = nn.LayerNorm(dim, eps=1e-6)
|
|
254
|
+
self.pwconv1 = nn.Linear(dim, intermediate_dim) # pointwise/1x1 convs, implemented with linear layers
|
|
255
|
+
self.act = nn.GELU()
|
|
256
|
+
self.grn = GRN(intermediate_dim)
|
|
257
|
+
self.pwconv2 = nn.Linear(intermediate_dim, dim)
|
|
258
|
+
|
|
259
|
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
260
|
+
residual = x
|
|
261
|
+
x = x.transpose(1, 2) # b n d -> b d n
|
|
262
|
+
x = self.dwconv(x)
|
|
263
|
+
x = x.transpose(1, 2) # b d n -> b n d
|
|
264
|
+
x = self.norm(x)
|
|
265
|
+
x = self.pwconv1(x)
|
|
266
|
+
x = self.act(x)
|
|
267
|
+
x = self.grn(x)
|
|
268
|
+
x = self.pwconv2(x)
|
|
269
|
+
return residual + x
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
# AdaLayerNormZero
|
|
273
|
+
# return with modulated x for attn input, and params for later mlp modulation
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
class AdaLayerNormZero(nn.Module):
|
|
277
|
+
def __init__(self, dim):
|
|
278
|
+
super().__init__()
|
|
279
|
+
|
|
280
|
+
self.silu = nn.SiLU()
|
|
281
|
+
self.linear = nn.Linear(dim, dim * 6)
|
|
282
|
+
|
|
283
|
+
self.norm = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-6)
|
|
284
|
+
|
|
285
|
+
def forward(self, x, emb=None):
|
|
286
|
+
emb = self.linear(self.silu(emb))
|
|
287
|
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = torch.chunk(emb, 6, dim=1)
|
|
288
|
+
|
|
289
|
+
x = self.norm(x) * (1 + scale_msa[:, None]) + shift_msa[:, None]
|
|
290
|
+
return x, gate_msa, shift_mlp, scale_mlp, gate_mlp
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
# AdaLayerNormZero for final layer
|
|
294
|
+
# return only with modulated x for attn input, cuz no more mlp modulation
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
class AdaLayerNormZero_Final(nn.Module):
|
|
298
|
+
def __init__(self, dim):
|
|
299
|
+
super().__init__()
|
|
300
|
+
|
|
301
|
+
self.silu = nn.SiLU()
|
|
302
|
+
self.linear = nn.Linear(dim, dim * 2)
|
|
303
|
+
|
|
304
|
+
self.norm = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-6)
|
|
305
|
+
|
|
306
|
+
def forward(self, x, emb):
|
|
307
|
+
emb = self.linear(self.silu(emb))
|
|
308
|
+
scale, shift = torch.chunk(emb, 2, dim=1)
|
|
309
|
+
|
|
310
|
+
x = self.norm(x) * (1 + scale)[:, None, :] + shift[:, None, :]
|
|
311
|
+
return x
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
# FeedForward
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
class FeedForward(nn.Module):
|
|
318
|
+
def __init__(self, dim, dim_out=None, mult=4, dropout=0.0, approximate: str = "none"):
|
|
319
|
+
super().__init__()
|
|
320
|
+
inner_dim = int(dim * mult)
|
|
321
|
+
dim_out = dim_out if dim_out is not None else dim
|
|
322
|
+
|
|
323
|
+
activation = nn.GELU(approximate=approximate)
|
|
324
|
+
project_in = nn.Sequential(nn.Linear(dim, inner_dim), activation)
|
|
325
|
+
self.ff = nn.Sequential(project_in, nn.Dropout(dropout), nn.Linear(inner_dim, dim_out))
|
|
326
|
+
|
|
327
|
+
def forward(self, x):
|
|
328
|
+
return self.ff(x)
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
# Attention with possible joint part
|
|
332
|
+
# modified from diffusers/src/diffusers/models/attention_processor.py
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
class Attention(nn.Module):
|
|
336
|
+
def __init__(
|
|
337
|
+
self,
|
|
338
|
+
processor: JointAttnProcessor | AttnProcessor,
|
|
339
|
+
dim: int,
|
|
340
|
+
heads: int = 8,
|
|
341
|
+
dim_head: int = 64,
|
|
342
|
+
dropout: float = 0.0,
|
|
343
|
+
context_dim: Optional[int] = None, # if not None -> joint attention
|
|
344
|
+
context_pre_only=None,
|
|
345
|
+
):
|
|
346
|
+
super().__init__()
|
|
347
|
+
|
|
348
|
+
if not hasattr(F, "scaled_dot_product_attention"):
|
|
349
|
+
raise ImportError("Attention equires PyTorch 2.0, to use it, please upgrade PyTorch to 2.0.")
|
|
350
|
+
|
|
351
|
+
self.processor = processor
|
|
352
|
+
|
|
353
|
+
self.dim = dim
|
|
354
|
+
self.heads = heads
|
|
355
|
+
self.inner_dim = dim_head * heads
|
|
356
|
+
self.dropout = dropout
|
|
357
|
+
|
|
358
|
+
self.context_dim = context_dim
|
|
359
|
+
self.context_pre_only = context_pre_only
|
|
360
|
+
|
|
361
|
+
self.to_q = nn.Linear(dim, self.inner_dim)
|
|
362
|
+
self.to_k = nn.Linear(dim, self.inner_dim)
|
|
363
|
+
self.to_v = nn.Linear(dim, self.inner_dim)
|
|
364
|
+
|
|
365
|
+
if self.context_dim is not None:
|
|
366
|
+
self.to_k_c = nn.Linear(context_dim, self.inner_dim)
|
|
367
|
+
self.to_v_c = nn.Linear(context_dim, self.inner_dim)
|
|
368
|
+
if self.context_pre_only is not None:
|
|
369
|
+
self.to_q_c = nn.Linear(context_dim, self.inner_dim)
|
|
370
|
+
|
|
371
|
+
self.to_out = nn.ModuleList([])
|
|
372
|
+
self.to_out.append(nn.Linear(self.inner_dim, dim))
|
|
373
|
+
self.to_out.append(nn.Dropout(dropout))
|
|
374
|
+
|
|
375
|
+
if self.context_pre_only is not None and not self.context_pre_only:
|
|
376
|
+
self.to_out_c = nn.Linear(self.inner_dim, dim)
|
|
377
|
+
|
|
378
|
+
def forward(
|
|
379
|
+
self,
|
|
380
|
+
x: float["b n d"], # noised input x # noqa: F722
|
|
381
|
+
c: float["b n d"] = None, # context c # noqa: F722
|
|
382
|
+
mask: bool["b n"] | None = None, # noqa: F722
|
|
383
|
+
rope=None, # rotary position embedding for x
|
|
384
|
+
c_rope=None, # rotary position embedding for c
|
|
385
|
+
) -> torch.Tensor:
|
|
386
|
+
if c is not None:
|
|
387
|
+
return self.processor(self, x, c=c, mask=mask, rope=rope, c_rope=c_rope)
|
|
388
|
+
else:
|
|
389
|
+
return self.processor(self, x, mask=mask, rope=rope)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
# Attention processor
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
class AttnProcessor:
|
|
396
|
+
def __init__(self):
|
|
397
|
+
pass
|
|
398
|
+
|
|
399
|
+
def __call__(
|
|
400
|
+
self,
|
|
401
|
+
attn: Attention,
|
|
402
|
+
x: float["b n d"], # noised input x # noqa: F722
|
|
403
|
+
mask: bool["b n"] | None = None, # noqa: F722
|
|
404
|
+
rope=None, # rotary position embedding
|
|
405
|
+
) -> torch.FloatTensor:
|
|
406
|
+
batch_size = x.shape[0]
|
|
407
|
+
|
|
408
|
+
# `sample` projections.
|
|
409
|
+
query = attn.to_q(x)
|
|
410
|
+
key = attn.to_k(x)
|
|
411
|
+
value = attn.to_v(x)
|
|
412
|
+
|
|
413
|
+
# apply rotary position embedding
|
|
414
|
+
if rope is not None:
|
|
415
|
+
freqs, xpos_scale = rope
|
|
416
|
+
q_xpos_scale, k_xpos_scale = (xpos_scale, xpos_scale**-1.0) if xpos_scale is not None else (1.0, 1.0)
|
|
417
|
+
|
|
418
|
+
query = apply_rotary_pos_emb(query, freqs, q_xpos_scale)
|
|
419
|
+
key = apply_rotary_pos_emb(key, freqs, k_xpos_scale)
|
|
420
|
+
|
|
421
|
+
# attention
|
|
422
|
+
inner_dim = key.shape[-1]
|
|
423
|
+
head_dim = inner_dim // attn.heads
|
|
424
|
+
query = query.view(batch_size, -1, attn.heads, head_dim).transpose(1, 2)
|
|
425
|
+
key = key.view(batch_size, -1, attn.heads, head_dim).transpose(1, 2)
|
|
426
|
+
value = value.view(batch_size, -1, attn.heads, head_dim).transpose(1, 2)
|
|
427
|
+
|
|
428
|
+
# mask. e.g. inference got a batch with different target durations, mask out the padding
|
|
429
|
+
if mask is not None:
|
|
430
|
+
attn_mask = mask
|
|
431
|
+
attn_mask = attn_mask.unsqueeze(1).unsqueeze(1) # 'b n -> b 1 1 n'
|
|
432
|
+
attn_mask = attn_mask.expand(batch_size, attn.heads, query.shape[-2], key.shape[-2])
|
|
433
|
+
else:
|
|
434
|
+
attn_mask = None
|
|
435
|
+
|
|
436
|
+
x = F.scaled_dot_product_attention(query, key, value, attn_mask=attn_mask, dropout_p=0.0, is_causal=False)
|
|
437
|
+
x = x.transpose(1, 2).reshape(batch_size, -1, attn.heads * head_dim)
|
|
438
|
+
x = x.to(query.dtype)
|
|
439
|
+
|
|
440
|
+
# linear proj
|
|
441
|
+
x = attn.to_out[0](x)
|
|
442
|
+
# dropout
|
|
443
|
+
x = attn.to_out[1](x)
|
|
444
|
+
|
|
445
|
+
if mask is not None:
|
|
446
|
+
mask = mask.unsqueeze(-1)
|
|
447
|
+
x = x.masked_fill(~mask, 0.0)
|
|
448
|
+
|
|
449
|
+
return x
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
# Joint Attention processor for MM-DiT
|
|
453
|
+
# modified from diffusers/src/diffusers/models/attention_processor.py
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
class JointAttnProcessor:
|
|
457
|
+
def __init__(self):
|
|
458
|
+
pass
|
|
459
|
+
|
|
460
|
+
def __call__(
|
|
461
|
+
self,
|
|
462
|
+
attn: Attention,
|
|
463
|
+
x: float["b n d"], # noised input x # noqa: F722
|
|
464
|
+
c: float["b nt d"] = None, # context c, here text # noqa: F722
|
|
465
|
+
mask: bool["b n"] | None = None, # noqa: F722
|
|
466
|
+
rope=None, # rotary position embedding for x
|
|
467
|
+
c_rope=None, # rotary position embedding for c
|
|
468
|
+
) -> torch.FloatTensor:
|
|
469
|
+
residual = x
|
|
470
|
+
|
|
471
|
+
batch_size = c.shape[0]
|
|
472
|
+
|
|
473
|
+
# `sample` projections.
|
|
474
|
+
query = attn.to_q(x)
|
|
475
|
+
key = attn.to_k(x)
|
|
476
|
+
value = attn.to_v(x)
|
|
477
|
+
|
|
478
|
+
# `context` projections.
|
|
479
|
+
c_query = attn.to_q_c(c)
|
|
480
|
+
c_key = attn.to_k_c(c)
|
|
481
|
+
c_value = attn.to_v_c(c)
|
|
482
|
+
|
|
483
|
+
# apply rope for context and noised input independently
|
|
484
|
+
if rope is not None:
|
|
485
|
+
freqs, xpos_scale = rope
|
|
486
|
+
q_xpos_scale, k_xpos_scale = (xpos_scale, xpos_scale**-1.0) if xpos_scale is not None else (1.0, 1.0)
|
|
487
|
+
query = apply_rotary_pos_emb(query, freqs, q_xpos_scale)
|
|
488
|
+
key = apply_rotary_pos_emb(key, freqs, k_xpos_scale)
|
|
489
|
+
if c_rope is not None:
|
|
490
|
+
freqs, xpos_scale = c_rope
|
|
491
|
+
q_xpos_scale, k_xpos_scale = (xpos_scale, xpos_scale**-1.0) if xpos_scale is not None else (1.0, 1.0)
|
|
492
|
+
c_query = apply_rotary_pos_emb(c_query, freqs, q_xpos_scale)
|
|
493
|
+
c_key = apply_rotary_pos_emb(c_key, freqs, k_xpos_scale)
|
|
494
|
+
|
|
495
|
+
# attention
|
|
496
|
+
query = torch.cat([query, c_query], dim=1)
|
|
497
|
+
key = torch.cat([key, c_key], dim=1)
|
|
498
|
+
value = torch.cat([value, c_value], dim=1)
|
|
499
|
+
|
|
500
|
+
inner_dim = key.shape[-1]
|
|
501
|
+
head_dim = inner_dim // attn.heads
|
|
502
|
+
query = query.view(batch_size, -1, attn.heads, head_dim).transpose(1, 2)
|
|
503
|
+
key = key.view(batch_size, -1, attn.heads, head_dim).transpose(1, 2)
|
|
504
|
+
value = value.view(batch_size, -1, attn.heads, head_dim).transpose(1, 2)
|
|
505
|
+
|
|
506
|
+
# mask. e.g. inference got a batch with different target durations, mask out the padding
|
|
507
|
+
if mask is not None:
|
|
508
|
+
attn_mask = F.pad(mask, (0, c.shape[1]), value=True) # no mask for c (text)
|
|
509
|
+
attn_mask = attn_mask.unsqueeze(1).unsqueeze(1) # 'b n -> b 1 1 n'
|
|
510
|
+
attn_mask = attn_mask.expand(batch_size, attn.heads, query.shape[-2], key.shape[-2])
|
|
511
|
+
else:
|
|
512
|
+
attn_mask = None
|
|
513
|
+
|
|
514
|
+
x = F.scaled_dot_product_attention(query, key, value, attn_mask=attn_mask, dropout_p=0.0, is_causal=False)
|
|
515
|
+
x = x.transpose(1, 2).reshape(batch_size, -1, attn.heads * head_dim)
|
|
516
|
+
x = x.to(query.dtype)
|
|
517
|
+
|
|
518
|
+
# Split the attention outputs.
|
|
519
|
+
x, c = (
|
|
520
|
+
x[:, : residual.shape[1]],
|
|
521
|
+
x[:, residual.shape[1] :],
|
|
522
|
+
)
|
|
523
|
+
|
|
524
|
+
# linear proj
|
|
525
|
+
x = attn.to_out[0](x)
|
|
526
|
+
# dropout
|
|
527
|
+
x = attn.to_out[1](x)
|
|
528
|
+
if not attn.context_pre_only:
|
|
529
|
+
c = attn.to_out_c(c)
|
|
530
|
+
|
|
531
|
+
if mask is not None:
|
|
532
|
+
mask = mask.unsqueeze(-1)
|
|
533
|
+
x = x.masked_fill(~mask, 0.0)
|
|
534
|
+
# c = c.masked_fill(~mask, 0.) # no mask for c (text)
|
|
535
|
+
|
|
536
|
+
return x, c
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
# DiT Block
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
class DiTBlock(nn.Module):
|
|
543
|
+
def __init__(self, dim, heads, dim_head, ff_mult=4, dropout=0.1):
|
|
544
|
+
super().__init__()
|
|
545
|
+
|
|
546
|
+
self.attn_norm = AdaLayerNormZero(dim)
|
|
547
|
+
self.attn = Attention(
|
|
548
|
+
processor=AttnProcessor(),
|
|
549
|
+
dim=dim,
|
|
550
|
+
heads=heads,
|
|
551
|
+
dim_head=dim_head,
|
|
552
|
+
dropout=dropout,
|
|
553
|
+
)
|
|
554
|
+
|
|
555
|
+
self.ff_norm = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-6)
|
|
556
|
+
self.ff = FeedForward(dim=dim, mult=ff_mult, dropout=dropout, approximate="tanh")
|
|
557
|
+
|
|
558
|
+
def forward(self, x, t, mask=None, rope=None): # x: noised input, t: time embedding
|
|
559
|
+
# pre-norm & modulation for attention input
|
|
560
|
+
norm, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.attn_norm(x, emb=t)
|
|
561
|
+
|
|
562
|
+
# attention
|
|
563
|
+
attn_output = self.attn(x=norm, mask=mask, rope=rope)
|
|
564
|
+
|
|
565
|
+
# process attention output for input x
|
|
566
|
+
x = x + gate_msa.unsqueeze(1) * attn_output
|
|
567
|
+
|
|
568
|
+
norm = self.ff_norm(x) * (1 + scale_mlp[:, None]) + shift_mlp[:, None]
|
|
569
|
+
ff_output = self.ff(norm)
|
|
570
|
+
x = x + gate_mlp.unsqueeze(1) * ff_output
|
|
571
|
+
|
|
572
|
+
return x
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
# MMDiT Block https://arxiv.org/abs/2403.03206
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
class MMDiTBlock(nn.Module):
|
|
579
|
+
r"""
|
|
580
|
+
modified from diffusers/src/diffusers/models/attention.py
|
|
581
|
+
|
|
582
|
+
notes.
|
|
583
|
+
_c: context related. text, cond, etc. (left part in sd3 fig2.b)
|
|
584
|
+
_x: noised input related. (right part)
|
|
585
|
+
context_pre_only: last layer only do prenorm + modulation cuz no more ffn
|
|
586
|
+
"""
|
|
587
|
+
|
|
588
|
+
def __init__(self, dim, heads, dim_head, ff_mult=4, dropout=0.1, context_pre_only=False):
|
|
589
|
+
super().__init__()
|
|
590
|
+
|
|
591
|
+
self.context_pre_only = context_pre_only
|
|
592
|
+
|
|
593
|
+
self.attn_norm_c = AdaLayerNormZero_Final(dim) if context_pre_only else AdaLayerNormZero(dim)
|
|
594
|
+
self.attn_norm_x = AdaLayerNormZero(dim)
|
|
595
|
+
self.attn = Attention(
|
|
596
|
+
processor=JointAttnProcessor(),
|
|
597
|
+
dim=dim,
|
|
598
|
+
heads=heads,
|
|
599
|
+
dim_head=dim_head,
|
|
600
|
+
dropout=dropout,
|
|
601
|
+
context_dim=dim,
|
|
602
|
+
context_pre_only=context_pre_only,
|
|
603
|
+
)
|
|
604
|
+
|
|
605
|
+
if not context_pre_only:
|
|
606
|
+
self.ff_norm_c = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-6)
|
|
607
|
+
self.ff_c = FeedForward(dim=dim, mult=ff_mult, dropout=dropout, approximate="tanh")
|
|
608
|
+
else:
|
|
609
|
+
self.ff_norm_c = None
|
|
610
|
+
self.ff_c = None
|
|
611
|
+
self.ff_norm_x = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-6)
|
|
612
|
+
self.ff_x = FeedForward(dim=dim, mult=ff_mult, dropout=dropout, approximate="tanh")
|
|
613
|
+
|
|
614
|
+
def forward(self, x, c, t, mask=None, rope=None, c_rope=None): # x: noised input, c: context, t: time embedding
|
|
615
|
+
# pre-norm & modulation for attention input
|
|
616
|
+
if self.context_pre_only:
|
|
617
|
+
norm_c = self.attn_norm_c(c, t)
|
|
618
|
+
else:
|
|
619
|
+
norm_c, c_gate_msa, c_shift_mlp, c_scale_mlp, c_gate_mlp = self.attn_norm_c(c, emb=t)
|
|
620
|
+
norm_x, x_gate_msa, x_shift_mlp, x_scale_mlp, x_gate_mlp = self.attn_norm_x(x, emb=t)
|
|
621
|
+
|
|
622
|
+
# attention
|
|
623
|
+
x_attn_output, c_attn_output = self.attn(x=norm_x, c=norm_c, mask=mask, rope=rope, c_rope=c_rope)
|
|
624
|
+
|
|
625
|
+
# process attention output for context c
|
|
626
|
+
if self.context_pre_only:
|
|
627
|
+
c = None
|
|
628
|
+
else: # if not last layer
|
|
629
|
+
c = c + c_gate_msa.unsqueeze(1) * c_attn_output
|
|
630
|
+
|
|
631
|
+
norm_c = self.ff_norm_c(c) * (1 + c_scale_mlp[:, None]) + c_shift_mlp[:, None]
|
|
632
|
+
c_ff_output = self.ff_c(norm_c)
|
|
633
|
+
c = c + c_gate_mlp.unsqueeze(1) * c_ff_output
|
|
634
|
+
|
|
635
|
+
# process attention output for input x
|
|
636
|
+
x = x + x_gate_msa.unsqueeze(1) * x_attn_output
|
|
637
|
+
|
|
638
|
+
norm_x = self.ff_norm_x(x) * (1 + x_scale_mlp[:, None]) + x_shift_mlp[:, None]
|
|
639
|
+
x_ff_output = self.ff_x(norm_x)
|
|
640
|
+
x = x + x_gate_mlp.unsqueeze(1) * x_ff_output
|
|
641
|
+
|
|
642
|
+
return c, x
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
# time step conditioning embedding
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
class TimestepEmbedding(nn.Module):
|
|
649
|
+
def __init__(self, dim, freq_embed_dim=256):
|
|
650
|
+
super().__init__()
|
|
651
|
+
self.time_embed = SinusPositionEmbedding(freq_embed_dim)
|
|
652
|
+
self.time_mlp = nn.Sequential(nn.Linear(freq_embed_dim, dim), nn.SiLU(), nn.Linear(dim, dim))
|
|
653
|
+
|
|
654
|
+
def forward(self, timestep: float["b"]): # noqa: F821
|
|
655
|
+
time_hidden = self.time_embed(timestep)
|
|
656
|
+
time_hidden = time_hidden.to(timestep.dtype)
|
|
657
|
+
time = self.time_mlp(time_hidden) # b d
|
|
658
|
+
return time
|