chatllm.cpp

foldlMIT活跃维护

纯 C++ 实现的大模型推理引擎,无需 Python 环境即可在电脑的 CPU 和 GPU 上实时运行对话模型。

Pure C++ implementation of several models for real-time chatting on your computer (CPU & GPU)

v25发布于 2026-10-18 05:04 UTC942star +1 / 7 天76fork同步于 2026-11-10 17:54 UTC

怎么上手

由 README 提炼,执行前请确认
git clone --recursive https://github.com/foldl/chatllm.cpp.git && cd chatllm.cpp
cmake -B build && cmake --build build -j --config Release
./build/bin/main -m model.bin -i
硬件要求按 README 说明

README 未说明具体显存要求;支持 CPU 与 GPU 推理,GPU 加速需在 CMake 中开启对应后端(如 -DGGML_VULKAN=1),具体支持的 GPU 厂商与型号见 docs/gpu.md。

支持 Apple Silicon
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

纯 C++ 实现的本地大模型推理引擎,支持 CPU/GPU 实时多模态对话与 RAG

纯 C++ 实现的大模型推理引擎,无需 Python 环境即可在电脑的 CPU 和 GPU 上实时运行对话模型。

核心能力

  • 基于 ggml 用纯 C++ 实现 Transformer 系列模型推理
  • 支持 int4/int8 量化与优化 KV 缓存降低内存占用
  • 流式打字机式输出,支持连续对话与上下文扩展
  • 内置 RAG 检索增强与 LoRA 模型加载
  • 提供 Python/JavaScript/C/Nim 绑定与 OpenAI 兼容 API

容易踩的坑

克隆时必须加 --recursive,否则需手动执行 git submodule update --init --recursive 拉取 ggml;需先用 convert.py 转换并量化模型,且只支持 HF 格式,生成的 .bin 与 llama.cpp 的 GGUF 格式不兼容;GPU 加速需在 CMake 配置时显式开启对应后端选项,默认不启用。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v25
  1. v25最新正式版2026-10-18 · 2026-10-18 05:04 UTC

    New Models

    • Intern-Decision
    • Spark-2.5
    • TeleOCR
    • MiniCPM5-2B
    • Instella-MoE

    Highlight

    • Improved prefilling performance for qwen3.5 arch 🚀🚀🚀.
    • Decision API (text only. stay tuned for multi-media support):
      • models: Intern-Decision, H2O-Lightning.
      • actually, any model can be used to serve decision API.

    Lowlight

    • RPC is not working.
  2. v242026-08-15 · 2026-08-15 09:50 UTC
    查看更新说明

    New models

    • Nanbeige4.2
    • G9v3
    • OvisOCR2
    • PaddleOCR-VL
    • Mellum-2
    • HY-MT2
    • MiniCPM5

    Other updates

    • Introspection with lens
    • Polished for Qwen3.8 (-no-thinking, --reasoning-effort low/medium/xhigh)
    • Version numbering changed again
    • Disable other modalities to save RAM: --max-proj-length 0
  3. v2026.052026-05-27 · 2026-05-27 06:55 UTC
    查看更新说明

    New models

    • Gemma-4 (known issue #128)
    • InternVL3.5

    Other updates

    • Video input implemented for all models that support it.
    • q4_k quantization works now.
    • A modified version of WebUI from llama.cpp is used.
  4. v0.222026-03-27 · 2026-03-27 10:34 UTC
    查看更新说明

    New Models

    • Qianfan-OCR
    • Penguin-VL

    Bug fixing

    • A nearly one-year old bug (Issue #65)
  5. v0.212026-03-10 · 2026-03-10 10:45 UTC
    查看更新说明

    New models:

    • Qwen3.5
    • GLM-OCR
    • Youtu-VL
    • Youtu-LLM
    • Qwen3-TTS (voice clone only support xvec)

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    ChatLLM.cpp

    中文版

    License: MIT CI

    Inference of a bunch of models from less than 1B to more than 300B, for real-time multimodal chat with RAG on your computer (CPU & GPU), pure C++ implementation based on @ggerganov's ggml.

    Deliver accurate or better results than other implementations o-c-c-a-s-i-onally.

    | Supported Models | Download Quantized Models |

    graph TD;
    ggml --> chatllm.cpp
    chatllm.cpp --> AlphaGeometryRE
    chatllm.cpp --> WritingTools
    chatllm.cpp --> LittleAcademia
    chatllm.cpp --> LLMirror
    subgraph coding[ ]
        AlphaGeometryRE
        WritingTools
        LittleAcademia
        LLMirror
    end
    ggml[<a href="https://github.com/ggml-org/ggml"                     style="text-decoration:none;">ggml</a>            <br><span style="font-size:10px;">Machine learning library</span>];
    chatllm.cpp[<a href="https://github.com/foldl/chatllm.cpp"          style="text-decoration:none;">chatllm.cpp</a>     <br><span style="font-size:10px;">LLM inference</span>];
    AlphaGeometryRE[<a href="https://github.com/foldl/alphageometryre"  style="text-decoration:none;">AlphaGeometryRE</a> <br><span style="font-size:10px;">AlphaGeometry Re-engineered</span>];
    WritingTools[<a href="https://github.com/foldl/WritingTools"        style="text-decoration:none;">Writing Tools</a>   <br><span style="font-size:10px;">AI aided writing</span>];
    LittleAcademia[<a href="https://github.com/foldl/little-academia"   style="text-decoration:none;">Little Academia</a> <br><span style="font-size:10px;">Learn programming</span>];
    LLMirror[<a href="https://github.com/foldl/llmirror"   style="text-decoration:none;">LL·Mirror</a> <br><span style="font-size:10px;">LLM introspection</span>];
    

    What's New:

    • 2026-10-02: Intern-Decision
    • 2026-09-27: Spark-2.5
    • 2026-09-25: TeleOCR
    • 2026-09-08: MiniCPM5-2B
    • 2026-08-22: Instella-MoE
    • 2026-08-04: Nanbeige4.2
    • 2026-07-24: G9v3
    • 2026-07-16: Introspection with lens
    • 2026-07-15: OvisOCR2
    • 2026-06-27: PaddleOCR-VL
    • 2026-06-22: Mellum-2
    • 2026-06-14: HY-MT2
    • 2026-05-28: MiniCPM5
    • 2026-05-05: Gemma-4
    • 2026-03-28: InternVL3.5
    • 2026-03-27: Qianfan-OCR
    • 2026-03-22: Penguin-VL
    • 2026-03-06: Qwen3.5
    • 2026-03-03: GLM-OCR
    • 2025-10-10: I can draw: Janus-Pro
    • 2025-06-21: I can hear: Qwen2-Audio
    • 2025-05-23: I can see: Fuyu
    • 2025-05-21: Re-quantization when loading (e.g. --re-quantize q4_k)
    • 2025-05-17: I can speak: Orpheus-TTS
    • 2025-03-24: GGMM file format
    • 2025-02-21: Distributed inference
    • 2025-02-10: GPU acceleration 🔥
    • 2024-12-09: Reversed role
    • 2024-11-21: Continued generation
    • 2024-11-01: generation steering
    • 2024-06-15: Tool calling
    • 2024-05-29: ggml is forked instead of submodule
    • 2024-05-14: OpenAI API, CodeGemma Base & Instruct supported
    • 2024-05-08: Layer shuffling

    Features

    • Accelerated memory-efficient CPU/GPU inference with int4/int8 quantization, optimized KV cache and parallel computing;

    • Use OOP to address the similarities between different Transformer based models;

    • Streaming generation with typewriter effect;

    • Continuous chatting (content length is virtually unlimited)

      Two methods are available: Restart and Shift. See --extending options.

    • Retrieval Augmented Generation (RAG) 🔥

    • LoRA;

    • Python/JavaScript/C/Nim Bindings, web demo, and more possibilities.

    Quick Start

    As simple as main_nim -i -m :model_id. Check it out.

    Usage

    Preparation

    Clone the ChatLLM.cpp repository into your local machine:

    git clone --recursive https://github.com/foldl/chatllm.cpp.git && cd chatllm.cpp
    

    If you forgot the --recursive flag when cloning the repository, run the following command in the chatllm.cpp folder:

    git submodule update --init --recursive
    

    Quantize Model

    Some quantized models can be downloaded on demand.

    Install dependencies of convert.py:

    pip install -r requirements.txt
    

    Use convert.py to transform models into quantized GGML format. For example, to convert the fp16 base model to q8_0 (quantized int8) GGML model, run:

    # For models such as ChatLLM2-6B, InternLM, LlaMA, LlaMA-2, Baichuan-2, etc
    python convert.py -i path/to/model -t q8_0 -o quantized.bin --name ModelName
    
    # For some models such as CodeLlaMA, model type should be provided by `-a`
    # Find `-a ...` option for each model in `docs/models.md`.
    python convert.py -i path/to/model -t q8_0 -o quantized.bin -a CodeLlaMA --name ModelName
    

    Use --name to specify model's name in English. Optionally, use --native_name to specify model's name in another language. Use -l to specify the path of the LoRA model to be merged, such as:

    python convert.py -i path/to/model -l path/to/lora/model -o quantized.bin --name ModelName
    

    Note: Appropriately, only HF format is supported (with a few exceptions); Format of the generated .bin files is different from the one (GGUF) used by llama.cpp.

    Customized Quantization

    It's possible to specify quantization for each tensor using -tt pattern type, where pattern is a regex pattern to match against tensor names. Multiple -tt ... ... can be used. In this example, all tensors are using q4_k quantization except embeddings are using q8_0.

    ... -t q4_k -tt lm_head q8_0 -tt model.embed_tokens.weight q8_0
    
    Supported Types
    TypeGGML_TYPE
    f32GGML_TYPE_F32
    f16GGML_TYPE_F16
    q8_0GGML_TYPE_Q8_0
    q4_0GGML_TYPE_Q4_0
    q4_1GGML_TYPE_Q4_1
    q4_kGGML_TYPE_Q4_K

    Build

    In order to build this project you have several different options.

    • Using CMake:

      cmake -B build
      cmake --build build -j --config Release
      

      The executable is ./build/bin/main.

      There are lots of GGML_... options to play with. Example: Vulkan acceleration together with RPC and backend dynamic loading:

      cmake -B build -DGGML_VULKAN=1 -DGGML_RPC=1 -DGGML_CPU_ALL_VARIANTS=1 -DGGML_BACKEND_DL=1
      

    Run

    Now you may chat with a quantized model by running:

    ./build/bin/main -m llama2.bin  --seed 100                      # Llama-2-Chat-7B
    # Hello! I'm here to help you with any questions or concerns ....
    

    To run the model in interactive mode, add the -i flag. For example:

    # On Windows
    .\build\bin\Release\main -m model.bin -i
    
    # On Linux (or WSL)
    rlwrap ./build/bin/main -m model.bin -i
    

    In interactive mode, your chat history will serve as the context for the next-round conversation.

    Run ./build/bin/main -h to explore more options!

    Plan Nim

    All Python scripts are going to be rewritten in Nim, with following exceptions:

    • when pickle is used

    Acknowledgements

    • This project is started as refactoring of ChatGLM.cpp, without which, this project could not be possible.

    • Thank those who have released their the model sources and checkpoints.

    • chat_ui.html adapted from Ollama-Chat.

    Note

    • This project is a hobby project to learn DL & GGML, and under active development.

    • This project is never supposed to be used seriously and security vulnerabilities won't be treated seriously, either.

    • PRs of features won't be accepted, while PRs for bug fixes are warmly welcome.

      AI Usage Policy: Slop codes generated by AI won't be accepted.