Elffuss BraidHub

utopia-ia/elffuss-engine public

main · 8.0 KiBSourceRawPermalink

<img src="assets/logo.svg" alt="" width="72">

Elffuss Engine

A modular WebGPU runtime for GGUF language models: a GGUF reader, a tokenizer and a sampler in plain ES modules, behind a small chat API. No dependencies, no build step.

License Dependencies Runs on

Elffuss

Provisional. This is version 0.0.0, a snapshot of the engine published before its first release. The API below works and will change: read the limits of this version and the changelog before you depend on it.

In this README: quick start · what it runs · limits of this version · layout · how it is checked · licence

Quick start

Inference runs in the page, on WebGPU, and the weights are read from Hugging Face with HTTP range requests. The page needs a secure context (https://, or http://localhost and http://127.0.0.1) and a WebGPU adapter that offers the shader-f16 feature and a storage-buffer binding limit large enough for the model's largest tensor (see the limits of this version). Serve this repository with any static file server and open a page like this one from it.

<!doctype html>
<meta charset="utf-8">
<pre id="out"></pre>
<script type="module">
  import * as engine from './js/provider.js';

  console.log(engine.models());          // [{ id, label }, …]
  engine.configure('qwen35-0.8b');       // the small model from Hugging Face (already the default)
  await engine.load((status) => console.log(status));

  engine.setSampling({ temperature: 0.7, seed: 1, maxTokens: 120 });
  const out = document.getElementById('out');
  const reply = await engine.chat(
    [{ role: 'user', content: 'Write one short sentence about the sea.' }],
    'You are a concise assistant.',
    (piece) => { out.textContent += piece; },
  );
  console.log(reply);

  await engine.unload();
</script>

This exact page is the one we ran, in headless Chrome, against this tree served from http://127.0.0.1.

What it runs

Other GGUF files may fail to load, or load and answer worse without an error: the engine has two architecture profiles (qwen35 and llama), reads only the gpt2 tokenizer family, and always writes a ChatML prompt instead of reading the chat template of the file.

Limits of this version

Layout

js/         the runtime: 19 ES modules, served as they are written
            provider.js    the chat API of the quick start
            registro.js    the model registry; it imports nothing, so a page can list models without the engine
            gguf.js        the GGUF reader, which reads by byte ranges
            tokenizer.js   the tokenizer
            sample.js      the sampler
            model.js       a model session on WebGPU
            device.js      the WebGPU device
            the rest       the shaders (kernels.*.wgsl.js) and what runs them (ops.js, state.js, hadamard.js,
                           quant-tables.js)
assets/     the logo

This repository receives curated snapshots of the engine. Development happens elsewhere, so the history here moves in snapshots.

How it is checked

We check it internally against llama.cpp: the GGUF reader against llama.cpp's reader, the tokenizer token by token against llama-tokenize, the weight types against llama.cpp's decoder (the two ternary formats, which llama.cpp does not have, against their published definition), and forward passes, layer by layer, against llama.cpp's activations for the model formats that llama.cpp reads. The ternary model is checked piece by piece and end to end. Those tests and their reference data are not part of this repository.

Licence

Apache-2.0, see LICENSE. js/quant-tables.js carries grid tables copied from llama.cpp under the MIT licence of the ggml authors, reproduced in full at the top of that file; see NOTICE.