| 35 | } |
| 36 | |
| 37 | void validate_weight_shape(const LinearConfig & config, const LinearWeights & weights) { |
| 38 | core::validate_shape( |
| 39 | weights.weight, |
| 40 | core::TensorShape::from_dims({config.out_features, config.in_features}), |
| 41 | "weight"); |
| 42 | |
| 43 | if (!config.use_bias) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | if (!weights.bias.has_value()) { |
| 48 | throw std::runtime_error("bias is required when LinearConfig.use_bias is true"); |
| 49 | } |
| 50 | |
| 51 | core::validate_shape( |
| 52 | *weights.bias, |
| 53 | core::TensorShape::from_dims({config.out_features}), |
| 54 | "bias"); |
| 55 | } |
| 56 | |
| 57 | } // namespace |
| 58 | |