ktransformers icon indicating copy to clipboard operation
ktransformers copied to clipboard

How to enable optimize rules?

Open ArYuZzz opened this issue 1 year ago • 11 comments

There are already some optimize_rules for DeepSeek-R1/V3 in the latest v0.2 Release.

root@ccd23aad1a14:/usr/local/lib/python3.11/dist-packages/ktransformers/optimize# ll optimize_rules/
total 72
drwxr-xr-x 2 root root 4096 Feb 12 13:01 ./
drwxr-xr-x 4 root root   82 Feb 12 16:33 ../
-rw-r--r-- 1 root root 8158 Feb 12 13:01 DeepSeek-V2-Chat-multi-gpu-4.yaml
-rw-r--r-- 1 root root 4231 Feb 12 13:01 DeepSeek-V2-Chat-multi-gpu.yaml
-rw-r--r-- 1 root root 1946 Feb 12 13:01 DeepSeek-V2-Chat.yaml
-rw-r--r-- 1 root root 4141 Feb 12 13:01 DeepSeek-V2-Lite-Chat-multi-gpu.yaml
-rw-r--r-- 1 root root 1946 Feb 12 13:01 DeepSeek-V2-Lite-Chat.yaml
-rw-r--r-- 1 root root 4824 Feb 12 13:01 DeepSeek-V3-Chat-multi-gpu-marlin.yaml
-rw-r--r-- 1 root root 4824 Feb 12 13:01 DeepSeek-V3-Chat-multi-gpu.yaml
-rw-r--r-- 1 root root 2155 Feb 12 13:01 DeepSeek-V3-Chat.yaml
-rw-r--r-- 1 root root  771 Feb 12 13:01 Internlm2_5-7b-Chat-1m.yaml
-rw-r--r-- 1 root root 1495 Feb 12 13:01 Mixtral.yaml
-rw-r--r-- 1 root root 3779 Feb 12 13:01 Qwen2-57B-A14B-Instruct-multi-gpu.yaml
-rw-r--r-- 1 root root 1923 Feb 12 13:01 Qwen2-57B-A14B-Instruct.yaml

But it seems like they are not enabled since my second GPU is not used. I've read the Injection tutorial and other relevant issues , but still confused about how to enable the rules.

ArYuZzz avatar Feb 12 '25 08:02 ArYuZzz

So by the way, which optimize_rule can be used for DeepSeek-R1 ? 😂 I am quite confused when I want to run a local DeepSeek-R1 but I cannot find proper rule file 😂

NeilAlfred avatar Feb 12 '25 09:02 NeilAlfred

So by the way, which optimize_rule can be used for DeepSeek-R1 ? 😂 I am quite confused when I want to run a local DeepSeek-R1 but I cannot find proper rule file 😂

you can specify the --optimize_rule_path arg (for local_chat.py). We have set default rule path, but you can switch to a new or even customize yours. See optional files [here] (https://github.com/kvcache-ai/ktransformers/tree/main/ktransformers/optimize/optimize_rules)

KMSorSMS avatar Feb 12 '25 12:02 KMSorSMS

So by the way, which optimize_rule can be used for DeepSeek-R1 ? 😂 I am quite confused when I want to run a local DeepSeek-R1 but I cannot find proper rule file 😂

you can specify the --optimize_rule_path arg (for local_chat.py). We have set default rule path, but you can switch to a new or even customize yours. See optional files [here] (https://github.com/kvcache-ai/ktransformers/tree/main/ktransformers/optimize/optimize_rules)

😂 Thanks a lot for your reply. Well, I still don't find any filename contain "DeepSeek-R1" . Do you mean that I can just use like DeepSeek-V3-Chat.yaml for DeepSeek-R1? That seems a bit weird 😂 I guess I need to replace some name of some class in it?

NeilAlfred avatar Feb 12 '25 17:02 NeilAlfred

我是cli运行的,应该使用哪个优化规则文件

python -m ktransformers.local_chat --model_path deepseek-ai/DeepSeek-R1  --gguf_path ./gguf_file --optimize_rule_path /home/user/app/ktransformers/ktransformers/optimize/optimize_rules

Zha-Miku avatar Feb 13 '25 07:02 Zha-Miku

So by the way, which optimize_rule can be used for DeepSeek-R1 ? 😂 I am quite confused when I want to run a local DeepSeek-R1 but I cannot find proper rule file 😂

you can specify the --optimize_rule_path arg (for local_chat.py). We have set default rule path, but you can switch to a new or even customize yours. See optional files [here] (https://github.com/kvcache-ai/ktransformers/tree/main/ktransformers/optimize/optimize_rules)

😂 Thanks a lot for your reply. Well, I still don't find any filename contain "DeepSeek-R1" . Do you mean that I can just use like DeepSeek-V3-Chat.yaml for DeepSeek-R1? That seems a bit weird 😂 I guess I need to replace some name of some class in it?

the same question. Can anyone give DeepSeek-R1.yaml? I use DeepSeek-R1-Distill-Qwen-7B model

qingqinghu1026 avatar Feb 13 '25 07:02 qingqinghu1026

So by the way, which optimize_rule can be used for DeepSeek-R1 ? 😂 I am quite confused when I want to run a local DeepSeek-R1 but I cannot find proper rule file 😂

you can specify the --optimize_rule_path arg (for local_chat.py). We have set default rule path, but you can switch to a new or even customize yours. See optional files [here] (https://github.com/kvcache-ai/ktransformers/tree/main/ktransformers/optimize/optimize_rules)

😂 Thanks a lot for your reply. Well, I still don't find any filename contain "DeepSeek-R1" . Do you mean that I can just use like DeepSeek-V3-Chat.yaml for DeepSeek-R1? That seems a bit weird 😂 I guess I need to replace some name of some class in it?

the same question. Can anyone give DeepSeek-R1.yaml? I use DeepSeek-R1-Distill-Qwen-7B model

seems that ktransformers do not ever support qwen model

Anionex avatar Feb 15 '25 21:02 Anionex

So by the way, which optimize_rule can be used for DeepSeek-R1 ? 😂 I am quite confused when I want to run a local DeepSeek-R1 but I cannot find proper rule file 😂

you can specify the --optimize_rule_path arg (for local_chat.py). We have set default rule path, but you can switch to a new or even customize yours. See optional files [here] (https://github.com/kvcache-ai/ktransformers/tree/main/ktransformers/optimize/optimize_rules)

😂 Thanks a lot for your reply. Well, I still don't find any filename contain "DeepSeek-R1" . Do you mean that I can just use like DeepSeek-V3-Chat.yaml for DeepSeek-R1? That seems a bit weird 😂 I guess I need to replace some name of some class in it?

Yes, you just need to use DeepSeek-V3-Chat.yaml as v3 and r1's architectures are the same.

KMSorSMS avatar Mar 05 '25 03:03 KMSorSMS

我用了一台4卡的A40(4*A40),我的命令: python ./ktransformers/local_chat.py --model_path /nas_data/DeepSeek-R1/ --gguf_path /nas_data/DeepSeek-R1-GGUF/DeepSeek-R1-Q8_0/ --force_think true --cpu_infer 65 --max_new_tokens 4096 --optimize_rule_path ktransformers/optimize/optimize_rules/DeepSeek-V3-Chat-multi-gpu-4.yaml,但是结果还是只启动了一张GPU,为什么?还有什么参数需要修改吗

ghost avatar Mar 12 '25 09:03 ghost

我用了一台4卡的A40(4*A40),我的命令: python ./ktransformers/local_chat.py --model_path /nas_data/DeepSeek-R1/ --gguf_path /nas_data/DeepSeek-R1-GGUF/DeepSeek-R1-Q8_0/ --force_think true --cpu_infer 65 --max_new_tokens 4096 --optimize_rule_path ktransformers/optimize/optimize_rules/DeepSeek-V3-Chat-multi-gpu-4.yaml,但是结果还是只启动了一张GPU,为什么?还有什么参数需要修改吗

目前这个参数名称改为了 --optimize_cofig_path, 你可以在这里看到它的名称

KMSorSMS avatar Mar 13 '25 16:03 KMSorSMS

我用了一台4卡的A40(4*A40),我的命令: python ./ktransformers/local_chat.py --model_path /nas_data/DeepSeek-R1/ --gguf_path /nas_data/DeepSeek-R1-GGUF/DeepSeek-R1-Q8_0/ --force_think true --cpu_infer 65 --max_new_tokens 4096 --optimize_rule_path ktransformers/optimize/optimize_rules/DeepSeek-V3-Chat-multi-gpu-4.yaml,但是结果还是只启动了一张GPU,为什么?还有什么参数需要修改吗

目前这个参数名称改为了 --optimize_cofig_path, 你可以在这里看到它的名称

感谢回复,改了参数之后可以看到启动了4张GPU,但是好像每个GPU上加载的显存变成了原来的1/4,对于我的int8版本的模型来说,还是空间不够,请问有什么办法可以增大模型加载到GPU显存上吗?

ghost avatar Mar 14 '25 03:03 ghost

我用了一台4卡的A40(4*A40),我的命令: python ./ktransformers/local_chat.py --model_path /nas_data/DeepSeek-R1/ --gguf_path /nas_data/DeepSeek-R1-GGUF/DeepSeek-R1-Q8_0/ --force_think true --cpu_infer 65 --max_new_tokens 4096 --optimize_rule_path ktransformers/optimize/optimize_rules/DeepSeek-V3-Chat-multi-gpu-4.yaml,但是结果还是只启动了一张GPU,为什么?还有什么参数需要修改吗

目前这个参数名称改为了 --optimize_cofig_path, 你可以在这里看到它的名称

感谢回复,改了参数之后可以看到启动了4张GPU,但是好像每个GPU上加载的显存变成了原来的1/4,对于我的int8版本的模型来说,还是空间不够,请问有什么办法可以增大模型加载到GPU显存上吗?

可以修改yaml里面具体的每个模块的的计算方式,以及对应的设备,这个教程参考在这里

KMSorSMS avatar Mar 14 '25 14:03 KMSorSMS