persistent_value_state#

RuntimeSession owns its passive PersistentValueState and reuses it between calls. Construct a session with initial retained values, then call RuntimeSession::Run(context, feeds) without passing a separate state:

  1. Uses retained values for persistent inputs alongside current feeds.

  2. Runs the session, reusing eligible append buffers or allocating new ones.

  3. Validates outputs and checks cancellation.

  4. Publishes the selected outputs as the next state only on success.

Views share tensor data but keep separate names and shapes. In-place append writes only the new region; growth may copy the old prefix. Failure leaves the previous logical state unchanged.

Bindings#

  • model.graph.persistent_bindings maps whole outputs to next-call inputs. Each persistent input must have at least one value-use.

  • Names are literal: request.cache is a graph name, not a field path. Duplicate bindings and partial structured inputs are rejected.

  • Current feeds cannot override retained inputs, even with an empty field map.

  • Values() uses input names; returned outputs use output names.

  • Supported values are tensors, named structures and inline structured encodings. Persistent strings are rejected, including nested strings.

Ownership#

  • The model stays immutable; declarations are resolved once, without cloning it. C++ constructors borrow const ModelProto&. The caller keeps it alive through the session and all exported model-backed views. Python bindings retain the model for sessions and exported initializer views.

  • initial and Reset take maps by value in C++. Use std::move(initial) to avoid copying owned payloads.

  • Returned views share owners and remain valid after later calls, reset or session destruction. Callers must not modify shared payloads; publication does not undo such writes.

  • Retained borrows need owners, except views of immutable initializer-owned storage whose lifetime is guaranteed by the C++ caller. Arena allocations need self-owning I/O leases. Unsafe storage is rejected, not copied as a fallback.

  • All calls use the same allocators, kept alive until the session is destroyed.

  • Initializers borrowing external raw data still need their own storage owner. Model lifetime alone cannot extend the lifetime of external storage or ordinary kernel results.

Execution and lifecycle#

  • Execution uses the supplied RuntimeContext directly and the caller-owned RuntimeSession and its cached kernels. No child context is created. The state exposes no context-binding or execution methods; the session handles inputs, validation and publication as part of Run. Only declared persistent outputs bypass normal output materialization.

  • If and local functions transport selected outputs without payload copies. Other operators retain their ordinary computation and transport costs.

  • RuntimeSession::Reset(initial) replaces retained values without rebuilding the session or its cached kernels.

  • Session destruction releases its retained values and cached kernels.

  • Events use context.events() when events_enabled is true, including work before failure. ClearEvents() clears this log, not the persistent values.

See Persistent input/output feedback for usage and storage details, and runtime_context.h for event fields.

namespace onnx_light

Alias that makes onnx-light headers compatible with code that references ONNX_LIGHT_NAMESPACE (the macro used in the standard onnx package).

Set to ONNX_LIGHT_NAMESPACE so both names resolve to the same namespace.

Symbol-visibility attribute for the public onnx-light C++ API.

Maps the upstream compatibility macro to onnx-light’s explicit proto ABI annotation. This keeps declarations from vendored ONNX headers visible when lib_onnx_proto uses hidden visibility by default.

Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal onnx namespace — rather than the ONNX_NAMESPACE macro — resolves to the onnx-light namespace. The standard onnx package lives in namespace onnx; onnx-light uses onnx_light (via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs from onnx.

namespace core
namespace runtime
class PersistentValueState#
#include <persistent_value_state.h>

Carries graph-declared persistent values between model calls.

During a RuntimeSession run:

  1. Uses retained values for persistent inputs alongside the current feeds.

  2. Executes the session, reusing eligible append buffers or allocating new ones.

  3. Validates the outputs and checks cancellation.

  4. Publishes selected outputs as the next state only on success.

Storage:

  • Views share tensor data but have separate names and shapes.

  • In-place append writes only the new region; growth may copy the old prefix.

  • Failure leaves the previous logical state unchanged.

Requirements:

  • Each binding names a whole input/output pair; the input has at least one value-use.

  • Current feeds cannot replace persistent inputs.

  • Supports tensors, typed sequences, named structures and inline encoded values.

  • Tensor leaves may use dense storage or inline affine encoding of the declared logical type.

  • Shared payloads are read-only; only immutable initializer views may borrow ownerless storage.

  • The model stays immutable. All calls use the same allocators, kept alive by the caller.

Public Functions

PersistentValueState(const ModelProto &model, RuntimeValueMap initial, RuntimeSessionOptions options = {})#

Initializes retained values from the graph’s persistent bindings.

Accepts std::move(initial) to avoid copying owned payloads. The caller keeps the model alive through the state and exported initializer views.

void Reset(RuntimeValueMap initial)#

Replaces retained values with explicitly transferred initial contents.

void TransferFrom(PersistentValueState &source)#

Transfers compatible retained values and append reservations from another state.

Validates matching input/output binding pairs and values before either state changes. Payloads and append-capacity metadata move without copying. Captured allocators must agree; an uncaptured destination inherits the source’s allocator identity. The source rejects retained-state Run and Values until Reset or another transfer restores its values. Both states must be idle. Source model and allocator owners must outlive any transferred initializer-backed views.

RuntimeValueMap Values() const#

Returns read-only aliases keyed by exact retained graph input names.

inline const ModelProto &model() const#

Returns the immutable model.

inline const StructTypeCatalogue &struct_type_catalogue() const#

Returns the validated catalogue.

Private Types

using ShapeSymbols = std::unordered_map<std::string, int64_t>#

Private Functions

std::vector<PersistentValue> ValidateInitial(RuntimeValueMap initial) const#

Private Members

const ModelProto &model_#
StructTypeCatalogue catalogue_#
mutable std::unordered_map<const TypeProto*, RuntimeSequence::Memo<ShapeSymbols>> sequence_validation_#
std::vector<Binding> bindings_#
std::vector<PersistentValue> values_#
size_t persistent_tensor_initial_capacity_ = 0#
bool allocators_captured_ = false#
RawBufferAllocator *execution_allocator_ = nullptr#
RawBufferAllocator *io_allocator_ = nullptr#
mutable std::atomic_flag busy_ = ATOMIC_FLAG_INIT#

Friends

friend class RuntimeSession
struct Binding#

Public Members

std::string input#
std::string output#
const TypeProto *input_type#