Observed since 20 Oct, 17:49 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Run BitNet b1.58 ternary LLMs with WebGPU
Run Microsoft BitNet b1.58 ternary LLMs with WebGPU — in browsers and native apps.
Live Chat Demo · TL;DR Widget Demo · Getting Started · API Reference
0xBitNet runs BitNet b1.58 ternary LLMs on WebGPU. Custom WGSL compute kernels handle the ternary matrix operations, with bindings for TypeScript, Rust, and Python. Works in browsers, Node.js, and native apps.
0xbitnet), Rust (oxbitnet), Python (oxbitnet), Swift (OxBitNet), Java/Android (oxbitnet-java), C (oxbitnet-ffi)npm install 0xbitnet
import { BitNet } from "0xbitnet";
const model = await BitNet.load(
"https://huggingface.co/microsoft/bitnet-b1.58-2B-4T-gguf/resolve/main/ggml-model-i2_s.gguf",
{ onProgress: (p) => console.log(`${p.phase}: ${(p.fraction * 100).toFixed(1)}%`) }
);
for await (const token of model.generate("The meaning of life is")) {
process.stdout.write(token);
}
model.dispose();
cargo add oxbitnet
use oxbitnet::BitNet;
use futures::StreamExt;
let mut model = BitNet::load("model.gguf", Default::default()).await?;
let mut stream = model.generate("Hello!", Default::default());
while let Some(token) = stream.next().await {
print!("{token}");
}
model.dispose();
pip install oxbitnet
from oxbitnet import BitNet
model = BitNet.load_sync("model.gguf")
model.chat(
[("system", "You are a helpful assistant."), ("user", "Hello!")],
on_token=lambda t: print(t, end="", flush=True),
temperature=0.7,
)
model.dispose()
import OxBitNet
let model = try await BitNet.load("model.gguf")
for try await token in model.chat([.user("Hello!")], options: .init(temperature: 0.7)) {
print(token, terminator: "")
}
model.dispose()
import io.github.m96chan.oxbitnet.*;
import java.util.List;
try (BitNet model = BitNet.loadSync("model.gguf")) {
model.chat(
List.of(new ChatMessage("user", "Hello!")),
token -> {
System.out.print(token);
return true;
},
new GenerateOptions().temperature(0.7f)
);
}
#include "oxbitnet.h"
static int32_t on_token(const char *token, uintptr_t len, void *userdata) {
fwrite(token, 1, len, stdout);
return 0; /* 0 = continue, non-zero = stop */
}
int main(void) {
OxBitNet *model = oxbitnet_load("model.gguf", NULL);
OxBitNetChatMessage messages[] = {
{ .role = "user", .content = "Hello!" },
};
OxBitNetGenerateOptions opts = oxbitnet_default_generate_options();
oxbitnet_chat(model, messages, 1, &opts, on_token, NULL);
oxbitnet_free(model);
}
const messages = [
{ role: "system" as const, content: "You are a helpful assistant." },
{ role: "user" as const, content: "Explain quantum computing in one sentence." },
];
for await (const token of model.generate(messages, { maxTokens: 128, temperature: 0.7 })) {
process.stdout.write(token);
}
| Model | GGUF | Parameters | VRAM |
|---|---|---|---|
| BitNet b1.58 2B-4T | ggml-model-i2_s.gguf | 2B | ~1.5 GB |
| Falcon-E 1B Instruct | ggml-model-i2_s.gguf | 1B | ~666 MB |
| Falcon-E 3B Instruct | ggml-model-i2_s.gguf | 3B | ~1 GB |
Any I2_S GGUF model with a compatible architecture should work — see Model Compatibility for details.
| Language | Package | Install |
|---|---|---|
| TypeScript / JS | 0xbitnet | npm install 0xbitnet |
| Rust | oxbitnet | cargo add oxbitnet |
| Python | oxbitnet | pip install oxbitnet |
| Swift / iOS | OxBitNet | Swift Package Manager (see oxbitnet-swift) |
| Java / Android | oxbitnet-java | cargo build -p oxbitnet-java --release |
| C / FFI | oxbitnet-ffi | cargo build -p oxbitnet-ffi --release |
| Method | Description |
|---|---|
BitNet.load(url, options?) | Load a GGUF model from a URL |
bitnet.generate(prompt, options?) | Stream tokens as an AsyncGenerator<string> |
bitnet.diagnose(prompt?) | Run GPU diagnostics on a forward pass |
bitnet.dispose() | Release all GPU resources |
| Method | Description |
|---|---|
BitNet::load(source, options).await | Load a GGUF model |
bitnet.generate(prompt, options) | Stream tokens as impl Stream<Item = String> |
bitnet.generate_chat(messages, options) | Chat with template formatting |
bitnet.dispose() | Release all GPU resources |
| Method | Description |
|---|---|
BitNet.load_sync(source) | Load a GGUF model |
model.chat(messages, on_token) | Chat with streaming callback |
model.generate(prompt, on_token) | Generate with streaming callback |
model.generate_sync(prompt) | Generate, return full string |
model.dispose() | Release all GPU resources |
| Method | Description |
|---|---|
BitNet.load(source, options:) | Load a GGUF model (async) |
BitNet.loadSync(source, options:) | Load a GGUF model (blocking) |
model.generate(prompt, options:) | Stream tokens as AsyncThrowingStream<String, Error> |
model.chat(messages, options:) | Chat with streaming via AsyncThrowingStream |
model.dispose() | Release all GPU resources (also called by deinit) |
| Method | Description |
|---|---|
BitNet.loadSync(source, options?) | Load a GGUF model |
model.chat(messages, callback, options?) | Chat with streaming callback |
model.generate(prompt, callback, options?) | Generate with streaming callback |
model.dispose() / model.close() | Release all GPU resources (AutoCloseable) |
| Function | Description |
|---|---|
oxbitnet_load(source, options) | Load a GGUF model, returns opaque handle |
oxbitnet_chat(model, messages, n, opts, cb, ud) | Chat with streaming callback |
oxbitnet_generate(model, prompt, opts, cb, ud) | Generate with streaming callback |
oxbitnet_free(model) | Release all GPU resources |
oxbitnet_error_message() | Get last error (thread-local) |
0xBitNet runs on any platform with a WebGPU implementation:
Browsers:
Native (Rust / Python):
Native (Node.js / Deno):
webgpu npm package (Dawn bindings) — see Node.js CLI exampleA dedicated GPU with sufficient VRAM is required (see Supported Models for estimates).
A WebGPU-powered chat application. Downloads the model on first visit, then runs LLM chat completely on-device — no backend needed.
An offline-ready summarization widget. Provides LLM-powered TL;DR without any network dependency.
Run BitNet from the command line using Node.js and the webgpu npm package (Dawn bindings). Interactive chat with streaming output and tok/s metrics.
cd examples/node-cli
npm install && npm start
Interactive chat using native wgpu.
cd packages/rust
cargo run --example chat --release
Interactive chat via Python bindings.
pip install oxbitnet
python packages/rust/crates/oxbitnet-python/examples/chat.py
Minimal Swift chat example wrapping the C FFI layer.
cd packages/rust
cargo build -p oxbitnet-ffi --release
cd crates/oxbitnet-swift
swift run -Xlinker -L../../../../target/release Chat model.gguf "Hello!"
Minimal Java chat example using JNI bindings.
cd packages/rust
cargo build -p oxbitnet-java --release
cd crates/oxbitnet-java/examples
javac -cp ../java/src/main/java:. Chat.java
java -Djava.library.path=../../../../target/release -cp ../java/src/main/java:. Chat model.gguf "Hello!"
Minimal C example using the FFI bindings.
cd packages/rust
cargo build -p oxbitnet-ffi --release
gcc crates/oxbitnet-ffi/examples/chat.c -Icrates/oxbitnet-ffi -Ltarget/release -loxbitnet_ffi -o chat
LD_LIBRARY_PATH=target/release ./chat model.gguf "Hello!"
0xbitnet/
├── packages/
│ ├── core/ # WGSL kernels + TypeScript API (npm: 0xbitnet)
│ │ └── src/
│ │ ├── gpu/ # WebGPU device init, buffer pool
│ │ ├── model/ # GGUF parser, weight loader, config
│ │ ├── nn/ # Transformer layers, attention, BitLinear
│ │ ├── shaders/ # 12 WGSL compute shaders (shared with Rust)
│ │ └── tokenizer/ # BPE tokenizer, chat templates
│ └── rust/ # Rust + Python bindings
│ └── crates/
│ ├── oxbitnet/ # Rust library (crates.io: oxbitnet)
│ ├── oxbitnet-python/ # Python bindings via PyO3 (PyPI: oxbitnet)
│ ├── oxbitnet-swift/ # Swift bindings via C FFI (SPM package)
│ ├── oxbitnet-java/ # Java/JNI bindings (Android-ready)
│ └── oxbitnet-ffi/ # C FFI bindings (cdylib + staticlib)
├── examples/
│ ├── web-chat/ # Chat app demo (Vite)
│ ├── tl-dr-widget/ # Offline TL;DR widget demo (Vite)
│ └── node-cli/ # Node.js CLI using Dawn WebGPU bindings
└── docs/
See Architecture for data flow and internals.
pip install oxbitnetContributions are welcome! Whether it's a bug report, feature request, or pull request — all input is appreciated.
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)Please see CONTRIBUTING.md for detailed guidelines.
Download counts and popularity will appear here as the collector receives them.
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 17:49 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:5b647d49f929d19e9d37e60d9d9b41fb56badb022ab919c36559acbf11b2032f