← All models

text-generation · code · WASM · ~383 MB

StarCoder — fill in the middle of your code

Most autocomplete only continues from the left. A fill-in-the-middle (FIM) code model reads both sides — the code before a gap and the code after it — and writes what belongs in between. This is the trick the BigCode StarCoder family pioneered, and it runs here entirely in your browser on WebAssembly. You give it a prefix and a suffix; it streams the middle, with the exact <fim_prefix>…<fim_suffix>…<fim_middle> wire on show and live tokens-per-second. Nothing is uploaded and it works offline once cached.

Which model runs here. StarCoder2-3B has no browser build today — no ONNX export for the starcoder2 architecture exists on the Hub, and MLC's WebLLM ships no starcoder2 weights — so this page runs the genuine same-family model that does load in a browser: tiny_starcoder_py (164M, BigCode StarCoder lineage, Python-focused). Same FIM sentinels, same mechanism — a small model, so its completions are modest, but every token you see is real and computed on your device.

At a glance

Modelonnx-community/tiny_starcoder_py-ONNX (ONNX of bigcode/tiny_starcoder_py)
FamilyBigCode StarCoder (architecture gpt_bigcode) — the same lineage as StarCoder2, which has no browser build yet
Task / pipelinetext-generation — a causal LM, driven in fill-in-the-middle mode
FIM tokens<fim_prefix>, <fim_suffix>, <fim_middle>, <fim_pad>
Params / dtype164M · q8 (8-bit) ONNX
BackendWebAssembly — runs anywhere, no WebGPU required
Download~383 MB, cached after first load
Trained onThe Stack (Python subset) — this checkpoint is Python-specialised
Licensebigcode-openrail-m
Web APIsWebAssembly, Web Workers, ES module imports — all Baseline widely available

Run it — fill the gap

Put the code that comes before the gap in the first box and the code that comes after it in the second. StarCoder writes what belongs between them, reading both sides. Try an example, then edit either half and watch the middle change.

Temperature 0 is greedy/deterministic; higher samples more varied completions.

python
Your filled-in code appears here.

See inside — the FIM wire and the token stream

A FIM model isn't a different architecture — it's a normal left-to-right language model trained on a rearranged input. Instead of feeding the code in order, training splices it as <fim_prefix> BEFORE <fim_suffix> AFTER <fim_middle>, and the model learns to continue from <fim_middle> with the text that fits between the two halves. Because it's still ordinary next-token prediction, it streams — the numbers below are measured live on your device. Here is the exact wire the model received on the last run:

Run something to see the FIM wire the model received.
decode speed
–
time to first token
–
generated
–
total time
–
backend
–

Why it matters

Fill-in-the-middle is what turns a code model from a line-continuation toy into an editor-grade assistant: real edits happen inside existing code, not just at the end. A FIM model that runs locally makes that private by construction and free to run — the code around your cursor never leaves the machine.

Use cases

Basics

Complete a function from a comment — plain left-to-right generation, the fundamental move.

Practical

Fill a real gap between a prefix and a suffix — the FIM mechanism doing editor-style completion.

Wild

Push it across languages and watch where a Python-trained model shines and where it strains.

Multi-model

StarCoder writes code → a code-embedding model finds the nearest example in a corpus.

How the API works

There's nothing FIM-specific in the pipeline call — FIM lives entirely in how you assemble the prompt string. You wrap the two halves in the sentinel tokens and let the code-tuned weights continue from <fim_middle>:

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

const gen = await pipeline("text-generation", "onnx-community/tiny_starcoder_py-ONNX", { dtype: "q8" });

const prefix = "def fibonacci(n):\n    a, b = 0, 1\n    ";
const suffix = "\n    return a";
// Assemble the FIM wire: BEFORE, then AFTER, then ask for the MIDDLE.
const wire = `<fim_prefix>${prefix}<fim_suffix>${suffix}<fim_middle>`;

const [out] = await gen(wire, { max_new_tokens: 80, return_full_text: false });
// out.generated_text is just the MIDDLE — splice it back: prefix + middle + suffix.

This page runs exactly that in worker.js (off the main thread), streaming each token via a TextStreamer so the middle appears live, and reports the real tok/s and time-to-first-token measured on your device. Plain completion (the Basics page) is the same call without the sentinels.

References