Skip to main content

dl::RuntimeModelSpec

dl::RuntimeModelSpec

JSON-serializable specification for a runtime-defined model. More…

#include <RuntimeModelSpec.hpp>

Public Functions

Name
rfl::Result< RuntimeModelSpec > fromJson(std::string const & json_str)
Parse a RuntimeModelSpec from a JSON string.
rfl::Result< RuntimeModelSpec > fromJsonFile(std::filesystem::path const & path)
Parse a RuntimeModelSpec from a JSON file.
std::string toJson() const
Serialize this spec to a JSON string.
std::vector< TensorSlotDescriptor > inputDescriptors() const
Convert all input SlotSpecs to TensorSlotDescriptors.
std::vector< TensorSlotDescriptor > outputDescriptors() const
Convert all output SlotSpecs to TensorSlotDescriptors.
std::vector< std::string > validate() const
Validate semantic correctness beyond JSON schema.

Public Attributes

Name
std::string model_id
std::string display_name
std::optional< std::string > description
std::optional< std::string > weights_path
std::optional< std::string > backend
std::optional< int > preferred_batch_size
std::optional< int > max_batch_size
std::optional< BatchModeSpec > batch_mode
std::optional< std::vector< WeightsVariant > > weights_variants
std::vector< SlotSpec > inputs
std::vector< SlotSpec > outputs
std::optional< std::string > recommended_post_encoder
std::optional< std::vector< PostEncoderStepSpec > > post_encoder

Detailed Description

struct dl::RuntimeModelSpec;

JSON-serializable specification for a runtime-defined model.

Allows users to specify an ExecuTorch model’s inputs and outputs via JSON at runtime, without recompilation.

JSON example: ```json

{ “model_id”: “my_tracker”, “display_name”: “My Tracker”, “description”: “Tracks whisker tips”, “weights_path”: “model.pte”, “preferred_batch_size”: 1, “max_batch_size”: 1, “batch_mode”: { “dynamic”: { “min”: 1, “max”: 8 } }, “weights_variants”: [ { “path”: “model_batch1.pt2”, “batch_size”: 1, “label”: “recurrent” }, { “path”: “model_batch8.pt2”, “batch_size”: 8, “label”: “batched” } ], “inputs”: [ { “name”: “image”, “shape”: [3, 256, 256], “recommended_encoder”: “ImageEncoder” } ], “outputs”: [ { “name”: “heatmap”, “shape”: [1, 256, 256], “recommended_decoder”: “TensorToMask2D” } ], “post_encoder”: [ { “module”: “global_avg_pool” } ] }


## Public Functions Documentation

### function fromJson

```cpp
static rfl::Result< RuntimeModelSpec > fromJson(
    std::string const & json_str
)

Parse a RuntimeModelSpec from a JSON string.

function fromJsonFile

static rfl::Result< RuntimeModelSpec > fromJsonFile(
    std::filesystem::path const & path
)

Parse a RuntimeModelSpec from a JSON file.

Relative [weights_path](/api_generated/Classes/structdl_1_1RuntimeModelSpec.md#variable-weights-path) values are resolved against the file’s directory.

function toJson

std::string toJson() const

Serialize this spec to a JSON string.

function inputDescriptors

std::vector< TensorSlotDescriptor > inputDescriptors() const

Convert all input SlotSpecs to TensorSlotDescriptors.

function outputDescriptors

std::vector< TensorSlotDescriptor > outputDescriptors() const

Convert all output SlotSpecs to TensorSlotDescriptors.

function validate

std::vector< std::string > validate() const

Validate semantic correctness beyond JSON schema.

Return: Error messages; empty if valid.

Public Attributes Documentation

variable model_id

std::string model_id;

variable display_name

std::string display_name;

variable description

std::optional< std::string > description;

variable weights_path

std::optional< std::string > weights_path;

variable backend

std::optional< std::string > backend;

“auto”, “torchscript”, “aotinductor”, “executorch”

variable preferred_batch_size

std::optional< int > preferred_batch_size;

variable max_batch_size

std::optional< int > max_batch_size;

variable batch_mode

std::optional< BatchModeSpec > batch_mode;

Rich batch-size constraint

variable weights_variants

std::optional< std::vector< WeightsVariant > > weights_variants;

Multi-variant weights

variable inputs

std::vector< SlotSpec > inputs;

variable outputs

std::vector< SlotSpec > outputs;

variable recommended_post_encoder

std::optional< std::string > recommended_post_encoder;

UI hint: post-encoder module registry key (e.g. “global_avg_pool”)

variable post_encoder

std::optional< std::vector< PostEncoderStepSpec > > post_encoder;

Optional post-encoder pipeline


Updated on 2026-11-13 at 20:25:42 +0000