Skip to main content

dl::ExecuTorchBackend

dl::ExecuTorchBackend

ExecuTorch inference backend — loads .pte programs. More…

#include <ExecuTorchBackend.hpp>

Inherits from dl::InferenceBackend

Public Classes

Name
struct Impl

Public Functions

Name
ExecuTorchBackend()
~ExecuTorchBackend() override
ExecuTorchBackend(ExecuTorchBackend && )
ExecuTorchBackend & operator=(ExecuTorchBackend && )
virtual std::string name() const override
Human-readable backend name (e.g. “TorchScript”, “AOTInductor”).
virtual BackendType type() const override
The BackendType enum value for this backend.
virtual std::string fileExtension() const override
File extension this backend handles (e.g. “.pt”, “.pt2”, “.pte”).
virtual bool load(std::filesystem::path const & path) override
Load model weights/program from a file.
virtual bool isLoaded() const override
Whether a model is loaded and ready for execution.
virtual std::filesystem::path loadedPath() const override
Get the path of the currently loaded model.
virtual std::vector< at::Tensor > execute(std::vector< at::Tensor > const & inputs) override
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) override
Execute a named method with ordered inputs.

Additional inherited members

Public Functions inherited from dl::InferenceBackend

Name
virtual ~InferenceBackend() =default
InferenceBackend(InferenceBackend const & ) =delete

Protected Functions inherited from dl::InferenceBackend

Name
InferenceBackend() =default
InferenceBackend(InferenceBackend && ) =default

Detailed Description

class dl::ExecuTorchBackend;

ExecuTorch inference backend — loads .pte programs.

Note: ExecuTorch operates on CPU only in the default configuration. Input tensors are converted to contiguous CPU tensors before execution.

This backend wraps the ExecuTorch C++ runtime to load and execute ExecuTorch programs. It bridges between libtorch at::Tensor and ExecuTorch’s EValue execution API.

This backend is optional and only available when the project is built with ENABLE_EXECUTORCH=ON. It is designed for edge/mobile deployment scenarios.

Public Functions Documentation

function ExecuTorchBackend

ExecuTorchBackend()

function ~ExecuTorchBackend

~ExecuTorchBackend() override

function ExecuTorchBackend

ExecuTorchBackend(
    ExecuTorchBackend && 
)

function operator=

ExecuTorchBackend & operator=(
    ExecuTorchBackend && 
)

function name

virtual std::string name() const override

Human-readable backend name (e.g. “TorchScript”, “AOTInductor”).

Reimplements: dl::InferenceBackend::name

function type

virtual BackendType type() const override

The BackendType enum value for this backend.

Reimplements: dl::InferenceBackend::type

function fileExtension

virtual std::string fileExtension() const override

File extension this backend handles (e.g. “.pt”, “.pt2”, “.pte”).

Reimplements: dl::InferenceBackend::fileExtension

function load

virtual bool load(
    std::filesystem::path const & path
) override

Load model weights/program from a file.

Parameters:

  • path Path to the model file.

Return: true if loading succeeded.

Reimplements: dl::InferenceBackend::load

function isLoaded

virtual bool isLoaded() const override

Whether a model is loaded and ready for execution.

Reimplements: dl::InferenceBackend::isLoaded

function loadedPath

virtual std::filesystem::path loadedPath() const override

Get the path of the currently loaded model.

Reimplements: dl::InferenceBackend::loadedPath

function execute

virtual std::vector< at::Tensor > execute(
    std::vector< at::Tensor > const & inputs
) override

Execute 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.

Reimplements: dl::InferenceBackend::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
) override

Execute 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.

Reimplements: dl::InferenceBackend::execute

Not all backends support multiple methods. Backends that don’t should ignore the method_name and execute the default model.


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