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

Method PrefillGraph

src/models/qwen3_asr/thinker.cpp:454–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

452 const auto & config = runtime_->assets().config.text_decoder;
453 if (static_cast<int64_t>(token_ids.size()) != prompt_steps_) {
454 throw std::runtime_error("Qwen3 ASR thinker prefill token id count mismatch");
455 }
456 if (static_cast<int64_t>(audio_embeddings.size()) != audio_tokens_ * config.hidden_size) {
457 throw std::runtime_error("Qwen3 ASR thinker prefill audio embedding size mismatch");
458 }
459 if (static_cast<int64_t>(audio_positions.size()) != audio_tokens_) {
460 throw std::runtime_error("Qwen3 ASR thinker prefill audio position count mismatch");
461 }
462 auto timing_start = Clock::now();
463 // Re-uploaded on every run: the graph allocator may hand this leaf out to a
464 // later node once the graph has consumed it, so it cannot be written once at
465 // build time and left alone.
466 ggml_backend_tensor_set(positions_, position_ids_.data(), 0, position_ids_.size() * sizeof(int32_t));
467 ggml_backend_tensor_set(token_ids_, token_ids.data(), 0, token_ids.size() * sizeof(int32_t));
468 if (audio_tokens_ > 0) {
469 std::vector<int64_t> positions(audio_positions.begin(), audio_positions.end());
470 ggml_backend_tensor_set(
471 audio_embeddings_,
472 audio_embeddings.data(),
473 0,
474 audio_embeddings.size() * sizeof(float));
475 ggml_backend_tensor_set(
476 audio_positions_,
477 positions.data(),
478 0,
479 positions.size() * sizeof(int64_t));
480 }
481 debug::timing_log_scalar("qwen3_asr.thinker.prefill_input_upload_ms", engine::debug::elapsed_ms(timing_start, Clock::now()));
482 core::set_backend_threads(runtime_->backend(), runtime_->threads());
483 timing_start = Clock::now();
484 const ggml_status status = engine::core::compute_backend_graph(runtime_->backend(), graph_);
485 ggml_backend_synchronize(runtime_->backend());
486 debug::timing_log_scalar("qwen3_asr.thinker.prefill.graph.compute_ms", engine::debug::elapsed_ms(timing_start, Clock::now()));
487 if (status != GGML_STATUS_SUCCESS) {
488 throw std::runtime_error("Qwen3 ASR thinker prefill graph compute failed");
489 }
490 PrefillOutput out;
491 out.logits.resize(static_cast<size_t>(config.output_size));
492 timing_start = Clock::now();
493 ggml_backend_tensor_get(logits_, out.logits.data(), 0, out.logits.size() * sizeof(float));
494 out.kv_state.current_end = prompt_steps_;
495 out.kv_state.layers.resize(keys_.size());
496 const size_t layer_values = static_cast<size_t>(prompt_steps_ * config.num_key_value_heads * head_dim(config));
497 for (size_t layer = 0; layer < keys_.size(); ++layer) {
498 auto & state = out.kv_state.layers[layer];
499 state.valid_steps = prompt_steps_;
500 state.key.resize(layer_values);
501 state.value.resize(layer_values);
502 ggml_backend_tensor_get(keys_[layer], state.key.data(), 0, state.key.size() * sizeof(float));
503 ggml_backend_tensor_get(values_[layer], state.value.data(), 0, state.value.size() * sizeof(float));
504 }
505 debug::timing_log_scalar("qwen3_asr.thinker.prefill_output_read_ms", engine::debug::elapsed_ms(timing_start, Clock::now()));
506 return out;
507 }
508
509private:
510 std::shared_ptr<ThinkerWeightsRuntime> runtime_;
511 int64_t prompt_steps_ = 0;

Callers

nothing calls this directly

Calls 15

ggml_initFunction · 0.85
ggml_new_tensor_1dFunction · 0.85
ggml_new_tensor_2dFunction · 0.85
wrap_tensorFunction · 0.85
SliceModuleClass · 0.85
RMSNormModuleClass · 0.85
LinearModuleClass · 0.85
ggml_set_outputFunction · 0.85
ggml_new_graph_customFunction · 0.85
ggml_backend_tensor_setFunction · 0.85

Tested by

no test coverage detected