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

Function run_batch

tests/vibevoice/vibevoice_python_warm_bench.py:422–498  ·  view source on GitHub ↗
(
    model: Any,
    processor: Any,
    requests: list[dict[str, Any]],
    args: argparse.Namespace,
    device: str,
)

Source from the content-addressed store, hash-verified

420
421
422def run_batch(
423 model: Any,
424 processor: Any,
425 requests: list[dict[str, Any]],
426 args: argparse.Namespace,
427 device: str,
428) -> list[tuple[np.ndarray, int, float, dict[str, Any]]]:
429 if not requests:
430 raise RuntimeError("VibeVoice batch warmbench requires at least one request")
431 texts = [str(request.get("text", "")) for request in requests]
432 if any(not text for text in texts):
433 raise RuntimeError("VibeVoice batch warmbench request missing text")
434 fallback_voices = [str(resolve_repo_path(Path(path))) for path in (args.voice_samples or DEFAULT_VOICES)]
435 voice_samples = []
436 for request in requests:
437 samples = [str(resolve_repo_path(Path(path))) for path in request.get("voice_samples", [])]
438 voice_samples.append(samples if samples else fallback_voices)
439
440 seed = int(require_same_request_option(requests, "seed", args.seed))
441 ddpm_steps = int(require_same_request_option(requests, "ddpm_steps", args.ddpm_steps))
442 max_new_tokens = int(require_same_request_option(requests, "max_new_tokens", args.max_new_tokens))
443 max_length_times = float(require_same_request_option(requests, "max_length_times", args.max_length_times))
444 cfg_scale = float(require_same_request_option(requests, "cfg_scale", args.cfg_scale))
445 prompt_noise_file = str(require_same_request_option(requests, "prompt_noise_file", "")) or args.prompt_noise_file
446 noise_file = str(require_same_request_option(requests, "diffusion_noise_file", "")) or args.noise_file
447
448 seed_all(seed, args.backend)
449 model.set_ddpm_inference_steps(ddpm_steps)
450 inputs = processor(
451 text=texts,
452 voice_samples=voice_samples,
453 padding=True,
454 return_tensors="pt",
455 return_attention_mask=True,
456 )
457 inputs = move_batch_to_device(dict(inputs), device)
458 acoustic_vae_dim = int(model.model.config.acoustic_vae_dim)
459 with controlled_generation_noise(prompt_noise_file, noise_file, acoustic_vae_dim):
460 started = time.perf_counter()
461 outputs = model.generate(
462 **inputs,
463 max_new_tokens=max_new_tokens if max_new_tokens > 0 else None,
464 cfg_scale=cfg_scale,
465 tokenizer=processor.tokenizer,
466 generation_config={"do_sample": False},
467 verbose=False,
468 show_progress_bar=False,
469 is_prefill=not args.disable_prefill,
470 max_length_times=max_length_times,
471 )
472 if args.backend == "cuda":
473 torch.cuda.synchronize(args.device)
474 ended = time.perf_counter()
475 wall_ms = (ended - started) * 1000.0
476 input_lengths = [int(value) for value in inputs["attention_mask"].sum(dim=-1).detach().cpu().tolist()]
477 reach_max_step = getattr(outputs, "reach_max_step_sample", None)
478
479 results: list[tuple[np.ndarray, int, float, dict[str, Any]]] = []

Callers 2

runMethod · 0.85
mainFunction · 0.85

Calls 10

move_batch_to_deviceFunction · 0.85
extract_audioFunction · 0.85
maxFunction · 0.85
token_windowFunction · 0.85
resolve_repo_pathFunction · 0.70
seed_allFunction · 0.70
getMethod · 0.45
generateMethod · 0.45

Tested by

no test coverage detected