update finetuning pipeline and runtime device handling
Support optional ref_audio samples in finetuning and make runtime device selection explicit while keeping auto fallback behavior consistent. Also ignore the local app override file to avoid accidental commits. Made-with: Cursor
This commit is contained in:
@@ -58,6 +58,7 @@ def test_parser_defaults_to_voxcpm2():
|
||||
parser = cli._build_parser()
|
||||
args = parser.parse_args(["design", "--text", "hello", "--output", "out.wav"])
|
||||
assert args.hf_model_id == "openbmb/VoxCPM2"
|
||||
assert args.device == "auto"
|
||||
assert args.no_optimize is False
|
||||
|
||||
|
||||
@@ -85,6 +86,7 @@ def test_load_model_respects_no_optimize_for_local_model(monkeypatch):
|
||||
|
||||
cli.load_model(args)
|
||||
|
||||
assert calls["kwargs"]["device"] == "auto"
|
||||
assert calls["kwargs"]["optimize"] is False
|
||||
|
||||
|
||||
@@ -110,6 +112,7 @@ def test_load_model_defaults_optimize_for_hf(monkeypatch):
|
||||
|
||||
cli.load_model(args)
|
||||
|
||||
assert calls["kwargs"]["device"] == "auto"
|
||||
assert calls["kwargs"]["optimize"] is True
|
||||
|
||||
|
||||
@@ -136,9 +139,37 @@ def test_load_model_respects_no_optimize_for_hf(monkeypatch):
|
||||
|
||||
cli.load_model(args)
|
||||
|
||||
assert calls["kwargs"]["device"] == "auto"
|
||||
assert calls["kwargs"]["optimize"] is False
|
||||
|
||||
|
||||
def test_load_model_passes_explicit_device_to_hf(monkeypatch):
|
||||
calls = {}
|
||||
|
||||
class FakeVoxCPM:
|
||||
@classmethod
|
||||
def from_pretrained(cls, **kwargs):
|
||||
calls["kwargs"] = kwargs
|
||||
return DummyModel()
|
||||
|
||||
monkeypatch.setattr(cli, "VoxCPM", FakeVoxCPM)
|
||||
args = cli._build_parser().parse_args(
|
||||
[
|
||||
"design",
|
||||
"--text",
|
||||
"hello",
|
||||
"--output",
|
||||
"out.wav",
|
||||
"--device",
|
||||
"mps",
|
||||
]
|
||||
)
|
||||
|
||||
cli.load_model(args)
|
||||
|
||||
assert calls["kwargs"]["device"] == "mps"
|
||||
|
||||
|
||||
def test_design_subcommand_applies_control(monkeypatch, tmp_path):
|
||||
dummy_model = DummyModel()
|
||||
monkeypatch.setattr(cli, "load_model", lambda args: dummy_model)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import sys
|
||||
import types
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
UTILS_PATH = ROOT / "src" / "voxcpm" / "model" / "utils.py"
|
||||
|
||||
transformers_stub = types.ModuleType("transformers")
|
||||
transformers_stub.PreTrainedTokenizer = object
|
||||
sys.modules.setdefault("transformers", transformers_stub)
|
||||
|
||||
spec = importlib.util.spec_from_file_location("voxcpm.model.utils", UTILS_PATH)
|
||||
utils = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(utils)
|
||||
|
||||
|
||||
def test_resolve_runtime_device_auto_falls_back_to_cpu(monkeypatch):
|
||||
monkeypatch.setattr(utils.torch.cuda, "is_available", lambda: False)
|
||||
monkeypatch.setattr(utils, "_has_mps", lambda: False)
|
||||
|
||||
assert utils.resolve_runtime_device(None, "cuda") == "cpu"
|
||||
|
||||
|
||||
def test_resolve_runtime_device_auto_uses_mps_when_available(monkeypatch):
|
||||
monkeypatch.setattr(utils.torch.cuda, "is_available", lambda: False)
|
||||
monkeypatch.setattr(utils, "_has_mps", lambda: True)
|
||||
|
||||
assert utils.resolve_runtime_device("auto", "cuda") == "mps"
|
||||
|
||||
|
||||
def test_resolve_runtime_device_respects_explicit_cpu(monkeypatch):
|
||||
monkeypatch.setattr(utils.torch.cuda, "is_available", lambda: True)
|
||||
monkeypatch.setattr(utils, "_has_mps", lambda: True)
|
||||
|
||||
assert utils.resolve_runtime_device("cpu", "cuda") == "cpu"
|
||||
|
||||
|
||||
def test_resolve_runtime_device_rejects_unavailable_explicit_cuda(monkeypatch):
|
||||
monkeypatch.setattr(utils.torch.cuda, "is_available", lambda: False)
|
||||
monkeypatch.setattr(utils, "_has_mps", lambda: True)
|
||||
|
||||
with pytest.raises(ValueError, match="CUDA is not available"):
|
||||
utils.resolve_runtime_device("cuda:0", "cuda")
|
||||
Reference in New Issue
Block a user