pub struct SessionBuilder { /* private fields */ }Expand description
Builder for advanced session configuration (§20.6).
Implementations§
Source§impl SessionBuilder
impl SessionBuilder
pub fn new() -> Self
pub fn model(self, path: impl AsRef<Path>) -> Self
pub fn model_bytes(self, bytes: &[u8]) -> Self
pub fn device(self, pref: DevicePreference) -> Self
Sourcepub fn execution_provider(
self,
execution_provider: Arc<dyn ExecutionProvider>,
) -> Self
pub fn execution_provider( self, execution_provider: Arc<dyn ExecutionProvider>, ) -> Self
Use an explicitly constructed execution provider instead of device auto-selection.
pub fn memory_limit(self, bytes: usize) -> Self
pub fn profiling(self, enable: bool) -> Self
pub fn warmup(self, shapes: Vec<WarmupShape>) -> Self
Sourcepub fn decode_precision(self, precision: DecodePrecision) -> Self
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.
Sourcepub fn option(self, key: &str, value: &str) -> Self
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
| Key | Values | Default | Effect |
|---|---|---|---|
"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.onnx | Output 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.
Sourcepub fn build(self) -> Result<InferenceSession, SessionError>
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) → allocateThe 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
impl Default for SessionBuilder
Source§fn default() -> SessionBuilder
fn default() -> SessionBuilder
Auto Trait Implementations§
impl !RefUnwindSafe for SessionBuilder
impl !UnwindSafe for SessionBuilder
impl Freeze for SessionBuilder
impl Send for SessionBuilder
impl Sync for SessionBuilder
impl Unpin for SessionBuilder
impl UnsafeUnpin for SessionBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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