Tlntin / Qwen-TensorRT-LLM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to build Qwen-72B-Chat-Int4 with tp=2

liyunhan opened this issue · comments

For Qwen, in the int4-gptq section of examples, it uses tp = 1, but when I configure tp = 2 or more, it raises an assertation error:
AssertationError: The current implementation of GQA requires the number of K/V heads to match the number of GPUs. This limitation will be removed in a future version.

tp * pp =world_size(显卡数)

我用的是官方triton23.12-trtllm容器,模型是qwen-72b-chat-int4。
有两个问题想请教:

  1. 已经量化的模型能不能直接编译?我试了各种命令都会报错,是不是int4模型只能用gptq那个demo编译了?
  2. 我是两张A6000-48G卡,world_size理论上应该设置2,对应的tp_size那也应该是2,但是4int编译gptq的时候代码里n_kv_head==tp_size,这个好像是写死的,默认的n_kv_head是32,如果改成n_kv_head=2我看别人说效果很差很差很差..

默认的n_kv_head是32 这里应该是错了,qwen并没有使用GQA,所以n_kv_head默认应该是None,或者说取和num_attention_heads一样的数值。
对于你的Qwen-72B-Chat-Int4你可以将这一行换成None或者64

默认的n_kv_head是32 这里应该是错了,qwen并没有使用GQA,所以n_kv_head默认应该是None,或者说取和num_attention_heads一样的数值。 对于你的Qwen-72B-Chat-Int4你可以将这一行换成None或者64

还要请教您,直接下载的int4权重,不能直接编译trt_engine吗?(我用的官方容器,不过trt-llm是编译的v0.8.0)

可以,看代码是支持的。

可以,看代码是支持的。

那很好奇还需要加上'--use_weight_only'、 '--weight_only_precision int4'和'--per_group'这几个参数吗?
(我记得--per_group'是gptq编译才要加的)

需要

@Tlntin 大佬,还是要请教您... 我只有两张A6000,这是我的命令 :
python build.py --hf_model_dir /mnt/trtllm/Qwen-72B-Chat-Int4/ --quant_ckpt_path /mnt/trtllm/Qwen-72B-Chat-Int4/ --dtype float16 --remove_input_padding --use_gpt_attention_plugin float16 --enable_context_fmha --use_gemm_plugin float16 --use_weight_only --weight_only_precision int4_gptq --per_group --world_size 2 --tp_size 2 --output_dir /mnt/trtllm/qwen_trt_engines/int4_gptq/2-gpu --use_inflight_batching
然后我遇到了这个问题:
[backendBuilderConfig.cpp::validateBasicAssumptions::28] Error Code 9: Internal Error (Builder was created on device different than current device.) AssertionError: Failed to build engine for rank 0
有人提议只用单卡build,我试了单卡确实可以走的更远一些,但是会被突然killed,查了查说这种情况一般都是显存不够被kill了..实在不知道怎么办了

建议暂时先不要用官方的0.8.0,我刚刚测试了一下1.8b都跑不起来(可以build,没办法run)。
可以先试试当前项目的main分支,也就是0.7.0试试。

@Tlntin 那现在这种情况我是不是要重新部署triton23.12-trtllm的container,再去install tensorrt-llm了。我记得在您的另一个回答下看到是建议这样的。

@Tlntin 那现在这种情况我是不是要重新部署triton23.12-trtllm的container,再去install tensorrt-llm了。我记得在您的另一个回答下看到是建议这样的。

看你用不用triton,不用triton可以直接部署triton23.12-trtllm的container。
需要用triton部署的话,那就需要自己编译triton23.12-trtllm的container。编译参考

@Tlntin 那现在这种情况我是不是要重新部署triton23.12-trtllm的container,再去install tensorrt-llm了。我记得在您的另一个回答下看到是建议这样的。

看你用不用triton,不用triton可以直接部署triton23.12-trtllm的container。 需要用triton部署的话,那就需要自己编译triton23.12-trtllm的container。编译参考

放弃思考,我还是根据您的流程再走一遍吧。

@Tlntin 我现在还是有点懵,我看官方tensorrt-llm v0.8.0才支持针对qwen的gptq编译,v0.7.0是不支持的。这种情况,我必须要用您提供的包吗?或者说如果我放弃gptq了,但是我手里目前只有int4的权重,直接Build。但是直接build,我试过的命令都不行...

@Tlntin 我现在还是有点懵,我看官方tensorrt-llm v0.8.0才支持针对qwen的gptq编译,v0.7.0是不支持的。这种情况,我必须要用您提供的包吗?或者说如果我放弃gptq了,但是我手里目前只有int4的权重,直接Build。但是直接build,我试过的命令都不行...

gptq和trt-llm版本没啥关系,本项目0.5.0版本就开始支持了。0.7.0基本可以随便用了。

也就是说官方v0.7.0版本也是支持qwen gptq 这个功能的?

------------------ Original ------------------ From: Tlntin @.> Date: Thu,Mar 21,2024 5:24 PM To: Tlntin/Qwen-TensorRT-LLM @.> Cc: liyunhan @.>, Author @.> Subject: Re: [Tlntin/Qwen-TensorRT-LLM] how to build Qwen-72B-Chat-Int4 withtp=2 (Issue #94) @Tlntin 我现在还是有点懵,我看官方tensorrt-llm v0.8.0才支持针对qwen的gptq编译,v0.7.0是不支持的。这种情况,我必须要用您提供的包吗?或者说如果我放弃gptq了,但是我手里目前只有int4的权重,直接Build。但是直接build,我试过的命令都不行... gptq和trt-llm版本没啥关系,本项目0.5.0版本就开始支持了。0.7.0基本可以随便用了。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

不一定

@Tlntin 大佬,我显卡是两张A6000,按照教程编译的docker镜像(看dockerfile版本是trtllm23.10),git clone的您这个项目文件,模型权重用的qwen-72b-chat-4int版本(看官方应该是gptq量化的),以下是我的build命令:
python build.py --use_weight_only --weight_only_precision int4_gptq --per_group --hf_model_dir /mnt/trtllm/qwen-72b-chat-int4-gptq/ --quant_ckpt_path /mnt/trtllm/qwen-72b-chat-int4-gptq/ --tp_size 2 --world_size 2 --output_dir /mnt/trtllm/trt_engines/

我明明设置了 tp_size和world_size,但是加载权重的时候好像都在一张显卡上,然后就没报错的被killed了

@Tlntin 大佬,我显卡是两张A6000,按照教程编译的docker镜像(看dockerfile版本是trtllm23.10),git clone的您这个项目文件,模型权重用的qwen-72b-chat-4int版本(看官方应该是gptq量化的),以下是我的build命令: python build.py --use_weight_only --weight_only_precision int4_gptq --per_group --hf_model_dir /mnt/trtllm/qwen-72b-chat-int4-gptq/ --quant_ckpt_path /mnt/trtllm/qwen-72b-chat-int4-gptq/ --tp_size 2 --world_size 2 --output_dir /mnt/trtllm/trt_engines/

我明明设置了 tp_size和world_size,但是加载权重的时候好像都在一张显卡上,然后就没报错的被killed了

对了,我还安装了flash-attention。 我查了查有的说是服务器内存问题,但是我内存是62G,两张A6000应该也不存在显存不够的问题吧。

flash-attention 可以不用装。
加载权重的时候都在一张卡上?可以参考这位的 issues/85
被killed?说明是cpu 内存不太够,可以将模型都放在两个gpu上面(device_map="cuda"),省点cpu内存试试?

flash-attention 可以不用装。 加载权重的时候都在一张卡上?可以参考这位的 issues/85 被killed?说明是cpu 内存不太够,可以将模型都放在两个gpu上面(device_map="cuda"),省点cpu内存试试?

我懂了,我去看了您readme里面写的配置要求。我单机内存在60G,72B模型的显存我够了,但是内存还差了一倍多...应该是..摸不起72B了...我去试试14B吧..

@Tlntin 您好,我已经成功走到triton部署这一步了。按照triton_deploy_trt-llm.md的操作配合好了,但是提示我chat_format key error,我发现qwen1.5的generation_config.json是没有chat_format这个字段的

@Tlntin 您好,我已经成功走到triton部署这一步了。按照triton_deploy_trt-llm.md的操作配合好了,但是提示我chat_format key error,我发现qwen1.5的generation_config.json是没有chat_format这个字段的

是的, triton部署0.7.0只适用于qwen,感兴趣可以自己改改让他兼容qwen1.5,也可以参考看dev分支(对应0.8.0),那个triton部署是用qwen1.5做的。

@Tlntin 大佬我还想请教一个问题,比如我用qwen-14b-chat模型,未量化的情况下build成功并且部署在triton上,batch_size=2,我发现部署成功后双卡A6000的GPU几乎都被占用满了(nvidia-smi看的),这是为什么?单纯的运行tensorrt-llm的模型看到显存用不了这么多

@Tlntin 大佬我还想请教一个问题,比如我用qwen-14b-chat模型,未量化的情况下build成功并且部署在triton上,batch_size=2,我发现部署成功后双卡A6000的GPU几乎都被占用满了(nvidia-smi看的),这是为什么?单纯的运行tensorrt-llm的模型看到显存用不了这么多

开了paged-kv-cache,默认会将剩余显存提前存起来(这个参数可以在triton_model_repo/tensorrt_llm/config.pbtxt的kv_cache_free_gpu_mem_fraction中看到,默认比例是0.5,推荐0.8-0.9),太低了可能会导致kv-cache无法分配而失败。。

@Tlntin 我在build的时候没有指定该参数,是默认开启了吗?

@Tlntin 我在build的时候没有指定该参数,是默认开启了吗?

开了inflight_batching就会开启page-kv-cache,除非你用V1模式。

@Tlntin 呃,我在triton_model_repo/tensorrt_llm/config.pbtxt的inflight_batching中设置的V1