MCPcopy
hub / github.com/OpenBMB/VoxCPM / main

Function main

scripts/test_voxcpm_lora_infer.py:100–258  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98
99
100def main():
101 args = parse_args()
102
103 # 1. Check LoRA checkpoint directory
104 ckpt_dir = Path(args.lora_ckpt)
105 if not ckpt_dir.exists():
106 raise FileNotFoundError(f"LoRA checkpoint not found: {ckpt_dir}")
107
108 # 2. Load lora_config.json from checkpoint
109 lora_config_path = ckpt_dir / "lora_config.json"
110 if not lora_config_path.exists():
111 raise FileNotFoundError(
112 f"lora_config.json not found in {ckpt_dir}. "
113 "Make sure the checkpoint was saved with the updated training script."
114 )
115
116 with open(lora_config_path, "r", encoding="utf-8") as f:
117 lora_info = json.load(f)
118
119 # Get base model path (command line arg overrides config)
120 pretrained_path = args.base_model if args.base_model else lora_info.get("base_model")
121 if not pretrained_path:
122 raise ValueError("base_model not found in lora_config.json and --base_model not provided")
123
124 # Get LoRA config
125 lora_cfg_dict = lora_info.get("lora_config", {})
126 lora_cfg = LoRAConfig(**lora_cfg_dict) if lora_cfg_dict else None
127
128 print(f"Loaded config from: {lora_config_path}", file=sys.stderr)
129 print(f" Base model: {pretrained_path}", file=sys.stderr)
130 print(
131 f" LoRA config: r={lora_cfg.r}, alpha={lora_cfg.alpha}" if lora_cfg else " LoRA config: None", file=sys.stderr
132 )
133
134 # 3. Load model with LoRA (no denoiser)
135 print(f"\n[1/2] Loading model with LoRA: {pretrained_path}", file=sys.stderr)
136 print(f" LoRA weights: {ckpt_dir}", file=sys.stderr)
137 model = VoxCPM.from_pretrained(
138 hf_model_id=pretrained_path,
139 load_denoiser=False,
140 optimize=True,
141 lora_config=lora_cfg,
142 lora_weights_path=str(ckpt_dir),
143 )
144
145 # 4. Synthesize audio
146 prompt_wav_path = args.prompt_audio if args.prompt_audio else None
147 prompt_text = args.prompt_text if args.prompt_text else None
148 out_path = Path(args.output)
149 out_path.parent.mkdir(parents=True, exist_ok=True)
150
151 print("\n[2/2] Starting synthesis tests...", file=sys.stderr)
152
153 # === Test 1: With LoRA ===
154 print("\n [Test 1] Synthesize with LoRA...", file=sys.stderr)
155 audio_np = model.generate(
156 text=args.text,
157 prompt_wav_path=prompt_wav_path,

Callers 1

Calls 7

LoRAConfigClass · 0.90
unload_loraMethod · 0.80
load_loraMethod · 0.80
parse_argsFunction · 0.70
from_pretrainedMethod · 0.45
generateMethod · 0.45
set_lora_enabledMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…