termux-bitnet
Single C++ Core & Multi-Language Thin Gateways (Python SDK + Node.js npm) for 1.58-bit (i2_s) BitNet On-Device Inference on Android Termux & ARM64.
1. Architectural Philosophy: "Single C++ Core, Dual Thin Gateways"
termux-bitnet strictly adheres to the standard open-source AI systems design principle: "All heavy computation, memory management, and tensor algebra are executed exclusively in a single high-performance C++ core, while Python (pip) and Node.js (npm) act as zero-overhead lightweight entry points (Thin Gateways / FFI Boundaries)."
graph TD
subgraph Gateways ["Multi-Language Thin Gateways (Lightweight Entry Points)"]
G1["Python Gateway<br/><code>pip install termux-bitnet</code><br/>(ctypes Zero-Copy FFI)"]
G2["Node.js / TS Gateway<br/><code>npm install termux-bitnet</code><br/>(Native CLI / IPC)"]
G3["Native CLI<br/><code>termux-bitnet-cli</code>"]
end
subgraph Boundary ["Strict C ABI Boundary (include/termux_bitnet.h)"]
ABI["bitnet_init() | bitnet_eval() | bitnet_generate_stream() | bitnet_free()"]
end
subgraph Core ["Single High-Performance C++ Core (libtermux_bitnet.so)"]
K1["ARM64 NEON + DotProd Accel (vdotq_s32)"]
K2["ARM64 NEON + FMA Fallback (vmlal_s8)"]
K3["QK=128 32-Stride Interleaved Scalar Fallback"]
KV["KV Cache & Top-P / Temperature Sampler"]
end
G1 --> ABI
G2 --> ABI
G3 --> ABI
ABI --> Core
2. Verified BitNet Model Registry
termux-bitnet supports verified official and community 1.58-bit GGUF models on Hugging Face. Download and cache models with single-command HTTP Range resume support:
| Alias | Source Repository & Model File | Parameters / Size | Highlights |
|---|---|---|---|
bitnet-2b |
microsoft/bitnet-b1.58-2B-4T-gguf |
2.4B / 1.13 GB | Microsoft Official Flagship 1.58-bit Model (Mobile Recommended) |
bitnet-large |
RichardErkhov/1bitLLM_-_bitnet_b1_58-large-gguf |
0.7B / 404 MB | Ultra-lightweight model for low-spec mobile/Termux devices |
bitnet-3b |
Green-Sky/bitnet_b1_58-3B-GGUF |
3.3B / 730 MB | High-precision on-device 3B BitNet model |
bitnet-3b-q4 |
RichardErkhov/1bitLLM_-_bitnet_b1_58-3B-gguf |
3.3B / 1.83 GB | Q4 quantized high-performance 3B model |
# One-touch download with HTTP resume support
termux-bitnet download bitnet-2b
3. Quick Start
3.1 Python Gateway (pip)
# Install Python package
pip install termux-bitnet
# Run inference CLI with full parameter matrix control
termux-bitnet run -m ~/.cache/termux-bitnet/models/bitnet-2b-ggml-model-i2_s.gguf -p "The capital of France is" -t 8 -c 2048 -n 128 --temp 0.7 --top-p 0.95 --top-k 40 --repeat-penalty 1.15
from termux_bitnet import BitNetEngine, BitNetConfig
config = BitNetConfig(
model_path="~/.cache/termux-bitnet/models/bitnet-2b-ggml-model-i2_s.gguf",
n_threads=8,
temperature=0.7,
top_p=0.95,
top_k=40,
min_p=0.05,
repeat_penalty=1.15,
)
with BitNetEngine(config) as engine:
for token in engine.generate_stream("Write a Python palindrome check:"):
print(token, end="", flush=True)
3.2 Node.js Gateway (npm)
# Install npm package
npm install termux-bitnet
# Run Node.js CLI
npx termux-bitnet run -p "Explain harmonic mean in one sentence" -t 8 --temp 0.7 --top-p 0.95
const { createEngine } = require('termux-bitnet');
async function main() {
const engine = createEngine({
threads: 8,
temperature: 0.7,
topP: 0.95,
topK: 40,
repeatPenalty: 1.15,
});
await engine.generateStream('Question: Explain harmonic mean:', 128, (token) => {
process.stdout.write(token);
});
}
main();
4. Full Parameter Matrix
| CLI Flag | Python (BitNetConfig) |
Node.js (BitNetOptions) |
C ABI (bitnet_params_t) |
Default | Description |
|---|---|---|---|---|---|
-m, --model |
model_path |
modelPath |
model_path |
"" |
Path to GGUF model binary |
-p, --prompt |
prompt |
prompt |
prompt |
"" |
Input prompt text |
-t, --threads |
n_threads |
threads |
n_threads |
cores |
Number of CPU worker threads |
-c, --ctx-size |
n_ctx |
contextSize |
n_ctx |
2048 |
KV Cache context window size |
-b, --batch-size |
n_batch |
batchSize |
n_batch |
512 |
Prompt evaluation batch size |
-n, --n-predict |
n_predict |
maxTokens |
n_predict |
128 |
Maximum tokens to generate |
--temp |
temperature |
temperature |
temperature |
0.7 |
Softmax temperature (0.0 = Greedy) |
--top-p |
top_p |
topP |
top_p |
0.95 |
Nucleus Top-P sampling cutoff |
--top-k |
top_k |
topK |
top_k |
40 |
Top-K sampling cutoff |
--min-p |
min_p |
minP |
min_p |
0.05 |
Min-P relative probability cutoff |
--repeat-penalty |
repeat_penalty |
repeatPenalty |
repeat_penalty |
1.15 |
Repetition penalty coefficient |
-s, --seed |
seed |
seed |
seed |
0 |
Random seed (0 = non-deterministic) |
--system-prompt |
system_prompt |
systemPrompt |
system_prompt |
"" |
Optional system prompt prefix |
-r, --stop |
stop_tokens |
stopTokens |
stop_tokens |
"" |
Stop sequence tokens |
5. Direct C ABI Embedding (C/C++)
#include "termux_bitnet.h"
#include <stdio.h>
int main() {
bitnet_params_t params = bitnet_default_params();
params.temperature = 0.7f;
params.top_p = 0.95f;
params.top_k = 40;
bitnet_context_t ctx = bitnet_init(¶ms);
bitnet_generate_stream(ctx, "The capital of France is", 64,
[](const char* token, int32_t id, void* u) {
printf("%s", token);
return true;
}, NULL);
bitnet_free(ctx);
return 0;
}
6. License
Apache License 2.0. Copyright (c) 2026 uno-km.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file termux_bitnet-1.0.1.tar.gz.
File metadata
- Download URL: termux_bitnet-1.0.1.tar.gz
- Upload date:
- Size: 31.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd3e3ec3adfb08cb2e6f6ddb51e081bc1a4cc865cc23b7aeabac8089a5014699
|
|
| MD5 |
840359113b8415d160be359db902b7fb
|
|
| BLAKE2b-256 |
cb341b45a6b819a9071ce74fa92d1184a12ed4e05947d52069308ab4a031d329
|
File details
Details for the file termux_bitnet-1.0.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: termux_bitnet-1.0.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 18.0 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40a1a63879e6ec2d6bd91439eafb05ac9a9decbb61c417e5daae8f44cec8f1f9
|
|
| MD5 |
b70acfd10661cff19ec02625515b600c
|
|
| BLAKE2b-256 |
937fa62af967cc00724b1c84a773a1361aee70edb588eb65e301b9b0709841f1
|