engine

cactus-compute活跃维护

面向手机等消费级设备的 LLM 推理引擎,用 2bit 量化和手写内核把大模型塞进端侧运行,主打低显存、跨 Android/iOS 的 ARM 部署。

2bit quants, kernels and runtime for consumer devices.

v2.2.2发布于 2026-09-26 03:13 UTC6,188star515fork同步于 2026-11-10 11:34 UTC

怎么上手

由 README 提炼,执行前请确认
brew install cactus-compute/cactus/cactus
cactus run
硬件要求按 README 说明

README 未给出最低显存或内存门槛,仅列出 Mac M 系列、iPad/Vision Pro、iPhone 15 Pro/17 Pro 等实测设备;后端可选 cpu 或 metal,CPU 可跑。

支持 Apple Silicon
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

面向手机与可穿戴设备的边缘云端混合 AI 引擎,用 2bit 量化在消费级设备上跑 LLM、语音和视觉

面向手机等消费级设备的 LLM 推理引擎,用 2bit 量化和手写内核把大模型塞进端侧运行,主打低显存、跨 Android/iOS 的 ARM 部署。

核心能力

  • 提供兼容 OpenAI 的文本、语音、视觉 API
  • 零拷贝计算图 Cactus Graph 组织张量运算
  • ARM NEON SIMD 内核覆盖矩阵乘、注意力、卷积与量化
  • 自研旋转码本量化,支持 4bit 到 1bit 权重
  • 按本地模型置信度自动把难题转交云端

容易踩的坑

首次运行 cactus run 会自动下载或转换模型,需联网且耗时;Linux 需先装 python3.12、cmake、build-essential 等依赖;cactus serve 默认只绑定 127.0.0.1:8080,外部访问需改 --host/--port。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v2.2.2
  1. v2.2.2最新正式版2026-09-26 · 2026-09-26 03:13 UTC

    What's Changed

    Full Changelog: https://github.com/cactus-compute/cactus/compare/v2.2.1...v2.2.2

  2. v2.2.12026-09-25 · 2026-09-25 01:05 UTC
    查看更新说明
  3. v2.2.02026-09-08 · 2026-09-08 13:53 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/cactus-compute/cactus/compare/v2.1.0...v2.2.0

  4. v2.1.02026-08-17 · 2026-08-17 17:42 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/cactus-compute/cactus/compare/v2.0.1...v2.1.0

  5. v2.0.12026-07-09 · 2026-07-09 23:25 UTC
    查看更新说明

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Cactus

    Docs Website GitHub HuggingFace Reddit Blog

    A hybrid edge-cloud AI engine for mobile devices & wearables.

    ┌─────────────────┐
    │  Cactus Engine  │ ←── OpenAI-compatible APIs for text, speech, and vision.
    └─────────────────┘     
             │
    ┌─────────────────┐
    │  Cactus Graph   │ ←── Zero-copy computation graph
    └─────────────────┘     
             │
    ┌─────────────────┐
    │ Cactus Kernels  │ ←── CPU/GPU kernels for (Apple, Samsung, Pixel, etc.)
    └─────────────────┘     
             │
    ┌─────────────────┐
    │ Cactus Quants   │ ←── Custom rotation-based quantization technique
    └─────────────────┘  
    

    Quick Demo (Mac)

    • Step 1: brew install cactus-compute/cactus/cactus
    • Step 2: cactus run

    Cactus Engine

    #include "cactus_engine.h"
    
    cactus_model_t model = cactus_init(
        "path/to/weight/folder",
        "path to txt or dir of txts for auto-rag",
        false
    );
    
    const char* messages = R"([
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "My name is Henry Ndubuaku"}
    ])";
    
    const char* options = R"({
        "max_tokens": 50,
        "stop_sequences": ["<|im_end|>"]
    })";
    
    char response[4096];
    int result = cactus_complete(
        model,            // model handle
        messages,         // JSON chat messages
        response,         // response buffer
        sizeof(response), // buffer size
        options,          // generation options
        nullptr,          // tools JSON
        nullptr,          // streaming callback
        nullptr,          // user data
        nullptr,          // pcm audio buffer
        0                 // pcm buffer size
    );
    

    Example response from Gemma4-E2B

    {
        "success": true,        // generation succeeded
        "error": null,          // error details if failed
        "cloud_handoff": false, // true if cloud model used
        "response": "Hi there!",
        "function_calls": [],   // parsed tool calls
        "segments": [],         // transcription segments (empty for chat)
        "confidence": 0.8193,   // model confidence
        "confidence_threshold": 0.7, // resolved handoff threshold (model-dependent)
        "time_to_first_token_ms": 45.23,
        "total_time_ms": 163.67,
        "prefill_tps": 1621.89,
        "decode_tps": 168.42,
        "ram_usage_mb": 245.67,
        "prefill_tokens": 28,
        "decode_tokens": 50,
        "total_tokens": 78
    }
    

    Cactus Graph

    #include "cactus_graph.h"
    
    CactusGraph graph;
    auto a = graph.input({2, 3}, Precision::FP16);
    auto b = graph.input({3, 4}, Precision::INT8);
    
    auto x1 = graph.matmul(a, b, false);
    auto x2 = graph.transpose(x1);
    auto result = graph.matmul(b, x2, true);
    
    float a_data[6] = {1.1f, 2.3f, 3.4f, 4.2f, 5.7f, 6.8f};
    float b_data[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
    
    graph.set_input(a, a_data, Precision::FP16);
    graph.set_input(b, b_data, Precision::INT8);
    
    graph.execute();
    void* output_data = graph.get_output(result);
    
    graph.hard_reset(); 
    

    Inference Speed

    • LLM: Gemma-4-E2B-CQ4 (1k-context prefill / decode for 100 tokens)
    • VLM: Gemma-4-E2B-CQ4 (256px image encode time / decode)
    • Transcribe: Parakeet-TDT-0.6B-CQ4 (20s audio end-to-end transcribe time)
    • 1k-Context RAM: peak MB during the LLM benchmark
    • No speculative decode or MTP, pure decode

    Command: cactus benchmark [optional --ios or --android]

    DeviceLLMVLMTranscribeRAM
    Mac M5 Max2964tps / 154tps0.09s / 168tps0.15s1348MB
    Mac M4 Pro1963tps / 101tps0.25s / 112tps0.21s1225MB
    Mac M3 Pro1294tps / 64tps0.40s / 72tps0.37s735MB
    iPad/Vision Pro M51336tps / 71tps0.25s / 80tps0.27s703MB
    iPhone 17 Pro729tps / 37tps0.5s / 39tps0.51s644MB
    iPhone 15 Pro517tps / 26tps1.15s / 27tps0.82s633MB

    N/B: With 1k-context prefill and decode for 100 runs on M5 Max

    • LFM2.5-VL-1.6B = 289toks/sec
    • Qwen3-1.7B = 155toks/sec
    • LFM2.5-VL-450m = 472toks/sec, image encodes in 43ms
    • LFM22.5-VL-230m = 555toks/sec

    Output Quality

    • Gemma-4-E2B-it accuracy across bit widths, averaged over 3 seeds.
    • CQ3.26 and CQ2.54 are mixed-precision, CQ2/CQ3/CQ4 are uniformly quantized.
    • Full results in docs/cactus_quants.md:
    TaskF16 (Original)CQ4CQ3.26CQ2.54CQ2
    ARC-E73.8073.7374.2068.2050.80
    ARC-C56.4752.4751.5337.2024.73
    HellaSwag46.9347.0745.2040.7335.87
    WinoGrande61.0061.1359.6060.1351.27
    MMLU62.3359.4557.6347.1933.18
    GPQA34.3434.3431.8230.8123.23
    GSM8K73.6771.2066.2022.000.40
    HumanEval54.8857.1153.6615.241.02
    BFCL Simple92.0092.4291.5082.2518.75
    BFCL Multi89.0088.3389.0052.5013.67
    BFCL Parallel84.0083.6782.5030.003.33
    BFCL Parallel-Multi78.0083.3382.0037.001.33

    Supported Models

    • Any HuggingFace model can be converted using cactus convert [HF-Name], though experimental.
    • Liquid, Gemma. whisper. parakeet and Qwen model families are especially tested.
    • Some models have been pre-uploaded here, just run cactus download [HF-Name].
    • cactus run [HF-Name] albeit first downloads or convert the model if not found.

    Needle

    Needle is a 26m parameter model for on-device tool calling:

    cactus run Cactus-Compute/needle [--tools my_tools.json]  # OpenAI function-calling format; demo toolset by default
    

    Learn More

    ReferenceLanguageDescription
    Cactus EngineCChat completion, streaming, tool calling, transcription, embeddings, RAG, vision, vector index, cloud handoff
    Cactus GraphC++Tensor operations, matrix multiplication, attention, normalization, activation functions
    Cactus KernelsC++ARM NEON SIMD kernels for matmul, attention, convolution, quantization, DSP, image processing
    Cactus QuantsC++Rotation-and-codebook quantization from 4-bit to 1-bit for all weight tensors
    Cactus HybridC/PythonRoute hard queries to the cloud automatically based on local model confidence
    Python PackagePythonPython package and CLI

    Bindings

    Using this repo

    ┌────────────────────────────────────────────────────────────────────────────────┐
    │                                                                                │
    │ Step 0: if on Linux (Ubuntu/Debian)                                            │
    │ sudo apt-get install python3.12 python3.12-venv python3-pip cmake              │
    │   build-essential libcurl4-openssl-dev                                         │
    │                                                                                │
    │ Step 1: clone and setup                                                        │
    │ git clone https://github.com/cactus-compute/cactus && cd cactus                │
    │ source ./setup                                                                 │
    │                                                                                │
    │ Step 2: use the commands                                                       │
    │────────────────────────────────────────────────────────────────────────────────│
    │                                                                                │
    │  cactus auth                         manage cloud API key                      │
    │    --status                          show key status                           │
    │    --clear                           remove saved key                          │
    │                                                                                │
    │  cactus run [model|path]             run a model (downloads if needed)         │
    │    --bits 1|2|3|4|2.54|3.26          CQ quantization (default: 4)              │
    │    --backend cpu|metal               inference backend (default: auto)         │
    │    --image <path>                    image file for VLM inference              │
    │    --audio <path>                    audio file for audio chat                 │
    │    --system <prompt>                 system prompt                             │
    │    --prompt <text>                   send prompt immediately                   │
    │    --tools <json|file>               tool definitions for tool calling         │
    │    --thinking                        enable thinking/reasoning mode            │
    │    --token <token>                   HuggingFace token (gated models)          │
    │    --reconvert                       force local rebuild from source           │
    │                                                                                │
    │  cactus transcribe [model]           live microphone transcription with a model│
    │    --file <audio.wav>                audio file to transcribe (WAV)            │
    │    --language <code>                 language code (default: en)               │
    │    --bits 1|2|3|4|2.54|3.26          CQ quantization (default: 4)              │
    │    --token <token>                   HuggingFace token (gated models)          │
    │    --reconvert                       force local rebuild from source           │
    │                                                                                │
    │  cactus download [model]             get a bundle (prebuilt, else build)       │
    │    --bits 1|2|3|4|2.54|3.26          CQ quantization (default: 4)              │
    │    --token <token>                   HuggingFace token (gated models)          │
    │    --reconvert                       refresh cached bundle                     │
    │                                                                                │
    │  cactus convert <model> [dir]        HuggingFace -> Cactus CQ weights          │
    │    --bits 1|2|3|4                    CQ quantization (default: 4)              │
    │    --token <token>                   HuggingFace token (gated models)          │
    │    --reconvert                       force weight conversion from source       │
    │    --lora <path>                     merge a LoRA adapter before converting    │
    │    --weights-only                    stop after CQ weights (skip the graph)    │
    │    --artifact-dir <path>             bundle output (default: weights/<model>)  │
    │                                                                                │
    │  cactus serve [model]                OpenAI-compatible local HTTP server       │
    │    --host <addr>                     bind address (default: 127.0.0.1)         │
    │    --port <port>                     port (default: 8080)                      │
    │    --bits 1|2|3|4|2.54|3.26          CQ quantization (default: 4)              │
    │    --backend cpu|metal               inference backend (default: auto)         │
    │    --token <token>                   HuggingFace token (gated models)          │
    │    --reconvert                       force local rebuild from source           │
    │    --no-cloud-handoff                disable automatic cloud handoff           │
    │    --confidence-threshold <0..1>     handoff to cloud below this confidence    │
    │    --cloud-timeout-ms <n>            max wait for cloud handoff                │
    │                                                                                │
    │  cactus code                         run the AI coding agent (TUI / print)     │
    │    --serve-model <id>                auto-start a server with this model       │
    │    --bits 1|2|3|4|2.54|3.26          CQ quantization (default: 4)              │
    │    --backend cpu|metal               inference backend (default: auto)         │
    │    --token <token>                   HuggingFace token (gated models)          │
    │    --reconvert                       force local rebuild from source           │
    │    --host <addr>                     server address (default: 127.0.0.1)       │
    │    --port <port>                     server port (default: 8080)               │
    │    --no-serve                        require a running server (no auto-start)  │
    │    --no-cloud-handoff                disable automatic cloud handoff           │
    │    --confidence-threshold <0..1>     handoff to cloud below this confidence    │
    │    --cloud-timeout-ms <n>            max wait for cloud handoff                │
    │    -- <args...>                      pass remaining args to the agent          │
    │                                                                                │
    │  cactus list                         list downloaded models                    │
    │                                                                                │
    │  cactus build                        build cactus libraries                    │
    │    --apple                           Apple (iOS/macOS)                         │
    │    --android                         Android                                   │
    │    --python                          shared lib for Python FFI                 │
    │                                                                                │
    │  cactus test                         run the test suite                        │
    │    --component <name>                kernels | graph | engine | all            │
    │                                      (default: all)                            │
    │    --model <hf-id>                   default: google/gemma-4-E2B-it            │
    │    --transcription-model <hf-id>     default: nvidia/parakeet-tdt-0.6b-v3      │
    │    --bits 1|2|3|4|2.54|3.26          CQ quantization (default: 4)              │
    │    --backend cpu|metal               inference backend (default: auto)         │
    │    --token <token>                   HuggingFace token (gated models)          │
    │    --reconvert                       force local rebuild of test models        │
    │    --suite <name>                    run a single test suite by name           │
    │                                      (resolved across components,              │
    │                                      e.g. llm → engine)                        │
    │    --list                            list components and suites                │
    │    --ios                             run on connected iPhone                   │
    │    --android                         run on connected Android                  │
    │    --enable-telemetry                send cloud telemetry (off by default)     │
    │                                                                                │
    │  cactus benchmark                    run the engine benchmark suite            │
    │    --model <hf-id>                   default: google/gemma-4-E2B-it            │
    │    --transcription-model <hf-id>     default: nvidia/parakeet-tdt-0.6b-v3      │
    │    --bits 1|2|3|4|2.54|3.26          CQ quantization (default: 4)              │
    │    --backend cpu|metal               inference backend (default: auto)         │
    │    --ios                             run on connected iPhone                   │
    │    --android                         run on connected Android                  │
    │                                                                                │
    │  cactus clean                        delete build artifacts, weights, venv     │
    │  cactus --help                       show this help                            │
    │                                                                                │
    └────────────────────────────────────────────────────────────────────────────────┘
    

    Citation

    If you use Cactus in your research, please cite it as follows:

    @software{cactus,
      title        = {Cactus: AI Inference Engine for Phones & Wearables},
      author       = {Ndubuaku, Henry and Cactus Team},
      url          = {https://github.com/cactus-compute/cactus},
      year         = {2025}
    }
    

    N/B: Scroll all the way up and click the shields link for resources!