Skip to content

sgns::neoswarm::core::MNNInferenceEngine

MNN-backed inference engine with composable configuration. More...

#include <mnn_inference_engine.hpp>

Inherits from sgns::neoswarm::core::InferenceEngine

Public Classes

Name
struct Config

Public Functions

Name
MNNInferenceEngine()
MNNInferenceEngine(Config cfg)
~MNNInferenceEngine() override
virtual outcome::result< void > LoadModel(const std::string & model_path) override
Load a model from disk (MNN .mnn file or similar).
virtual outcome::result< InferenceResponse > Infer(const Task & task) override
Synchronous inference — returns the full generated output.
virtual outcome::result< void > StreamInfer(const Task & task, std::function< void(const std::string &token)> callback) override
Streaming inference — calls callback for each generated token.
virtual bool IsLoaded() const override
virtual std::string BackendName() const override
void SetTokenizer(std::shared_ptr< Tokenizer > tok)
Attach a tokenizer (required for "interpreter" mode).
void SetStubMode()
Mark engine as loaded in stub/test mode (no real model file needed).
void SetSGClient(network::SGClient * client)
Set the SGClient for Phase 2 network dispatch.

Additional inherited members

Public Functions inherited from sgns::neoswarm::core::InferenceEngine

Name
virtual ~InferenceEngine() =default

Detailed Description

class sgns::neoswarm::core::MNNInferenceEngine;

MNN-backed inference engine with composable configuration.

Inference paths (selected at runtime via Config::m_engineMode):

"sgprocessing" — Primary path. Routes through SGProcessingManager which handles model loading, chunking, and execution. Cross-platform. Network-ready (Phase 2).

"interpreter" — Fallback. Uses MNN's native Transformer::Llm API for LLM-directory models only (mnn_llm_). There is no hand-rolled sampling loop / standard single-file .mnn support in this mode (removed per Phase 4 D-06).

GPU backend (selected at runtime via Config::m_backend):

"vulkan" — Vulkan (cross-platform). MoltenVK translates to Metal on Apple. "cpu" — CPU-only fallback.

Public Functions Documentation

function MNNInferenceEngine

MNNInferenceEngine()

function MNNInferenceEngine

explicit MNNInferenceEngine(
    Config cfg
)

function ~MNNInferenceEngine

~MNNInferenceEngine() override

function LoadModel

virtual outcome::result< void > LoadModel(
    const std::string & model_path
) override

Load a model from disk (MNN .mnn file or similar).

Parameters:

  • model_path Path to the model file.

Return: outcome::success or ModelLoadFailed.

Reimplements: sgns::neoswarm::core::InferenceEngine::LoadModel

function Infer

virtual outcome::result< InferenceResponse > Infer(
    const Task & task
) override

Synchronous inference — returns the full generated output.

Parameters:

  • task Inference task with prompt and generation parameters.

Return: InferenceResponse or InferenceFailed.

Reimplements: sgns::neoswarm::core::InferenceEngine::Infer

function StreamInfer

virtual outcome::result< void > StreamInfer(
    const Task & task,
    std::function< void(const std::string &token)> callback
) override

Streaming inference — calls callback for each generated token.

Parameters:

  • task Inference task.
  • callback Called with each token string as it is generated.

Return: outcome::success or InferenceFailed.

Reimplements: sgns::neoswarm::core::InferenceEngine::StreamInfer

function IsLoaded

inline virtual bool IsLoaded() const override

Return: True if a model has been loaded.

Reimplements: sgns::neoswarm::core::InferenceEngine::IsLoaded

function BackendName

virtual std::string BackendName() const override

Return: Human-readable backend name (e.g. "MNN/Vulkan", "MNN/CPU").

Reimplements: sgns::neoswarm::core::InferenceEngine::BackendName

function SetTokenizer

inline void SetTokenizer(
    std::shared_ptr< Tokenizer > tok
)

Attach a tokenizer (required for "interpreter" mode).

function SetStubMode

inline void SetStubMode()

Mark engine as loaded in stub/test mode (no real model file needed).

function SetSGClient

void SetSGClient(
    network::SGClient * client
)

Set the SGClient for Phase 2 network dispatch.

Parameters:

  • client The SGClient instance (owned by ApiServer).

Call once during initialization after both the engine and the SGClient are created. The client pointer is passed through to the internal SGProcessingBridge.


Updated on 2026-10-09 at 03:59:42 +0000