timesfm-ts - v1.0.0
    Preparing search index...

    Class TimesFMWebInferenceEngine

    Browser-compatible inference engine backed by onnxruntime-web.

    Supports WASM, WebGPU, and WebGL backends with automatic fallback. Accepts model URLs (fetched) or pre-loaded ArrayBuffers.

    Implements

    • IInferenceEngine
    Index

    Constructors

    • Parameters

      • config: ModelConfig

        Model architecture configuration.

      • executionProviders: ("webgpu" | "wasm" | "webgl")[] = ...

        Execution providers to try, in order. Default: ['webgpu', 'wasm']

      • cdnVersion: string = '1.22.0'

        onnxruntime-web CDN version for browser WASM fallback. Default: matches the package's peerDependency version.

      • Optionallogger: WebEngineLogger

        Optional structured logger for diagnostics. When omitted, provider selection messages are silenced (only the final loaded provider is logged).

      Returns TimesFMWebInferenceEngine

    Methods

    • Set a custom WASM binary path for onnxruntime-web.

      Required when running in Node.js (not a browser) since the default CDN URL won't work. Point this to the dist/ directory of the onnxruntime-web package.

      Parameters

      • wasmPath: string

      Returns void

      // In Node.js testing:
      import { createRequire } from 'node:module';
      const require = createRequire(import.meta.url);
      const wasmDir = require.resolve('onnxruntime-web').replace('/lib/index.js', '/dist/');
      engine.setWasmPath(wasmDir);
    • Load the ONNX model.

      Parameters

      • modelPath: string | ArrayBuffer

        URL to the ONNX model file, or an ArrayBuffer.

      • Optionaloptions: { skipWarmup?: boolean }

      Returns Promise<void>

    • Run inference for a batch of patched time series.

      Aligned with TimesFMNodeEngine.forward: each batch element is processed sequentially via the ONNX session and results are returned as per-element arrays in the RawModelOutput.

      Builds the tokenizer input identically to the Node.js engine: each 64-dim patch is [patch_values(32), patch_mask(32)] where mask=0 means "visible" and mask=1 means "padding/ignored".

      Parameters

      • inputs: Float32Array<ArrayBufferLike>[]
      • masks: Uint8Array<ArrayBufferLike>[]

      Returns Promise<RawModelOutput>