| 126 | result = core::wrap_tensor(ggml_mul(ctx.ggml, result.tensor, weight.tensor), result.shape, GGML_TYPE_F32); |
| 127 | } |
| 128 | if (config.use_bias) { |
| 129 | if (!weights.bias.has_value()) { |
| 130 | throw std::runtime_error("bias is required when NormConfig.use_bias is true"); |
| 131 | } |
| 132 | core::validate_shape(*weights.bias, core::TensorShape::from_dims({config.hidden_size}), "bias"); |
| 133 | const auto bias = ensure_f32(ctx, *weights.bias); |
| 134 | result = core::wrap_tensor(ggml_add(ctx.ggml, result.tensor, bias.tensor), result.shape, GGML_TYPE_F32); |
| 135 | } |
| 136 | return result; |
| 137 | } |
| 138 | |
| 139 | void validate_norm_config(const NormConfig & config) { |
| 140 | if (config.hidden_size <= 0) { |
| 141 | throw std::runtime_error("NormConfig.hidden_size must be positive"); |
| 142 | } |
| 143 | if (!(config.eps > 0.0f)) { |
| 144 | throw std::runtime_error("NormConfig.eps must be positive"); |
| 145 | } |
no test coverage detected