#pragma once
#include "transcribe.h"
#include <cstdint>
#include <string>
#include <vector>
struct gguf_context;
struct ggml_context;
struct ggml_tensor;
namespace transcribe::granite5_ctc {
struct Granite5CtcHParams {
std::string variant;
int32_t enc_n_layers = 0; int32_t enc_hidden = 0; int32_t enc_n_heads = 0; int32_t enc_head_dim = 0; int32_t enc_intermediate = 0; int32_t enc_input_dim = 0; int32_t enc_output_dim = 0; int32_t enc_conv_kernel_size = 0; int32_t enc_conv_expansion = 0; int32_t enc_context_size = 0; int32_t enc_max_pos_emb = 0;
int32_t enc_self_cond_layer = 0;
std::vector<int32_t> enc_subsample_layers;
int32_t blank_id = 0;
std::string fe_type; int32_t fe_num_mels = 0; int32_t fe_sample_rate = 0; int32_t fe_n_fft = 0; int32_t fe_win_length = 0; int32_t fe_hop_length = 0; std::string fe_window; std::string fe_normalize; std::string fe_pad_mode; std::string fe_mel_norm; float fe_dither = 0.0f; bool fe_deltas = true;
int32_t fe_delta_win_length = 0; float fe_logmel_floor_db = 0.0f; int32_t fe_stack_factor = 0; };
transcribe_status read_granite5_ctc_hparams(const gguf_context * gguf, Granite5CtcHParams & hp);
struct Granite5CtcEncTop {
ggml_tensor * input_linear_w = nullptr; ggml_tensor * input_linear_b = nullptr; ggml_tensor * ctc_proj_w = nullptr; ggml_tensor * ctc_proj_b = nullptr; ggml_tensor * ctc_bypass_w = nullptr; ggml_tensor * ctc_bypass_b = nullptr; };
struct Granite5CtcEncBlock {
ggml_tensor * norm_ff1_w = nullptr; ggml_tensor * norm_ff1_b = nullptr;
ggml_tensor * ff1_lin1_w = nullptr; ggml_tensor * ff1_lin1_b = nullptr; ggml_tensor * ff1_lin2_w = nullptr; ggml_tensor * ff1_lin2_b = nullptr;
ggml_tensor * norm_attn_w = nullptr; ggml_tensor * norm_attn_b = nullptr;
ggml_tensor * attn_q_w = nullptr; ggml_tensor * attn_kv_w = nullptr; ggml_tensor * attn_out_w = nullptr; ggml_tensor * attn_out_b = nullptr; ggml_tensor * attn_rel_pos_emb = nullptr;
ggml_tensor * norm_conv_w = nullptr; ggml_tensor * norm_conv_b = nullptr;
ggml_tensor * conv_pointwise1_w = nullptr; ggml_tensor * conv_pointwise1_b = nullptr; ggml_tensor * conv_depthwise_w = nullptr; ggml_tensor * conv_bn_w = nullptr; ggml_tensor * conv_bn_b = nullptr; ggml_tensor * conv_bn_mean = nullptr; ggml_tensor * conv_bn_var = nullptr; ggml_tensor * conv_pointwise2_w = nullptr; ggml_tensor * conv_pointwise2_b = nullptr; ggml_tensor * conv_bn_fused_scale = nullptr; ggml_tensor * conv_bn_fused_bias = nullptr;
ggml_tensor * norm_ff2_w = nullptr;
ggml_tensor * norm_ff2_b = nullptr;
ggml_tensor * ff2_lin1_w = nullptr;
ggml_tensor * ff2_lin1_b = nullptr;
ggml_tensor * ff2_lin2_w = nullptr;
ggml_tensor * ff2_lin2_b = nullptr;
ggml_tensor * norm_out_w = nullptr;
ggml_tensor * norm_out_b = nullptr;
};
struct Granite5CtcWeights {
Granite5CtcEncTop enc_top;
std::vector<Granite5CtcEncBlock> enc_blocks;
ggml_tensor * frontend_mel_filterbank = nullptr; ggml_tensor * frontend_window = nullptr; };
transcribe_status build_granite5_ctc_weights(ggml_context * ctx_meta,
const Granite5CtcHParams & hp,
Granite5CtcWeights & weights);
}