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

Method DecodeGraph

src/models/ace_step/planner.cpp:1894–1971  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1892 ggml_tensor * token_ids_ = nullptr;
1893 ggml_tensor * positions_ = nullptr;
1894 ggml_tensor * attention_mask_ = nullptr;
1895 ggml_tensor * query_mask_ = nullptr;
1896 ggml_tensor * logits_ = nullptr;
1897 std::vector<ggml_tensor *> keys_;
1898 std::vector<ggml_tensor *> values_;
1899 ggml_cgraph * graph_ = nullptr;
1900 std::unique_ptr<ggml_gallocr, decltype(&ggml_gallocr_free)> graph_allocator_{nullptr, ggml_gallocr_free};
1901};
1902
1903class Qwen3PlannerDecodeGraph {
1904public:
1905 Qwen3PlannerDecodeGraph(
1906 std::shared_ptr<Qwen3PlannerWeightsRuntime> runtime,
1907 int64_t cache_steps,
1908 size_t graph_arena_bytes)
1909 : runtime_(std::move(runtime)),
1910 cache_steps_(cache_steps) {
1911 if (cache_steps_ <= 0) {
1912 throw std::runtime_error("ACE-Step planner decode requires positive cache length");
1913 }
1914 ggml_init_params params{graph_arena_bytes, nullptr, true};
1915 ctx_.reset(ggml_init(params));
1916 if (ctx_ == nullptr) {
1917 throw std::runtime_error("failed to initialize ACE-Step planner decode graph context");
1918 }
1919 const auto & config = runtime_->assets().config.planner;
1920 const auto & weights = runtime_->weights();
1921 core::ModuleBuildContext ctx{ctx_.get(), "ace_step.planner.decode", runtime_->backend_type()};
1922 token_id_ = ggml_new_tensor_1d(ctx_.get(), GGML_TYPE_I32, 1);
1923 auto token = core::wrap_tensor(token_id_, core::TensorShape::from_dims({1}), GGML_TYPE_I32);
1924 auto x = modules::EmbeddingModule({config.vocab_size, config.hidden_size})
1925 .build(ctx, token, weights.token_embedding);
1926 x = core::reshape_tensor(ctx, x, core::TensorShape::from_dims({1, 1, config.hidden_size}));
1927 positions_ = ggml_new_tensor_1d(ctx_.get(), GGML_TYPE_I32, 1);
1928 auto positions = core::wrap_tensor(positions_, core::TensorShape::from_dims({1}), GGML_TYPE_I32);
1929 attention_mask_ = ggml_new_tensor_4d(ctx_.get(), GGML_TYPE_F16, cache_steps_ + 1, 1, 1, 1);
1930 auto attention_mask = core::wrap_tensor(
1931 attention_mask_,
1932 core::TensorShape::from_dims({1, 1, 1, cache_steps_ + 1}),
1933 GGML_TYPE_F16);
1934 graph_ = ggml_new_graph_custom(ctx_.get(), 65536, false);
1935
1936 std::vector<core::TensorValue> cache_keys;
1937 std::vector<core::TensorValue> cache_values;
1938 for (const auto & layer : weights.layers.layers) {
1939 cache_keys.push_back(core::make_tensor(
1940 ctx,
1941 GGML_TYPE_F32,
1942 core::TensorShape::from_dims({1, cache_steps_ + 1, config.num_key_value_heads, config.head_dim})));
1943 cache_values.push_back(core::make_tensor(
1944 ctx,
1945 GGML_TYPE_F32,
1946 core::TensorShape::from_dims({1, cache_steps_ + 1, config.num_key_value_heads, config.head_dim})));
1947 auto out = planner_decoder_layer_with_static_cache_tail_batched(
1948 ctx,
1949 graph_,
1950 x,
1951 positions,

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
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