| 35 | const core::ModuleSchema & FastKVSetRowsModule::schema() const noexcept { |
| 36 | return static_schema(); |
| 37 | } |
| 38 | |
| 39 | core::TensorValue FastKVSetRowsModule::build( |
| 40 | core::ModuleBuildContext & ctx, |
| 41 | const core::TensorValue & cache, |
| 42 | const core::TensorValue & row, |
| 43 | const core::TensorValue & row_index) const { |
| 44 | if (ctx.ggml == nullptr) { |
| 45 | throw std::runtime_error("ModuleBuildContext.ggml is null"); |
| 46 | } |
| 47 | core::validate_rank_between(cache, 4, 4, "cache"); |
| 48 | core::validate_shape( |
| 49 | row, |
| 50 | core::TensorShape::from_dims({cache.shape.dims[0], 1, cache.shape.dims[2], cache.shape.dims[3]}), |
| 51 | "row"); |
| 52 | const int64_t batch = cache.shape.dims[0]; |
| 53 | if (row_index.shape.rank != 1 || (row_index.shape.dims[0] != 1 && row_index.shape.dims[0] != batch)) { |
| 54 | throw std::runtime_error("FastKVSetRowsModule row_index must have shape {1} or {batch}"); |
| 55 | } |
| 56 | const bool optimized = config_.mode == FastKVSetRowsMode::BackendViewOptimized; |
| 57 | if (((!optimized && cache.type != GGML_TYPE_F32) || |
| 58 | (optimized && cache.type != GGML_TYPE_F32 && cache.type != GGML_TYPE_F16 && cache.type != GGML_TYPE_BF16)) || |
| 59 | row.type != GGML_TYPE_F32) { |
| 60 | throw std::runtime_error( |
| 61 | optimized |
| 62 | ? "FastKVSetRowsModule requires an f32/f16/bf16 cache and an f32 row tensor" |
| 63 | : "FastKVSetRowsModule requires f32 cache and row tensors"); |
| 64 | } |
| 65 | if (row_index.type != GGML_TYPE_I32 && row_index.type != GGML_TYPE_I64) { |
| 66 | throw std::runtime_error("FastKVSetRowsModule requires i32 or i64 row_index tensor"); |
| 67 | } |
| 68 | if (!core::has_backend_addressable_layout(cache.tensor)) { |
| 69 | throw std::runtime_error("FastKVSetRowsModule requires a contiguous cache tensor"); |
| 70 | } |
| 71 | |
| 72 | const int64_t steps = cache.shape.dims[1]; |
nothing calls this directly
no test coverage detected