| 41 | } |
| 42 | |
| 43 | engine::core::TensorValue GreedyDecodeModule::build(engine::core::ModuleBuildContext & ctx, const engine::core::TensorValue & logits) const { |
| 44 | if (ctx.ggml == nullptr) { |
| 45 | throw std::runtime_error("ModuleBuildContext.ggml is null"); |
| 46 | } |
| 47 | engine::core::validate_rank_between(logits, 3, 3, "logits"); |
| 48 | |
| 49 | auto flat = engine::core::reshape_tensor( |
| 50 | ctx, |
| 51 | engine::core::ensure_backend_addressable_layout(ctx, logits), |
| 52 | engine::core::TensorShape::from_dims({logits.shape.num_elements() / logits.shape.last_dim(), logits.shape.last_dim()})); |
| 53 | auto argmax = engine::core::wrap_tensor( |
| 54 | ggml_argmax(ctx.ggml, flat.tensor), |
| 55 | engine::core::TensorShape::from_dims({flat.shape.dims[0]}), |
| 56 | GGML_TYPE_I32); |
| 57 | return engine::core::reshape_tensor(ctx, argmax, engine::core::TensorShape::from_dims({logits.shape.dims[0], logits.shape.dims[1]})); |
| 58 | } |
| 59 | |
| 60 | const engine::core::ModuleSchema & GreedyDecodeModule::static_schema() noexcept { |
| 61 | return kGreedyDecodeSchema; |
nothing calls this directly
no test coverage detected