Codex commited on
Commit ·
09e79ed
1
Parent(s): 8711321
Use file-system torch sharing for training
Browse files
app.py
CHANGED
|
@@ -255,6 +255,20 @@ def run_cmd(command, cwd=None, env=None):
|
|
| 255 |
raise RuntimeError(f"命令失败 (exit={code}): {' '.join(command)}")
|
| 256 |
|
| 257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
def has_transformers_model(path: Path):
|
| 259 |
return path.exists() and (path / "config.json").exists() and (
|
| 260 |
any(path.glob("*.bin")) or any(path.glob("*.safetensors"))
|
|
@@ -864,7 +878,7 @@ def prepare_data_steps(logs, version, live_path: Path | None = None):
|
|
| 864 |
)
|
| 865 |
env = build_process_env(ctx)
|
| 866 |
for line in run_cmd(
|
| 867 |
-
|
| 868 |
cwd=GPT_SOVITS_DIR,
|
| 869 |
env=env,
|
| 870 |
):
|
|
@@ -875,7 +889,7 @@ def prepare_data_steps(logs, version, live_path: Path | None = None):
|
|
| 875 |
part_text.replace(ctx.text_path)
|
| 876 |
yield push(logs, "✅ 文本分词与 BERT 特征提取完成。", live_path)
|
| 877 |
for line in run_cmd(
|
| 878 |
-
|
| 879 |
cwd=GPT_SOVITS_DIR,
|
| 880 |
env=env,
|
| 881 |
):
|
|
@@ -883,14 +897,14 @@ def prepare_data_steps(logs, version, live_path: Path | None = None):
|
|
| 883 |
yield push(logs, "✅ CN-HuBERT 特征与 32k wav 已生成。", live_path)
|
| 884 |
if ctx.spec.uses_sv:
|
| 885 |
for line in run_cmd(
|
| 886 |
-
|
| 887 |
cwd=GPT_SOVITS_DIR,
|
| 888 |
env=env,
|
| 889 |
):
|
| 890 |
yield push(logs, line, live_path)
|
| 891 |
yield push(logs, "✅ speaker embedding 特征已生成。", live_path)
|
| 892 |
for line in run_cmd(
|
| 893 |
-
|
| 894 |
cwd=GPT_SOVITS_DIR,
|
| 895 |
env=env,
|
| 896 |
):
|
|
@@ -964,7 +978,12 @@ def start_training(version=DEFAULT_VERSION, epochs=2, batch_size=1, save_every_e
|
|
| 964 |
env = build_process_env(ctx)
|
| 965 |
yield push(logs, f"开始 SoVITS 训练({ctx.spec.version})...", ctx.sovits_live_log), None
|
| 966 |
for line in run_cmd(
|
| 967 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 968 |
cwd=GPT_SOVITS_DIR,
|
| 969 |
env=env,
|
| 970 |
):
|
|
@@ -994,7 +1013,12 @@ def start_gpt_training(version=DEFAULT_VERSION, epochs=1, batch_size=1, save_eve
|
|
| 994 |
env = build_process_env(ctx)
|
| 995 |
yield push(logs, f"开始 GPT 训练({ctx.spec.version})...", ctx.gpt_live_log), None
|
| 996 |
for line in run_cmd(
|
| 997 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 998 |
cwd=GPT_SOVITS_DIR,
|
| 999 |
env=env,
|
| 1000 |
):
|
|
|
|
| 255 |
raise RuntimeError(f"命令失败 (exit={code}): {' '.join(command)}")
|
| 256 |
|
| 257 |
|
| 258 |
+
def python_script_command(script_path, *script_args, file_system_sharing=False):
|
| 259 |
+
if not file_system_sharing:
|
| 260 |
+
return [sys.executable, "-s", script_path, *[str(arg) for arg in script_args]]
|
| 261 |
+
launcher = (
|
| 262 |
+
"import runpy, sys;"
|
| 263 |
+
"import torch.multiprocessing as mp;"
|
| 264 |
+
"mp.set_sharing_strategy('file_system');"
|
| 265 |
+
"script = sys.argv[1];"
|
| 266 |
+
"sys.argv = sys.argv[1:];"
|
| 267 |
+
"runpy.run_path(script, run_name='__main__')"
|
| 268 |
+
)
|
| 269 |
+
return [sys.executable, "-s", "-c", launcher, script_path, *[str(arg) for arg in script_args]]
|
| 270 |
+
|
| 271 |
+
|
| 272 |
def has_transformers_model(path: Path):
|
| 273 |
return path.exists() and (path / "config.json").exists() and (
|
| 274 |
any(path.glob("*.bin")) or any(path.glob("*.safetensors"))
|
|
|
|
| 878 |
)
|
| 879 |
env = build_process_env(ctx)
|
| 880 |
for line in run_cmd(
|
| 881 |
+
python_script_command("GPT_SoVITS/prepare_datasets/1-get-text.py"),
|
| 882 |
cwd=GPT_SOVITS_DIR,
|
| 883 |
env=env,
|
| 884 |
):
|
|
|
|
| 889 |
part_text.replace(ctx.text_path)
|
| 890 |
yield push(logs, "✅ 文本分词与 BERT 特征提取完成。", live_path)
|
| 891 |
for line in run_cmd(
|
| 892 |
+
python_script_command("GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py"),
|
| 893 |
cwd=GPT_SOVITS_DIR,
|
| 894 |
env=env,
|
| 895 |
):
|
|
|
|
| 897 |
yield push(logs, "✅ CN-HuBERT 特征与 32k wav 已生成。", live_path)
|
| 898 |
if ctx.spec.uses_sv:
|
| 899 |
for line in run_cmd(
|
| 900 |
+
python_script_command("GPT_SoVITS/prepare_datasets/2-get-sv.py"),
|
| 901 |
cwd=GPT_SOVITS_DIR,
|
| 902 |
env=env,
|
| 903 |
):
|
| 904 |
yield push(logs, line, live_path)
|
| 905 |
yield push(logs, "✅ speaker embedding 特征已生成。", live_path)
|
| 906 |
for line in run_cmd(
|
| 907 |
+
python_script_command("GPT_SoVITS/prepare_datasets/3-get-semantic.py"),
|
| 908 |
cwd=GPT_SOVITS_DIR,
|
| 909 |
env=env,
|
| 910 |
):
|
|
|
|
| 978 |
env = build_process_env(ctx)
|
| 979 |
yield push(logs, f"开始 SoVITS 训练({ctx.spec.version})...", ctx.sovits_live_log), None
|
| 980 |
for line in run_cmd(
|
| 981 |
+
python_script_command(
|
| 982 |
+
"GPT_SoVITS/s2_train.py",
|
| 983 |
+
"--config",
|
| 984 |
+
str(config_path),
|
| 985 |
+
file_system_sharing=True,
|
| 986 |
+
),
|
| 987 |
cwd=GPT_SOVITS_DIR,
|
| 988 |
env=env,
|
| 989 |
):
|
|
|
|
| 1013 |
env = build_process_env(ctx)
|
| 1014 |
yield push(logs, f"开始 GPT 训练({ctx.spec.version})...", ctx.gpt_live_log), None
|
| 1015 |
for line in run_cmd(
|
| 1016 |
+
python_script_command(
|
| 1017 |
+
"GPT_SoVITS/s1_train.py",
|
| 1018 |
+
"--config_file",
|
| 1019 |
+
str(config_path),
|
| 1020 |
+
file_system_sharing=True,
|
| 1021 |
+
),
|
| 1022 |
cwd=GPT_SOVITS_DIR,
|
| 1023 |
env=env,
|
| 1024 |
):
|