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

Method Vevo2ARDecodeGraph

src/models/vevo2/ar.cpp:709–791  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

707 core::TensorShape::from_dims({1, cache_steps + 1, config.num_key_value_heads, dim})));
708 auto out = decoder_layer_with_static_cache_tail(
709 build_ctx,
710 graph,
711 x,
712 position_values,
713 layer,
714 config,
715 cache_keys.back(),
716 cache_values.back(),
717 mask);
718 x = out.output;
719 key_sources.push_back(ggml_view_1d(ctx.get(), out.key.tensor, config.num_key_value_heads * dim, 0));
720 value_sources.push_back(ggml_view_1d(ctx.get(), out.value.tensor, config.num_key_value_heads * dim, 0));
721 }
722 step_cache = runtime::TransformerKVCache(
723 cache_steps + 1,
724 config.num_key_value_heads * dim,
725 std::move(cache_keys),
726 std::move(cache_values));
727 build_transfer_views(config.num_key_value_heads * dim);
728 x = modules::RMSNormModule({config.hidden_size, config.rms_norm_eps, true, false})
729 .build(build_ctx, x, this->weights->norm);
730 logits = modules::LinearModule({config.hidden_size, config.vocab_size, false})
731 .build(build_ctx, x, {this->weights->lm_head, std::nullopt})
732 .tensor;
733 ggml_set_output(logits);
734 ggml_build_forward_expand(graph, logits);
735 buffer = ggml_backend_alloc_ctx_tensors(ctx.get(), backend);
736 if (buffer == nullptr) {
737 throw std::runtime_error("failed to allocate Vevo2 AR decode graph");
738 }
739 attention_mask_values.assign(static_cast<size_t>(cache_steps + 1), ggml_fp32_to_fp16(-INFINITY));
740 }
741
742 ~Vevo2ARDecodeGraph() {
743 engine::core::release_backend_graph_resources(backend, graph);
744 if (buffer != nullptr) {
745 ggml_backend_buffer_free(buffer);
746 }
747 }
748
749 bool can_run(const Vevo2ARWeights & other_weights, int64_t required_steps) const noexcept {
750 return weights.get() == &other_weights && cache_steps >= required_steps;
751 }
752
753 void import_state(const runtime::TransformerKVState & state) {
754 step_cache.import_state(state);
755 }
756
757 std::vector<float> run_step(int32_t token, const Vevo2ARConfig & config) {
758 if (step_cache.valid_steps() >= cache_steps) {
759 throw std::runtime_error("Vevo2 AR decode cache exhausted");
760 }
761 ggml_backend_tensor_set(token_id, &token, 0, sizeof(int32_t));
762 const int32_t position = static_cast<int32_t>(step_cache.current_end());
763 ggml_backend_tensor_set(positions, &position, 0, sizeof(int32_t));
764 const auto masked = ggml_fp32_to_fp16(-INFINITY);
765 const auto visible = ggml_fp32_to_fp16(0.0F);
766 std::fill(attention_mask_values.begin(), attention_mask_values.end(), masked);

Callers

nothing calls this directly

Calls 15

ar_head_dimFunction · 0.85
ggml_initFunction · 0.85
ggml_new_tensor_1dFunction · 0.85
wrap_tensorFunction · 0.85
EmbeddingModuleClass · 0.85
reshape_tensorFunction · 0.85
ggml_new_tensor_4dFunction · 0.85
ggml_new_graph_customFunction · 0.85
make_tensorFunction · 0.85
ggml_view_1dFunction · 0.85
TransformerKVCacheClass · 0.85
RMSNormModuleClass · 0.85

Tested by

no test coverage detected