项目简介
欢迎使用libLLM,这是一个专为在普通个人电脑和移动设备上高效推理大型语言模型(LLM)而设计的开源项目。核心使用C++14编写,没有第三方依赖(BLAS、SentencePiece等),能在各种设备中无缝运行。
特点
支持的模型
Model
|
Download
|
Llama2
|
HuggingFace
|
ChatGLM3-6b
|
HuggingFace
|
ChatGLM2-6b
|
HuggingFace
|
构建
libLLM CPU only
$ mkdir build && cd build
$ cmake ..
$ make -j
使用 CUDA 构建
注意:如果您的操作系统中有多个 CUDA 版本,请指定 -DCUDAToolkit_ROOT=
。
推荐版本有:
$ mkdir build && cd build
$ cmake -DLLYN_CUDA=ON [-DCUDAToolkit_ROOT=] ..
$ make -j
运行 libllm 命令行
$ ./src/llm/llm -config ../model/chatglm3-6b-libllm-q4/chatglm3.config
INFO 2023-12-19T08:56:47Z lymath.cc:42] lymath: Use Avx512 backend.
INFO 2023-12-19T08:56:48Z cuda_operators.cc:46] cuda numDevices = 1
INFO 2023-12-19T08:56:48Z cuda_operators.cc:47] cuda:0 maxThreadsPerMultiProcessor = 2048
INFO 2023-12-19T08:56:48Z cuda_operators.cc:49] cuda:0 multiProcessorCount = 20
INFO 2023-12-19T08:56:48Z llm.cc:123] OMP max_threads = 20
INFO 2023-12-19T08:56:48Z bpe_model.cc:34] read tokenizer from ../model/chatglm3-6b-libllm-q4/chatglm3.tokenizer.bin
INFO 2023-12-19T08:56:48Z model_factory.cc:35] model_type = chatglm3
INFO 2023-12-19T08:56:48Z model_factory.cc:36] device = cuda
INFO 2023-12-19T08:56:48Z state_map.cc:58] read state map from ../model/chatglm3-6b-libllm-q4/chatglm3.q4.bin
INFO 2023-12-19T08:56:51Z state_map.cc:68] reading ... 100.0%
INFO 2023-12-19T08:56:51Z state_map.cc:69] 200 tensors read.
> 你好
你好👋!我是人工智能助手 ChatGLM3-6B,很高兴见到你,欢迎问我任何问题。
(29 token, time=0.92s, 31.75ms per token)
>
API 示例
Python
from libllm import Model, ControlToken
model = Model("model/chatglm3-6b-libllm-q4/chatglm3.config")
prompt = [ControlToken(""), "\n", "你好", ControlToken("")]
for chunk in model.complete(prompt):
print(chunk.text, end="", flush=True)
print("\nDone!")
导出 Huggingface 模型
Here is an example of exporting ChatGLM3 model from huggingface.
以下是从 Huggingface 导出 ChatGLM3 模型的示例。