#pragma once
#include "transcribe.h"
#include <cstdint>
#include <string>
#include <vector>
struct gguf_context;
struct ggml_context;
struct ggml_tensor;
namespace transcribe::funasr_nano {
struct FunAsrNanoHParams {
int32_t enc_n_blocks = 0; int32_t enc_tp_blocks = 0; int32_t enc_d_model = 0; int32_t enc_d_input = 0; int32_t enc_n_heads = 0; int32_t enc_d_ff = 0; int32_t enc_kernel = 0; int32_t enc_sanm_shift = 0; std::string enc_attn_type; bool enc_normalize_before = true;
int32_t adaptor_n_blocks = 0; int32_t adaptor_encoder_dim = 0; int32_t adaptor_llm_dim = 0; int32_t adaptor_pre_ffn_dim = 0; int32_t adaptor_block_ffn_dim = 0; int32_t adaptor_n_heads = 0; int32_t adaptor_d_head = 0; float adaptor_layer_norm_eps = 1e-12f;
std::string adaptor_activation; int32_t adaptor_downsample_rate = 0; bool adaptor_use_low_frame_rate = true;
int32_t dec_n_layers = 0; int32_t dec_hidden = 0; int32_t dec_intermediate = 0; int32_t dec_n_heads = 0; int32_t dec_n_kv_heads = 0; int32_t dec_head_dim = 0; int32_t dec_vocab_size = 0; int32_t dec_max_position_embeddings = 0; float dec_rms_norm_eps = 0.0f; float dec_rope_theta = 0.0f; bool dec_tie_word_embeddings = true;
std::string dec_activation;
int32_t bos_token_id = -1;
int32_t eos_token_id = -1;
int32_t pad_token_id = -1;
int32_t vocab_size = 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_fbank_style; float fe_dither = 0.0f;
bool fe_upscale_samples = true;
bool fe_snip_edges = true;
int32_t fe_lfr_m = 0; int32_t fe_lfr_n = 0; bool fe_apply_cmvn = false;
};
transcribe_status read_funasr_nano_hparams(const gguf_context * gguf, FunAsrNanoHParams & hp);
struct EncBlock {
ggml_tensor * norm_attn_w = nullptr; ggml_tensor * norm_attn_b = nullptr; ggml_tensor * attn_qkv_w = nullptr; ggml_tensor * attn_qkv_b = nullptr; ggml_tensor * attn_out_w = nullptr; ggml_tensor * attn_out_b = nullptr; ggml_tensor * attn_fsmn_w = nullptr; ggml_tensor * norm_ffn_w = nullptr; ggml_tensor * norm_ffn_b = nullptr; ggml_tensor * ffn_fc1_w = nullptr; ggml_tensor * ffn_fc1_b = nullptr; ggml_tensor * ffn_fc2_w = nullptr; ggml_tensor * ffn_fc2_b = nullptr; };
struct AdaptorBlock {
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_ffn_w = nullptr; ggml_tensor * norm_ffn_b = nullptr; ggml_tensor * ffn_fc1_w = nullptr; ggml_tensor * ffn_fc1_b = nullptr; ggml_tensor * ffn_fc2_w = nullptr; ggml_tensor * ffn_fc2_b = nullptr; };
struct AdaptorWeights {
ggml_tensor * linear1_w = nullptr; ggml_tensor * linear1_b = nullptr; ggml_tensor * linear2_w = nullptr; ggml_tensor * linear2_b = nullptr;
std::vector<AdaptorBlock> blocks;
};
struct DecEmbed {
ggml_tensor * token_w = nullptr; };
struct DecBlock {
ggml_tensor * norm_attn_w = nullptr; ggml_tensor * norm_ffn_w = nullptr; ggml_tensor * attn_q_w = nullptr; ggml_tensor * attn_k_w = nullptr; ggml_tensor * attn_v_w = nullptr; ggml_tensor * attn_o_w = nullptr; ggml_tensor * attn_q_norm = nullptr; ggml_tensor * attn_k_norm = nullptr; ggml_tensor * ffn_gate_w = nullptr; ggml_tensor * ffn_up_w = nullptr; ggml_tensor * ffn_down_w = nullptr; ggml_tensor * ffn_gate_up_w = nullptr;
};
struct DecFinal {
ggml_tensor * norm_w = nullptr;
};
struct FunAsrNanoWeights {
EncBlock encoders0; std::vector<EncBlock> encoders; ggml_tensor * after_norm_w = nullptr;
ggml_tensor * after_norm_b = nullptr;
std::vector<EncBlock> tp_encoders;
ggml_tensor * tp_norm_w = nullptr;
ggml_tensor * tp_norm_b = nullptr;
AdaptorWeights adaptor;
DecEmbed dec_embed;
std::vector<DecBlock> dec_blocks;
DecFinal dec_final;
};
transcribe_status build_funasr_nano_weights(ggml_context * ctx_meta,
const FunAsrNanoHParams & hp,
FunAsrNanoWeights & weights);
}