xinference 1.0.1__py3-none-any.whl → 1.1.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 +2 -0
- xinference/_version.py +3 -3
- xinference/api/restful_api.py +28 -6
- xinference/core/utils.py +10 -6
- xinference/deploy/cmdline.py +3 -1
- xinference/deploy/test/test_cmdline.py +56 -0
- xinference/isolation.py +24 -0
- xinference/model/audio/core.py +10 -0
- xinference/model/audio/cosyvoice.py +25 -3
- xinference/model/audio/f5tts.py +200 -0
- xinference/model/audio/f5tts_mlx.py +260 -0
- xinference/model/audio/fish_speech.py +36 -111
- xinference/model/audio/model_spec.json +27 -3
- xinference/model/audio/model_spec_modelscope.json +18 -0
- xinference/model/audio/utils.py +32 -0
- xinference/model/embedding/core.py +203 -142
- xinference/model/embedding/model_spec.json +7 -0
- xinference/model/embedding/model_spec_modelscope.json +8 -0
- xinference/model/image/core.py +69 -1
- xinference/model/image/model_spec.json +127 -4
- xinference/model/image/model_spec_modelscope.json +130 -4
- xinference/model/image/stable_diffusion/core.py +45 -13
- xinference/model/llm/__init__.py +2 -2
- xinference/model/llm/llm_family.json +219 -53
- xinference/model/llm/llm_family.py +15 -36
- xinference/model/llm/llm_family_modelscope.json +167 -20
- xinference/model/llm/mlx/core.py +287 -51
- xinference/model/llm/sglang/core.py +1 -0
- xinference/model/llm/transformers/chatglm.py +9 -5
- xinference/model/llm/transformers/core.py +1 -0
- xinference/model/llm/transformers/qwen2_vl.py +2 -0
- xinference/model/llm/transformers/utils.py +16 -8
- xinference/model/llm/utils.py +5 -1
- xinference/model/llm/vllm/core.py +16 -2
- 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/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 +94 -83
- xinference/thirdparty/fish_speech/fish_speech/models/text2semantic/llama.py +63 -20
- xinference/thirdparty/fish_speech/fish_speech/text/clean.py +1 -26
- 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/webui/manage.py +1 -1
- xinference/thirdparty/fish_speech/tools/{post_api.py → api_client.py} +7 -13
- 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/fish_e2e.py +2 -2
- 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 +117 -89
- xinference/thirdparty/fish_speech/tools/run_webui.py +104 -0
- xinference/thirdparty/fish_speech/tools/schema.py +11 -28
- 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/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/web/ui/build/asset-manifest.json +3 -3
- xinference/web/ui/build/index.html +1 -1
- xinference/web/ui/build/static/js/{main.2f269bb3.js → main.4eb4ee80.js} +3 -3
- xinference/web/ui/build/static/js/main.4eb4ee80.js.map +1 -0
- xinference/web/ui/node_modules/.cache/babel-loader/8c5eeb02f772d02cbe8b89c05428d0dd41a97866f75f7dc1c2164a67f5a1cf98.json +1 -0
- {xinference-1.0.1.dist-info → xinference-1.1.1.dist-info}/METADATA +41 -17
- {xinference-1.0.1.dist-info → xinference-1.1.1.dist-info}/RECORD +160 -88
- xinference/thirdparty/cosyvoice/bin/export_trt.py +0 -8
- xinference/thirdparty/cosyvoice/flow/__init__.py +0 -0
- xinference/thirdparty/cosyvoice/hifigan/__init__.py +0 -0
- xinference/thirdparty/cosyvoice/llm/__init__.py +0 -0
- xinference/thirdparty/fish_speech/tools/__init__.py +0 -0
- xinference/thirdparty/fish_speech/tools/api.py +0 -943
- xinference/thirdparty/fish_speech/tools/msgpack_api.py +0 -95
- xinference/thirdparty/fish_speech/tools/webui.py +0 -548
- xinference/web/ui/build/static/js/main.2f269bb3.js.map +0 -1
- xinference/web/ui/node_modules/.cache/babel-loader/bd6ad8159341315a1764c397621a560809f7eb7219ab5174c801fca7e969d943.json +0 -1
- /xinference/thirdparty/{cosyvoice/bin → f5_tts}/__init__.py +0 -0
- /xinference/web/ui/build/static/js/{main.2f269bb3.js.LICENSE.txt → main.4eb4ee80.js.LICENSE.txt} +0 -0
- {xinference-1.0.1.dist-info → xinference-1.1.1.dist-info}/LICENSE +0 -0
- {xinference-1.0.1.dist-info → xinference-1.1.1.dist-info}/WHEEL +0 -0
- {xinference-1.0.1.dist-info → xinference-1.1.1.dist-info}/entry_points.txt +0 -0
- {xinference-1.0.1.dist-info → xinference-1.1.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
sys.path.append(os.getcwd())
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import time
|
|
8
|
+
from importlib.resources import files
|
|
9
|
+
|
|
10
|
+
import torch
|
|
11
|
+
import torchaudio
|
|
12
|
+
from accelerate import Accelerator
|
|
13
|
+
from tqdm import tqdm
|
|
14
|
+
|
|
15
|
+
from f5_tts.eval.utils_eval import (
|
|
16
|
+
get_inference_prompt,
|
|
17
|
+
get_librispeech_test_clean_metainfo,
|
|
18
|
+
get_seedtts_testset_metainfo,
|
|
19
|
+
)
|
|
20
|
+
from f5_tts.infer.utils_infer import load_checkpoint, load_vocoder
|
|
21
|
+
from f5_tts.model import CFM, DiT, UNetT
|
|
22
|
+
from f5_tts.model.utils import get_tokenizer
|
|
23
|
+
|
|
24
|
+
accelerator = Accelerator()
|
|
25
|
+
device = f"cuda:{accelerator.process_index}"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# --------------------- Dataset Settings -------------------- #
|
|
29
|
+
|
|
30
|
+
target_sample_rate = 24000
|
|
31
|
+
n_mel_channels = 100
|
|
32
|
+
hop_length = 256
|
|
33
|
+
win_length = 1024
|
|
34
|
+
n_fft = 1024
|
|
35
|
+
target_rms = 0.1
|
|
36
|
+
|
|
37
|
+
rel_path = str(files("f5_tts").joinpath("../../"))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def main():
|
|
41
|
+
# ---------------------- infer setting ---------------------- #
|
|
42
|
+
|
|
43
|
+
parser = argparse.ArgumentParser(description="batch inference")
|
|
44
|
+
|
|
45
|
+
parser.add_argument("-s", "--seed", default=None, type=int)
|
|
46
|
+
parser.add_argument("-d", "--dataset", default="Emilia_ZH_EN")
|
|
47
|
+
parser.add_argument("-n", "--expname", required=True)
|
|
48
|
+
parser.add_argument("-c", "--ckptstep", default=1200000, type=int)
|
|
49
|
+
parser.add_argument("-m", "--mel_spec_type", default="vocos", type=str, choices=["bigvgan", "vocos"])
|
|
50
|
+
parser.add_argument("-to", "--tokenizer", default="pinyin", type=str, choices=["pinyin", "char"])
|
|
51
|
+
|
|
52
|
+
parser.add_argument("-nfe", "--nfestep", default=32, type=int)
|
|
53
|
+
parser.add_argument("-o", "--odemethod", default="euler")
|
|
54
|
+
parser.add_argument("-ss", "--swaysampling", default=-1, type=float)
|
|
55
|
+
|
|
56
|
+
parser.add_argument("-t", "--testset", required=True)
|
|
57
|
+
|
|
58
|
+
args = parser.parse_args()
|
|
59
|
+
|
|
60
|
+
seed = args.seed
|
|
61
|
+
dataset_name = args.dataset
|
|
62
|
+
exp_name = args.expname
|
|
63
|
+
ckpt_step = args.ckptstep
|
|
64
|
+
ckpt_path = rel_path + f"/ckpts/{exp_name}/model_{ckpt_step}.pt"
|
|
65
|
+
mel_spec_type = args.mel_spec_type
|
|
66
|
+
tokenizer = args.tokenizer
|
|
67
|
+
|
|
68
|
+
nfe_step = args.nfestep
|
|
69
|
+
ode_method = args.odemethod
|
|
70
|
+
sway_sampling_coef = args.swaysampling
|
|
71
|
+
|
|
72
|
+
testset = args.testset
|
|
73
|
+
|
|
74
|
+
infer_batch_size = 1 # max frames. 1 for ddp single inference (recommended)
|
|
75
|
+
cfg_strength = 2.0
|
|
76
|
+
speed = 1.0
|
|
77
|
+
use_truth_duration = False
|
|
78
|
+
no_ref_audio = False
|
|
79
|
+
|
|
80
|
+
if exp_name == "F5TTS_Base":
|
|
81
|
+
model_cls = DiT
|
|
82
|
+
model_cfg = dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4)
|
|
83
|
+
|
|
84
|
+
elif exp_name == "E2TTS_Base":
|
|
85
|
+
model_cls = UNetT
|
|
86
|
+
model_cfg = dict(dim=1024, depth=24, heads=16, ff_mult=4)
|
|
87
|
+
|
|
88
|
+
if testset == "ls_pc_test_clean":
|
|
89
|
+
metalst = rel_path + "/data/librispeech_pc_test_clean_cross_sentence.lst"
|
|
90
|
+
librispeech_test_clean_path = "<SOME_PATH>/LibriSpeech/test-clean" # test-clean path
|
|
91
|
+
metainfo = get_librispeech_test_clean_metainfo(metalst, librispeech_test_clean_path)
|
|
92
|
+
|
|
93
|
+
elif testset == "seedtts_test_zh":
|
|
94
|
+
metalst = rel_path + "/data/seedtts_testset/zh/meta.lst"
|
|
95
|
+
metainfo = get_seedtts_testset_metainfo(metalst)
|
|
96
|
+
|
|
97
|
+
elif testset == "seedtts_test_en":
|
|
98
|
+
metalst = rel_path + "/data/seedtts_testset/en/meta.lst"
|
|
99
|
+
metainfo = get_seedtts_testset_metainfo(metalst)
|
|
100
|
+
|
|
101
|
+
# path to save genereted wavs
|
|
102
|
+
output_dir = (
|
|
103
|
+
f"{rel_path}/"
|
|
104
|
+
f"results/{exp_name}_{ckpt_step}/{testset}/"
|
|
105
|
+
f"seed{seed}_{ode_method}_nfe{nfe_step}_{mel_spec_type}"
|
|
106
|
+
f"{f'_ss{sway_sampling_coef}' if sway_sampling_coef else ''}"
|
|
107
|
+
f"_cfg{cfg_strength}_speed{speed}"
|
|
108
|
+
f"{'_gt-dur' if use_truth_duration else ''}"
|
|
109
|
+
f"{'_no-ref-audio' if no_ref_audio else ''}"
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
# -------------------------------------------------#
|
|
113
|
+
|
|
114
|
+
use_ema = True
|
|
115
|
+
|
|
116
|
+
prompts_all = get_inference_prompt(
|
|
117
|
+
metainfo,
|
|
118
|
+
speed=speed,
|
|
119
|
+
tokenizer=tokenizer,
|
|
120
|
+
target_sample_rate=target_sample_rate,
|
|
121
|
+
n_mel_channels=n_mel_channels,
|
|
122
|
+
hop_length=hop_length,
|
|
123
|
+
mel_spec_type=mel_spec_type,
|
|
124
|
+
target_rms=target_rms,
|
|
125
|
+
use_truth_duration=use_truth_duration,
|
|
126
|
+
infer_batch_size=infer_batch_size,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# Vocoder model
|
|
130
|
+
local = False
|
|
131
|
+
if mel_spec_type == "vocos":
|
|
132
|
+
vocoder_local_path = "../checkpoints/charactr/vocos-mel-24khz"
|
|
133
|
+
elif mel_spec_type == "bigvgan":
|
|
134
|
+
vocoder_local_path = "../checkpoints/bigvgan_v2_24khz_100band_256x"
|
|
135
|
+
vocoder = load_vocoder(vocoder_name=mel_spec_type, is_local=local, local_path=vocoder_local_path)
|
|
136
|
+
|
|
137
|
+
# Tokenizer
|
|
138
|
+
vocab_char_map, vocab_size = get_tokenizer(dataset_name, tokenizer)
|
|
139
|
+
|
|
140
|
+
# Model
|
|
141
|
+
model = CFM(
|
|
142
|
+
transformer=model_cls(**model_cfg, text_num_embeds=vocab_size, mel_dim=n_mel_channels),
|
|
143
|
+
mel_spec_kwargs=dict(
|
|
144
|
+
n_fft=n_fft,
|
|
145
|
+
hop_length=hop_length,
|
|
146
|
+
win_length=win_length,
|
|
147
|
+
n_mel_channels=n_mel_channels,
|
|
148
|
+
target_sample_rate=target_sample_rate,
|
|
149
|
+
mel_spec_type=mel_spec_type,
|
|
150
|
+
),
|
|
151
|
+
odeint_kwargs=dict(
|
|
152
|
+
method=ode_method,
|
|
153
|
+
),
|
|
154
|
+
vocab_char_map=vocab_char_map,
|
|
155
|
+
).to(device)
|
|
156
|
+
|
|
157
|
+
dtype = torch.float32 if mel_spec_type == "bigvgan" else None
|
|
158
|
+
model = load_checkpoint(model, ckpt_path, device, dtype=dtype, use_ema=use_ema)
|
|
159
|
+
|
|
160
|
+
if not os.path.exists(output_dir) and accelerator.is_main_process:
|
|
161
|
+
os.makedirs(output_dir)
|
|
162
|
+
|
|
163
|
+
# start batch inference
|
|
164
|
+
accelerator.wait_for_everyone()
|
|
165
|
+
start = time.time()
|
|
166
|
+
|
|
167
|
+
with accelerator.split_between_processes(prompts_all) as prompts:
|
|
168
|
+
for prompt in tqdm(prompts, disable=not accelerator.is_local_main_process):
|
|
169
|
+
utts, ref_rms_list, ref_mels, ref_mel_lens, total_mel_lens, final_text_list = prompt
|
|
170
|
+
ref_mels = ref_mels.to(device)
|
|
171
|
+
ref_mel_lens = torch.tensor(ref_mel_lens, dtype=torch.long).to(device)
|
|
172
|
+
total_mel_lens = torch.tensor(total_mel_lens, dtype=torch.long).to(device)
|
|
173
|
+
|
|
174
|
+
# Inference
|
|
175
|
+
with torch.inference_mode():
|
|
176
|
+
generated, _ = model.sample(
|
|
177
|
+
cond=ref_mels,
|
|
178
|
+
text=final_text_list,
|
|
179
|
+
duration=total_mel_lens,
|
|
180
|
+
lens=ref_mel_lens,
|
|
181
|
+
steps=nfe_step,
|
|
182
|
+
cfg_strength=cfg_strength,
|
|
183
|
+
sway_sampling_coef=sway_sampling_coef,
|
|
184
|
+
no_ref_audio=no_ref_audio,
|
|
185
|
+
seed=seed,
|
|
186
|
+
)
|
|
187
|
+
# Final result
|
|
188
|
+
for i, gen in enumerate(generated):
|
|
189
|
+
gen = gen[ref_mel_lens[i] : total_mel_lens[i], :].unsqueeze(0)
|
|
190
|
+
gen_mel_spec = gen.permute(0, 2, 1).to(torch.float32)
|
|
191
|
+
if mel_spec_type == "vocos":
|
|
192
|
+
generated_wave = vocoder.decode(gen_mel_spec).cpu()
|
|
193
|
+
elif mel_spec_type == "bigvgan":
|
|
194
|
+
generated_wave = vocoder(gen_mel_spec).squeeze(0).cpu()
|
|
195
|
+
|
|
196
|
+
if ref_rms_list[i] < target_rms:
|
|
197
|
+
generated_wave = generated_wave * ref_rms_list[i] / target_rms
|
|
198
|
+
torchaudio.save(f"{output_dir}/{utts[i]}.wav", generated_wave, target_sample_rate)
|
|
199
|
+
|
|
200
|
+
accelerator.wait_for_everyone()
|
|
201
|
+
if accelerator.is_main_process:
|
|
202
|
+
timediff = time.time() - start
|
|
203
|
+
print(f"Done batch inference in {timediff / 60 :.2f} minutes.")
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
if __name__ == "__main__":
|
|
207
|
+
main()
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# e.g. F5-TTS, 16 NFE
|
|
4
|
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "F5TTS_Base" -t "seedtts_test_zh" -nfe 16
|
|
5
|
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "F5TTS_Base" -t "seedtts_test_en" -nfe 16
|
|
6
|
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "F5TTS_Base" -t "ls_pc_test_clean" -nfe 16
|
|
7
|
+
|
|
8
|
+
# e.g. Vanilla E2 TTS, 32 NFE
|
|
9
|
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "E2TTS_Base" -t "seedtts_test_zh" -o "midpoint" -ss 0
|
|
10
|
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "E2TTS_Base" -t "seedtts_test_en" -o "midpoint" -ss 0
|
|
11
|
+
accelerate launch src/f5_tts/eval/eval_infer_batch.py -s 0 -n "E2TTS_Base" -t "ls_pc_test_clean" -o "midpoint" -ss 0
|
|
12
|
+
|
|
13
|
+
# etc.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Evaluate with Librispeech test-clean, ~3s prompt to generate 4-10s audio (the way of valle/voicebox evaluation)
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import os
|
|
5
|
+
import argparse
|
|
6
|
+
|
|
7
|
+
sys.path.append(os.getcwd())
|
|
8
|
+
|
|
9
|
+
import multiprocessing as mp
|
|
10
|
+
from importlib.resources import files
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
from f5_tts.eval.utils_eval import (
|
|
15
|
+
get_librispeech_test,
|
|
16
|
+
run_asr_wer,
|
|
17
|
+
run_sim,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
rel_path = str(files("f5_tts").joinpath("../../"))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_args():
|
|
24
|
+
parser = argparse.ArgumentParser()
|
|
25
|
+
parser.add_argument("-e", "--eval_task", type=str, default="wer", choices=["sim", "wer"])
|
|
26
|
+
parser.add_argument("-l", "--lang", type=str, default="en")
|
|
27
|
+
parser.add_argument("-g", "--gen_wav_dir", type=str, required=True)
|
|
28
|
+
parser.add_argument("-p", "--librispeech_test_clean_path", type=str, required=True)
|
|
29
|
+
parser.add_argument("-n", "--gpu_nums", type=int, default=8, help="Number of GPUs to use")
|
|
30
|
+
parser.add_argument("--local", action="store_true", help="Use local custom checkpoint directory")
|
|
31
|
+
return parser.parse_args()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def main():
|
|
35
|
+
args = get_args()
|
|
36
|
+
eval_task = args.eval_task
|
|
37
|
+
lang = args.lang
|
|
38
|
+
librispeech_test_clean_path = args.librispeech_test_clean_path # test-clean path
|
|
39
|
+
gen_wav_dir = args.gen_wav_dir
|
|
40
|
+
metalst = rel_path + "/data/librispeech_pc_test_clean_cross_sentence.lst"
|
|
41
|
+
|
|
42
|
+
gpus = list(range(args.gpu_nums))
|
|
43
|
+
test_set = get_librispeech_test(metalst, gen_wav_dir, gpus, librispeech_test_clean_path)
|
|
44
|
+
|
|
45
|
+
## In LibriSpeech, some speakers utilized varying voice characteristics for different characters in the book,
|
|
46
|
+
## leading to a low similarity for the ground truth in some cases.
|
|
47
|
+
# test_set = get_librispeech_test(metalst, gen_wav_dir, gpus, librispeech_test_clean_path, eval_ground_truth = True) # eval ground truth
|
|
48
|
+
|
|
49
|
+
local = args.local
|
|
50
|
+
if local: # use local custom checkpoint dir
|
|
51
|
+
asr_ckpt_dir = "../checkpoints/Systran/faster-whisper-large-v3"
|
|
52
|
+
else:
|
|
53
|
+
asr_ckpt_dir = "" # auto download to cache dir
|
|
54
|
+
wavlm_ckpt_dir = "../checkpoints/UniSpeech/wavlm_large_finetune.pth"
|
|
55
|
+
|
|
56
|
+
# --------------------------- WER ---------------------------
|
|
57
|
+
if eval_task == "wer":
|
|
58
|
+
wers = []
|
|
59
|
+
with mp.Pool(processes=len(gpus)) as pool:
|
|
60
|
+
args = [(rank, lang, sub_test_set, asr_ckpt_dir) for (rank, sub_test_set) in test_set]
|
|
61
|
+
results = pool.map(run_asr_wer, args)
|
|
62
|
+
for wers_ in results:
|
|
63
|
+
wers.extend(wers_)
|
|
64
|
+
|
|
65
|
+
wer = round(np.mean(wers) * 100, 3)
|
|
66
|
+
print(f"\nTotal {len(wers)} samples")
|
|
67
|
+
print(f"WER : {wer}%")
|
|
68
|
+
|
|
69
|
+
# --------------------------- SIM ---------------------------
|
|
70
|
+
if eval_task == "sim":
|
|
71
|
+
sim_list = []
|
|
72
|
+
with mp.Pool(processes=len(gpus)) as pool:
|
|
73
|
+
args = [(rank, sub_test_set, wavlm_ckpt_dir) for (rank, sub_test_set) in test_set]
|
|
74
|
+
results = pool.map(run_sim, args)
|
|
75
|
+
for sim_ in results:
|
|
76
|
+
sim_list.extend(sim_)
|
|
77
|
+
|
|
78
|
+
sim = round(sum(sim_list) / len(sim_list), 3)
|
|
79
|
+
print(f"\nTotal {len(sim_list)} samples")
|
|
80
|
+
print(f"SIM : {sim}")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
main()
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Evaluate with Seed-TTS testset
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import os
|
|
5
|
+
import argparse
|
|
6
|
+
|
|
7
|
+
sys.path.append(os.getcwd())
|
|
8
|
+
|
|
9
|
+
import multiprocessing as mp
|
|
10
|
+
from importlib.resources import files
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
from f5_tts.eval.utils_eval import (
|
|
15
|
+
get_seed_tts_test,
|
|
16
|
+
run_asr_wer,
|
|
17
|
+
run_sim,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
rel_path = str(files("f5_tts").joinpath("../../"))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_args():
|
|
24
|
+
parser = argparse.ArgumentParser()
|
|
25
|
+
parser.add_argument("-e", "--eval_task", type=str, default="wer", choices=["sim", "wer"])
|
|
26
|
+
parser.add_argument("-l", "--lang", type=str, default="en", choices=["zh", "en"])
|
|
27
|
+
parser.add_argument("-g", "--gen_wav_dir", type=str, required=True)
|
|
28
|
+
parser.add_argument("-n", "--gpu_nums", type=int, default=8, help="Number of GPUs to use")
|
|
29
|
+
parser.add_argument("--local", action="store_true", help="Use local custom checkpoint directory")
|
|
30
|
+
return parser.parse_args()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def main():
|
|
34
|
+
args = get_args()
|
|
35
|
+
eval_task = args.eval_task
|
|
36
|
+
lang = args.lang
|
|
37
|
+
gen_wav_dir = args.gen_wav_dir
|
|
38
|
+
metalst = rel_path + f"/data/seedtts_testset/{lang}/meta.lst" # seed-tts testset
|
|
39
|
+
|
|
40
|
+
# NOTE. paraformer-zh result will be slightly different according to the number of gpus, cuz batchsize is different
|
|
41
|
+
# zh 1.254 seems a result of 4 workers wer_seed_tts
|
|
42
|
+
gpus = list(range(args.gpu_nums))
|
|
43
|
+
test_set = get_seed_tts_test(metalst, gen_wav_dir, gpus)
|
|
44
|
+
|
|
45
|
+
local = args.local
|
|
46
|
+
if local: # use local custom checkpoint dir
|
|
47
|
+
if lang == "zh":
|
|
48
|
+
asr_ckpt_dir = "../checkpoints/funasr" # paraformer-zh dir under funasr
|
|
49
|
+
elif lang == "en":
|
|
50
|
+
asr_ckpt_dir = "../checkpoints/Systran/faster-whisper-large-v3"
|
|
51
|
+
else:
|
|
52
|
+
asr_ckpt_dir = "" # auto download to cache dir
|
|
53
|
+
wavlm_ckpt_dir = "../checkpoints/UniSpeech/wavlm_large_finetune.pth"
|
|
54
|
+
|
|
55
|
+
# --------------------------- WER ---------------------------
|
|
56
|
+
|
|
57
|
+
if eval_task == "wer":
|
|
58
|
+
wers = []
|
|
59
|
+
with mp.Pool(processes=len(gpus)) as pool:
|
|
60
|
+
args = [(rank, lang, sub_test_set, asr_ckpt_dir) for (rank, sub_test_set) in test_set]
|
|
61
|
+
results = pool.map(run_asr_wer, args)
|
|
62
|
+
for wers_ in results:
|
|
63
|
+
wers.extend(wers_)
|
|
64
|
+
|
|
65
|
+
wer = round(np.mean(wers) * 100, 3)
|
|
66
|
+
print(f"\nTotal {len(wers)} samples")
|
|
67
|
+
print(f"WER : {wer}%")
|
|
68
|
+
|
|
69
|
+
# --------------------------- SIM ---------------------------
|
|
70
|
+
if eval_task == "sim":
|
|
71
|
+
sim_list = []
|
|
72
|
+
with mp.Pool(processes=len(gpus)) as pool:
|
|
73
|
+
args = [(rank, sub_test_set, wavlm_ckpt_dir) for (rank, sub_test_set) in test_set]
|
|
74
|
+
results = pool.map(run_sim, args)
|
|
75
|
+
for sim_ in results:
|
|
76
|
+
sim_list.extend(sim_)
|
|
77
|
+
|
|
78
|
+
sim = round(sum(sim_list) / len(sim_list), 3)
|
|
79
|
+
print(f"\nTotal {len(sim_list)} samples")
|
|
80
|
+
print(f"SIM : {sim}")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
main()
|