#pragma once
#include "causal_lm/causal_lm.h"
#include "ggml-backend.h"
#include "ggml.h"
#include "transcribe-backend.h"
#include "transcribe-mel.h"
#include "transcribe-model.h"
#include "transcribe-session.h"
#include "transcribe-tokenizer.h"
#include "weights.h"
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
struct ggml_context;
struct ggml_tensor;
struct ggml_backend;
struct ggml_backend_buffer;
struct ggml_backend_sched;
typedef struct ggml_backend * ggml_backend_t;
typedef struct ggml_backend_buffer * ggml_backend_buffer_t;
typedef struct ggml_backend_sched * ggml_backend_sched_t;
namespace transcribe::granite {
void apply_family_invariants(transcribe_model & model);
struct ChatTokens {
int32_t audio = -1; int32_t end_of_text = -1; int32_t pad = -1; int32_t start_of_role = -1; int32_t end_of_role = -1; };
struct GraniteModel final : public transcribe_model {
Tokenizer tok;
GraniteHParams hparams;
GraniteWeights weights;
ggml_context * ctx_meta = nullptr;
transcribe::BackendPlan plan;
ggml_backend_buffer_t backend_buffer = nullptr;
ggml_context * bn_fused_ctx = nullptr;
ggml_backend_buffer_t bn_fused_buffer = nullptr;
transcribe::causal_lm::PackedGateUpHandles packed_gate_up;
std::optional<transcribe::MelFrontend> mel;
std::string chat_template;
ChatTokens chat_tokens;
GraniteModel() = default;
~GraniteModel() override;
const transcribe::Tokenizer * tokenizer() const override { return &tok; }
};
struct GraniteSession final : public transcribe_session {
ggml_context * compute_ctx = nullptr;
ggml_backend_sched_t sched = nullptr;
std::vector<float> mel_buf;
std::vector<float> audio_tokens_host;
int32_t n_audio_tokens = 0;
bool encoder_use_flash = true;
bool decoder_use_flash = true;
transcribe::causal_lm::KvCache kv;
transcribe::causal_lm::KvCache kv_batch;
int kv_batch_cap = 0;
int kv_batch_n_ctx = 0;
GraniteSession() = default;
~GraniteSession() override;
};
}