| 360 | } // namespace |
| 361 | |
| 362 | HeartMuLaGeneratedFrames generate_heartmula_frames( |
| 363 | const HeartMuLaPromptRequest & request, |
| 364 | const HeartMuLaTextTokenizer & tokenizer, |
| 365 | const HeartMuLaWeightsRuntime & mula, |
| 366 | uint64_t seed) { |
| 367 | const auto & assets = mula.assets(); |
| 368 | const auto & config = assets.mula_config; |
| 369 | const auto encoding = tokenizer.encode_prompt(request); |
| 370 | const bool use_cfg = request.options.guidance_scale > 1.0F && encoding.batch_size > 1 && encoding.batch_size % 2 == 0; |
| 371 | auto prompt_embeddings = mula.merge_frame_embeddings(prompt_embedding_inputs(encoding, config, use_cfg)); |
| 372 | auto backbone = mula.backbone_prefill_embeddings( |
| 373 | prompt_embeddings.values, |
| 374 | prompt_embeddings.batch_size, |
| 375 | prompt_embeddings.steps); |
| 376 | HeartMuLaBackboneCachedState backbone_state; |
| 377 | mula.reset_backbone_cached_state(backbone_state, std::move(backbone.state)); |
| 378 | |
| 379 | const TorchCudaSamplingPolicy policy = engine::sampling::resolve_torch_cuda_sampling_policy( |
| 380 | mula.backend_type(), |
| 381 | mula.device(), |
| 382 | "heartmula.cuda_sampling_policy", |
| 383 | "HeartMuLa", |
| 384 | engine::sampling::TorchCudaSamplingPolicyFailureMode::StrictCuda); |
| 385 | TopKSamplerScratch scratch; |
| 386 | uint64_t sample_call_index = 0; |
| 387 | HeartMuLaGeneratedFrames out; |
| 388 | out.codebooks = config.audio_num_codebooks; |
| 389 | auto current_frame = generate_frame_from_backbone( |
| 390 | backbone.result, |
| 391 | mula, |
| 392 | encoding.batch_size, |
| 393 | request.options, |
| 394 | seed, |
| 395 | sample_call_index, |
| 396 | policy, |
| 397 | scratch); |
| 398 | append_first_branch_frame(out, current_frame, config); |
| 399 | |
| 400 | const int64_t max_audio_frames = static_cast<int64_t>(request.options.duration_seconds * 1000.0F) / 80; |
| 401 | for (int64_t frame_index = 0; frame_index < max_audio_frames; ++frame_index) { |
| 402 | auto next_embeddings = mula.merge_frame_embeddings(next_frame_embedding_inputs(current_frame, encoding.batch_size, config)); |
| 403 | auto next_backbone = mula.backbone_cached_step( |
| 404 | next_embeddings.values, |
| 405 | encoding.batch_size, |
| 406 | backbone_state, |
| 407 | encoding.prompt_len + max_audio_frames + 1); |
| 408 | current_frame = generate_frame_from_backbone( |
| 409 | next_backbone, |
| 410 | mula, |
| 411 | encoding.batch_size, |
| 412 | request.options, |
| 413 | seed, |
| 414 | sample_call_index, |
| 415 | policy, |
| 416 | scratch); |
| 417 | if (first_branch_has_eos(current_frame, assets)) { |
| 418 | break; |
| 419 | } |
no test coverage detected