Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,54 @@ __pycache__/
poetry.toml

build/
logs/
logs/
.env
.env.*
*.env
*.env.*
.env.local
.env.prd
.env.dev
.env.docker
secrets/
*.pem
*.key

# ── AMEVA Master Enterprise Security & Environment Isolation Rules ──
.env.development
.env.test
.env.production
.env.staging
*.secret
*.secrets
*credentials*
*.token
*.pfx
*.pkcs12
*.crt
*.cert
id_rsa
id_rsa.pub
id_ed25519
id_ed25519.pub
*.sqlite
*.sqlite3
*.db-journal
*.db-wal
*.db-shm
*.dump
node_modules/
venv/
.venv/
*.py[cod]
.pytest_cache/
.coverage
Thumbs.db
scratch/
tmp/
temp/
.turbo/

state.json
*.tmp

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ bitnet.cpp achieves speedups of **1.37x** to **5.07x** on ARM CPUs, with larger
- For Debian/Ubuntu users, you can download with [Automatic installation script](https://apt.llvm.org/)

`bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"`
- For Android (Termux / ARM64) users (e.g. Samsung Galaxy S21 / A35 / S25):
`pkg install -y clang cmake python git openblas`
- conda (highly recommend)

### Build from source
Expand Down Expand Up @@ -378,6 +380,14 @@ python utils/generate-dummy-bitnet-model.py models/bitnet_b1_58-large --outfile
python utils/e2e_benchmark.py -m models/dummy-bitnet-125m.tl1.gguf -p 512 -n 128
```

### On-Device Mobile ARM Benchmark (BitNet b1.58 2B-4T i2_s)
Measured on Samsung Galaxy devices running natively in Android Termux (ARMv8.2-A+dotprod, 4 worker threads):

| Device | SoC / Processor | Cores / Arch | Inference Speed | Prompt Eval (TTFT) |
| :--- | :--- | :--- | :--- | :--- |
| **Samsung Galaxy S25** | Qualcomm Snapdragon 8 Elite | Oryon (ARMv8.2-A+dotprod) | **1.15 tokens/sec** | ~2814 ms |
| **Samsung Galaxy A35 5G** | Samsung Exynos 1380 | 4x Cortex-A78 + 4x A55 | **0.58 tokens/sec** | ~8501 ms |

### Convert from `.safetensors` Checkpoints

```sh
Expand Down
6 changes: 5 additions & 1 deletion run_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
def run_command(command, shell=False):
"""Run a system command and ensure it succeeds."""
try:
subprocess.run(command, shell=shell, check=True)
env = os.environ.copy()
lib_dirs = [os.path.abspath("build/bin"), os.path.abspath("build/3rdparty/llama.cpp/src"), os.path.abspath("build/3rdparty/llama.cpp/ggml/src")]
existing_ld = env.get("LD_LIBRARY_PATH", "")
env["LD_LIBRARY_PATH"] = ":".join(lib_dirs) + (f":{existing_ld}" if existing_ld else "")
subprocess.run(command, shell=shell, check=True, env=env)
except subprocess.CalledProcessError as e:
print(f"Error occurred while running command: {e}")
sys.exit(1)
Expand Down
8 changes: 7 additions & 1 deletion setup_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ def compile():
logging.error(f"Arch {arch} is not supported yet")
exit(0)
logging.info("Compiling the code using CMake.")
run_command(["cmake", "-B", "build", *COMPILER_EXTRA_ARGS[arch], *OS_EXTRA_ARGS.get(platform.system(), []), "-DCMAKE_C_COMPILER=clang", "-DCMAKE_CXX_COMPILER=clang++", "-DLLAMA_BUILD_TOOLS=ON", "-DLLAMA_BUILD_EXAMPLES=ON", "-DLLAMA_BUILD_COMMON=ON", "-DLLAMA_BUILD_SERVER=ON"], log_step="generate_build_files")
extra_cmake_flags = []
is_termux = "com.termux" in os.environ.get("PREFIX", "") or os.path.exists("/data/data/com.termux")
if is_termux and arch == "arm64":
extra_cmake_flags.extend(["-DGGML_NEON=ON", "-DGGML_ARM_DOTPROD=ON"])
logging.info("Detected Android / Termux environment: enabled ARM NEON and DotProd acceleration")

run_command(["cmake", "-B", "build", *COMPILER_EXTRA_ARGS[arch], *OS_EXTRA_ARGS.get(platform.system(), []), *extra_cmake_flags, "-DCMAKE_C_COMPILER=clang", "-DCMAKE_CXX_COMPILER=clang++", "-DLLAMA_BUILD_TOOLS=ON", "-DLLAMA_BUILD_EXAMPLES=ON", "-DLLAMA_BUILD_COMMON=ON", "-DLLAMA_BUILD_SERVER=ON"], log_step="generate_build_files")
# run_command(["cmake", "--build", "build", "--target", "llama-cli", "--config", "Release"])
run_command(["cmake", "--build", "build", "--config", "Release"], log_step="compile")

Expand Down
Loading