(
dit_handler: AceStepHandler,
llm_handler: LLMHandler,
request: dict[str, Any],
output_dir: Path,
device: str,
noise_file: str,
)
| 239 | |
| 240 | |
| 241 | def run_request( |
| 242 | dit_handler: AceStepHandler, |
| 243 | llm_handler: LLMHandler, |
| 244 | request: dict[str, Any], |
| 245 | output_dir: Path, |
| 246 | device: str, |
| 247 | noise_file: str, |
| 248 | ) -> tuple[dict[str, Any], list[str]]: |
| 249 | params = make_generation_params(request) |
| 250 | config = make_generation_config(request, noise_file) |
| 251 | output_dir.mkdir(parents=True, exist_ok=True) |
| 252 | |
| 253 | request_seed = int(request.get("seed", 0)) |
| 254 | if request_seed < 0: |
| 255 | raise RuntimeError("ACE-Step warmbench requires a non-negative request seed") |
| 256 | torch.manual_seed(request_seed) |
| 257 | if device == "cuda" and torch.cuda.is_available(): |
| 258 | torch.cuda.manual_seed_all(request_seed) |
| 259 | elif device == "mps" and hasattr(torch, "mps") and hasattr(torch.mps, "manual_seed"): |
| 260 | torch.mps.manual_seed(request_seed) |
| 261 | elif device == "xpu" and hasattr(torch, "xpu") and hasattr(torch.xpu, "manual_seed_all"): |
| 262 | torch.xpu.manual_seed_all(request_seed) |
| 263 | np.random.seed(request_seed & 0xFFFFFFFF) |
| 264 | |
| 265 | started = time.perf_counter() |
| 266 | result = generate_music( |
| 267 | dit_handler, |
| 268 | llm_handler, |
| 269 | params, |
| 270 | config, |
| 271 | save_dir=str(output_dir), |
| 272 | ) |
| 273 | sync_device(device) |
| 274 | wall_ms = (time.perf_counter() - started) * 1000.0 |
| 275 | |
| 276 | if not result.success: |
| 277 | raise RuntimeError(f"ACE-Step generation failed: {result.error or result.status_message}") |
| 278 | if not result.audios: |
| 279 | raise RuntimeError("ACE-Step generation returned no audios") |
| 280 | |
| 281 | stems: list[dict[str, Any]] = [] |
| 282 | for index, audio_entry in enumerate(result.audios): |
| 283 | audio_path = Path(audio_entry["path"]) |
| 284 | waveform, sample_rate = sf.read(str(audio_path), always_2d=True) |
| 285 | normalized_path = output_dir / f"audio_{index:02d}.wav" |
| 286 | sf.write(str(normalized_path), waveform, sample_rate, subtype="PCM_16") |
| 287 | stems.append( |
| 288 | { |
| 289 | "name": audio_entry.get("key", f"audio_{index:02d}"), |
| 290 | "audio": str(normalized_path), |
| 291 | "summary": summarize_audio(np.asarray(waveform, dtype=np.float32), sample_rate), |
| 292 | } |
| 293 | ) |
| 294 | |
| 295 | step = { |
| 296 | "request": request, |
| 297 | "stems": stems, |
| 298 | "metrics": {"wall_ms": wall_ms}, |
no test coverage detected