cactus-compute/engine

2bit quants, kernels and runtime for consumer devices.

Cactus: An AI Engine for Phones and Wearables

What it is: Cactus is a software engine that runs AI models (like chatbots, speech recognition, and vision models) directly on mobile devices and wearables, with the option to hand off harder requests to the cloud. It's designed to be fast and memory-efficient on consumer hardware like iPhones, iPads, and Macs.

The Four Layers

Cactus is built from four main pieces, each with its own job:

  1. Cactus Engine — The top layer. It provides a standard, OpenAI-compatible interface for text chat, speech, and vision. You send it a JSON chat message (like {"role": "user", "content": "Hi"}) and it returns a JSON response with the generated text, timing stats, memory usage, and a confidence score.

  2. Cactus Graph — A computation graph that describes AI operations (matrix multiplication, transposes, etc.) as a series of steps. It's "zero-copy," meaning data isn't needlessly duplicated between steps. You define inputs, chain operations, execute, and read the output.

  3. Cactus Kernels — Low-level CPU/GPU code optimized for specific hardware (Apple, Samsung, Pixel, etc.). These are the actual math routines that run fast on each device.

  4. Cactus Quants — A custom compression technique that shrinks AI model weights from 16-bit down to as low as 1-bit, using rotation and codebook methods. This makes models smaller and faster on limited hardware.

How You Use It

There's a command-line tool called cactus with several commands:

  • cactus run [model] — Start a model and chat with it. Options include quantization level (--bits 1|2|3|4|2.54|3.26), backend (--backend cpu|metal), image/audio input, tool definitions, and a thinking mode.
  • cactus transcribe [model] — Live microphone transcription or transcribe a WAV file.
  • cactus download [model] — Fetch a pre-built model bundle, or build it locally if needed.
  • cactus convert <model> — Convert any HuggingFace model into Cactus's compressed format.
  • cactus serve [model] — Run a local HTTP server with an OpenAI-compatible API, so other apps can talk to it.
  • cactus code — An AI coding agent (terminal UI).
  • cactus benchmark — Measure speed on your device.
  • cactus test — Run the test suite.
  • cactus build — Build the libraries for Apple, Android, or Python.
  • cactus list / cactus clean — List downloaded models or clean up artifacts.

There's also a C API (shown in the README) for embedding the engine directly in your own program, and bindings for Swift, Kotlin, Flutter, React Native, Python, and Rust.

Performance Claims

The README includes benchmark tables (run with cactus benchmark) on Apple devices. A few examples:

  • Mac M5 Max: ~2964 tokens/sec prefill, ~154 tokens/sec decode for a 1k-context LLM; 0.09s image encode for a vision model; 0.15s to transcribe 20s of audio; peak RAM ~1348MB.
  • iPhone 15 Pro: ~517 tokens/sec prefill, ~26 tokens/sec decode; 1.15s image encode; 0.82s transcription; ~633MB RAM.

These numbers are for a specific model (Gemma-4-E2B-CQ4) and are presented as-is — the README doesn't explain methodology beyond noting "no speculative decode or MTP, pure decode."

Quality vs. Compression Trade-off

The README includes accuracy tables comparing the original 16-bit model against compressed versions (CQ4, CQ3.26, CQ2.54, CQ2) across tasks like reasoning (ARC, MMLU, GPQA), math (GSM8K), coding (HumanEval), and tool calling (BFCL). The pattern: CQ4 stays close to the original on most tasks, while CQ2 degrades sharply (e.g., GSM8K drops from 73.67% to 0.40%). So the compression is a trade-off between size/speed and accuracy.

Supported Models

  • Any HuggingFace model can be converted with cactus convert, though the README calls this "experimental."
  • Liquid, Gemma, Whisper, Parakeet, and Qwen model families are "especially tested."
  • Some pre-converted models are hosted on HuggingFace under the Cactus-Compute account.
  • There's also Needle, a 26-million-parameter model specifically for on-device tool calling (function calling in the OpenAI format).

Key Idea: Cloud Handoff

One distinctive feature: the engine can automatically route a query to the cloud if the local model's confidence is below a threshold. The response JSON includes a cloud_handoff flag and a confidence score, and the server command has options like --confidence-threshold and --cloud-timeout-ms to control this behavior. So it's a hybrid: fast local inference when confident, cloud fallback when not.

Bottom Line

Cactus is a performance-focused AI inference engine that brings LLMs, vision, and speech to phones and wearables by combining aggressive compression, hardware-tuned kernels, and a hybrid local/cloud strategy. It's open source (GitHub), has a Python package, and is designed to be a drop-in replacement for OpenAI-style APIs on-device.

Note: All facts above come directly from the README. No claims about real-world performance, compatibility, or quality beyond what's stated there should be assumed.

Related

  • Project
  • Project
  • Project
  • Project