text-generation · code LLM · WASM · ~365 MB
CodeGen, from Salesforce, was one of the first open models trained specifically to write code. This 350M version is the smallest: give it a function signature and docstring, and it writes the body — left to right, token by token, entirely on your device. No telemetry, no cloud, no network needed once cached.
| Model | Xenova/codegen-350M-multi (ONNX) · original Salesforce/codegen-350M-multi |
|---|---|
| Task | text-generation (autoregressive next-token prediction over code) |
| Architecture | CodeGen — a 350M-parameter decoder (20 layers), trained on The Pile + BIGQUERY (public GitHub code); multi = multi-language (Python/Java/JavaScript/C++) |
| Params / dtype | 350M · q8 (8-bit quantized ONNX) |
| Backend | WebAssembly (CPU) — no GPU required |
| Download | ~365 MB, cached after first load |
| License | BSD-3-Clause |
| Web APIs | Web Workers, Cache Storage (via Transformers.js), WebAssembly |
Generated token IDs include special tokens and exclude the prompt; average tok/s includes prefill.
Every token below is a real forward pass of CodeGen on your CPU — the exact same
predict-distribution-then-sample loop that powers a cloud IDE's autocomplete, running locally. Watch
it emit a docstring, then the def line, then the body, one token at a time.
the decoded text stream
CodeGen proved that a focused, code-only model could autocomplete real programs. Today that idea is everywhere — but a 350M version still runs on a plain CPU in a browser tab, which means code completion and generation with zero cloud round-trips.
The friendly one-liner is the text-generation pipeline:
import { pipeline } from "@huggingface/transformers";
const gen = await pipeline("text-generation", "Xenova/codegen-350M-multi", { dtype: "q8" });
const out = await gen(
'def fibonacci(n):\n """Return the first n numbers of the Fibonacci sequence."""',
{ max_new_tokens: 80, do_sample: true, temperature: 0.7 },
);
// out[0].generated_text → the signature plus CodeGen's implementation
The demo streams tokens through a TextStreamer inside a Web Worker, so the page never
blocks — the chips above show decoded text chunks as words become available; the readout counts generated token IDs.