dl::ModelExecution
dl::ModelExecution
Multi-backend model execution layer. More…
#include <ModelExecution.hpp>
Public Functions
| Name | |
|---|---|
| ModelExecution(BackendType backend =BackendType::Auto) Create with auto-detection (default) or explicit backend selection. |
|
| ~ModelExecution() | |
| ModelExecution(ModelExecution const & ) =delete | |
| ModelExecution & | operator=(ModelExecution const & ) =delete |
| ModelExecution(ModelExecution && ) | |
| ModelExecution & | operator=(ModelExecution && ) |
| bool | load(std::filesystem::path const & path) Load a model file. |
| bool | isLoaded() const Whether a model is loaded and ready for execution. |
| std::filesystem::path | loadedPath() const Get the path of the currently loaded model. |
| BackendType | activeBackend() const Get the active backend type (Auto if no model is loaded yet). |
| std::string | activeBackendName() const Get the active backend’s human-readable name. |
| std::vector< at::Tensor > | execute(std::vector< at::Tensor > const & inputs) Execute the default “forward” method with ordered input tensors. |
| std::vector< at::Tensor > | execute(std::string const & method_name, std::vector< at::Tensor > const & inputs) Execute a named method with ordered input tensors. |
| std::vector< at::Tensor > | executeNamed(std::unordered_map< std::string, at::Tensor > const & named_inputs, std::vector< std::string > const & input_order) Execute the “forward” method with named input tensors. |
Detailed Description
class dl::ModelExecution;Multi-backend model execution layer.
[ModelExecution](/api_generated/Classes/classdl_1_1ModelExecution.md) dispatches inference to one of several backends (TorchScript, AOT Inductor, ExecuTorch) via the [InferenceBackend](/api_generated/Classes/classdl_1_1InferenceBackend.md) strategy pattern. The backend is selected either explicitly via [BackendType](/api_generated/Namespaces/namespacedl.md#enum-backendtype) or auto-detected from the model file extension:
.pt→ TorchScript (legacy, deprecated but functional).pt2→ AOT Inductor (recommended for new models).pte→ ExecuTorch (optional, requires ENABLE_EXECUTORCH)
The public API is identical to the previous ExecuTorch-only implementation, so downstream code ([NeuroSAMModel](/api_generated/Classes/classdl_1_1NeuroSAMModel.md), [RuntimeModel](/api_generated/Classes/classdl_1_1RuntimeModel.md), [SlotAssembler](/api_generated/Classes/classSlotAssembler.md)) requires no changes.
Usage:
// Auto-detect from extension:
dl::ModelExecution exec;
exec.load("/path/to/model.pt2"); // → AOTInductorBackend
// Explicit backend:
dl::ModelExecution exec2(dl::BackendType::TorchScript);
exec2.load("/path/to/model.pt"); // → TorchScriptBackend
if (exec.isLoaded()) {
auto outputs = exec.execute({input_tensor_1, input_tensor_2});
}Public Functions Documentation
function ModelExecution
explicit ModelExecution(
BackendType backend =BackendType::Auto
)Create with auto-detection (default) or explicit backend selection.
Parameters:
- backend BackendType::Auto selects backend from file extension at load() time. Other values force a specific backend.
function ~ModelExecution
~ModelExecution()function ModelExecution
ModelExecution(
ModelExecution const &
) =deletefunction operator=
ModelExecution & operator=(
ModelExecution const &
) =deletefunction ModelExecution
ModelExecution(
ModelExecution &&
)function operator=
ModelExecution & operator=(
ModelExecution &&
)function load
bool load(
std::filesystem::path const & path
)Load a model file.
Parameters:
- path Path to the model file.
Return: true if loading succeeded.
If BackendType is Auto, selects backend from extension: .pt → TorchScript .pt2 → AOTInductor .pte → ExecuTorch (requires ENABLE_EXECUTORCH build)
function isLoaded
bool isLoaded() constWhether a model is loaded and ready for execution.
function loadedPath
std::filesystem::path loadedPath() constGet the path of the currently loaded model.
function activeBackend
BackendType activeBackend() constGet the active backend type (Auto if no model is loaded yet).
function activeBackendName
std::string activeBackendName() constGet the active backend’s human-readable name.
function execute
std::vector< at::Tensor > execute(
std::vector< at::Tensor > const & inputs
)Execute the default “forward” method with ordered input tensors.
Parameters:
- inputs Ordered vector of input tensors.
Exceptions:
- std::runtime_error if the model is not loaded or execution fails.
Return: Ordered vector of output tensors.
function execute
std::vector< at::Tensor > execute(
std::string const & method_name,
std::vector< at::Tensor > const & inputs
)Execute a named method with ordered input tensors.
Parameters:
- method_name Name of the method to execute (e.g. “forward”, “encode”).
- inputs Ordered vector of input tensors.
Exceptions:
- std::runtime_error if the model is not loaded or execution fails.
Return: Ordered vector of output tensors.
function executeNamed
std::vector< at::Tensor > executeNamed(
std::unordered_map< std::string, at::Tensor > const & named_inputs,
std::vector< std::string > const & input_order
)Execute the “forward” method with named input tensors.
Parameters:
- named_inputs Map of slot_name → Tensor.
- input_order Ordered slot names matching the model’s forward() signature.
Return: Ordered vector of output tensors.
Reorders named inputs according to input_order, then delegates to [execute()](/api_generated/Classes/classdl_1_1ModelExecution.md#function-execute).
Updated on 2026-11-13 at 20:25:42 +0000