#pragma once
#include "ggml.h"
#include <vector>
struct ggml_context;
struct ggml_tensor;
struct ggml_cgraph;
namespace transcribe::moonshine {
struct MoonshineHParams;
struct MoonshineWeights;
struct MoonshineKvCache;
struct DecoderDumps {
ggml_tensor * token_emb = nullptr; ggml_tensor * embed_sum = nullptr; std::vector<ggml_tensor *> block_outs; ggml_tensor * out_before_head = nullptr; ggml_tensor * logits_raw = nullptr; ggml_tensor * logits = nullptr; };
struct DecoderBuild {
ggml_tensor * token_ids_in = nullptr; ggml_tensor * pos_ids_in = nullptr; ggml_tensor * encoder_out_in = nullptr; ggml_tensor * causal_mask_in = nullptr;
ggml_tensor * out = nullptr; ggml_tensor * argmax_out = nullptr;
DecoderDumps dumps {};
ggml_cgraph * graph = nullptr;
};
DecoderBuild build_cross_kv_graph(ggml_context * compute_ctx,
const MoonshineWeights & weights,
const MoonshineHParams & hp,
MoonshineKvCache & kv_cache,
int T_enc);
DecoderBuild build_decoder_graph_kv(ggml_context * compute_ctx,
const MoonshineWeights & weights,
const MoonshineHParams & hp,
MoonshineKvCache & kv_cache,
int n_tokens,
int n_past,
int T_enc,
bool skip_log_softmax = false,
bool use_flash = true);
struct StepBuild {
ggml_tensor * token_id_in = nullptr; ggml_tensor * pos_id_in = nullptr; ggml_tensor * kv_idx_in = nullptr; ggml_tensor * mask_in = nullptr; ggml_tensor * argmax_out = nullptr; int max_n_kv = 0;
ggml_cgraph * graph = nullptr;
};
StepBuild build_step_graph(ggml_context * compute_ctx,
const MoonshineWeights & weights,
const MoonshineHParams & hp,
MoonshineKvCache & kv_cache,
int max_n_kv,
int T_enc,
bool use_flash = true);
DecoderBuild build_cross_kv_graph_batched(ggml_context * ctx,
const MoonshineWeights & w,
const MoonshineHParams & hp,
MoonshineKvCache & kv_cache,
int T_enc_max,
int n_batch);
struct StepBuildBatched {
ggml_tensor * token_ids_in = nullptr; ggml_tensor * pos_ids_in = nullptr; ggml_tensor * kv_idx_in = nullptr; ggml_tensor * self_mask_in = nullptr; ggml_tensor * cross_mask_in = nullptr; ggml_tensor * argmax_out = nullptr; int max_n_kv = 0;
int n_batch = 0;
ggml_cgraph * graph = nullptr;
};
StepBuildBatched build_step_graph_batched(ggml_context * ctx,
const MoonshineWeights & w,
const MoonshineHParams & hp,
MoonshineKvCache & kv_cache,
int max_n_kv,
int T_enc_max,
int n_batch,
bool use_flash = true);
}