Spaces:
Running
Running
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,63 +1,29 @@
|
|
| 1 |

|
| 2 |
|
| 3 |
-
Cross-platform & energy-efficient kernels, runtime and AI inference engine for mobile devices.
|
| 4 |
|
| 5 |
```
|
| 6 |
-
βββββββββββββββββββ
|
| 7 |
-
β
|
| 8 |
-
βββββββββββββββββββ
|
| 9 |
β
|
| 10 |
-
βββββββββββββββββββ
|
| 11 |
-
β Cactus
|
| 12 |
-
βββββββββββββββββββ
|
| 13 |
β
|
| 14 |
-
βββββββββββββββββββ
|
| 15 |
-
β Cactus
|
| 16 |
-
βββββββββββββββββββ
|
| 17 |
-
β
|
| 18 |
-
βββββββββββββββββββ
|
| 19 |
-
β Cactus Graph β βββ Unified zero-copy computation graph (think NumPy for mobile)
|
| 20 |
-
βββββββββββββββββββ
|
| 21 |
-
β
|
| 22 |
-
βββββββββββββββββββ
|
| 23 |
-
β Cactus Kernels β βββ Low-level ARM-specific SIMD operations (think CUDA for mobile)
|
| 24 |
-
βββββββββββββββββββ
|
| 25 |
```
|
| 26 |
|
| 27 |
-
# Cactus Graph & Kernel
|
| 28 |
-
```cpp
|
| 29 |
-
#include cactus.h
|
| 30 |
-
|
| 31 |
-
CactusGraph graph;
|
| 32 |
-
auto a = graph.input({2, 3}, Precision::FP16);
|
| 33 |
-
auto b = graph.input({3, 4}, Precision::INT8);
|
| 34 |
-
|
| 35 |
-
auto x1 = graph.matmul(a, b, false);
|
| 36 |
-
auto x2 = graph.transpose(x1);
|
| 37 |
-
auto result = graph.matmul(b, x2, true);
|
| 38 |
|
| 39 |
-
|
| 40 |
-
float b_data[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
| 41 |
|
| 42 |
-
graph.set_input(a, a_data, Precision::FP16);
|
| 43 |
-
graph.set_input(b, b_data, Precision::INT8);
|
| 44 |
-
|
| 45 |
-
graph.execute();
|
| 46 |
-
void* output_data = graph.get_output(result);
|
| 47 |
-
|
| 48 |
-
graph.hard_reset();
|
| 49 |
-
|
| 50 |
-
```
|
| 51 |
-
|
| 52 |
-
# Cactus Engine & FFI
|
| 53 |
```cpp
|
| 54 |
#include cactus.h
|
| 55 |
|
| 56 |
-
cactus_set_pro_key(""); // email founders@cactuscompute.com for optional key
|
| 57 |
-
|
| 58 |
cactus_model_t model = cactus_init(
|
| 59 |
-
"path/to/weight/folder",
|
| 60 |
-
"
|
| 61 |
);
|
| 62 |
|
| 63 |
const char* messages = R"([
|
|
@@ -72,91 +38,115 @@ const char* options = R"({
|
|
| 72 |
|
| 73 |
char response[4096];
|
| 74 |
int result = cactus_complete(
|
| 75 |
-
model,
|
| 76 |
-
messages,
|
| 77 |
-
response,
|
| 78 |
-
sizeof(response),
|
| 79 |
-
options,
|
| 80 |
-
nullptr,
|
| 81 |
-
nullptr,
|
| 82 |
-
nullptr
|
| 83 |
);
|
| 84 |
```
|
| 85 |
Example response from Gemma3-270m
|
| 86 |
```json
|
| 87 |
{
|
| 88 |
-
"success": true,
|
| 89 |
-
"error": null,
|
| 90 |
-
"cloud_handoff": false,
|
| 91 |
-
"response": "Hi there!",
|
| 92 |
-
"function_calls": [],
|
| 93 |
-
"confidence": 0.8193,
|
| 94 |
-
"time_to_first_token_ms": 45.23,
|
| 95 |
-
"total_time_ms": 163.67,
|
| 96 |
-
"prefill_tps": 1621.89,
|
| 97 |
-
"decode_tps": 168.42,
|
| 98 |
-
"ram_usage_mb": 245.67,
|
| 99 |
"prefill_tokens": 28,
|
| 100 |
"decode_tokens": 50,
|
| 101 |
"total_tokens": 78
|
| 102 |
}
|
| 103 |
```
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
| 133 |
-
|
| 134 |
-
|
|
| 135 |
-
|
|
| 136 |
-
|
|
| 137 |
-
|
|
| 138 |
-
|
|
| 139 |
-
|
|
| 140 |
-
|
| 141 |
-
|
|
| 142 |
-
|
| 143 |
-
|
|
| 144 |
-
|
|
| 145 |
-
|
|
| 146 |
-
|
|
| 147 |
-
|
|
| 148 |
-
|
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
```bash
|
|
|
|
| 154 |
git clone https://github.com/cactus-compute/cactus && cd cactus && source ./setup
|
| 155 |
```
|
| 156 |
|
| 157 |
-
- <sub> `[model]` is a HuggingFace name from the table above (default: `google/gemma-3-270m-it`)</sub>
|
| 158 |
-
- <sub> Common flags: `--precision INT4|INT8|FP16` (default: INT4), `--token <hf_token>`</sub>
|
| 159 |
-
- <sub>Always run `source ./setup` in any new terminal.</sub>
|
| 160 |
|
| 161 |
| Command | Description |
|
| 162 |
|---------|-------------|
|
|
@@ -164,11 +154,12 @@ git clone https://github.com/cactus-compute/cactus && cd cactus && source ./setu
|
|
| 164 |
| `cactus download [model]` | Downloads model to `./weights` |
|
| 165 |
| `cactus convert [model] [dir]` | Converts model, supports LoRA merging (`--lora <path>`) |
|
| 166 |
| `cactus build` | Builds for ARM (`--apple` or `--android`) |
|
| 167 |
-
| `cactus test` | Runs tests (`--ios` / `--android`, `--model [name/path]`) |
|
|
|
|
| 168 |
| `cactus clean` | Removes build artifacts |
|
| 169 |
-
| `cactus --help` | Shows all commands and flags |
|
| 170 |
|
| 171 |
-
|
| 172 |
|
| 173 |
- [Python for Mac](/python/)
|
| 174 |
- [React Native SDK](https://github.com/cactus-compute/cactus-react-native)
|
|
@@ -177,11 +168,21 @@ git clone https://github.com/cactus-compute/cactus && cd cactus && source ./setu
|
|
| 177 |
- [Flutter SDK](https://github.com/cactus-compute/cactus-flutter)
|
| 178 |
- [Rust SDK](https://github.com/mrsarac/cactus-rs)
|
| 179 |
|
| 180 |
-
|
| 181 |
|
| 182 |
- [iOS Demo](https://apps.apple.com/gb/app/cactus-chat/id6744444212)
|
| 183 |
- [Android Demo](https://play.google.com/store/apps/details?id=com.rshemetsubuser.myapp)
|
| 184 |
|
| 185 |
-
|
| 186 |
1. [Cactus Compute, Inc](https://cactuscompute.com/)
|
| 187 |
-
2. [UCLA's BruinAI](https://bruinai.org/)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |

|
| 2 |
|
|
|
|
| 3 |
|
| 4 |
```
|
| 5 |
+
βββββββββββββββββββ Energy-efficient inference engine for running AI on mobile devices
|
| 6 |
+
β Cactus Engine β βββ OpenAI compatible APIs for C/C++, Swift, Kotlin, Flutter & React-Native
|
| 7 |
+
βββββββββββββββββββ Supports tool call, auto RAG, NPU, INT4, and cloud handoff for complex tasks
|
| 8 |
β
|
| 9 |
+
βββββββββββββββββββ Zero-copy computation graph, think PyTorch for mobile devices
|
| 10 |
+
β Cactus Graph β βββ You can implement custom models directly using this
|
| 11 |
+
βββββββββββββββββββ Highly optimised for RAM & lossless weight quantisation
|
| 12 |
β
|
| 13 |
+
βββββββββββββββββββ Low-level ARM-specific SIMD kernels (Apple, Snapdragon, Google, Exynos, MediaTek & Raspberry Pi)
|
| 14 |
+
β Cactus Kernels β βββ Optimised Matrix Multiplication & n
|
| 15 |
+
βββββββββββββββββββ Custom attention kernels with KV-Cache Quantisation, chunked prefill, streaming LLM, etc.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
```
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
## Cactus Engine
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
```cpp
|
| 22 |
#include cactus.h
|
| 23 |
|
|
|
|
|
|
|
| 24 |
cactus_model_t model = cactus_init(
|
| 25 |
+
"path/to/weight/folder",
|
| 26 |
+
"path to txt or dir of txts for auto-rag",
|
| 27 |
);
|
| 28 |
|
| 29 |
const char* messages = R"([
|
|
|
|
| 38 |
|
| 39 |
char response[4096];
|
| 40 |
int result = cactus_complete(
|
| 41 |
+
model, // model handle from cactus_init
|
| 42 |
+
messages, // JSON array of chat messages
|
| 43 |
+
response, // buffer to store response JSON
|
| 44 |
+
sizeof(response), // size of response buffer
|
| 45 |
+
options, // optional: generation options (nullptr for defaults)
|
| 46 |
+
nullptr, // optional: tools JSON for function calling
|
| 47 |
+
nullptr, // optional: streaming callback fn(token, id, user_data)
|
| 48 |
+
nullptr // optional: user data passed to callback
|
| 49 |
);
|
| 50 |
```
|
| 51 |
Example response from Gemma3-270m
|
| 52 |
```json
|
| 53 |
{
|
| 54 |
+
"success": true, // when successfully generated locally
|
| 55 |
+
"error": null, // returns specific errors if success = false
|
| 56 |
+
"cloud_handoff": false, // true when model is unconfident, simply route to cloud
|
| 57 |
+
"response": "Hi there!", // null when error is not null or cloud_handoff = true
|
| 58 |
+
"function_calls": [], // parsed to [{"name":"set_alarm","arguments":{"hour":"10","minute":"0"}}]
|
| 59 |
+
"confidence": 0.8193, // how confident the model is with its response
|
| 60 |
+
"time_to_first_token_ms": 45.23, // latency (time to first token)
|
| 61 |
+
"total_time_ms": 163.67, // total execution time
|
| 62 |
+
"prefill_tps": 1621.89, // prefill tokens per second
|
| 63 |
+
"decode_tps": 168.42, // decode tokens per second
|
| 64 |
+
"ram_usage_mb": 245.67, // current process RAM usage in MB
|
| 65 |
"prefill_tokens": 28,
|
| 66 |
"decode_tokens": 50,
|
| 67 |
"total_tokens": 78
|
| 68 |
}
|
| 69 |
```
|
| 70 |
|
| 71 |
+
## Cactus Graph
|
| 72 |
+
|
| 73 |
+
```cpp
|
| 74 |
+
#include cactus.h
|
| 75 |
+
|
| 76 |
+
CactusGraph graph;
|
| 77 |
+
auto a = graph.input({2, 3}, Precision::FP16);
|
| 78 |
+
auto b = graph.input({3, 4}, Precision::INT8);
|
| 79 |
+
|
| 80 |
+
auto x1 = graph.matmul(a, b, false);
|
| 81 |
+
auto x2 = graph.transpose(x1);
|
| 82 |
+
auto result = graph.matmul(b, x2, true);
|
| 83 |
+
|
| 84 |
+
float a_data[6] = {1.1f, 2.3f, 3.4f, 4.2f, 5.7f, 6.8f};
|
| 85 |
+
float b_data[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
| 86 |
+
|
| 87 |
+
graph.set_input(a, a_data, Precision::FP16);
|
| 88 |
+
graph.set_input(b, b_data, Precision::INT8);
|
| 89 |
+
|
| 90 |
+
graph.execute();
|
| 91 |
+
void* output_data = graph.get_output(result);
|
| 92 |
+
|
| 93 |
+
graph.hard_reset();
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
## Benchmark (INT8)
|
| 97 |
+
|
| 98 |
+
| Device | LFM2.5-1.2B<br>(1k-Prefill/100-Decode) | LFM2.5-VL-1.6B<br>(256px-Latency & Decode) | Whisper-Small<br>(30s-audio-Latency & Decode)
|
| 99 |
+
|--------|--------|--------|----------|
|
| 100 |
+
| Mac M4 Pro | 582/77 tps| 0.2s & 76tps | 0.1s & 111tps |
|
| 101 |
+
| iPad/Mac M4 | - | - | - |
|
| 102 |
+
| iPhone 17 Pro | 300/33 tps | 0.3s & 33tps | 0.6s & 114tps |
|
| 103 |
+
| Galaxy S25 Ultra | 226/36 tps | 2.6s & 33tps | 2.3s & 90tps |
|
| 104 |
+
| Pixel 10 Pro | - | - | - |
|
| 105 |
+
| Vivo X200 Pro | - | - | - |
|
| 106 |
+
|
| 107 |
+
| Device | LFM2-350m<br>(1k-Prefill/100-Decode) | LFM2-VL-450m<br>(256px-Latency & Decode) | Moonshine-Base<br>(30s-audio-Latency & Decode)
|
| 108 |
+
|--------|--------|--------|----------|
|
| 109 |
+
| iPad/Mac M1 | - | - | - |
|
| 110 |
+
| iPhone 13 Mini | - | - | - |
|
| 111 |
+
| Galaxy A56 | - | - | - |
|
| 112 |
+
| Pixel 6a | 218/44 tps | 2.5s & 36 tps | 1.5s & 189 tps |
|
| 113 |
+
| Nothing CMF | - | - | - |
|
| 114 |
+
| Raspberry Pi 5 | - | - | - |
|
| 115 |
+
|
| 116 |
+
## Supported Models
|
| 117 |
+
|
| 118 |
+
| Model | Features |
|
| 119 |
+
|-------|----------|
|
| 120 |
+
| google/gemma-3-270m-it | completion |
|
| 121 |
+
| google/functiongemma-270m-it | completion, tools |
|
| 122 |
+
| LiquidAI/LFM2-350M | completion, tools, embed |
|
| 123 |
+
| Qwen/Qwen3-0.6B | completion, tools, embed |
|
| 124 |
+
| LiquidAI/LFM2-700M | completion, tools, embed |
|
| 125 |
+
| google/gemma-3-1b-it | completion |
|
| 126 |
+
| LiquidAI/LFM2.5-1.2B-Thinking | completion, tools, embed |
|
| 127 |
+
| LiquidAI/LFM2.5-1.2B-Instruct | completion, tools, embed |
|
| 128 |
+
| Qwen/Qwen3-1.7B | completion, tools, embed |
|
| 129 |
+
| LiquidAI/LFM2-2.6B | completion, tools, embed |
|
| 130 |
+
| LiquidAI/LFM2-VL-450M | vision, txt & img embed, Apple NPU |
|
| 131 |
+
| LiquidAI/LFM2.5-VL-1.6B | vision, txt & img embed, Apple NPU |
|
| 132 |
+
| UsefulSensors/moonshine-base | transcription, speech embed |
|
| 133 |
+
| openai/whisper-small | transcription, speech embed, Apple NPU |
|
| 134 |
+
| openai/whisper-medium | transcribe, speech embed, Apple NPU |
|
| 135 |
+
| nomic-ai/nomic-embed-text-v2-moe | embed |
|
| 136 |
+
| Qwen/Qwen3-Embedding-0.6B | embed |
|
| 137 |
+
|
| 138 |
+
## Using this repo on Mac
|
| 139 |
+
```bash
|
| 140 |
+
git clone https://github.com/cactus-compute/cactus && cd cactus && source ./setup
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
## Using this repo on Linux (Ubuntu/Debian)
|
| 144 |
|
| 145 |
```bash
|
| 146 |
+
sudo apt-get install python3 python3-venv python3-pip cmake build-essential libcurl4-openssl-dev
|
| 147 |
git clone https://github.com/cactus-compute/cactus && cd cactus && source ./setup
|
| 148 |
```
|
| 149 |
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
| Command | Description |
|
| 152 |
|---------|-------------|
|
|
|
|
| 154 |
| `cactus download [model]` | Downloads model to `./weights` |
|
| 155 |
| `cactus convert [model] [dir]` | Converts model, supports LoRA merging (`--lora <path>`) |
|
| 156 |
| `cactus build` | Builds for ARM (`--apple` or `--android`) |
|
| 157 |
+
| `cactus test` | Runs tests (`--ios` / `--android`, `--model [name/path]`), `--precision` |
|
| 158 |
+
| `cactus transcribe [model]` | Transcribe audio file (`--file`) or live microphone |
|
| 159 |
| `cactus clean` | Removes build artifacts |
|
| 160 |
+
| `cactus --help` | Shows all commands and flags (always run this) |
|
| 161 |
|
| 162 |
+
## Using in your apps
|
| 163 |
|
| 164 |
- [Python for Mac](/python/)
|
| 165 |
- [React Native SDK](https://github.com/cactus-compute/cactus-react-native)
|
|
|
|
| 168 |
- [Flutter SDK](https://github.com/cactus-compute/cactus-flutter)
|
| 169 |
- [Rust SDK](https://github.com/mrsarac/cactus-rs)
|
| 170 |
|
| 171 |
+
## Try demo apps
|
| 172 |
|
| 173 |
- [iOS Demo](https://apps.apple.com/gb/app/cactus-chat/id6744444212)
|
| 174 |
- [Android Demo](https://play.google.com/store/apps/details?id=com.rshemetsubuser.myapp)
|
| 175 |
|
| 176 |
+
## Maintaining Organisations
|
| 177 |
1. [Cactus Compute, Inc](https://cactuscompute.com/)
|
| 178 |
+
2. [UCLA's BruinAI](https://bruinai.org/)
|
| 179 |
+
3. [Yale's AI Society](https://www.yale-ai.org/team)
|
| 180 |
+
4. [National Unoversity of Singapore's AI Society](https://www.nusaisociety.org/)
|
| 181 |
+
5. [UC Irvine's AI@UCI](https://aiclub.ics.uci.edu/)
|
| 182 |
+
6. [Imperial College's AI Society](https://www.imperialcollegeunion.org/csp/1391)
|
| 183 |
+
7. [University of Pennsylvania's AI@Penn](https://ai-at-penn-main-105.vercel.app/)
|
| 184 |
+
8. [University of Michigan Ann-Arbor MSAIL](https://msail.github.io/)
|
| 185 |
+
9. [University of Colorado Boulder's AI Club](https://www.cuaiclub.org/)
|
| 186 |
+
|
| 187 |
+
## Join The Community
|
| 188 |
+
- [Reddit Channel](https://www.reddit.com/r/cactuscompute/)
|