#pragma once
#include "granite.h"
#include "causal_lm/causal_lm.h"
#include "weights.h"
#include "ggml.h"
struct ggml_context;
struct ggml_cgraph;
struct ggml_tensor;
namespace transcribe::granite {
struct DecoderDumps {
ggml_tensor * token_emb = nullptr; ggml_tensor * audio_injected = nullptr; ggml_tensor * block_0_out = nullptr;
ggml_tensor * block_mid_out = nullptr; ggml_tensor * block_last_out = nullptr;
ggml_tensor * out_before_head = nullptr; ggml_tensor * logits_raw = nullptr; };
struct PrefillBuild {
ggml_tensor * input_ids_in = nullptr; ggml_tensor * audio_feats_in = nullptr; ggml_tensor * positions_in = nullptr; ggml_tensor * mask_in = nullptr; ggml_tensor * out = nullptr; DecoderDumps dumps {};
ggml_cgraph * graph = nullptr;
int T_prompt = 0;
int n_audio_tokens = 0;
int prefix_len = 0;
int suffix_len = 0;
};
PrefillBuild build_prefill_graph(ggml_context * ctx,
const GraniteWeights & weights,
const GraniteHParams & hp,
transcribe::causal_lm::KvCache & kv_cache,
int T_prompt,
int n_audio_tokens,
int prefix_len,
int suffix_len,
bool use_flash,
bool slice_last);
struct StepBuild {
ggml_tensor * input_id_in = nullptr; ggml_tensor * position_in = nullptr; ggml_tensor * kv_idx_in = nullptr; ggml_tensor * mask_in = nullptr; ggml_tensor * out = nullptr; ggml_cgraph * graph = nullptr;
int max_n_kv = 0;
};
StepBuild build_step_graph(ggml_context * ctx,
const GraniteWeights & weights,
const GraniteHParams & hp,
transcribe::causal_lm::KvCache & kv_cache,
int max_n_kv,
bool use_flash);
struct PrefillBuildBatched {
ggml_tensor * input_ids_in = nullptr; ggml_tensor * audio_dense_in = nullptr; ggml_tensor * keep_mask_in = nullptr; ggml_tensor * positions_in = nullptr; ggml_tensor * mask_in = nullptr; ggml_tensor * kv_idx_in = nullptr; ggml_tensor * last_idx_in = nullptr; ggml_tensor * logits = nullptr; ggml_tensor * out = nullptr; ggml_cgraph * graph = nullptr;
int T_prompt_max = 0;
int n_audio_max = 0;
int n_batch = 0;
};
PrefillBuildBatched build_prefill_graph_batched(
ggml_context * ctx,
const GraniteWeights & weights,
const GraniteHParams & hp,
transcribe::causal_lm::KvCache & kv_cache,
int T_prompt_max,
int n_audio_max,
int n_batch,
bool use_flash);
struct StepBuildBatched {
ggml_tensor * input_ids_in = nullptr; ggml_tensor * position_in = nullptr; ggml_tensor * kv_idx_in = nullptr; ggml_tensor * mask_in = nullptr; ggml_tensor * logits = nullptr; ggml_tensor * out = nullptr; ggml_cgraph * graph = nullptr;
int max_n_kv = 0;
int n_batch = 0;
};
StepBuildBatched build_step_graph_batched(
ggml_context * ctx,
const GraniteWeights & weights,
const GraniteHParams & hp,
transcribe::causal_lm::KvCache & kv_cache,
int max_n_kv,
int n_batch,
bool use_flash);
}