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:
Uses retained values for persistent inputs alongside current feeds.
Runs the session, reusing eligible append buffers or allocating new ones.
Validates outputs and checks cancellation.
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_bindingsmaps whole outputs to next-call inputs. Each persistent input must have at least one value-use.Names are literal:
request.cacheis 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.initialandResettake maps by value in C++. Usestd::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
RuntimeContextdirectly and the caller-ownedRuntimeSessionand 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 ofRun. Only declared persistent outputs bypass normal output materialization.Ifand 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()whenevents_enabledis 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_NAMESPACEso 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_protouses hidden visibility by default.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_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 fromonnx.-
namespace core
-
namespace runtime
-
class PersistentValueState#
- #include <persistent_value_state.h>
Carries graph-declared persistent values between model calls.
During a RuntimeSession run:
Uses retained values for persistent inputs alongside the current feeds.
Executes the session, reusing eligible append buffers or allocating new ones.
Validates the outputs and checks cancellation.
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 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<PersistentValue> values_#
-
size_t persistent_tensor_initial_capacity_ = 0#
-
bool allocators_captured_ = false#
-
RawBufferAllocator *execution_allocator_ = nullptr#
-
RawBufferAllocator *io_allocator_ = nullptr#
Friends
- friend class RuntimeSession
-
struct Binding#
-
class PersistentValueState#
-
namespace runtime
-
namespace core