Documentation
¶
Index ¶
- type Backend
- type BackendOptions
- type ExtraExecutionProvider
- type GenAIAdapterConfig
- type GenAIEngineMemoryOptions
- type GoMLXOptions
- type GraphOptimizationLevel
- type LoggingLevel
- type Options
- type OrtOptions
- type WithOption
- func WithCPUMemArena(enable bool) WithOption
- func WithCoreML(flags map[string]string) WithOption
- func WithCuda(options map[string]string) WithOption
- func WithDirectML(deviceID int) WithOption
- func WithExecutionMode(parallel bool) WithOption
- func WithExtraExecutionProvider(name string, options map[string]string) WithOption
- func WithFileSystem(system fileutil.FileSystem) WithOption
- func WithGenAIActiveAdapter(name string) WithOption
- func WithGenAIAdapters(adapters ...GenAIAdapterConfig) WithOption
- func WithGenAIGPUDeviceID(deviceID int) WithOption
- func WithGenAILogFile(path string) WithOption
- func WithGenAILogStream(stream string) WithOption
- func WithGenAIMTP(enabled bool) WithOption
- func WithGenAIStreamingASR() WithOption
- func WithGenerativeEngine() WithOption
- func WithGenerativeEngineImageMarker(marker string) WithOption
- func WithGenerativeEngineMemory(memory GenAIEngineMemoryOptions) WithOption
- func WithGoMLX() WithOption
- func WithGoMLXBatchBuckets(buckets []int) WithOption
- func WithGoMLXSequenceBuckets(buckets []int) WithOption
- func WithGraphOptimizationLevel(level GraphOptimizationLevel) WithOption
- func WithInterOpNumThreads(numThreads int) WithOption
- func WithInterOpSpinning(spinning bool) WithOption
- func WithIntraOpNumThreads(numThreads int) WithOption
- func WithIntraOpSpinning(spinning bool) WithOption
- func WithLogSeverityLevel(level LoggingLevel) WithOption
- func WithMemPattern(enable bool) WithOption
- func WithNvTensorRTRTX(options map[string]string) WithOption
- func WithOnnxLibraryPath(ortLibraryPath string) WithOption
- func WithOpenVINO(options map[string]string) WithOption
- func WithOptimizedModelFilePath(path string) WithOption
- func WithProfiling(enabled bool, filePrefix string) WithOption
- func WithTPU() WithOption
- func WithTelemetry() WithOption
- func WithTensorRT(options map[string]string) WithOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶ added in v0.7.8
type Backend string
Backend identifies the execution backend selected for a session.
type BackendOptions ¶ added in v0.7.8
type BackendOptions interface {
Destroy() error
}
BackendOptions contains backend-owned session state that can be released by the session without exposing a concrete runtime type to the options package.
type ExtraExecutionProvider ¶ added in v0.6.3
type GenAIAdapterConfig ¶ added in v0.8.1
GenAIAdapterConfig names a single LoRA / adapter file to load into the session. Path is the file on disk; Name is the in-session identifier used by SetActiveAdapter.
type GenAIEngineMemoryOptions ¶ added in v0.9.0
type GenAIEngineMemoryOptions struct {
DeviceMemoryBudgetBytes uint64
DeviceMemoryHeadroomBytes uint64
}
GenAIEngineMemoryOptions contains CUDA cache sizing hints, not allocator quotas. Zero values preserve the package settings. Requires engine.dynamic_batching.
type GoMLXOptions ¶ added in v0.4.0
type GoMLXOptions struct {
// BatchBuckets defines the bucket sizes for batch dimension padding.
// Coarse bucketing reduces JIT cache pressure by limiting unique shapes.
// Default: []int{1, 8, 32}
BatchBuckets []int
// SequenceBuckets defines the bucket sizes for sequence length padding.
// Coarse bucketing reduces JIT cache pressure by limiting unique shapes.
// Default: []int{32, 128, 512}
SequenceBuckets []int
Cuda bool
XLA bool
TPU bool
}
type GraphOptimizationLevel ¶ added in v0.6.3
type GraphOptimizationLevel int
const ( GraphOptimizationLevelDisableAll GraphOptimizationLevel = 0 GraphOptimizationLevelEnableBasic GraphOptimizationLevel = 1 GraphOptimizationLevelEnableExtended GraphOptimizationLevel = 2 GraphOptimizationLevelEnableAll GraphOptimizationLevel = 99 )
type LoggingLevel ¶ added in v0.6.3
type LoggingLevel int
const ( LoggingLevelVerbose LoggingLevel = 0 LoggingLevelInfo LoggingLevel = 1 LoggingLevelWarning LoggingLevel = 2 LoggingLevelError LoggingLevel = 3 LoggingLevelFatal LoggingLevel = 4 )
type Options ¶
type Options struct {
BackendOptions BackendOptions
ORTOptions *OrtOptions
GoMLXOptions *GoMLXOptions
Destroy func() error
Backend Backend
UseGoMLX bool
FileSystem fileutil.FileSystem
}
type OrtOptions ¶
type OrtOptions struct {
LibraryPath *string
LibraryDir *string
Telemetry *bool
IntraOpNumThreads *int
InterOpNumThreads *int
CPUMemArena *bool
MemPattern *bool
ParallelExecutionMode *bool
IntraOpSpinning *bool
InterOpSpinning *bool
LogSeverityLevel *LoggingLevel
GraphOptimizationLevel *GraphOptimizationLevel
CudaOptions map[string]string
CoreMLOptions map[string]string
DirectMLOptions *int
OpenVINOOptions map[string]string
TensorRTOptions map[string]string
NvTensorRTRTXOptions map[string]string
OptimizedModelFilePath *string
ProfilingEnabled *bool
ProfilingFilePrefix *string
ExtraExecutionProviders []ExtraExecutionProvider
UseEngine bool
// EngineMemory controls CUDA cache sizing for dynamic batching packages.
EngineMemory GenAIEngineMemoryOptions
// EngineImageMarker is inserted for each image; empty uses Qwen vision markers.
EngineImageMarker string
// UseStreamingASR selects a chunked speech package instead of a chat session.
UseStreamingASR bool
// ── ORT GenAI process-wide controls (session path) ────────────────────
// SetGPUDeviceID sets the process-wide GPU device for ORT GenAI.
GenAIGPUDeviceID *int
// SetLogString("filename", …) — nil disables; empty string resets.
GenAILogFile *string
// SetLogString("stream", …) — "stdout", "stderr", or file path.
GenAILogStream *string
// ── ORT GenAI adapters (session path only) ─────────────────────────────
// Adapters to load after session creation.
GenAIAdapters []GenAIAdapterConfig
// ActiveAdapter selects which loaded adapter is used for inference.
GenAIActiveAdapter *string
// ── ORT GenAI MTP speculative generation (session path only) ───────────
// UseMTP enables MTP (multi-token prediction) speculative generation for
// text-only batches (requires an MTP model under <modelPath>/MTP in the
// ORT GenAI session directory). The native MTP path is greedy:
// Temperature, TopP, Seed, and Guidance are ignored.
UseMTP *bool
}
type WithOption ¶
WithOption is the interface for all option functions.
func WithCPUMemArena ¶ added in v0.5.9
func WithCPUMemArena(enable bool) WithOption
WithCPUMemArena (ORT only) Enable/Disable the usage of the memory arena on CPU. Arena may pre-allocate memory for future usage. Default is true.
func WithCoreML ¶
func WithCoreML(flags map[string]string) WithOption
WithCoreML (ORT only) Use this function to set the CoreML options flags for the ONNX backend configuration. The `flags` parameter represents the CoreML options flags. The `o.CoreMLOptions` field in `OrtOptions` struct will be set to the provided flags parameter.
func WithCuda ¶
func WithCuda(options map[string]string) WithOption
WithCuda Use this function to set the options for CUDA provider. It takes a map of CUDA parameters as input. The options will be applied to the OrtOptions or GoMLXOptions struct, depending on your current backend.
func WithDirectML ¶
func WithDirectML(deviceID int) WithOption
WithDirectML (ORT only) Use this function to set the DirectML device ID for the onnxbackend. By default, this option is not set.
func WithExecutionMode ¶ added in v0.3.1
func WithExecutionMode(parallel bool) WithOption
WithExecutionMode sets the parallel execution mode for the ORT backend. Returns an error if the backend is not ORT.
func WithExtraExecutionProvider ¶ added in v0.6.3
func WithExtraExecutionProvider(name string, options map[string]string) WithOption
WithExtraExecutionProvider (ORT only) Adds an extra execution provider to the session.
func WithFileSystem ¶ added in v0.7.8
func WithFileSystem(system fileutil.FileSystem) WithOption
WithFileSystem scopes storage operations to the session being created. It avoids changing package-global state and is safe for concurrent sessions.
func WithGenAIActiveAdapter ¶ added in v0.8.1
func WithGenAIActiveAdapter(name string) WithOption
WithGenAIActiveAdapter (ORT only, session path) selects which loaded adapter is used for inference. Must match the Name field of one of the adapters configured via WithGenAIAdapters.
func WithGenAIAdapters ¶ added in v0.8.1
func WithGenAIAdapters(adapters ...GenAIAdapterConfig) WithOption
WithGenAIAdapters (ORT only, session path) names LoRA / adapter files to load after session creation. ActiveAdapter selects which loaded adapter is used for inference.
func WithGenAIGPUDeviceID ¶ added in v0.8.1
func WithGenAIGPUDeviceID(deviceID int) WithOption
WithGenAIGPUDeviceID (ORT only, session path) sets the process-wide GPU device for ORT GenAI. Must be called before the first session is created.
func WithGenAILogFile ¶ added in v0.8.1
func WithGenAILogFile(path string) WithOption
WithGenAILogFile (ORT only, session path) sets the ORT GenAI log file path (process-wide). Pass an empty string to reset to the default log file.
func WithGenAILogStream ¶ added in v0.8.1
func WithGenAILogStream(stream string) WithOption
WithGenAILogStream (ORT only, session path) sets the ORT GenAI log output stream (process-wide). Accepts "stdout", "stderr", or a file path.
func WithGenAIMTP ¶ added in v0.8.1
func WithGenAIMTP(enabled bool) WithOption
WithGenAIMTP (ORT only, session path) enables opt-in MTP (multi-token prediction) speculative generation for text-only batches. The session must ship an MTP model under <modelPath>/MTP; the native path is greedy, so Temperature, TopP, Seed, and Guidance are ignored. MTP is dispatched at generation time and is not supported by the generative engine path.
func WithGenAIStreamingASR ¶ added in v0.9.0
func WithGenAIStreamingASR() WithOption
WithGenAIStreamingASR selects a local streaming speech package. Each audio stream owns its native state. Configure PCM chunk size and VAD on the ASR pipeline.
func WithGenerativeEngine ¶ added in v0.7.1
func WithGenerativeEngine() WithOption
WithGenerativeEngine uses the ORT GenAI request engine for concurrent text or image generation. Images require an Engine-compatible vision export. Session-specific execution-provider options are not supported.
func WithGenerativeEngineImageMarker ¶ added in v0.9.0
func WithGenerativeEngineImageMarker(marker string) WithOption
WithGenerativeEngineImageMarker sets the model-specific marker for each image and enables engine mode. The default is <|vision_start|><|image_pad|><|vision_end|>.
func WithGenerativeEngineMemory ¶ added in v0.9.0
func WithGenerativeEngineMemory(memory GenAIEngineMemoryOptions) WithOption
WithGenerativeEngineMemory sets the engine's CUDA cache sizing hints and enables engine mode.
func WithGoMLX ¶ added in v0.7.8
func WithGoMLX() WithOption
WithGoMLX (ORT only) uses GoMLX with ONNX Runtime as the execution backend.
func WithGoMLXBatchBuckets ¶ added in v0.6.1
func WithGoMLXBatchBuckets(buckets []int) WithOption
WithGoMLXBatchBuckets (XLA and GO only) sets the bucket sizes for batch dimension padding. Inputs are padded to the smallest bucket >= their batch size. Fewer/coarser buckets reduce JIT cache pressure but increase padding overhead. Default is []int{1, 8, 32}. IMPORTANT: Ensure MaxCache >= len(BatchBuckets) * len(SequenceBuckets).
func WithGoMLXSequenceBuckets ¶ added in v0.6.1
func WithGoMLXSequenceBuckets(buckets []int) WithOption
WithGoMLXSequenceBuckets (XLA and GO only) sets the bucket sizes for sequence length padding. Inputs are padded to the smallest bucket >= their sequence length. Fewer/coarser buckets reduce JIT cache pressure but increase padding overhead. Default is []int{32, 128, 512}. IMPORTANT: Ensure MaxCache >= len(BatchBuckets) * len(SequenceBuckets).
func WithGraphOptimizationLevel ¶ added in v0.6.3
func WithGraphOptimizationLevel(level GraphOptimizationLevel) WithOption
WithGraphOptimizationLevel (ORT only) Sets the graph optimization level for the session.
func WithInterOpNumThreads ¶
func WithInterOpNumThreads(numThreads int) WithOption
WithInterOpNumThreads (ORT only) Sets the number of threads used to parallelize execution across separate onnxbackend graph nodes. If unspecified, onnxbackend uses the number of physical CPU cores.
func WithInterOpSpinning ¶ added in v0.3.1
func WithInterOpSpinning(spinning bool) WithOption
WithInterOpSpinning sets the spinning behavior for inter-op threads when the backend is ORT. It returns an error if used with a backend other than ORT.
func WithIntraOpNumThreads ¶
func WithIntraOpNumThreads(numThreads int) WithOption
WithIntraOpNumThreads (ORT only) Sets the number of threads used to parallelize execution within onnxbackend graph nodes. If unspecified, onnxbackend uses the number of physical CPU cores.
func WithIntraOpSpinning ¶ added in v0.3.1
func WithIntraOpSpinning(spinning bool) WithOption
WithIntraOpSpinning configures whether intra-op spinning is enabled for the ORT backend. It returns an error if used with a backend other than ORT.
func WithLogSeverityLevel ¶ added in v0.6.3
func WithLogSeverityLevel(level LoggingLevel) WithOption
WithLogSeverityLevel (ORT only) Sets the log severity level for the session.
func WithMemPattern ¶
func WithMemPattern(enable bool) WithOption
WithMemPattern (ORT only) Enable/Disable the memory pattern optimization. If this is enabled memory is preallocated if all shapes are known. Default is true.
func WithNvTensorRTRTX ¶ added in v0.6.3
func WithNvTensorRTRTX(options map[string]string) WithOption
WithNvTensorRTRTX (ORT only) Use this function to set the options for the NvTensorRTRTX provider. The options parameter should be a pointer to an instance of NvTensorRTRTXOptions. By default, the options will be nil and the NvTensorRTRTX provider will not be used. Example usage:
WithNvTensorRTRTX(map[string]string{"device_id": "0"})
Note: For the TensorRT provider to work, the onnxbackend library must be built with TensorRT support.
func WithOnnxLibraryPath ¶
func WithOnnxLibraryPath(ortLibraryPath string) WithOption
WithOnnxLibraryPath (ORT only) Use this function to set the path to the "libonnxuntime.so", "libonnxuntime.dylib" or "onnxruntime.dll" files.
func WithOpenVINO ¶
func WithOpenVINO(options map[string]string) WithOption
WithOpenVINO (ORT only) Use this function to set the OpenVINO options for the OpenVINO execution provider. The options parameter should be a map of string keys and string values, representing the configuration options. For each key-value pair in the map, the specified option will be set in the OpenVINO execution provider. Example usage: WithOpenVINO(map[string]string{"device_type": "CPU", "num_threads": "4"}) This will configure the OpenVINO execution provider to use CPU as the device type and set the number of threads to 4.
func WithOptimizedModelFilePath ¶ added in v0.6.5
func WithOptimizedModelFilePath(path string) WithOption
WithOptimizedModelFilePath (ORT only) Sets the path to the optimized model file.
func WithProfiling ¶ added in v0.6.5
func WithProfiling(enabled bool, filePrefix string) WithOption
WithProfiling (ORT only) Enables or disables profiling.
func WithTPU ¶ added in v0.6.0
func WithTPU() WithOption
WithTPU (XLA only) Use this function to enable TPU acceleration for the XLA backend. Requires libtpu.so to be available (pre-installed on GKE TPU nodes). Set PJRT_PLUGIN_LIBRARY_PATH to the directory containing pjrt_plugin_tpu.so or libtpu.so.
func WithTelemetry ¶
func WithTelemetry() WithOption
WithTelemetry (ORT only) Enables telemetry events for the onnxbackend environment. Default is off.
func WithTensorRT ¶
func WithTensorRT(options map[string]string) WithOption
WithTensorRT (ORT only) Use this function to set the options for the TensorRT provider. The options parameter should be a pointer to an instance of TensorRTProviderOptions. By default, the options will be nil and the TensorRT provider will not be used. Example usage:
WithTensorRT(map[string]string{"device_id": "0"})
Note: For the TensorRT provider to work, the onnxbackend library must be built with TensorRT support.