cd /news/large-language-models/fastllm-a-llm-inference-library-that… · home topics large-language-models article
[ARTICLE · art-44297] src=github.com ↗ pub= topic=large-language-models verified=true sentiment=↑ positive

Fastllm: A LLM inference library that runs DeepSeek-V4 with 10GB VRAM

Fastllm, a C++ LLM inference library, now supports running DeepSeek-V4 and the full DeepSeek R1 671B model on a single GPU with just 10GB VRAM. The library is compatible with Nvidia, AMD, and domestic GPUs, and supports FP8 inference on any GPU.

read4 min views1 publishedJun 30, 2026
Fastllm: A LLM inference library that runs DeepSeek-V4 with 10GB VRAM
Image: source

| 快速开始 | 部署DeepSeek | 部署Qwen3 | 版本日志 | English Document

本项目参考了许多开源项目的代码和相关文章,具体请参考 参考代码和文章

fastllm是c++实现自有算子替代Pytorch的高性能全功能大模型推理库,可以推理Qwen, Llama, Phi等稠密模型,以及DeepSeek, Qwen-moe等moe模型

  • 具有优良的兼容性,支持M40, K80到5090全系列N卡,支持MI50,7900等A卡,支持天数,沐曦等国产卡,支持ThinkForce NPU推理
  • 支持任意显卡的FP8推理
  • 任意显卡只需要显存 > 10G就可以支持单卡推理满血DeepSeek R1 671B模型
  • 双路9004/9005服务器 + 单显卡部署DeepSeek R1 671B - FP8原版模型,单并发速度可达20左右,部署INT4模型单并发速度可达30左右,最高并发速度可达60+

部署交流QQ群:831641348

微信

  • Fastllm目前支持DeepSeek-V4模型了
  • Fastllm目前支持导出通用动态量化模型了!参考 动态量化说明 - Fastllm目前可以支持部分GGUF模型的读取了!需要注意,目前需要使用 --ori

参数指定源模型配置文件夹,请阅读使用指南

  • 🚀 安装使用简单方便,一条命令就能成功安装,一条命令就能成功运行。
  • 🚀 支持CPU + GPU混合推理MOE大参数模型(单显卡即可推理DEEPSEEK 671B)。
  • 🚀 使用C++实现自有底层算子,不依赖PyTorch。
  • 🚀 兼容性好,PIP安装支持可以支持到P100、MI50等老卡,源码安装支持更多设备。
  • 🚀 支持多卡张量并行推理,支持3、5、7等奇数张卡。
  • 🚀 支持GPU + CPU混合张量并行推理
  • 🚀 支持CPU和显卡实现FP8运算,老设备也可以运行
  • 🚀 支持多CPU加速,且只占用1份内存
  • 🚀 支持ROCM,AMD GPU;支持天数,沐曦,燧原;支持华为昇腾。
  • 🚀 支持动态Batch,流式输出;前后端分离设计,可跨平台移植,可在安卓上直接编译。
  • 🚀 支持Python 自定义模型结构

pip

安装支持Nvidia GPU

AMD GPU

,其余GPU

请使用源码安装pip

安装速度慢时,可使用镜像加速

pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
pip install ftllm -U

由于目前PyPI限制库大小,安装包中不含ROCM依赖,安装ftllm之前建议先手动安装ROCM 6.3.3 (若已安装ROCM可跳过)

wget wget https://repo.radeon.com/amdgpu-install/6.3.3/ubuntu/jammy/amdgpu-install_6.3.60303-1_all.deb
apt install ./amdgpu-install_6.3.60303-1_all.deb -y
amdgpu-install --usecase=hiplibsdk,rocm,dkms -y

然后用pip安装,命令如下:

pip install ftllm-rocm -U

第一次安装前需要安装依赖库:

pip install https://www.modelscope.cn/models/huangyuyang/fastllmdepend-windows/resolve/master/ftllmdepend-0.0.0.2-py3-none-win_amd64.whl

然后用pip安装,命令如下:

pip install ftllm -U
  • Hint

Conda下安装有时候会出现环境错误,如果出现可以尝试在Conda外或使用venv等虚拟环境尝试

(若使用时报错,可参考ftllm报错 )

可以运行一个较小模型测试安装是否成功, 以Qwen/Qwen3-0.6B模型为例

ftllm run Qwen/Qwen3-0.6B
ftllm webui Qwen/Qwen3-0.6B
ftllm server Qwen/Qwen3-0.6B
ftllm
ftllm tui

ftllm

不带参数时会进入终端部署向导,等价于 ftllm tui

。它会保存部署配置到本机用户配置目录,首页可通过键盘选择已保存命令进行新建、编辑、启动或删除。部署表单默认只显示基础配置,更多参数放在高级选项中;模型路径必须填写为已存在的本地目录,可按 Tab 补全目录;也可以从常用 ModelScope 模型列表中选择模型并下载到指定目录。

基本的启动命令格式如下:

ftllm run Qwen/Qwen3-0.6B # 启动本地对话
ftllm webui Qwen/Qwen3-0.6B # 启动WebUI
ftllm server Qwen/Qwen3-0.6B # 启动API Server
ftllm # 通过终端命令列表选择/编辑/启动部署配置,模型路径必须是已存在目录

根据你需要开启的服务,选择相应的命令。以 server

命令为例,格式如下:

ftllm server model

这里的model

可以是:

  • Huggingface上的模型,例如 Qwen/Qwen3-0.6B

代表千问3-0.6B模型 - 本地模型路径。例如 /mnt/Qwen3-0.6B

,高速下载模型可以参考模型下载

无论是在线模型还是本地模型,目前支持以下几种格式 (均以在线模型举例,可以在Huggingface上搜到对应模型):

FP16

,BF16

格式的原始模型,例如Qwen/Qwen3-0.6B

FP8

格式的模型,例如Qwen/Qwen3-0.6B-FP8

AWQ

格式的模型,例如Qwen/Qwen3-14B-AWQ

Fastllm

格式的模型,例如fastllm/DeepSeek-V3-0324-INT4

。也可以下载原始模型后通过模型导出中的命令导出GGUF

格式的模型,需要用--ori

参数指定原始模型路径,例如

ftllm server DeepSeek-V3-0324-Q4_K_M-00001-of-00009.gguf --ori DeepSeek-V3

这里的DeepSeek-V3

是原始模型文件夹,无需下载权重文件,可以参考如下命令下载:

ftllm download deepseek-ai/DeepSeek-V3 --exclude "*safetensors*"

如果您是第一次使用ftllm,建议直接使用基本的启动命令启动,所有的参数都会自动设置。如果您希望继续调参,请参照下面的参数设置说明

当启动的模型为浮点精度时(BF16

, FP16

, FP8

)时,可以通过以下参数来设置模型的推理精度:

--dtype

:描述: 指定模型的数据类型。可选值:int4g

int4

int8

fp8

float16

或其他支持的数据类型。示例:--dtype int4

--moe_dtype

:描述: 指定模型MOE层的数据类型。可选值:int4g

int4

int8

fp8

float16

或其他支持的数据类型。示例:--moe_dtype int4

说明: 如果指定的模型不是moe

结构的模型,这个参数不会生效

命令示例:

ftllm server Qwen/Qwen3-0.6B --dtype int8 

ftllm server deepseek-ai/DeepSeek-V3-0324 --dtype fp8 --moe_dtype int4

--dtype_config

:描述: 指定动态量化配置文件。说明: 参考动态量化说明

若不设定这些参数,ftllm会使用模型中设定的精度来进行推理

若使用的模型已经是量化好的模型(例如AWQ模型,Fastllm导出的量化模型等),建议不指定这些参数

可以通过以下参数来设定执行推理的设备

--device

:描述: 指定模型运行的计算设备。示例:--device cpu

,--device cuda

常用值说明:cpu

使用cpu

推理cuda

使用gpu

推理numa

使用多路numa

节点加速推理,在多CPU的机器才会有提升。使用numa加速时,强烈建议关闭系统numa平衡。(ubuntu中可使用命令sudo sysctl -w kernel.numa_balancing=0

)multicuda

使用多设备张量并行推理使用多显卡:--device multicuda:0,1

使用多显卡+CPU:--device multicuda:0,cpu

按比例使用多显卡+CPU:--device multicuda:0:4,1:5,cpu:1

(cuda:0

计算4/10,cuda:1

计算5/10,cpu

计算1/10)

串行计算: 一些场景下可以指定不同的device串行执行。例如--device "{'cuda:0':3,'cuda:1':2}"

: 这样3/5

的层会运行在cuda:0

上,2/5

的层会运行在cuda:1

--device "{'multicuda:0,1':3,'cuda:1':2}"

: 这样3/5

的层会使用cuda:0

,cuda:1

张量并行,2/5

的层仅仅运行在cuda:1

简写:--device cudapp=N

表示N卡均匀串行,例如--device cudapp=4

等价于--device "{'cuda:0':1,'cuda:1':1,'cuda:2':1,'cuda:3':1}"

简写:--device cudapp=1:2:3

表示三卡按1:2:3比例串行,等价于--device "{'cuda:0':1,'cuda:1':2,'cuda:2':3}"

--moe_device

:描述: 指定 MOE(Mixture of Experts)层的计算设备。示例:--moe_device cpu

,--moe_device numa

常用值说明:cpu

使用cpu

推理numa

使用多路numa

节点加速推理,在多CPU的机器才会有提升cuda

使用gpu

推理 (MOE层需要大量显存,一般不建议指定为cuda

说明: 一般和device指定为不同的设备实现混合推理,例如--device cuda --moe_device cpu

来实现MOE模型的单卡+CPU混合推理。--device cuda --moe_device numa

来实现MOE模型的单卡+多NUMA节点加速推理 如果指定的模型不是moe

结构的模型,这个参数不会生效

--moe_device_layers

:描述: 指定最后多少层 MOE 使用--moe_device

,前面的 MOE 层继续使用主设备或--tp

指定的 CUDA 张量并行设备。示例:--tp 0,1 --moe_device numa --moe_device_layers 8

说明: 默认-1

表示所有 MOE 层都使用--moe_device

,设置为0

表示不单独把后段 MOE 放到--moe_device

若不设定这些参数,会使用默认配置来推理,默认配置如下:

模型类型 device moe_device
稠密模型 cuda 不生效
MOE模型 cuda cpu

如果只设置了device没设置moe_device,则moe_device会跟随device

对于发烧友而言,如果想更进一步榨干硬件,可以参考 混合推理指南

multicuda专用worker线程的调优环境变量见 混合推理指南:multicuda调优环境变量

可以通过下列参数设置运行参数。

需要注意的是,速度和参数设置并不一定正相关,如果对性能要求高,可以多方向尝试一下

-t

--threads

:描述: 设置使用的CPU线程数。- 当 device

cpu

时,这个参数决定了推理使用的线程数 - 当 device

numa

时,推理线程数主要由环境变量FASTLLM_NUMA_THREADS

决定,threads

参数请设得小一点(推荐设为1)

  • 示例:-t 27

例如我们在多CPU设备上用GPU + 多CPU混合部署一个MOE

模型fastllm/DeepSeek-V3-0324-INT4

,可以尝试这些命令:

export FASTLLM_NUMA_THREADS=27 && ftllm server fastllm/DeepSeek-V3-0324-INT4 --device cuda --moe_device numa -t 1 

export FASTLLM_NUMA_THREADS=16 && ftllm server fastllm/DeepSeek-V3-0324-INT4 --device cuda --moe_device numa -t 1 

numactl -C 0-31 -m 0 ftllm server fastllm/DeepSeek-V3-0324-INT4 --device cuda --moe_device cpu -t 27 

不同硬件上,不同参数发挥出的性能有很大不同。一般而言,CPU上使用的线程数不建议超过物理核数

--moe_experts

:描述: 指定 MOE(Mixture of Experts)层使用的专家数。不设定则根据模型配置设定。减少专家数可以提高推理速度,但可能降低推理准确度示例:--moe_experts 6

--cuda_se

:描述: 指定 MOE中的共享专家 是否在cuda上执行,默认为true示例:--cuda_se false

--cuda_slab

:描述: 设置 CUDA 模型权重 slab 分配块大小,单位 MB。默认0

表示关闭。将大量 MOE 专家权重放在 CUDA 上时,可用它减少小权重分别cudaMalloc

带来的显存页对齐和碎片开销。示例:--cuda_slab 1024

--port

:描述: 指定服务运行的端口号。示例:--port 8080

--help

:描述: 查看模块参数详细信息。示例:ftllm server --help

--version

-v

:描述: 查看ftllm版本号。示例:ftllm -v

--hide_input

:描述: server模式隐藏日志中的请求信息。示例:ftllm server --hide_input

--api_key

:描述: server模式设定api_key。示例:ftllm server --api_key xxxxxxxx

--max_token

:描述: webui模式指定最大输出。示例:ftllm webui --max_token

--think

:描述: 强制思考。示例:ftllm webui --think

--cache_dir

:描述: 指定在线Huggingface模型的缓存目录示例:ftllm --cache_dir /mnt

--chat_template

:描述: 指定chat_template文件示例:ftllm --chat_template deepseekv31.jinja

目前以下模型支持工具调用:

  • GLM4.5, GLM4.5-AIR
  • Qwen3-Instruct系列
  • Qwen3-Coder系列
  • Kimi-K2
  • DeepSeekV3.1, 需要指定chat_template, 文件位于本项目 example/chat_template/deepseekv31.jinja

可以使用如下命令将模型下载到本地(使用高速镜像,无需科学上网)

ftllm download deepseek-ai/DeepSeek-R1

如果使用量化加载模型(如--dtype int4

),那么每次读取模型时会在线量化,读取速度较慢。

ftllm export 是一个用于导出和转换模型权重的工具。它支持将模型权重转换为不同的数据类型。以下是如何使用 ftllm export 的详细说明。

ftllm export <模型路径> -o <输出路径> --dtype <数据类型> -t <线程数>
ftllm export /mnt/DeepSeek-V3 -o /mnt/DeepSeek-V3-INT4 --dtype int4 -t 16

可以通过指定--moe_dtype

来实现混合精度,例如

ftllm export /mnt/DeepSeek-V3 -o /mnt/DeepSeek-V3-FP16INT4 --dtype float16 --moe_dtype int4 -t 16

导出后的模型使用方法和原始模型类似,使用导出模型时--dtype

参数将被忽略

例如

ftllm run /mnt/DeepSeek-V3-INT4/

如果需要运行更多早期的模型,请参考支持模型列表

若pip安装失败或有其它特殊需求,可以用源码编译安装 源码安装后如果需要卸载,方法和PIP安装一样

pip uninstall ftllm

建议使用cmake编译,需要提前安装gcc,g++ (建议9.4以上), make, cmake (建议3.23以上)

需要安装numa库,在Ubuntu下的安装命令一般使用:

apt-get install libnuma-dev

如果编译出错,建议使用AI工具帮忙安装环境

GPU编译需要提前安装好CUDA编译环境,建议使用尽可能新的CUDA版本,并安装NCCL包

使用如下命令编译

bash install.sh -DUSE_CUDA=ON -D CMAKE_CUDA_COMPILER=$(which nvcc) # 编译GPU版本

其他不同平台的编译可参考文档

编译中遇到问题可参考 FAQ文档

1Cat-vLLM 中的 awq_sm70_gemm 适配思路

感谢大佬对开源社区的贡献!如发现未标明的引用代码可在issue中提出

── more in #large-language-models 4 stories · sorted by recency
── more on @fastllm 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/fastllm-a-llm-infere…] indexed:0 read:4min 2026-06-30 ·