npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@unrdf/ml-inference

v26.4.8

Published

UNRDF ML Inference - High-performance ONNX model inference pipeline for RDF streams

Downloads

634

Readme

@unrdf/ml-inference

High-performance machine learning inference pipeline for RDF streams using ONNX Runtime.

Features

  • ONNX Runtime Integration: Native ONNX model execution with GPU support
  • Streaming Inference: Process RDF change feeds with automatic batching
  • Model Registry: Version management, A/B testing, and hot-swapping
  • Performance Optimized: Batching, backpressure handling, and metrics tracking
  • Production Ready: OpenTelemetry instrumentation and error handling

Installation

pnpm add @unrdf/ml-inference

Quick Start

Basic Inference

import { createONNXRunner } from '@unrdf/ml-inference';

const runner = createONNXRunner({
  executionProviders: ['cpu'], // or ['cuda', 'cpu'] for GPU
});

await runner.loadModel('./models/classifier.onnx');

const result = await runner.infer({
  input: new Float32Array([1.0, 2.0, 3.0])
});

Streaming Pipeline

import { createONNXRunner, createStreamingInferencePipeline } from '@unrdf/ml-inference';

const runner = createONNXRunner();
await runner.loadModel('./model.onnx');

const pipeline = createStreamingInferencePipeline(runner, {
  batchSize: 32,
  batchTimeoutMs: 100,
  enableBackpressure: true
});

// Subscribe to results
pipeline.subscribe((batch) => {
  console.log('Batch results:', batch);
});

// Stream data
for (const item of dataStream) {
  await pipeline.process({
    id: item.id,
    features: item.data
  });
}

Model Registry

import { createModelRegistry } from '@unrdf/ml-inference';

const registry = createModelRegistry();

// Register models
await registry.register('v1.0', './model-v1.onnx', {
  name: 'classifier',
  accuracy: 0.85
});

await registry.register('v2.0', './model-v2.onnx', {
  name: 'classifier',
  accuracy: 0.92
});

// Canary deployment (10% traffic to v2.0)
await registry.deploy('v2.0', 'canary', 10);

// Promote if successful
registry.promoteCanary();

Architecture

┌─────────────────────────────────────────────────────────┐
│                 ML Inference Pipeline                   │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  ┌──────────────┐    ┌──────────────┐   ┌───────────┐ │
│  │ RDF Stream   │───▶│  Batching    │──▶│  ONNX     │ │
│  │ Input        │    │  Pipeline    │   │  Runtime  │ │
│  └──────────────┘    └──────────────┘   └───────────┘ │
│         │                   │                  │       │
│         ▼                   ▼                  ▼       │
│  ┌──────────────────────────────────────────────────┐ │
│  │           Model Registry                         │ │
│  │  - Version Management                            │ │
│  │  - A/B Testing                                   │ │
│  │  - Hot-swapping                                  │ │
│  └──────────────────────────────────────────────────┘ │
│                                                         │
└─────────────────────────────────────────────────────────┘

Performance

Typical throughput on commodity hardware:

  • Single inference: 2-5ms latency
  • Batch inference (32): 500-2000 inferences/sec
  • Streaming pipeline: 1000-5000 items/sec (batch size 32)
  • GPU acceleration: 5-10x improvement with CUDA

API Reference

ONNXRunner

createONNXRunner(options)

Create ONNX inference runner.

Options:

  • executionProviders: Array of providers (e.g., ['cuda', 'cpu'])
  • graphOptimizationLevel: 'disabled' | 'basic' | 'extended' | 'all'
  • enableCpuMemArena: Boolean (default: true)

runner.loadModel(pathOrBuffer)

Load ONNX model from file or buffer.

runner.infer(inputs, batchSize?)

Run inference on input tensors.

runner.inferBatch(batchInputs)

Run batched inference for multiple samples.

runner.getMetrics()

Get performance metrics (throughput, latency).

StreamingInferencePipeline

createStreamingInferencePipeline(runner, options)

Create streaming inference pipeline.

Options:

  • batchSize: Number of items per batch (default: 32)
  • batchTimeoutMs: Max wait time for partial batch (default: 100)
  • maxQueueSize: Maximum queue size (default: 1000)
  • enableBackpressure: Enable backpressure handling (default: true)

pipeline.process(item)

Process single item through pipeline.

pipeline.subscribe(callback)

Subscribe to inference results.

pipeline.flush()

Flush remaining buffer.

ModelRegistry

createModelRegistry()

Create model version registry.

registry.register(version, modelPath, metadata, options?)

Register new model version.

registry.deploy(version, strategy?, canaryPercent?)

Deploy model with strategy ('immediate', 'blue-green', 'canary').

registry.getRunner()

Get runner for inference (handles A/B routing).

Examples

Run the demo:

cd packages/ml-inference
pnpm demo

Testing

pnpm test
pnpm test:coverage

Performance Tuning

Batch Size

Larger batches = higher throughput, higher latency:

// Low latency (real-time)
{ batchSize: 1, batchTimeoutMs: 10 }

// Balanced
{ batchSize: 32, batchTimeoutMs: 100 }

// High throughput
{ batchSize: 128, batchTimeoutMs: 500 }

Execution Providers

// CPU only
{ executionProviders: ['cpu'] }

// GPU with CPU fallback
{ executionProviders: ['cuda', 'cpu'] }

// TensorRT (NVIDIA)
{ executionProviders: ['tensorrt', 'cuda', 'cpu'] }

License

MIT