dl::RuntimeModel
dl::RuntimeModel
A ModelBase implementation driven entirely by a RuntimeModelSpec (JSON). More…
#include <RuntimeModel.hpp>
Inherits from dl::ModelBase
Public Functions
| Name | |
|---|---|
| RuntimeModel(RuntimeModelSpec spec) Construct from a parsed spec. |
|
| ~RuntimeModel() override | |
| virtual std::string | modelId() const override Unique string identifier for this model class (e.g. “neurosam”). |
| virtual std::string | displayName() const override Human-readable display name (e.g. “NeuroSAM”). |
| virtual std::string | description() const override Description for UI tooltip. |
| virtual std::vector< TensorSlotDescriptor > | inputSlots() const override Input slot descriptors (ordered). |
| virtual std::vector< TensorSlotDescriptor > | outputSlots() const override Output slot descriptors (ordered). |
| virtual std::string | recommendedPostEncoderModule() const override Recommended post-encoder module key for the UI (e.g. “global_avg_pool”). |
| virtual void | loadWeights(std::filesystem::path const & path) override Load weights from a file (e.g. a .pte ExecuTorch program or a TorchScript model). |
| virtual bool | isReady() const override Whether weights are loaded and model is ready for inference. |
| virtual int | preferredBatchSize() const override Preferred batch size. |
| virtual int | maxBatchSize() const override Maximum batch size the model supports. |
| virtual dl::BatchMode | batchMode() const override Batch mode describing the model’s batch-size constraints. |
| bool | loadWeightsForBatchSize(int batch_size) Select and load the best weights variant for the given batch size. |
| std::vector< WeightsVariant > | weightsVariants() const Get the list of available weights variants (if any). |
| virtual std::unordered_map< std::string, at::Tensor > | forward(std::unordered_map< std::string, at::Tensor > const & inputs) override Run inference. |
| RuntimeModelSpec const & | spec() const Access the underlying spec. |
Additional inherited members
Public Functions inherited from dl::ModelBase
| Name | |
|---|---|
| virtual | ~ModelBase() =default |
Detailed Description
class dl::RuntimeModel;A ModelBase implementation driven entirely by a RuntimeModelSpec (JSON).
RuntimeModel allows users to define model inputs, outputs, and metadata via a JSON specification file, without recompiling. It uses ModelExecution to load and run ExecuTorch .pte programs.
Usage:
auto spec_result = RuntimeModelSpec::fromJsonFile("model.json");
if (spec_result) {
auto model = std::make_unique<RuntimeModel>(std::move(spec_result.value()));
model->loadWeights("/path/to/model.pte");
// ... use like any ModelBase ...
}Public Functions Documentation
function RuntimeModel
explicit RuntimeModel(
RuntimeModelSpec spec
)Construct from a parsed spec.
If the spec contains a weights_path, the model will attempt to load weights from that path during construction.
function ~RuntimeModel
~RuntimeModel() overridefunction modelId
virtual std::string modelId() const overrideUnique string identifier for this model class (e.g. “neurosam”).
Reimplements: dl::ModelBase::modelId
function displayName
virtual std::string displayName() const overrideHuman-readable display name (e.g. “NeuroSAM”).
Reimplements: dl::ModelBase::displayName
function description
virtual std::string description() const overrideDescription for UI tooltip.
Reimplements: dl::ModelBase::description
function inputSlots
virtual std::vector< TensorSlotDescriptor > inputSlots() const overrideInput slot descriptors (ordered).
Reimplements: dl::ModelBase::inputSlots
Each describes one named tensor the model expects. Does not include the batch dimension.
function outputSlots
virtual std::vector< TensorSlotDescriptor > outputSlots() const overrideOutput slot descriptors (ordered).
Reimplements: dl::ModelBase::outputSlots
Each describes one named tensor the model produces. Does not include the batch dimension.
function recommendedPostEncoderModule
virtual std::string recommendedPostEncoderModule() const overrideRecommended post-encoder module key for the UI (e.g. “global_avg_pool”).
Reimplements: dl::ModelBase::recommendedPostEncoderModule
Empty string means no post-encoder module is recommended. The UI pre-selects this but the user can override it.
function loadWeights
virtual void loadWeights(
std::filesystem::path const & path
) overrideLoad weights from a file (e.g. a .pte ExecuTorch program or a TorchScript model).
Reimplements: dl::ModelBase::loadWeights
function isReady
virtual bool isReady() const overrideWhether weights are loaded and model is ready for inference.
Reimplements: dl::ModelBase::isReady
function preferredBatchSize
virtual int preferredBatchSize() const overridePreferred batch size.
Reimplements: dl::ModelBase::preferredBatchSize
0 = model decides; 1 = single-frame (e.g. NeuroSAM with output→input feedback); N = process N frames at once. UI uses this as the default for the “Batch Size” spinbox.
function maxBatchSize
virtual int maxBatchSize() const overrideMaximum batch size the model supports.
Reimplements: dl::ModelBase::maxBatchSize
0 = unlimited.
function batchMode
virtual dl::BatchMode batchMode() const overrideBatch mode describing the model’s batch-size constraints.
Reimplements: dl::ModelBase::batchMode
The default returns [DynamicBatch](/api_generated/Classes/structdl_1_1DynamicBatch.md){1, 0} (any batch size). Override in subclasses to report [FixedBatch](/api_generated/Classes/structdl_1_1FixedBatch.md), [RecurrentOnlyBatch](/api_generated/Classes/structdl_1_1RecurrentOnlyBatch.md), or a [DynamicBatch](/api_generated/Classes/structdl_1_1DynamicBatch.md) with specific limits.
The widget uses this to configure the batch-size spinbox and to auto-select the correct weights variant for multi-variant models.
function loadWeightsForBatchSize
bool loadWeightsForBatchSize(
int batch_size
)Select and load the best weights variant for the given batch size.
Return: true if a variant was found and loaded successfully
Searches weights_variants for an exact batch_size match. If none is found, falls back to the default weights_path.
function weightsVariants
std::vector< WeightsVariant > weightsVariants() constGet the list of available weights variants (if any).
function forward
virtual std::unordered_map< std::string, at::Tensor > forward(
std::unordered_map< std::string, at::Tensor > const & inputs
) overrideRun inference.
Parameters:
- inputs Map of slot_name → Tensor, each with a leading batch dimension.
Return: Map of slot_name → Tensor for each output slot.
Reimplements: dl::ModelBase::forward
Tensors have a leading batch dimension whose size is controlled by the caller (and bounded by [maxBatchSize()](/api_generated/Classes/classdl_1_1RuntimeModel.md#function-maxbatchsize)).
function spec
RuntimeModelSpec const & spec() constAccess the underlying spec.
Updated on 2026-11-13 at 20:25:42 +0000