#pragma once
#include "ggml.h"
#include <cstdint>
struct ggml_context;
struct ggml_tensor;
struct ggml_cgraph;
namespace transcribe::canary {
struct CanaryHParams;
struct CanaryWeights;
struct CanaryKvCache;
struct DecoderDumps {
ggml_tensor * token_emb = nullptr;
ggml_tensor * pos_emb = nullptr;
ggml_tensor * embed_norm = nullptr;
ggml_tensor * sub_self [64] = {};
ggml_tensor * sub_cross[64] = {};
ggml_tensor * sub_ffn [64] = {};
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 * out = nullptr; ggml_tensor * argmax_out = nullptr;
DecoderDumps dumps {};
ggml_cgraph * graph = nullptr;
};
DecoderBuild build_cross_kv_graph(ggml_context * ctx,
const CanaryWeights & w,
const CanaryHParams & hp,
CanaryKvCache & kv_cache,
int T_enc);
DecoderBuild build_decoder_graph_kv(ggml_context * ctx,
const CanaryWeights & w,
const CanaryHParams & hp,
CanaryKvCache & 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 * ctx,
const CanaryWeights & w,
const CanaryHParams & hp,
CanaryKvCache & kv_cache,
int max_n_kv,
int T_enc,
bool use_flash = true);
DecoderBuild build_cross_kv_graph_batched(ggml_context * ctx,
const CanaryWeights & w,
const CanaryHParams & hp,
CanaryKvCache & 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 CanaryWeights & w,
const CanaryHParams & hp,
CanaryKvCache & kv_cache,
int max_n_kv,
int T_enc_max,
int n_batch,
bool use_flash = true);
}