MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / roformer_loader

Function roformer_loader

tests/perf/model_perf.py:1129–1193  ·  view source on GitHub ↗
(case: dict[str, Any], args: argparse.Namespace)

Source from the content-addressed store, hash-verified

1127
1128
1129def roformer_loader(case: dict[str, Any], args: argparse.Namespace) -> tuple[Any, RunnerFn]:
1130 import types
1131 import yaml
1132 import soundfile as sf
1133 import torch
1134
1135 set_threads(args.threads)
1136 ref_root = REPO_ROOT / "reference" / "Mel-Band-Roformer-Vocal-Model"
1137 if str(ref_root) not in sys.path:
1138 sys.path.insert(0, str(ref_root))
1139 if "ml_collections" not in sys.modules:
1140 class ConfigDict(dict):
1141 def __init__(self, *args, **kwargs):
1142 super().__init__()
1143 payload = dict(*args, **kwargs)
1144 for key, value in payload.items():
1145 self[key] = self._convert(value)
1146
1147 @classmethod
1148 def _convert(cls, value):
1149 if isinstance(value, dict):
1150 return cls(value)
1151 if isinstance(value, list):
1152 return [cls._convert(item) for item in value]
1153 if isinstance(value, tuple):
1154 return tuple(cls._convert(item) for item in value)
1155 return value
1156
1157 def __getattr__(self, name):
1158 return self[name]
1159
1160 def __setattr__(self, name, value):
1161 self[name] = self._convert(value)
1162 module = types.ModuleType("ml_collections")
1163 module.ConfigDict = ConfigDict
1164 sys.modules["ml_collections"] = module
1165 from ml_collections import ConfigDict
1166 from inference import run_folder
1167 from utils import get_model_from_config
1168
1169 ckpt_path = ensure_absolute_path("models/melbandroformer/MelBandRoformer.ckpt")
1170 config_path = REPO_ROOT / "reference" / "Mel-Band-Roformer-Vocal-Model" / "configs" / "config_vocals_mel_band_roformer.yaml"
1171 config = ConfigDict(yaml.load(config_path.read_text(encoding="utf-8"), Loader=yaml.FullLoader))
1172 model = get_model_from_config("mel_band_roformer", config)
1173 state = torch.load(ckpt_path, map_location="cpu")
1174 model.load_state_dict(state, strict=False)
1175 device = torch.device(f"cuda:{args.device}" if args.backend == "cuda" else "cpu")
1176 model = model.to(device=device).eval()
1177
1178 def run(request: dict[str, Any], _args: argparse.Namespace) -> tuple[float, float]:
1179 work_dir = REPO_ROOT / "build" / "perf" / "roformer"
1180 input_dir = work_dir / "input"
1181 store_dir = work_dir / "store"
1182 input_dir.mkdir(parents=True, exist_ok=True)
1183 store_dir.mkdir(parents=True, exist_ok=True)
1184 staged = input_dir / Path(request["audio"]).name
1185 shutil.copyfile(request["audio"], staged)
1186 started = time.perf_counter()

Callers

nothing calls this directly

Calls 7

set_threadsFunction · 0.85
ensure_absolute_pathFunction · 0.85
ConfigDictClass · 0.85
read_textMethod · 0.80
evalMethod · 0.80
loadMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected