← All models

text-generation · code LLM · WASM · ~365 MB

CodeGen-350M — code autocomplete, fully offline

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.

At a glance

ModelXenova/codegen-350M-mono (ONNX) · original Salesforce/codegen-350M-mono
Tasktext-generation (autoregressive next-token prediction over code)
ArchitectureCodeGen — a 350M-parameter decoder (20 layers), trained on The Pile + BIGQUERY (public GitHub code); mono = Python-focused
Params / dtype350M · q8 (8-bit quantized ONNX)
BackendWebAssembly (CPU) — no GPU required
Download~365 MB, cached after first load
LicenseBSD-3-Clause
Web APIsWeb Workers, Cache Storage (via Transformers.js), WebAssembly

Run it

The generated code will stream here.

Generated token IDs include special tokens and exclude the prompt; average tok/s includes prefill.

See inside — the token stream

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.

Why it matters

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.

Use cases

Basics

Complete a function body from its signature — the fundamental autocomplete move.

Practical

Spec → code: write a docstring, get an implementation. Scaffold three helpers at once.

Wild

Silly spec theater — describe a ridiculous function in prose and see what CodeGen builds.

How the API works

The friendly one-liner is the text-generation pipeline:

import { pipeline } from "@huggingface/transformers";

const gen = await pipeline("text-generation", "Xenova/codegen-350M-mono", { 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.

References