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

Method Vevo2ARPrefillGraph

src/models/vevo2/ar.cpp:596–652  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

594 .build(build_ctx, x, this->weights->norm);
595 logits = modules::LinearModule({config.hidden_size, config.vocab_size, false})
596 .build(build_ctx, x, {this->weights->lm_head, std::nullopt})
597 .tensor;
598 ggml_set_output(logits);
599 graph = ggml_new_graph_custom(ctx.get(), 65536, false);
600 ggml_build_forward_expand(graph, logits);
601 engine::debug::timing_log_context_reservation("vevo2.ar.prefill.graph", ctx.get());
602 gallocr = ggml_gallocr_new(ggml_backend_get_default_buffer_type(backend));
603 if (gallocr == nullptr || !ggml_gallocr_reserve(gallocr, graph) || !ggml_gallocr_alloc_graph(gallocr, graph)) {
604 throw std::runtime_error("failed to allocate Vevo2 AR prefill graph");
605 }
606 std::vector<int32_t> pos(static_cast<size_t>(prompt_steps), 0);
607 for (int64_t i = 0; i < prompt_steps; ++i) {
608 pos[static_cast<size_t>(i)] = static_cast<int32_t>(i);
609 }
610 ggml_backend_tensor_set(positions, pos.data(), 0, pos.size() * sizeof(int32_t));
611 }
612
613 ~Vevo2Qwen2ARPrefillGraph() {
614 engine::core::release_backend_graph_resources(backend, graph);
615 if (gallocr != nullptr) {
616 ggml_gallocr_free(gallocr);
617 }
618 }
619
620 bool matches(const Vevo2Qwen2ARWeights & other_weights, int64_t steps) const noexcept {
621 return weights.get() == &other_weights && prompt_steps == steps;
622 }
623
624 Vevo2ARPrefillOutput run(const std::vector<int32_t> & ids, const Vevo2Qwen2ARConfig & config) {
625 if (static_cast<int64_t>(ids.size()) != prompt_steps) {
626 throw std::runtime_error("Vevo2 AR prefill token id count mismatch");
627 }
628 ggml_backend_tensor_set(token_ids, ids.data(), 0, ids.size() * sizeof(int32_t));
629 core::set_backend_threads(backend, threads);
630 const ggml_status status = engine::core::compute_backend_graph(backend, graph);
631 ggml_backend_synchronize(backend);
632 if (status != GGML_STATUS_SUCCESS) {
633 throw std::runtime_error("Vevo2 AR prefill graph compute failed");
634 }
635 Vevo2ARPrefillOutput out;
636 out.logits.resize(static_cast<size_t>(config.vocab_size));
637 ggml_backend_tensor_get(logits, out.logits.data(), 0, out.logits.size() * sizeof(float));
638 out.kv_state.current_end = prompt_steps;
639 out.kv_state.layers.resize(keys.size());
640 const size_t layer_values = static_cast<size_t>(prompt_steps * config.num_key_value_heads * ar_head_dim(config));
641 for (size_t layer = 0; layer < keys.size(); ++layer) {
642 auto & state = out.kv_state.layers[layer];
643 state.valid_steps = prompt_steps;
644 state.key.resize(layer_values);
645 state.value.resize(layer_values);
646 ggml_backend_tensor_get(keys[layer], state.key.data(), 0, state.key.size() * sizeof(float));
647 ggml_backend_tensor_get(values[layer], state.value.data(), 0, state.value.size() * sizeof(float));
648 }
649 return out;
650 }
651
652 ggml_backend_t backend = nullptr;
653 core::BackendType backend_type = core::BackendType::Cpu;

Callers

nothing calls this directly

Calls 15

ggml_initFunction · 0.85
ggml_new_tensor_1dFunction · 0.85
wrap_tensorFunction · 0.85
EmbeddingModuleClass · 0.85
reshape_tensorFunction · 0.85
SliceModuleClass · 0.85
RMSNormModuleClass · 0.85
LinearModuleClass · 0.85
ggml_set_outputFunction · 0.85
ggml_new_graph_customFunction · 0.85

Tested by

no test coverage detected