#!/bin/bash set -e export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True echo '== SETUP ==' apt-get update -qq && apt-get install -y -qq git build-essential ffmpeg >/dev/null 2>&1 git clone -q https://github.com/vibevoice-community/VibeVoice /VibeVoice-classic git -C /VibeVoice-classic checkout -q d5895e7 git clone -q https://github.com/vibevoice-community/VibeVoice /vv-main git clone -q https://github.com/voicepowered-ai/VibeVoice-finetuning /vvft cd /vvft && pip install -q -e . 2>&1 | tail -1 pip uninstall -y -q transformers 2>&1 | tail -1 pip install -q 'setuptools<81' 'torch==2.6.0' 'transformers==4.51.3' 'peft==0.15.2' 'diffusers==0.29.0' 'safetensors==0.5.3' 'datasets==3.6.0' 'resampy==0.4.3' 'librosa==0.11.0' 'numpy<2' 'resemble-perth==1.0.1' 'omegaconf==2.3.0' 'conformer==0.3.2' 's3tokenizer' 'soundfile' 'jiwer' 'resemblyzer' 2>&1 | tail -1 echo '== PREFLIGHT ==' for b in git gcc ffmpeg; do command -v $b >/dev/null || { echo "PREFLIGHT FAIL: missing binary $b"; exit 2; }; done python - <<'PF' import importlib from huggingface_hub import HfApi for m, v in [("torch", "2.6.0"), ("transformers", "4.51.3"), ("peft", "0.15.2"), ("diffusers", "0.29.0"), ("resemblyzer", None), ("webrtcvad", None)]: mod = importlib.import_module(m) if v: assert mod.__version__.split('+')[0] == v, f"{m} {mod.__version__} != {v}" api = HfApi() files = api.list_repo_files("ACloudCenter/vibevoice-lora-joint", repo_type="model") for need in ("fullv3/lora/adapter_config.json", "fullv3/lora/adapter_model.safetensors", "fullv3/lora/diffusion_head_full.bin"): assert need in files, f"{need} missing" assert api.repo_exists("ACloudCenter/fast-vibevoice-notes", repo_type="dataset"), "notes missing" print("PREFLIGHT OK", flush=True) PF echo '== DAILYTALK PREP (500 convs) ==' python -c "import urllib.request; urllib.request.urlretrieve('https://huggingface.co/datasets/ACloudCenter/fast-vibevoice-notes/resolve/main/prep_dailytalk.py', '/prep_dailytalk.py'); s=open('/prep_dailytalk.py').read(); assert 'PREP DONE' in s; print('PREP FETCH OK')" python /prep_dailytalk.py /data 500 echo '== EMO DATA PREP ==' python -c "import urllib.request; urllib.request.urlretrieve('https://huggingface.co/datasets/ACloudCenter/fast-vibevoice-notes/resolve/main/emo_data_prep.py', '/emo_data_prep.py'); s=open('/emo_data_prep.py').read(); assert 'EMO PREP DONE' in s and 'voice_prompts = [' in s; print('EMO FETCH OK')" python /emo_data_prep.py echo '== FETCH FULLV3 (warm-start init) ==' python - <<'CK' import os from huggingface_hub import HfApi, hf_hub_download api = HfApi() sub = "fullv3/lora" for f in [f for f in api.list_repo_files("ACloudCenter/vibevoice-lora-joint", repo_type="model") if f.startswith(sub + "/")]: local = hf_hub_download("ACloudCenter/vibevoice-lora-joint", f, repo_type="model") with open(local, "rb") as fh: data = fh.read() op = os.path.join("/fullv3", f[len(sub) + 1:]) os.makedirs(os.path.dirname(op), exist_ok=True) with open(op, "wb") as fh: fh.write(data) assert os.path.isfile(op) and os.path.getsize(op) == len(data) print("FULLV3 FETCH OK:", sorted(os.listdir("/fullv3")), flush=True) CK echo '== WARMSTART PATCH ==' python - <<'WS' p = "/vvft/src/finetune_vibevoice_lora.py" s = open(p).read() a1 = " model.model.language_model = get_peft_model(model.model.language_model, lora_cfg)" assert a1 in s, "lm anchor missing" s = s.replace(a1, a1 + """ if os.path.isfile("/fullv3/adapter_config.json"): import importlib.util as _ilu2 import sys as _sys2 from pathlib import Path as _P _spec2 = _ilu2.spec_from_file_location("lora_loading_ws", "/vv-main/vibevoice/modular/lora_loading.py") _mod2 = _ilu2.module_from_spec(_spec2) _sys2.modules[_spec2.name] = _mod2 _spec2.loader.exec_module(_mod2) _rep = _mod2._LoadReport() _dev = next(model.parameters()).device _mod2._load_language_model(model, _P("/fullv3"), _dev, _rep) print(f"WARMSTART LM via peft loader: lm={_rep.language_model}", flush=True)""") a2 = """ if getattr(model_args, "train_diffusion_head", False) and hasattr(model.model, "prediction_head"): for p in model.model.prediction_head.parameters(): p.requires_grad = True""" assert a2 in s, "head anchor missing" s = s.replace(a2, a2 + """ if os.path.isfile("/fullv3/diffusion_head_full.bin"): _hsd = torch.load("/fullv3/diffusion_head_full.bin", map_location="cpu") _hm, _hu = model.model.prediction_head.load_state_dict(_hsd, strict=False) print(f"WARMSTART HEAD: missing={len(_hm)} unexpected={len(_hu)}", flush=True) for _cname in ("acoustic_connector", "semantic_connector"): _cp = f"/fullv3/{_cname}/pytorch_model.bin" if os.path.isfile(_cp): getattr(model.model, _cname).load_state_dict(torch.load(_cp, map_location="cpu"), strict=False) print(f"WARMSTART {_cname} OK", flush=True)""") open(p, "w").write(s) print("WARMSTART PATCH OK (peft-loader LM init, sys bound)", flush=True) WS echo '== TRAIN (emotion-LoRA warm-start, 800 steps) ==' python -m src.finetune_vibevoice_lora \ --model_name_or_path microsoft/VibeVoice-1.5B \ --processor_name_or_path src/vibevoice/processor \ --train_jsonl /data/mixed_train.jsonl --validation_jsonl /data/mixed_val.jsonl \ --output_dir out_emo --per_device_train_batch_size 1 --gradient_accumulation_steps 16 \ --max_steps 800 --learning_rate 1e-5 --logging_steps 10 --save_steps 200 --save_total_limit 2 \ --eval_strategy steps --eval_steps 200 --do_eval \ --load_best_model_at_end --metric_for_best_model eval_loss --greater_is_better False \ --label_names input_ids \ --remove_unused_columns False --bf16 True --do_train --gradient_clipping \ --gradient_checkpointing True --gradient_checkpointing_kwargs '{"use_reentrant": false}' \ --ddpm_batch_mul 2 --diffusion_loss_weight 1.4 --train_diffusion_head True --ce_loss_weight 0.04 \ --voice_prompt_drop_rate 0.2 \ --lora_target_modules q_proj,k_proj,v_proj,o_proj,gate_proj,up_proj,down_proj \ --lr_scheduler_type cosine --warmup_ratio 0.03 --max_grad_norm 0.8 --report_to none \ 2>&1 | tee /tmp/joblog.txt echo '== PUSH ==' python - <<'PUSH' from huggingface_hub import HfApi import glob, os api = HfApi() n = 0 for p in glob.glob('out_emo/**/*', recursive=True): if os.path.isfile(p): api.upload_file(path_or_fileobj=p, path_in_repo='emo3/' + os.path.relpath(p, 'out_emo'), repo_id='ACloudCenter/vibevoice-lora-joint') n += 1 print(f'PUSH OK ({n} files)', flush=True) PUSH python - <<'LOG' from huggingface_hub import HfApi try: HfApi().upload_file(path_or_fileobj="/tmp/joblog.txt", path_in_repo="emo-train-log-v4.txt", repo_id="ACloudCenter/fast-vibevoice-notes", repo_type="dataset") print("LOG OK", flush=True) except Exception as e: print("LOG FAIL", e, flush=True) LOG