← All models

text-generation Β· text Β· WebGPU q4f16 / WASM fp32 Β· ~260 MB–1.4 GB

LFM2 β€” Liquid AI's hybrid on-device LLM

Most small browser LLMs (SmolLM, Qwen, Llama, Gemma) are scaled-down transformers. LFM2 is a different shape: Liquid AI's second-generation foundation model (2025) interleaves short-range gated convolution blocks with grouped-query attention β€” a hybrid designed from the ground up for fast CPU/edge inference, not a shrunk GPT. This is the 350M instruct model, running locally via Transformers.js: it streams real tokens on WebGPU (q4f16) when you have a GPU, and on plain CPU/WASM (fp32) when you don't. Nothing leaves your device.

At a glance

ModelLiquidAI/LFM2-350M Β· run via the onnx-community/LFM2-350M-ONNX Transformers.js build
ArchitectureHybrid β€” gated short convolution blocks + grouped-query attention (the lfm2 model class), ~354M params. Built for edge/CPU latency.
Task / pipelinetext-generation (instruct chat, applies LFM2's chat template)
RuntimeTransformers.js 4.3.0, pinned locally in this model's worker (the lfm2 class isn't in the shared 3.7.5 pin β€” isolated escape hatch, same as SAM2).
Backend & dtypeWebGPU β†’ q4f16 (~260 MB, fast) Β· CPU/WASM β†’ fp32 (~1.4 GB, works with no GPU). The page probes for a real GPU adapter and picks; both are real.
Why two dtypesThe quantized ONNX block-quantizes the token-embedding gather (GatherBlockQuantized), a WebGPU-only ORT-Web kernel β€” so on CPU we load the fp32 export, which uses a plain gather.
Context length32,768 tokens
LicenseLFM Open License v1.0 (review before production use)
Web APIsWebAssembly, Web Workers (Baseline); WebGPU for the fast path (progressive enhancement)

Run it

Chat with LFM2 locally. Tokens stream in as they're generated. On a GPU you get the fast q4f16 path; with no GPU it runs the fp32 build on CPU (larger download, slower, but real).

See inside β€” the exact prompt LFM2 receives

A chat model doesn't see your raw message β€” it sees a templated prompt with role markers and a generation cue. This is LFM2's chat template applied to the last turn, exactly as sent to the model.

Send a message to see the templated prompt.

Why it matters

LFM2's pitch is latency and footprint on the device: the hybrid conv+attention design targets fast decoding on CPUs and small accelerators, which is exactly the browser's constraint. A 350M instruct model that runs β€” really runs β€” with no GPU means private, offline assistants on ordinary hardware.

Use cases

Basics

Plain chat with a system prompt and live sampling controls β€” greedy vs sampled, side by side.

Practical

A structured rewriter: turn rough notes into a tidy email, summary or bullet list on-device.

Wild

A tiny text adventure: LFM2 is the game master, keeping state across turns, entirely local.

Multi-model

Grounded RAG: an embedder retrieves passages, LFM2 answers from just those β€” no hallucinated source.

How the API works

Standard Transformers.js text-generation β€” the LFM2 specifics are the version pin and the device-adaptive dtype:

// LFM2's model class lands in Transformers.js 4.x, so pin it locally in the worker:
import { pipeline, TextStreamer } from "@huggingface/transformers"; // @4.3.0

// WebGPU β†’ q4f16 (fast); no GPU β†’ fp32 (the WASM EP can't run the block-quantized gather):
const gpu = "gpu" in navigator && await navigator.gpu.requestAdapter();
const generator = await pipeline("text-generation", "onnx-community/LFM2-350M-ONNX", {
  device: gpu ? "webgpu" : "wasm",
  dtype:  gpu ? "q4f16"  : "fp32",
});

const messages = [{ role: "user", content: "Explain why the sky is blue in two sentences." }];
const streamer = new TextStreamer(generator.tokenizer, { skip_prompt: true, skip_special_tokens: true,
  callback_function: (t) => append(t) });                 // stream tokens as they arrive
await generator(messages, { max_new_tokens: 256, do_sample: true, temperature: 0.3, streamer });

Inference runs in a Web Worker so token streaming never blocks the page. Verified on this stack (headless Chrome, no GPU, fp32/WASM): greedy decode produced "The sky appears blue because of a phenomenon called Rayleigh scattering, where shorter wavelengths of light, like blue, scatter more" β€” real, coherent, non-degenerate.

References