dl::InferenceBackend
dl::InferenceBackend
Abstract interface for model inference backends. More…
#include <InferenceBackend.hpp>
Inherited by dl::AOTInductorBackend, dl::ExecuTorchBackend, dl::TorchScriptBackend
Public Functions
| Name | |
|---|---|
| virtual | ~InferenceBackend() =default |
| virtual std::string | name() const =0 Human-readable backend name (e.g. “TorchScript”, “AOTInductor”). |
| virtual BackendType | type() const =0 The BackendType enum value for this backend. |
| virtual std::string | fileExtension() const =0 File extension this backend handles (e.g. “.pt”, “.pt2”, “.pte”). |
| virtual bool | load(std::filesystem::path const & path) =0 Load model weights/program from a file. |
| virtual bool | isLoaded() const =0 Whether a model is loaded and ready for execution. |
| virtual std::filesystem::path | loadedPath() const =0 Get the path of the currently loaded model. |
| virtual std::vector< at::Tensor > | execute(std::vector< at::Tensor > const & inputs) =0 Execute the default method (typically “forward”) with ordered inputs. |
| virtual std::vector< at::Tensor > | execute(std::string const & method_name, std::vector< at::Tensor > const & inputs) =0 Execute a named method with ordered inputs. |
| InferenceBackend(InferenceBackend const & ) =delete | |
| InferenceBackend & | operator=(InferenceBackend const & ) =delete |
Protected Functions
| Name | |
|---|---|
| InferenceBackend() =default | |
| InferenceBackend(InferenceBackend && ) =default | |
| InferenceBackend & | operator=(InferenceBackend && ) =default |
Detailed Description
class dl::InferenceBackend;Abstract interface for model inference backends.
Each backend knows how to load a model file and execute inference, producing at::Tensor outputs from at::Tensor inputs. The at::Tensor type is the common currency across all backends.
Public Functions Documentation
function ~InferenceBackend
virtual ~InferenceBackend() =defaultfunction name
virtual std::string name() const =0Human-readable backend name (e.g. “TorchScript”, “AOTInductor”).
Reimplemented by: dl::AOTInductorBackend::name, dl::ExecuTorchBackend::name, dl::TorchScriptBackend::name
function type
virtual BackendType type() const =0The BackendType enum value for this backend.
Reimplemented by: dl::AOTInductorBackend::type, dl::ExecuTorchBackend::type, dl::TorchScriptBackend::type
function fileExtension
virtual std::string fileExtension() const =0File extension this backend handles (e.g. “.pt”, “.pt2”, “.pte”).
Reimplemented by: dl::AOTInductorBackend::fileExtension, dl::ExecuTorchBackend::fileExtension, dl::TorchScriptBackend::fileExtension
function load
virtual bool load(
std::filesystem::path const & path
) =0Load model weights/program from a file.
Parameters:
- path Path to the model file.
Return: true if loading succeeded.
Reimplemented by: dl::AOTInductorBackend::load, dl::ExecuTorchBackend::load, dl::TorchScriptBackend::load
function isLoaded
virtual bool isLoaded() const =0Whether a model is loaded and ready for execution.
Reimplemented by: dl::AOTInductorBackend::isLoaded, dl::ExecuTorchBackend::isLoaded, dl::TorchScriptBackend::isLoaded
function loadedPath
virtual std::filesystem::path loadedPath() const =0Get the path of the currently loaded model.
Reimplemented by: dl::AOTInductorBackend::loadedPath, dl::ExecuTorchBackend::loadedPath, dl::TorchScriptBackend::loadedPath
function execute
virtual std::vector< at::Tensor > execute(
std::vector< at::Tensor > const & inputs
) =0Execute the default method (typically “forward”) with ordered inputs.
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.
Reimplemented by: dl::AOTInductorBackend::execute, dl::ExecuTorchBackend::execute, dl::TorchScriptBackend::execute
All tensors are at::Tensor (libtorch) — the common currency across all backends.
function execute
virtual std::vector< at::Tensor > execute(
std::string const & method_name,
std::vector< at::Tensor > const & inputs
) =0Execute a named method with ordered inputs.
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.
Reimplemented by: dl::AOTInductorBackend::execute, dl::ExecuTorchBackend::execute, dl::TorchScriptBackend::execute
Not all backends support multiple methods. Backends that don’t should ignore the method_name and execute the default model.
function InferenceBackend
InferenceBackend(
InferenceBackend const &
) =deletefunction operator=
InferenceBackend & operator=(
InferenceBackend const &
) =deleteProtected Functions Documentation
function InferenceBackend
InferenceBackend() =defaultfunction InferenceBackend
InferenceBackend(
InferenceBackend &&
) =defaultfunction operator=
InferenceBackend & operator=(
InferenceBackend &&
) =defaultUpdated on 2026-11-13 at 20:25:42 +0000