#pragma once
#include "canary_qwen.h"
#include "causal_lm/causal_lm.h"
#include "ggml.h"
#include "weights.h"
struct ggml_context;
struct ggml_cgraph;
struct ggml_tensor;
namespace transcribe::canary_qwen {
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_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 T_audio = 0;
int prefix_len = 0;
int suffix_len = 0;
};
PrefillBuild build_prefill_graph(ggml_context * ctx,
const CanaryQwenWeights & weights,
const CanaryQwenHParams & hp,
transcribe::causal_lm::KvCache & kv_cache,
int T_prompt,
int T_audio,
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_tensor * logits = nullptr; ggml_cgraph * graph = nullptr;
int max_n_kv = 0;
};
StepBuild build_step_graph(ggml_context * ctx,
const CanaryQwenWeights & weights,
const CanaryQwenHParams & 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 T_audio_max = 0;
int n_batch = 0;
};
PrefillBuildBatched build_prefill_graph_batched(ggml_context * ctx,
const CanaryQwenWeights & weights,
const CanaryQwenHParams & hp,
transcribe::causal_lm::KvCache & kv_cache,
int T_prompt_max,
int T_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 CanaryQwenWeights & weights,
const CanaryQwenHParams & hp,
transcribe::causal_lm::KvCache & kv_cache,
int max_n_kv,
int n_batch,
bool use_flash);
}