| 268 | gate = modules::SiluModule{}.build(ctx, gate); |
| 269 | auto up = modules::LinearModule({config.hidden_size, config.intermediate_size, weights.up_proj.bias.has_value()}) |
| 270 | .build(ctx, input, weights.up_proj); |
| 271 | return modules::LinearModule({config.intermediate_size, config.hidden_size, weights.down_proj.bias.has_value()}) |
| 272 | .build(ctx, modules::MulModule{}.build(ctx, gate, up), weights.down_proj); |
| 273 | } |
| 274 | |
| 275 | Vevo2ARLayerOutput decoder_layer( |
| 276 | core::ModuleBuildContext & ctx, |
| 277 | const core::TensorValue & input, |
| 278 | const core::TensorValue & positions, |
| 279 | const Vevo2Qwen2ARWeights::Layer & weights, |
| 280 | const Vevo2Qwen2ARConfig & config) { |
| 281 | const int64_t dim = ar_head_dim(config); |
| 282 | const int64_t kv_repeats = config.num_attention_heads / config.num_key_value_heads; |
| 283 | auto x_norm = modules::RMSNormModule({config.hidden_size, config.rms_norm_eps, true, false}) |
| 284 | .build(ctx, input, weights.input_norm); |
| 285 | auto q = modules::LinearModule({config.hidden_size, config.num_attention_heads * dim, weights.q_proj.bias.has_value()}) |
| 286 | .build(ctx, x_norm, weights.q_proj); |
| 287 | auto k = modules::LinearModule({config.hidden_size, config.num_key_value_heads * dim, weights.k_proj.bias.has_value()}) |
| 288 | .build(ctx, x_norm, weights.k_proj); |
| 289 | auto v = modules::LinearModule({config.hidden_size, config.num_key_value_heads * dim, weights.v_proj.bias.has_value()}) |
| 290 | .build(ctx, x_norm, weights.v_proj); |
| 291 | q = modules::RoPEModule({dim, GGML_ROPE_TYPE_NEOX, config.rope_theta}).build(ctx, reshape_heads(ctx, q, config.num_attention_heads, dim), positions); |
| 292 | k = modules::RoPEModule({dim, GGML_ROPE_TYPE_NEOX, config.rope_theta}).build(ctx, reshape_heads(ctx, k, config.num_key_value_heads, dim), positions); |
| 293 | v = reshape_heads(ctx, v, config.num_key_value_heads, dim); |
| 294 | |
| 295 | auto q_heads = modules::TransposeModule({{0, 2, 1, 3}, q.shape.rank}).build(ctx, q); |
| 296 | auto k_heads = repeat_kv_heads(ctx, modules::TransposeModule({{0, 2, 1, 3}, k.shape.rank}).build(ctx, k), kv_repeats); |
| 297 | auto v_heads = repeat_kv_heads(ctx, modules::TransposeModule({{0, 2, 1, 3}, v.shape.rank}).build(ctx, v), kv_repeats); |
no test coverage detected