OnnxModelOptions

Options & Configuration · AiDotNet.Onnx

Configuration options for loading and running ONNX models.

For Beginners

Use defaults for most cases:

For GPU acceleration:

How It Works

This class provides comprehensive configuration for ONNX model inference, including execution provider selection, memory optimization, and threading.

Constructors

Constructor Summary
OnnxModelOptions() Initializes a new instance with default values.
OnnxModelOptions(OnnxModelOptions other) Initializes a new instance by copying from another instance.

Properties

Property Summary
Dictionary<string, string> CustomOptions { get; set; } Gets or sets custom session options as key-value pairs.
GraphOptimizationLevel OptimizationLevel { get; set; } Gets or sets the graph optimization level.
List<OnnxExecutionProvider> FallbackProviders { get; set; } Gets or sets fallback execution providers if the primary fails.
OnnxExecutionProvider ExecutionProvider { get; set; } Gets or sets the preferred execution provider.
OnnxLogLevel LogLevel { get; set; } Gets or sets the log severity level for ONNX Runtime.
bool AutoWarmUp { get; set; } Gets or sets whether to automatically warm up the model after loading.
bool CudaUseArena { get; set; } Gets or sets whether to use CUDA memory arena for better performance.
bool EnableMemoryArena { get; set; } Gets or sets whether to enable memory arena.
bool EnableMemoryPattern { get; set; } Gets or sets whether to enable memory pattern optimization.
bool EnableProfiling { get; set; } Gets or sets whether to enable profiling for performance analysis.
int GpuDeviceId { get; set; } Gets or sets the GPU device ID for CUDA/TensorRT/DirectML providers.
int InterOpNumThreads { get; set; } Gets or sets the number of threads for parallel operations.
int IntraOpNumThreads { get; set; } Gets or sets the number of threads for CPU execution.
long CudaMemoryLimit { get; set; } Gets or sets the CUDA memory limit in bytes (0 = no limit).
string ProfileOutputPath { get; set; } Gets or sets the path for saving profiling output.

Methods

Method Summary
OnnxModelOptions ForCpu(int? threads) Creates default options for CPU execution.
OnnxModelOptions ForCuda(int deviceId) Creates default options for CUDA GPU execution.
OnnxModelOptions ForDirectML(int deviceId) Creates default options for DirectML GPU execution (Windows).
OnnxModelOptions ForTensorRT(int deviceId) Creates default options for TensorRT execution (NVIDIA optimized).