Skip to main content

termux-bitnet

Production 1.58-bit (i2_s) BitNet On-Device Inference SDK & CLI for Android Termux & ARM64.

PyPI Version PyPI Downloads Python Versions License Core C++ Platform


1. Overview & Architecture

termux-bitnet is a native Python SDK and CLI tool designed for running 1.58-bit quantized Large Language Models (BitNet b1.58) directly on Android Termux, ARM64 mobile processors, and edge devices.

The underlying execution engine is written in native C++17 with optimized ARM64 NEON SIMD and DotProd vector instructions (vdotq_s32), exposed to Python via a high-throughput, zero-overhead C-types FFI layer.

[Python 3.8+ Application / CLI]
       │
       ▼ (BitNetEngine / BitNetConfig)
[termux-bitnet Python SDK (ctypes Zero-Copy FFI)]
       │
       ▼ (Strict C ABI: libtermux_bitnet.so)
[Native C++ BitNet Core] ──► ARM64 NEON + DotProd SIMD Vector Kernels

2. Verified BitNet GGUF Model Registry

termux-bitnet provides one-touch model downloading and caching from verified Hugging Face repositories with HTTP Range resume capability:

Model Alias Hugging Face Repository & File Parameters File Size Target Device
bitnet-2b microsoft/bitnet-b1.58-2B-4T-gguf 2.4B 1.13 GB Flagship Phones (Galaxy S20+, S24, S25, Pixel)
bitnet-large RichardErkhov/1bitLLM_-_bitnet_b1_58-large-gguf 0.7B 404 MB Entry-level / Low-RAM ARM64 Devices
bitnet-3b Green-Sky/bitnet_b1_58-3B-GGUF 3.3B 730 MB High-Capacity Mobile Workstations
bitnet-3b-q4 RichardErkhov/1bitLLM_-_bitnet_b1_58-3B-gguf 3.3B 1.83 GB High-Precision Q4 Quantized Model

3. Quick Start

3.1 Installation

# In Android Termux or ARM64 Linux
pip install termux-bitnet

3.2 CLI Commands

# 1. Hardware Diagnostic (Check NEON & DotProd SIMD Acceleration)
termux-bitnet info

# 2. List Available Verified Models
termux-bitnet models

# 3. Download Model with HTTP Range Resume Support
termux-bitnet download bitnet-2b

# 4. Run On-Device Inference
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

4. Python SDK Usage

4.1 Real-Time Token Streaming

from termux_bitnet import BitNetEngine, BitNetConfig

# 1. Configure Engine Parameters
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,
)

# 2. Stream Generation with Context Manager
with BitNetEngine(config) as engine:
    print("[Prompt]: Write a Python palindrome check function")
    print("[Response]: ", end="", flush=True)
    for token in engine.generate_stream("Write a Python palindrome check:"):
        print(token, end="", flush=True)
    print()

4.2 Programmatic Model Management

from termux_bitnet import download_model, detect_hardware, print_hardware_summary

# Inspect ARM64 Hardware Capabilities
hw = detect_hardware()
print_hardware_summary(hw)

# Download and Cache Model
model_path = download_model("bitnet-2b")
print(f"Model downloaded to: {model_path}")

5. Full Parameter Matrix (BitNetConfig)

CLI Flag Python (BitNetConfig) Default Description
-m, --model model_path "" Path to GGUF model binary
-p, --prompt prompt "" Input prompt text
-t, --threads n_threads cores Number of CPU worker threads
-c, --ctx-size n_ctx 2048 KV Cache context window size
-b, --batch-size n_batch 512 Prompt evaluation batch size
-n, --n-predict n_predict 128 Maximum tokens to generate
--temp temperature 0.7 Softmax temperature (0.0 = Greedy)
--top-p top_p 0.95 Nucleus Top-P sampling cutoff
--top-k top_k 40 Top-K sampling cutoff
--min-p min_p 0.05 Min-P relative probability cutoff
--repeat-penalty repeat_penalty 1.15 Repetition penalty coefficient
-s, --seed seed 0 Random seed (0 = non-deterministic)
--system-prompt system_prompt "" Optional system prompt prefix
-r, --stop stop_tokens "" Stop sequence tokens

6. Physical Device Benchmark (Samsung Galaxy S25 / Termux ARM64)

The following performance metrics were measured directly on a Samsung Galaxy S25 (Snapdragon 8 Elite / Termux Bionic ARM64):

Step Executed Command Latency / Time Validation Status Measured Metrics / Notes
Step 1 termux-bitnet info 1.43s 🟢 PASS 4-Core ARM64, NEON & DotProd (vdotq_s32) auto-detected
Step 2 termux-bitnet models 1.46s 🟢 PASS Verified 1.58-bit GGUF Model Registry queried
Step 3 termux-bitnet download bitnet-2b 241.47s (4m 1s) 🟢 PASS 1.13 GB Microsoft BitNet b1.58 downloaded (Avg 4.69 MB/s)
Step 4 termux-bitnet run -p "..." 1.50s 🟢 PASS Harmonic mean response streamed with 0-heap allocation
Total End-to-End Execution (4 Steps) 245.86s (4m 5s) 🟢 PASS Core engine processing <= 1.50s (excl. 1.13GB model download)

7. License

Apache License 2.0. Copyright (c) 2026 uno-km (AMEVA Foundation).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

termux_bitnet-1.0.4.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

termux_bitnet-1.0.4-cp312-cp312-win_amd64.whl (17.9 kB view details)

Uploaded CPython 3.12Windows x86-64

File details

Details for the file termux_bitnet-1.0.4.tar.gz.

File metadata

  • Download URL: termux_bitnet-1.0.4.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.0

File hashes

Hashes for termux_bitnet-1.0.4.tar.gz
Algorithm Hash digest
SHA256 aad95ac758a7d749dcb032101c4cf0c509e29e45d17d51457dd7bc8c0fe34be7
MD5 1a5f1d65c4b7cd4b957f2489a180f65e
BLAKE2b-256 4250ddd5c1e9b3aafcb2e4a96eb88eb598454af7efe88f3b7352f905e86acb13

See more details on using hashes here.

File details

Details for the file termux_bitnet-1.0.4-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for termux_bitnet-1.0.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dd49ff6a327560f44decd3d93fb2a52b811c6413297ce8dbbdab83cd51481bd5
MD5 44248cd2c9b50d7a710622316de38314
BLAKE2b-256 7b7d6a0d77b7f1c2d9f3f635efe111d6be098cdc6b3a8940ef21c2b0167746d4

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.5

2 files

This release

1.0.4 This release

2 files

1.0.3

2 files

1.0.1

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page