runntime 0.0.1-alpha.0 → 0.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,170 @@
1
- # runntime
1
+ <div align="center">
2
+ <h1>ruNNtime</h1>
3
+ <p><strong>AI models on the web, built with TypeGPU.</strong></p>
4
+ </div>
2
5
 
3
- Placeholder release. Real package coming soon.
6
+ <br />
7
+
8
+ **ruNNtime** is a framework for running AI models on the user's own GPU,
9
+ implemented using TypeGPU. It composes GPU kernels into the layers a model is
10
+ made of, attention, convolutions, norms, matmuls and builds common
11
+ architectures out of them. The kernels are plain TypeGPU code compiled to
12
+ WGSL at runtime, so there is no WASM binary to download, and
13
+ the same code runs anywhere WebGPU does: the browser, React Native and
14
+ Electron.
15
+
16
+ It ships as one package, `runntime`, with two entry points:
17
+
18
+ - **`runntime/zoo`** - ready-to-run model implementations for commonly used tasks: speech, vision, and natural language processing. You call a single function, and get a running model.
19
+ - **`runntime/core`** - this package is not yet exposed to the public. It is a set of pre-built kernels for building neural networks on the Web, mirroring PyTorch semantics.
20
+
21
+ ## Table of Contents
22
+
23
+ - [Key Features](#key-features)
24
+ - [Quickstart](#quickstart)
25
+ - [1. Installation](#1-installation)
26
+ - [2. Set up the engine](#2-set-up-the-engine)
27
+ - [3. Run a model](#3-run-a-model)
28
+ - [Documentation](#documentation)
29
+ - [Migrating from transformers.js](#coming-from-transformers.js)
30
+ - [Created by Software Mansion](#created-by-software-mansion)
31
+
32
+ ## Key Features
33
+
34
+ - **One function per task** - `createObjectDetector()` hands you a loaded
35
+ model. Call `detectObjects(image)`, get boxes back. The `zoo` api is meant to be straight-forward and just work.
36
+ - **No WASM to download** - the kernels are TypeGPU code compiled
37
+ to WGSL at runtime, so there is no WASM binary shipped alongside your
38
+ app.
39
+ - **Same code everywhere WebGPU runs** - the browser, React Native (through
40
+ [react-native-webgpu](https://github.com/wcandillon/react-native-webgpu))
41
+ and Electron.
42
+ - **Weights come from the Hub** - every model points at a
43
+ [software-mansion repo](https://huggingface.co/software-mansion). Turn on the OPFS cache and the second load skips the download.
44
+ - **Drop-in for transformers.js** - keep your `pipeline()` code, swap the
45
+ backend underneath.
46
+
47
+ ## Quickstart
48
+
49
+ ### 1. Installation
50
+
51
+ ```bash
52
+ npm install runntime
53
+ # or
54
+ pnpm add runntime
55
+ # or
56
+ yarn add runntime
57
+ ```
58
+
59
+ ruNNtime is built on [TypeGPU](https://docs.swmansion.com/TypeGPU/), so you need it
60
+ installed. The kernels are already compiled to shaders in the published package, so
61
+ no bundler plugin is required. Follow the
62
+ [TypeGPU installation guide](https://docs.swmansion.com/TypeGPU/getting-started/).
63
+
64
+ > [!IMPORTANT]
65
+ > ruNNtime needs WebGPU:
66
+ >
67
+ > - **Web** - Chrome, Edge, Safari 26 and newer, recent Firefox. See
68
+ > [caniuse](https://caniuse.com/webgpu).
69
+ > - **Electron** - ships Chromium, so the web setup works as is.
70
+ > - **React Native** - through `react-native-webgpu`. Call its
71
+ > `installWebGPU()`, request the device yourself and wrap it with
72
+ > `tgpu.initFromDevice({ device })`.
73
+ >
74
+ > Object detection, instance segmentation, pose, depth estimation and image
75
+ > classification run in half precision and need the `shader-f16` feature.
76
+ > Text embedding, speech to text and the privacy filter can run on
77
+ > devices without it.
78
+
79
+ ### 2. Set up the engine
80
+
81
+ Once per page, before you create any model:
82
+
83
+ ```ts
84
+ import { initRunntime } from 'runntime/zoo';
85
+ import tgpu from 'typegpu';
86
+
87
+ initRunntime(await tgpu.init({ device: { optionalFeatures: ['subgroups', 'shader-f16'] } }));
88
+ ```
89
+
90
+ Both features are optional, so the call succeeds on devices without them.
91
+ Many kernels are much faster with `subgroups`. If your app already uses
92
+ TypeGPU, pass the root you have.
93
+
94
+ ### 3. Run a model
95
+
96
+ ```ts
97
+ import { createObjectDetector, imageBufferFromImageData, models } from 'runntime/zoo';
98
+
99
+ // Load the model once. The weights download from the Hugging Face Hub.
100
+ const detector = await createObjectDetector(models.objectDetection.YOLO26.DEFAULT);
101
+
102
+ // Get the pixels, here from a canvas the picture is drawn on.
103
+ const ctx = canvas.getContext('2d');
104
+ const image = imageBufferFromImageData(ctx.getImageData(0, 0, canvas.width, canvas.height));
105
+
106
+ // Find the objects: one entry per object, best first.
107
+ const objects = await detector.detectObjects(image);
108
+ for (const { label, confidence, box } of objects) {
109
+ console.log(label, confidence, box);
110
+ }
111
+ // bus 0.93 { format: 'xyxy', xmin: 6, ymin: 228, xmax: 807, ymax: 749 }
112
+ // person 0.92 { format: 'xyxy', xmin: 47, ymin: 399, xmax: 237, ymax: 902 }
113
+
114
+ // Free the GPU memory when done.
115
+ detector.dispose();
116
+ ```
117
+
118
+ A video or a camera works the same way: draw each frame on the canvas and
119
+ call `detectObjects` again. The detector is loaded once.
120
+
121
+ ## Models
122
+
123
+ Every task has its own factory function and its own methods. Pass it an entry
124
+ from `models`, or spread one and change a field.
125
+
126
+ | Task | Factory | Models |
127
+ | --------------------- | ------------------------- | ------------------------------------- |
128
+ | Text embedding | `createTextEmbedder` | all-MiniLM-L6-v2 |
129
+ | Privacy filter | `createPrivacyFilter` | OpenAI privacy-filter (int8) |
130
+ | Speech to text | `createSpeechToText` | Moonshine tiny / base, streaming tiny |
131
+ | Object detection | `createObjectDetector` | YOLO26 n / m |
132
+ | Instance segmentation | `createInstanceSegmenter` | YOLO26-seg n / m |
133
+ | Pose & keypoints | `createKeypointDetector` | YOLO26-pose n / m |
134
+ | Depth estimation | `createDepthEstimator` | DepthART s / b |
135
+ | Image classification | `createImageClassifier` | MobileNetV4 small |
136
+
137
+ ## Coming from transformers.js
138
+
139
+ Already on transformers.js and don't want to move your whole codebase? Keep
140
+ your `pipeline()` code and swap the engine underneath. By default
141
+ transformers.js runs on ONNX Runtime, which pays for its generality in
142
+ speed. One `initRunntimeBackend()` call replaces that backend with ruNNtime.
143
+ It only changes anything for the models ruNNtime supports, everything else
144
+ keeps loading on ONNX Runtime.
145
+
146
+ ```ts
147
+ import { initRunntimeBackend } from 'runntime/zoo/transformers';
148
+ import { pipeline } from '@huggingface/transformers';
149
+
150
+ await initRunntimeBackend({ fallbackToOnnx: true });
151
+
152
+ const pipe = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2');
153
+ ```
154
+
155
+ ## Documentation
156
+
157
+ Full docs live at
158
+ [docs.swmansion.com/runntime](https://docs.swmansion.com/runntime) - a guide
159
+ per task, and some cool interactive examples you can run in the
160
+ browser on your own GPU.
161
+
162
+ ## Created by Software Mansion
163
+
164
+ Since 2012, [Software Mansion](https://swmansion.com) has been building
165
+ mobile and web apps, contributing to open-source software, and dealing with
166
+ all kinds of React Native and graphics challenges. We are Core React Native
167
+ Contributors and the authors of TypeGPU. We can help you build your next AI
168
+ product – [Hire us](https://swmansion.com/contact?utm_source=runntime&utm_medium=readme).
169
+
170
+ [![swm](https://logo.swmansion.com/logo?color=white&variant=desktop&width=150&tag=runntime-github 'Software Mansion')](https://swmansion.com)