| 108 | const AceStepQwen3TextEncoderConfig & config) { |
| 109 | const int64_t dim = head_dim(config); |
| 110 | const int64_t kv_repeats = config.num_attention_heads / config.num_key_value_heads; |
| 111 | const modules::LinearModule q_proj( |
| 112 | {config.hidden_size, config.num_attention_heads * dim, false, GGML_PREC_F32}); |
| 113 | const modules::LinearModule k_proj( |
| 114 | {config.hidden_size, config.num_key_value_heads * dim, false, GGML_PREC_F32}); |
| 115 | const modules::LinearModule v_proj( |
| 116 | {config.hidden_size, config.num_key_value_heads * dim, false, GGML_PREC_F32}); |
| 117 | const modules::LinearModule o_proj( |
| 118 | {config.num_attention_heads * dim, config.hidden_size, false, GGML_PREC_F32}); |
| 119 | const modules::RMSNormModule hidden_norm({config.hidden_size, config.rms_norm_eps, true, false}); |
| 120 | const modules::RMSNormModule head_norm({dim, config.rms_norm_eps, true, false}); |
| 121 | const modules::AddModule add; |
| 122 | |
| 123 | auto attn_in = hidden_norm.build(ctx, input, binding::norm_data(ctx, weights.input_norm)); |
| 124 | auto q = q_proj.build(ctx, attn_in, binding::linear_data(ctx, weights.q_proj)); |
| 125 | auto k = k_proj.build(ctx, attn_in, binding::linear_data(ctx, weights.k_proj)); |
| 126 | auto v = v_proj.build(ctx, attn_in, binding::linear_data(ctx, weights.v_proj)); |
| 127 | q = head_norm.build(ctx, reshape_heads(ctx, q, config.num_attention_heads, dim), binding::norm_data(ctx, weights.q_norm)); |
| 128 | k = head_norm.build(ctx, reshape_heads(ctx, k, config.num_key_value_heads, dim), binding::norm_data(ctx, weights.k_norm)); |
| 129 | v = reshape_heads(ctx, v, config.num_key_value_heads, dim); |
| 130 | q = modules::RoPEModule({dim, GGML_ROPE_TYPE_NEOX, config.rope_theta}).build(ctx, q, positions); |
| 131 | k = modules::RoPEModule({dim, GGML_ROPE_TYPE_NEOX, config.rope_theta}).build(ctx, k, positions); |
| 132 | |
| 133 | auto q_heads = modules::TransposeModule({{0, 2, 1, 3}, q.shape.rank}).build(ctx, q); |
| 134 | auto k_heads = |
| 135 | repeat_kv_heads(ctx, modules::TransposeModule({{0, 2, 1, 3}, k.shape.rank}).build(ctx, k), kv_repeats); |
| 136 | auto v_heads = |
| 137 | repeat_kv_heads(ctx, modules::TransposeModule({{0, 2, 1, 3}, v.shape.rank}).build(ctx, v), kv_repeats); |
no test coverage detected