|
| 1 | +--- |
| 2 | +additional_search_terms: |
| 3 | +- BitNet |
| 4 | +- ternary |
| 5 | +- LLM |
| 6 | +- inference |
| 7 | +- CPU |
| 8 | +- Arm |
| 9 | +- Graviton |
| 10 | +- Apple silicon |
| 11 | +- Python |
| 12 | + |
| 13 | +layout: installtoolsall |
| 14 | +minutes_to_complete: 10 |
| 15 | +author: |
| 16 | + - Nii Osae Osae Dade |
| 17 | + - Tony Morri |
| 18 | + - Sayandip Pal |
| 19 | +multi_install: false |
| 20 | +multitool_install_part: false |
| 21 | +official_docs: https://github.com/Mindbeam-AI/Litespark-Inference |
| 22 | +test_images: |
| 23 | +- ubuntu:latest |
| 24 | +test_link: null |
| 25 | +test_maintenance: true |
| 26 | +title: Litespark-Inference |
| 27 | +description: Install Litespark-Inference on Arm or x86 Linux and Apple silicon macOS to run BitNet ternary LLMs on the CPU. |
| 28 | +tool_install: true |
| 29 | +weight: 1 |
| 30 | +--- |
| 31 | + |
| 32 | +[Litespark-Inference](https://github.com/Mindbeam-AI/Litespark-Inference) |
| 33 | +is an open-source CPU inference runtime for |
| 34 | +[BitNet b1.58](https://arxiv.org/abs/2402.17764) ternary-weight LLMs. A |
| 35 | +single `pip install` reads your CPU's feature flags and compiles the |
| 36 | +right C++ kernel for it - NEON + SDOT on Arm, AVX-512/VNNI or AVX2+FMA |
| 37 | +on x86. You do not pick the kernel; it picks itself. |
| 38 | + |
| 39 | +## What do I need before installing Litespark-Inference? |
| 40 | + |
| 41 | +- **Python 3.10 or newer.** Check with `python3 --version`. |
| 42 | +- **A C++ toolchain** (`clang` or `g++`). Already present on most |
| 43 | + developer machines; install steps per platform are below. |
| 44 | +- **About 5 GB of free disk.** The BitNet-2B model downloads from |
| 45 | + Hugging Face on first run. |
| 46 | + |
| 47 | +It is good practice to install into a clean virtual environment so the |
| 48 | +install does not conflict with anything else on your machine: |
| 49 | + |
| 50 | +```console |
| 51 | +python3 -m venv .venv |
| 52 | +source .venv/bin/activate |
| 53 | +python -m pip install --upgrade pip wheel setuptools |
| 54 | +``` |
| 55 | + |
| 56 | +Then follow the section for your platform. |
| 57 | + |
| 58 | +## How do I install Litespark-Inference on Arm or x86 Linux? |
| 59 | + |
| 60 | +The released package builds the correct kernel for your CPU |
| 61 | +automatically - AVX-512 with an AVX2+FMA fallback on x86, and NEON + |
| 62 | +SDOT on Arm (Graviton 2/3/4, Ampere, Neoverse N1/N2/V1/V2, Raspberry |
| 63 | +Pi 5). Install the C++ toolchain, then the package: |
| 64 | + |
| 65 | +```bash |
| 66 | +sudo apt-get update |
| 67 | +sudo apt-get install -y build-essential clang ninja-build git python3-pip |
| 68 | +pip install litespark-inference |
| 69 | +``` |
| 70 | + |
| 71 | +For Red Hat, Fedora, or RHEL, install the toolchain with `dnf` instead: |
| 72 | + |
| 73 | +```console |
| 74 | +sudo dnf install -y gcc-c++ clang ninja-build git python3-pip |
| 75 | +``` |
| 76 | + |
| 77 | +Confirm the package imports and reports the kernel selected for your CPU: |
| 78 | + |
| 79 | +```bash |
| 80 | +python3 -c "import litespark_inference; print(litespark_inference.__version__)" |
| 81 | +``` |
| 82 | + |
| 83 | +To inspect which kernel was built, run: |
| 84 | + |
| 85 | +```console |
| 86 | +python -m litespark_inference.torchless info |
| 87 | +``` |
| 88 | + |
| 89 | +The output ends with one of the following, depending on your CPU: |
| 90 | + |
| 91 | +```output |
| 92 | +kernel : avx512 (torchless, extern "C" AVX-512/VNNI + OMP) |
| 93 | +kernel : avx2 (torchless, extern "C" AVX2+FMA fallback + OMP) |
| 94 | +kernel : neon (torchless, extern "C" NEON SDOT) |
| 95 | +``` |
| 96 | + |
| 97 | +## How do I install Litespark-Inference on Apple silicon macOS? |
| 98 | + |
| 99 | +Apple's CPUs have NEON SDOT and Litespark-Inference uses it directly. |
| 100 | +The only extra step versus Linux is installing `libomp` - Apple's |
| 101 | +toolchain does not ship a built-in OpenMP runtime, and Litespark uses |
| 102 | +OpenMP for multi-threading inside the kernel: |
| 103 | + |
| 104 | +```console |
| 105 | +# Xcode command-line tools (one-time setup; no full Xcode required) |
| 106 | +xcode-select --install |
| 107 | + |
| 108 | +# libomp via Homebrew |
| 109 | +brew install libomp |
| 110 | + |
| 111 | +# Install the released package from PyPI |
| 112 | +pip install litespark-inference |
| 113 | +``` |
| 114 | + |
| 115 | +Verify the install: |
| 116 | + |
| 117 | +```console |
| 118 | +python -m litespark_inference.torchless info |
| 119 | +``` |
| 120 | + |
| 121 | +Expected output includes: |
| 122 | + |
| 123 | +```output |
| 124 | +kernel : neon (torchless, extern "C" NEON SDOT) |
| 125 | +OpenMP : True (max_threads=...) |
| 126 | +``` |
| 127 | + |
| 128 | +If `OpenMP : False`, the build did not find Homebrew's `libomp`. The |
| 129 | +most common cause is that Homebrew is installed under `/opt/homebrew` |
| 130 | +(the Apple silicon default) but `pip install` ran in an environment that |
| 131 | +hides it. Re-running `pip install litespark-inference` from a normal |
| 132 | +shell usually fixes it. |
| 133 | + |
| 134 | +## How do I install from source? |
| 135 | + |
| 136 | +To modify the runtime or kernels, install from source instead of from |
| 137 | +PyPI: |
| 138 | + |
| 139 | +```console |
| 140 | +git clone https://github.com/Mindbeam-AI/Litespark-Inference.git |
| 141 | +cd Litespark-Inference |
| 142 | +pip install -e . |
| 143 | +``` |
| 144 | + |
| 145 | +## Sanity-check |
| 146 | + |
| 147 | +On all platforms, the same one-liner generates text. The first run |
| 148 | +downloads `microsoft/bitnet-b1.58-2B-4T-bf16` from Hugging Face (around |
| 149 | +4.5 GB into `~/.cache/huggingface/hub`); later runs start instantly: |
| 150 | + |
| 151 | +```console |
| 152 | +litespark-inference generate "Hello, world!" --max-tokens 16 |
| 153 | +``` |
| 154 | + |
| 155 | +You are now ready to run BitNet-2B. Continue with the |
| 156 | +[Accelerate LLM inference on Arm CPUs with Litespark-Inference](/learning-paths/laptops-and-desktops/litespark-inference/) |
| 157 | +Learning Path. |
0 commit comments