Workbench Context Provider
Relevant source files
The following files were used as context for generating this wiki page:
The Workbench Context Provider is the central state management hub for the ONNX-Station application. It utilizes the React Context API to provide a unified interface for model export configurations, benchmarking execution, logging, and model metadata across the component tree. It orchestrates the lifecycle of model ingestion—whether from the Hugging Face Hub or local files—and manages the transition between configuration, compilation, and performance evaluation.
By encapsulating the ExportConfig and the execution logic for the optimum-cli command generation, the provider ensures that the UI components, such as the Sidebar and CenterCanvas, remain synchronized with the underlying export parameters and benchmark results.
Sources: src/WorkbenchContext.tsx:1-120, src/App.tsx:13-26
Architecture and Data Flow
The provider maintains the global state within WorkbenchProvider and exposes it via the useWorkbench hook. The data flow primarily revolves around updating the ExportConfig object, which triggers simulated export sequences or live benchmarks using ONNX Runtime Web.
State Management Flow
The following diagram illustrates how user interactions trigger state updates and external process simulations:
The WorkbenchContext acts as the intermediary between user input and the heavy-lifting logic found in the benchmark library and model info utilities.
Sources: src/WorkbenchContext.tsx:84-130, src/lib/benchmark.ts:133-255
Key Components and Data Structures
Export Configuration (ExportConfig)
The ExportConfig interface defines the parameters used to generate the optimum-cli export command and configure the runtime environment.
| Field | Type | Description |
|---|---|---|
modelSourceType | 'hub' | 'local' | Determines if the model is fetched from Hugging Face or loaded from browser memory. |
modelPath | string | The Hugging Face Repo ID or the local filename. |
modality | Modality | Categorizes the model as 'audio', 'text', or 'vision'. |
task | string | The specific Optimum task (e.g., 'causal-lm', 'automatic-speech-recognition'). |
opset | number | The target ONNX operator set version (14, 15, or 17). |
optimize | string | Graph optimization level from 'none' to 'O4'. |
dtype | string | Precision format: 'fp32', 'fp16', or 'bf16'. |
Sources: src/types.ts:31-63
System Presets
The context includes SYSTEM_PRESETS, which are pre-defined optimization profiles for common hardware targets.
export const SYSTEM_PRESETS: Record<string, Partial<ExportConfig>> = {
'WebGPU fp16 Target': {
opset: 17,
device: 'cuda',
dtype: 'fp16',
optimize: 'O3',
monolith: false,
use_safetensors: true,
},
'CPU fp32 Portable': {
opset: 14,
device: 'cpu',
dtype: 'fp32',
optimize: 'O1',
monolith: true,
}
};
Sources: src/WorkbenchContext.tsx:5-40
Core Logic and Functional Modules
Model Export Simulation
The startExport function simulates the multi-step process of model compilation. It uses a setInterval to push progress logs to the console and finally generates a CompiledModelInfo object using generateCompiledModelInfo.
- Environment Initialization: Resolves execution providers based on selected device (CPU/CUDA).
- Architecture Mapping: Traces operations and maps them to the specified ONNX opset.
- Structural Validation: Checks for issues like missing fused attention support or unbounded sequence lengths.
Sources: src/WorkbenchContext.tsx:189-270, src/utils/modelInfo.ts:10-40
Benchmark Orchestration
The benchmarking system utilizes onnxruntime-web to execute performance tests.
Local File Ingestion
The provider supports "Local-First" model ingestion. When a user provides a file via the Sidebar, the context creates an object URL and updates the modelPath. This allows the Benchmark Runner to fetch the model bytes directly from the browser's memory-mapped sandbox.
Sources: src/WorkbenchContext.tsx:132-150, src/components/Sidebar.tsx:112-160
Log Registry and Telemetry
The context maintains a LogEntry[] array that acts as the application's orchestration log. Logs are categorized into levels: info, warn, error, and success. The Console component consumes this state to provide real-time feedback during exports and benchmarks.
Sources: src/WorkbenchContext.tsx:111-125, src/components/Console.tsx:1-50
Summary
The Workbench Context Provider serves as the architectural backbone of ONNX-Station, managing the complex state transitions required for model optimization. It provides a robust set of tools for developers to configure exports, simulate compilation workflows, and measure real-world performance using browser-native technologies like WebGPU and WASM via ONNX Runtime.