Skip to main content

SessionBuilder

Struct SessionBuilder 

Source
pub struct SessionBuilder { /* private fields */ }
Expand description

Builder for advanced session configuration (§20.6).

Implementations§

Source§

impl SessionBuilder

Source

pub fn new() -> Self

Source

pub fn model(self, path: impl AsRef<Path>) -> Self

Source

pub fn model_bytes(self, bytes: &[u8]) -> Self

Source

pub fn device(self, pref: DevicePreference) -> Self

Source

pub fn execution_provider( self, execution_provider: Arc<dyn ExecutionProvider>, ) -> Self

Use an explicitly constructed execution provider instead of device auto-selection.

Source

pub fn memory_limit(self, bytes: usize) -> Self

Source

pub fn profiling(self, enable: bool) -> Self

Source

pub fn warmup(self, shapes: Vec<WarmupShape>) -> Self

Source

pub fn decode_precision(self, precision: DecodePrecision) -> Self

Select the decoder-wide numeric precision (see DecodePrecision). Defaults to DecodePrecision::Model (graph as authored); selecting DecodePrecision::Fp16 opts into the fp32→fp16 decode rewrite, which only takes effect on a GPU fp32-activation quantized decoder.

Source

pub fn option(self, key: &str, value: &str) -> Self

Set a namespaced option. Unknown keys — and unknown values for a known key — are rejected at Self::build.

§Recognized options
KeyValuesDefaultEffect
"optimization""none", "basic", "all""none"Graph optimization level (see OptimizationLevel).
"ep.context_enable""0"/"1"/"false"/"true""0"Dump a *_ctx.onnx EPContext model after compile (§21.4 / §55.4).
"ep.context_file_path"any path<orig>_ctx.onnxOutput path for the generated context model.
"ep.context_embed_mode""0" (external) / "1" (embed)"1"How the compiled blob is stored in each EPContext node.

"optimization" = "none" (the default) leaves the loaded graph untouched, so behavior is byte-identical to a runtime with no optimizer. "basic" runs constant folding + dead-node elimination; "all" adds operator fusion. When any pass runs, the session re-runs shape inference on the rewritten graph before compiling so fused/introduced nodes get inferred shapes.

Source

pub fn build(self) -> Result<InferenceSession, SessionError>

Build the session: load → detect device → optimize → compile → allocate.

The optimize stage is driven by the "optimization" session option and defaults to OptimizationLevel::None (a no-op), so the default path is byte-identical to loading straight into the executor. When optimization is enabled the pipeline is:

load (+ loader shape inference)
  → run optimizer passes (constant-fold / DCE / fusion)
  → re-run shape inference on the rewritten graph
  → compile (kernel per node) → allocate

The re-inference step is essential: fusion can replace a multi-op decomposition (e.g. the 9-op LayerNorm) with a single fused node whose output has no inferred shape yet, and the compile/execute stages require every value to carry a resolved shape.

Device selection keeps CPU as the default and selects CUDA only when explicitly requested in a CUDA-enabled build. “Compile” resolves a kernel per node into the shape-keyed cache.

Trait Implementations§

Source§

impl Default for SessionBuilder

Source§

fn default() -> SessionBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.