3 Star 18 Fork 3

Gitee 极速下载/fastllm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github/workflows
docs
benchmark.md
custom.md
custom_op.md
deepseek.md
demo_arguments.md
dtype_config.md
english_custom.md
english_demo_arguments.md
faq.md
ftllm.md
llama_cookbook.md
mixforward.md
models.md
qwen3.md
rocm.md
tfacc.md
version.md
wechat_group0.jpg
example
include
pyfastllm
src
test
third_party
tools
whl_docker
whl_docker_rocm
.dockerignore
.gitignore
.gitmodules
CMakeLists.txt
Dockerfile
LICENSE
README.md
README_EN.md
docker-compose.yaml
install.sh
main.cpp
make_whl.sh
make_whl_rocm.sh
requirements-server.txt
simple_install.sh
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/ztxz16/fastllm
克隆/下载
dtype_config.md 2.71 KB
一键复制 编辑 原始数据 按行查看 历史
黄宇扬 提交于 2个月前 . 修改文档

动态量化使用说明

这个文档以DeepSeek-V3-0324模型为例,介绍如何使用动态量化功能

(注意,目前的量化功能为初版,后续会支持动态设定量化方法,以及设置重要性矩阵来提高量化精度)

基本用法

首先我们要编写一个配置文件(可以直接使用下一节中的示例)

假设配置文件保存在 /root/dtype_config.json

下面这条命令会读会读取/root/dtype_config.json中的的规则来进行动态量化,并部署api server

ftllm server fastllm/DeepSeek-V3-0324 --dtype_config /root/dtype_config.json

下面这条命令会读会读取/root/dtype_config.json中的的规则来进行动态量化,并导出模型

ftllm export fastllm/DeepSeek-V3-0324 --dtype_config /root/dtype_config.json -o DeepSeek-V3-0324-MIX

如何编写配置文件

编写动态量化配置时,最好先了解如下知识:

  • 需要对正则表达式有一定了解
  • 需要对json格式有一定了解
  • 需要对模型的结构有一定了解。可以通过查看模型文件夹下的model.safetensors.index.json来查看模型的权重名称。

我们以如下示例来说明如何编写配置文件:

[
    {
        "key" : "(.)*",
        "dtype" : "int4g",
        "comment": "default use dtype int4g"
    },
    {
        "key" : "model\\.layers\\.([0-9]|[1][0-9]|2[0-5])\\.(.)*",
        "dtype" : "fp8",
        "comment": "layer 0~25 use dtype fp8"
    },
    {
        "key" : "(.)*mlp\\.gate\\.weight",
        "dtype" : "float16",
        "comment": "gate use float16"
    },
    {
        "key" : "(.)*experts(.)*[gate|up|down]_proj(.)*",
        "dtype" : "int4",
        "comment": "moe use int4"
    }
]

将以上json代码保存为/root/dtype_config.json(这里的路径只是举例,你可以保存到任意位置) 然后就可以使用--dtype_config /root/dtype_config.json来读取其中的配置(如果你的文件不是保存在/root/dtype_config.json,那么请使用你保存文件的路径)

说明

  • 配置文件中是一个json的数组,数组中每个元素代表一条量化规则。
  • 每条规则中,目前有两个关键参数
    • key: 指定匹配权重的正则表达式
    • value: 当权重和key指定的正则表达式匹配时,使用value指定的类型
  • 越靠后的规则优先级越高,一个权重如果匹配上了多个规则,那么会使用最后一条规则
  • 规则中的其余参数不会有影响。例如上例中的comment参数仅为注释
  • 上例中:
    • 0~25层的MLA部分使用fp8类型
    • 剩余层的MLA部分使用int4g类型
    • gate权重均使用float16类型
    • moe部分均使用int4类型
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/mirrors/fastllm.git
git@gitee.com:mirrors/fastllm.git
mirrors
fastllm
fastllm
master

搜索帮助