Config Module
The Config module centralises ONNX Runtime (ORT) configuration so WASM paths stay flexible and never hard-coded. It provides a simple API for configuring ORT WASM file locations and ensures configuration is applied even when ORT loads asynchronously.
Overview
- Configure ONNX Runtime WASM locations – Set single or multiple fallback paths
- Initialize the ORT environment – Apply configuration before loading ONNX models
- Delayed configuration – Automatically applies configuration when ORT loads asynchronously
- Default paths – Provides sensible defaults for development
Quick Start
import {
initOrtEnvironment,
setOrtWasmPaths,
getDefaultOrtWasmPaths
} from 'src/config';
// Option 1: Use default paths
const wasmPaths = getDefaultOrtWasmPaths(); // '/src/ort/'
initOrtEnvironment(wasmPaths);
// Option 2: Configure custom paths
setOrtWasmPaths('/custom/ort/path/');
initOrtEnvironment();
// Option 3: Multiple fallback paths
setOrtWasmPaths([
'https://cdn.example.com/ort/',
'/local/cache/ort/',
'/src/ort/' // Fallback
]);
initOrtEnvironment();
When to Use It
- Customize ONNX Runtime WASM file locations (CDN, local mirrors, etc.)
- Ensure ORT loads with correct paths in both dev and production environments
- Handle asynchronous ORT loading – Configuration is applied automatically when ORT becomes available
- Integration with App module – Called automatically during
App.init()before WebGPU initialization
Integration with App Module
The Config module is automatically used by the App module during initialization:
// In App.init()
const wasmPaths = getDefaultOrtWasmPaths();
initOrtEnvironment(wasmPaths);
console.log(`[App] Initialized ORT environment with paths: ${wasmPaths}`);
This ensures ORT is properly configured before: - WebGPU initialization (which may share device with ORT) - ONNX model loading - Dynamic point cloud inference
Key Features
- Flexible Path Configuration – Single string or array of fallback paths
- Automatic Delayed Application – Polls for ORT availability if not yet loaded
- Non-blocking – Uses setTimeout polling (50ms intervals) to avoid blocking main thread
- Default Paths – Provides
/src/ort/as default for development - Configuration State Checking –
isOrtConfigured()verifies if ORT is ready
Related Docs
- Architecture – Sequence diagrams for ORT initialization and delayed configuration.
- API Reference – Function-by-function description of the config helpers.
- App Module – Shows where
initOrtEnvironmentis invoked during startup. - ONNX Module – Explains how ORT configuration impacts WebGPU inference.