#pragma once
#include "transcribe.h"
#include <cstdint>
#include <string>
#include <vector>
struct gguf_context;
struct ggml_context;
struct ggml_tensor;
namespace transcribe::gigaam {
enum class HeadKind { RNNT, CTC };
struct GigaamHParams {
HeadKind head_kind = HeadKind::RNNT;
int32_t enc_n_layers = 0;
int32_t enc_d_model = 0;
int32_t enc_n_heads = 0;
int32_t enc_d_ff = 0;
int32_t enc_conv_kernel = 0;
int32_t enc_subsampling_factor = 0;
int32_t enc_subs_kernel_size = 0;
int32_t enc_pos_emb_max_len = 0;
int32_t enc_feat_in = 0;
std::string enc_self_attention_model;
std::string enc_conv_norm_type;
int32_t pred_hidden = 0;
int32_t pred_n_layers = 0;
int32_t pred_vocab = 0;
int32_t joint_hidden = 0;
int32_t joint_n_classes = 0;
std::string joint_activation;
int32_t head_feat_in = 0;
int32_t head_n_classes = 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; float fe_dither = 0.0f;
float fe_pre_emphasis = 0.0f;
float fe_f_min = 0.0f;
float fe_f_max = 0.0f;
bool fe_center = false;
std::string fe_mel_norm; float fe_log_clamp_min = 1e-9f;
float fe_log_clamp_max = 1e9f;
int32_t enc_head_dim() const { return enc_n_heads > 0 ? enc_d_model / enc_n_heads : 0; }
};
transcribe_status read_gigaam_hparams(const gguf_context * gguf, GigaamHParams & hp);
struct GigaamPreEncode {
ggml_tensor * conv0_w = nullptr; ggml_tensor * conv0_b = nullptr; ggml_tensor * conv2_w = nullptr; ggml_tensor * conv2_b = nullptr; };
struct GigaamBlock {
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_conv_w = nullptr;
ggml_tensor * norm_conv_b = nullptr;
ggml_tensor * conv_pw1_w = nullptr; ggml_tensor * conv_pw1_b = nullptr; ggml_tensor * conv_dw_w = nullptr; ggml_tensor * conv_dw_b = nullptr; ggml_tensor * conv_ln_w = nullptr; ggml_tensor * conv_ln_b = nullptr; ggml_tensor * conv_pw2_w = nullptr; ggml_tensor * conv_pw2_b = nullptr;
ggml_tensor * norm_attn_w = nullptr;
ggml_tensor * norm_attn_b = nullptr;
ggml_tensor * attn_q_w = nullptr; ggml_tensor * attn_q_b = nullptr;
ggml_tensor * attn_k_w = nullptr;
ggml_tensor * attn_k_b = nullptr;
ggml_tensor * attn_v_w = nullptr;
ggml_tensor * attn_v_b = nullptr;
ggml_tensor * attn_out_w = nullptr;
ggml_tensor * attn_out_b = 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 GigaamPredictor {
ggml_tensor * embed_w = nullptr;
struct LstmLayer {
ggml_tensor * Wx = nullptr; ggml_tensor * Wh = nullptr; ggml_tensor * b = nullptr; };
std::vector<LstmLayer> lstm;
};
struct GigaamJoint {
ggml_tensor * enc_w = nullptr; ggml_tensor * enc_b = nullptr;
ggml_tensor * pred_w = nullptr; ggml_tensor * pred_b = nullptr;
ggml_tensor * out_w = nullptr; ggml_tensor * out_b = nullptr;
};
struct GigaamCtcHead {
ggml_tensor * weight = nullptr; ggml_tensor * bias = nullptr; };
struct GigaamWeights {
ggml_tensor * frontend_mel_filterbank = nullptr; ggml_tensor * frontend_window = nullptr;
GigaamPreEncode pre_encode;
std::vector<GigaamBlock> blocks;
GigaamPredictor predictor;
GigaamJoint joint;
GigaamCtcHead ctc_head;
};
transcribe_status build_gigaam_weights(ggml_context * ctx_meta, const GigaamHParams & hp, GigaamWeights & weights);
}