sophgo/LLM-TPU

Run generative AI models in sophgo BM1684X/BM1688

TL;DR

LLM‑TPU lets you run popular large language models (LLMs) and multimodal vision‑language models (VLMs) on SOPHGO’s TPU‑style accelerator chips (BM1684X, BM1688, CV186X). With a single command it compiles HuggingFace weights into a hardware‑specific bmodel and provides ready‑to‑run Python or C++ demos, supporting quantized models, KV‑cache for multi‑turn chat, and multi‑chip parallelism.


What it is

  • Domain: AI inference on specialized TPU‑like hardware.
  • Goal: Turn off‑the‑shelf HuggingFace models into fast, low‑memory executables that run on SOPHGO’s BM1684X/BM1688/CV186X chips.
  • Key idea: A conversion script (llm_convert.py) uses the open‑source TPU‑MLIR compiler to produce a bmodel (binary model) plus a config file. The resulting artifact can be loaded by the provided demo programs.

Who it’s for

Audience Why it matters
Hardware engineers / AI developers who have SOPHGO TPUs and need to run LLMs/VLMs without writing a custom compiler.
Research labs evaluating SOPHGO chips for inference workloads.
Product teams building AI‑powered edge devices (e.g., smart cameras, voice assistants) that rely on low‑latency on‑device inference.

How it works (high‑level flow)

  1. Pick a model – any HuggingFace checkpoint, preferably already quantized with AWQ/GPTQ/AutoRound.
  2. Run llm_convert.py – tells TPU‑MLIR the target chip, sequence length, and optional KV‑cache/history settings. The script emits a bmodel and a JSON config.
  3. Load the bmodel – use the supplied Python or C++ demo (e.g., python demo.py) which reads the config, allocates the TPU, and performs inference.
  4. Optional extras – enable dynamic compilation, multi‑chip parallelism, model encryption, or LoRA fine‑tuning via extra flags.

Core features

Feature What it gives you
One‑click compilation llm_convert.py turns HuggingFace weights into a ready‑to‑run bmodel in a single command.
Broad model catalog Supports dozens of LLM families (Qwen, Llama, DeepSeek, Phi, MiniCPM, etc.) and multimodal models (Mage‑VL, Qwen3‑TTS, InternVL3, etc.).
Quantization aware Works out‑of‑the‑box with INT4‑AWQ/GPTQ models; you can also quantize FP16 models yourself before conversion.
KV‑cache & history --use_history_kv adds pre‑fill with cache reuse, dramatically speeding multi‑turn chats.
Dynamic compilation --dynamic lets the runtime adapt to actual input lengths, reducing latency for short queries.
Multi‑chip parallelism --num_device N spreads a single model across several TPUs, enabling larger models or higher throughput.
Dual‑language demos Every model ships with both Python and C++ reference code, making integration easy for different stacks.
Pre‑compiled bmodels For quick testing you can download ready‑made bmodels; compilation is optional.
Extensible Advanced flags for custom quantization, LoRA rank, embedding off‑load, etc.

Getting started (quick example)

# 1. Clone the repo
git clone https://github.com/sophgo/LLM-TPU.git && cd LLM-TPU

# 2. Run the one‑liner demo (will download a Qwen3.5 model, compile, and launch a chat)
./run.sh --model qwen3.5

The script pulls the model, calls llm_convert.py with sensible defaults, and starts an interactive Python REPL where you can type prompts.


Strengths & limitations

Strengths

  • Hardware‑specific optimisation – leverages SOPHGO’s TPU‑MLIR pipeline for low‑latency, low‑memory inference.
  • Comprehensive model support – both text‑only LLMs and vision‑language models, many of them already quantised.
  • Ease of use – single‑command demos, pre‑compiled binaries, and clear docs.
  • Open source – Apache‑2.0 license, all conversion scripts and demos are visible.

Limitations

  • Chip‑only – works exclusively on SOPHGO BM1684X/BM1688/CV186X; no CPU/GPU fallback.
  • Quantization dependence – best accuracy with pre‑quantized models; converting FP16 models may require extra tooling.
  • Learning curve for advanced flags – multi‑chip or history‑KV modes need careful tuning of seq_length and chunk_length.
  • Ecosystem maturity – while the repo is actively maintained, the broader SOPHGO toolchain (TPU‑MLIR) is still niche compared to mainstream CUDA/ONNX runtimes.

Who’s behind it

  • SOPHGO – Chinese semiconductor company that designs the BM1684X/BM1688/CV186X TPU families. The project is officially maintained by them and linked from their website.
  • Community contributors – the GitHub stats show multiple external contributors, and the repo accepts PRs for new models or bug fixes.

When to use it

  • You have SOPHGO hardware and need to run LLMs/VLMs locally (edge, server, or research).
  • Latency or power budget matters – TPU inference is typically faster and more energy‑efficient than CPU/GPU for the same model size.
  • You want a turnkey path from HuggingFace checkpoint to on‑device execution without writing a custom compiler.

When to look elsewhere

  • You are targeting GPUs, CPUs, or other accelerators.
  • You need training capabilities – this repo only covers inference.
  • Your models are not compatible with the supported quantization formats.

Quick reference cheat‑sheet

Command Purpose
llm_convert.py -m <hf_path> -c bm1684x -s 2048 -o mymodel Compile a model for BM1684X with 2K token context.
--use_history_kv --chunk_length 1024 Enable KV‑cache for multi‑turn chat, splitting long prompts into 1K‑token chunks.
--dynamic Turn on dynamic shape handling (good for variable‑size images or short texts).
--num_device 4 Run the model across 4 TPU chips (parallel inference).
./run.sh --model qwen3 End‑to‑end demo: download, compile, and launch an interactive chat.

License

Apache‑2.0 – free for commercial and academic use, with standard attribution requirements.


Bottom line: If you own a SOPHGO TPU and want to squeeze the most out of modern LLMs or multimodal models without building a compiler from scratch, LLM‑TPU is a ready‑made, well‑documented bridge from HuggingFace to hardware‑accelerated inference.

Related

  • Project
  • Project
  • Project
  • Project
  • Project