@@ -94,222 +94,8 @@ https://github.com/user-attachments/assets/a865e5e4-bca3-401e-94b8-af3c080e6c12
9494
9595<h2 id =" quick-start " >🚀 快速入门</h2 >
9696
97- <h3 >准备工作</h3 >
98- 一些准备工作:
99-
100- - 如果您还没有 CUDA 12.1 及以上版本,可以从 [ 这里] ( https://developer.nvidia.com/cuda-downloads ) 安装。
101-
102- ``` sh
103- # Adding CUDA to PATH
104- export PATH=/usr/local/cuda/bin:$PATH
105- export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
106- export CUDA_PATH=/usr/local/cuda
107- ```
108-
109- - Linux-x86_64 系统,需要安装 gcc、g++ 和 cmake
110-
111- ``` sh
112- sudo apt-get update
113- sudo apt-get install gcc g++ cmake ninja-build
114- ```
115-
116- - 我们建议使用 Conda 创建一个 Python=3.11 的虚拟环境来运行我们的程序。
117-
118- ``` sh
119- conda create --name ktransformers python=3.11
120- conda activate ktransformers # 您可能需要先运行 ‘conda init’ 并重新打开 shell
121- ```
122-
123- - 确保安装了 PyTorch、packaging、ninja
124-
125- ```
126- pip install torch packaging ninja cpufeature numpy
127- ```
128-
129- <h3 >安装</h3 >
130-
131- 1 . 使用 Docker 镜像,详见 [ Docker 文档] ( ./doc/en/Docker.md )
132-
133- 2 . 您可以使用 Pypi 安装(适用于 Linux):
134-
135- ```
136- pip install ktransformers --no-build-isolation
137- ```
138-
139- 对于 Windows,我们提供了一个预编译的 whl 包 [ ktransformers-0.2.0+cu125torch24avx2-cp312-cp312-win_amd64.whl] ( https://github.com/kvcache-ai/ktransformers/releases/download/v0.2.0/ktransformers-0.2.0+cu125torch24avx2-cp312-cp312-win_amd64.whl ) ,需要 cuda-12.5、torch-2.4、python-3.11,更多预编译包正在制作中。
140-
141- 3 . 或者您可以下载源代码并编译:
142-
143- - init source code
144-
145- ``` sh
146- git clone https://github.com/kvcache-ai/ktransformers.git
147- cd ktransformers
148- git submodule init
149- git submodule update
150- ```
151-
152- - [可选] 如果您想运行网站,请在执行` ` ` bash install.sh` ` ` 之前, 进行 [compile the website](./doc/en/api/server/website.md)
153-
154- - 编译并安装(适用于 Linux)
155-
156- ```
157- bash install.sh
158- ```
159-
160- - 编译并安装(适用于 Windows)
161-
162- ```
163- install.bat
164- ```
165- 4. 如果您是开发者,可以使用 makefile 来编译和格式化代码。makefile 的详细用法请参见 [这里](./doc/en/makefile_usage.md)
166-
167- < h3> 本地聊天< /h3>
168- 我们提供了一个简单的命令行本地聊天 Python 脚本,您可以运行它进行测试。
169-
170- > 请注意,这只是一个非常简单的测试工具,仅支持一轮聊天,不记忆上一次输入。如果您想体验模型的全部功能,可以前往 RESTful API 和 Web UI。这里以 DeepSeek-V2-Lite-Chat-GGUF 模型为例,但我们也支持其他模型,您可以替换为您想要测试的任何模型。
171-
172- < h4> 运行示例< /h4>
173-
174- ` ` ` shell
175- # 从克隆的仓库根目录开始!
176- # 从克隆的仓库根目录开始!!
177- # 从克隆的仓库根目录开始!!!
178-
179- # 从 Hugging Face 下载 mzwing/DeepSeek-V2-Lite-Chat-GGUF
180- mkdir DeepSeek-V2-Lite-Chat-GGUF
181- cd DeepSeek-V2-Lite-Chat-GGUF
182-
183- wget https://huggingface.co/mzwing/DeepSeek-V2-Lite-Chat-GGUF/resolve/main/DeepSeek-V2-Lite-Chat.Q4_K_M.gguf -O DeepSeek-V2-Lite-Chat.Q4_K_M.gguf
184-
185- cd .. # 返回仓库根目录
186-
187- # 启动本地聊天
188- python -m ktransformers.local_chat --model_path deepseek-ai/DeepSeek-V2-Lite-Chat --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF
189-
190- # 如果遇到报错 “OSError: We couldn't connect to 'https://huggingface.co' to load this file”, 请尝试:
191- # GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite
192- # python ktransformers.local_chat --model_path ./DeepSeek-V2-Lite --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF
193- ` ` `
194-
195- 它具有以下参数:
196-
197- - ` --model_path` (required): 模型名称 (例如 " deepseek-ai/DeepSeek-V2-Lite-Chat" 将自动从 [Hugging Face](https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite) 下载配置)。或者,如果您已经有本地文件,可以直接使用该路径来初始化模型。
198-
199- > Note: < strong> .safetensors< /strong> 文件不是必需的。我们只需要配置文件来构建模型和分词器。
200-
201- - ` --gguf_path` (required): 包含 GGUF 文件的目录路径,可以从 [Hugging Face](https://huggingface.co/mzwing/DeepSeek-V2-Lite-Chat-GGUF/tree/main) 下载。请注意,该目录应仅包含当前模型的 GGUF,这意味着您需要为每个模型使用一个单独的目录。
202-
203- - ` --optimize_rule_path` (必需,Qwen2Moe 和 DeepSeek-V2 除外): 包含优化规则的 YAML 文件路径。在 [ktransformers/optimize/optimize_rules](ktransformers/optimize/optimize_rules) 目录中有两个预写的规则文件,用于优化 DeepSeek-V2 和 Qwen2-57B-A14,这两个是 SOTA MoE 模型。
204-
205- - ` --max_new_tokens` : Int (default=1000). 要生成的最大 new tokens。
206-
207- - ` --cpu_infer` : Int (default=10). 用于推理的 CPU 数量。理想情况下应设置为(总核心数 - 2)。
208-
209- < h3 id=" suggested-model" > 建议模型< /h3>
210-
211- | Model Name | Model Size | VRAM | Minimum DRAM | Recommended DRAM |
212- | ------------------------------ | ---------- | ----- | --------------- | ----------------- |
213- | DeepSeek-R1-q4_k_m | 377G | 14G | 382G | 512G |
214- | DeepSeek-V3-q4_k_m | 377G | 14G | 382G | 512G |
215- | DeepSeek-V2-q4_k_m | 133G | 11G | 136G | 192G |
216- | DeepSeek-V2.5-q4_k_m | 133G | 11G | 136G | 192G |
217- | DeepSeek-V2.5-IQ4_XS | 117G | 10G | 107G | 128G |
218- | Qwen2-57B-A14B-Instruct-q4_k_m | 33G | 8G | 34G | 64G |
219- | DeepSeek-V2-Lite-q4_k_m | 9.7G | 3G | 13G | 16G |
220- | Mixtral-8x7B-q4_k_m | 25G | 1.6G | 51G | 64G |
221- | Mixtral-8x22B-q4_k_m | 80G | 4G | 86.1G | 96G |
222- | InternLM2.5-7B-Chat-1M | 15.5G | 15.5G | 8G(32K context) | 150G (1M context) |
223-
224-
225- 更多即将推出。请告诉我们您最感兴趣的模型。
226-
227- 请注意,在使用 [DeepSeek](https://huggingface.co/deepseek-ai/DeepSeek-V2/blob/main/LICENSE) 和 [QWen](https://huggingface.co/Qwen/Qwen2-72B-Instruct/blob/main/LICENSE) 时,需要遵守相应的模型许可证。
228-
229- < details>
230- < summary> 点击显示如何运行其他示例< /summary>
231-
232- * Qwen2-57B
233-
234- ` ` ` sh
235- pip install flash_attn # For Qwen2
236-
237- mkdir Qwen2-57B-GGUF && cd Qwen2-57B-GGUF
238-
239- wget https://huggingface.co/Qwen/Qwen2-57B-A14B-Instruct-GGUF/resolve/main/qwen2-57b-a14b-instruct-q4_k_m.gguf?download=true -O qwen2-57b-a14b-instruct-q4_k_m.gguf
240-
241- cd ..
242-
243- python -m ktransformers.local_chat --model_name Qwen/Qwen2-57B-A14B-Instruct --gguf_path ./Qwen2-57B-GGUF
244-
245- # 如果遇到报错 “OSError: We couldn't connect to 'https://huggingface.co' to load this file”, 请尝试:
246- # GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/Qwen/Qwen2-57B-A14B-Instruct
247- # python ktransformers/local_chat.py --model_path ./Qwen2-57B-A14B-Instruct --gguf_path ./DeepSeek-V2-Lite-Chat-GGUF
248- ` ` `
249-
250- * DeepseekV2
251-
252- ` ` ` sh
253- mkdir DeepSeek-V2-Chat-0628-GGUF && cd DeepSeek-V2-Chat-0628-GGUF
254- # Download weights
255- wget https://huggingface.co/bartowski/DeepSeek-V2-Chat-0628-GGUF/resolve/main/DeepSeek-V2-Chat-0628-Q4_K_M/DeepSeek-V2-Chat-0628-Q4_K_M-00001-of-00004.gguf -o DeepSeek-V2-Chat-0628-Q4_K_M-00001-of-00004.gguf
256- wget https://huggingface.co/bartowski/DeepSeek-V2-Chat-0628-GGUF/resolve/main/DeepSeek-V2-Chat-0628-Q4_K_M/DeepSeek-V2-Chat-0628-Q4_K_M-00002-of-00004.gguf -o DeepSeek-V2-Chat-0628-Q4_K_M-00002-of-00004.gguf
257- wget https://huggingface.co/bartowski/DeepSeek-V2-Chat-0628-GGUF/resolve/main/DeepSeek-V2-Chat-0628-Q4_K_M/DeepSeek-V2-Chat-0628-Q4_K_M-00003-of-00004.gguf -o DeepSeek-V2-Chat-0628-Q4_K_M-00003-of-00004.gguf
258- wget https://huggingface.co/bartowski/DeepSeek-V2-Chat-0628-GGUF/resolve/main/DeepSeek-V2-Chat-0628-Q4_K_M/DeepSeek-V2-Chat-0628-Q4_K_M-00004-of-00004.gguf -o DeepSeek-V2-Chat-0628-Q4_K_M-00004-of-00004.gguf
259-
260- cd ..
261-
262- python -m ktransformers.local_chat --model_name deepseek-ai/DeepSeek-V2-Chat-0628 --gguf_path ./DeepSeek-V2-Chat-0628-GGUF
263-
264- # 如果遇到报错 “OSError: We couldn't connect to 'https://huggingface.co' to load this file”, 请尝试:
265-
266- # GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/deepseek-ai/DeepSeek-V2-Chat-0628
267-
268- # python -m ktransformers.local_chat --model_path ./DeepSeek-V2-Chat-0628 --gguf_path ./DeepSeek-V2-Chat-0628-GGUF
269- ` ` `
270-
271- | model name | weights download link |
272- | ----------| ----------|
273- | Qwen2-57B | [Qwen2-57B-A14B-gguf-Q4K-M](https://huggingface.co/Qwen/Qwen2-57B-A14B-Instruct-GGUF/tree/main) |
274- | DeepseekV2-coder | [DeepSeek-Coder-V2-Instruct-gguf-Q4K-M](https://huggingface.co/LoneStriker/DeepSeek-Coder-V2-Instruct-GGUF/tree/main) |
275- | DeepseekV2-chat | [DeepSeek-V2-Chat-gguf-Q4K-M](https://huggingface.co/bullerwins/DeepSeek-V2-Chat-0628-GGUF/tree/main) |
276- | DeepseekV2-lite | [DeepSeek-V2-Lite-Chat-GGUF-Q4K-M](https://huggingface.co/mzwing/DeepSeek-V2-Lite-Chat-GGUF/tree/main) |
277-
278- < /details>
279-
280- < ! -- pin block for jump -->
281- < span id=' id_666' >
282-
283- < h3> RESTful API and Web UI< /h3>
284-
285-
286- 启动不带网站的服务:
287-
288- ` ` ` sh
289- ktransformers --model_path deepseek-ai/DeepSeek-V2-Lite-Chat --gguf_path /path/to/DeepSeek-V2-Lite-Chat-GGUF --port 10002
290- ` ` `
291-
292- 启动带网站的服务:
293-
294- ` ` ` sh
295- ktransformers --model_path deepseek-ai/DeepSeek-V2-Lite-Chat --gguf_path /path/to/DeepSeek-V2-Lite-Chat-GGUF --port 10002 --web True
296- ` ` `
297-
298- 或者,如果您想使用 transformers 启动服务,model_path 应该包含 safetensors 文件:
299-
300- ` ` ` bash
301- ktransformers --type transformers --model_path /mnt/data/model/Qwen2-0.5B-Instruct --port 10002 --web True
302- ` ` `
303-
304- 通过 [http://localhost:10002/web/index.html#/chat](http://localhost:10002/web/index.html#/chat) 访问:
305-
306- < p align=" center" >
307- < picture>
308- < img alt=" Web UI" src=" https://github.com/user-attachments/assets/615dca9b-a08c-4183-bbd3-ad1362680faf" width=90%>
309- < /picture>
310- < /p>
31197
312- 关于 RESTful API 服务器的更多信息可以在这里找到 [这里](doc/en/api/server/server.md)。您还可以在这里找到与 Tabby 集成的示例 [这里](doc/en/api/server/tabby.md) 。
98+ KTransformers 的入门非常简单!请参考我们的 [ 安装指南 ] ( (https://kvcache-ai.github.io/ktransformers/) ) 进行安装 。
31399
314100<h2 id =" tutorial " >📃 简要注入教程</h2 >
315101KTransformers 的核心是一个用户友好的、基于模板的注入框架。这使得研究人员可以轻松地将原始 torch 模块替换为优化的变体。它还简化了多种优化的组合过程,允许探索它们的协同效应。
@@ -320,7 +106,7 @@ KTransformers 的核心是一个用户友好的、基于模板的注入框架。
320106 </picture >
321107</p >
322108
323- 鉴于 vLLM 已经是一个用于大规模部署优化的优秀框架,KTransformers 特别关注受资源限制的本地部署。我们特别关注异构计算时机,例如量化模型的 GPU/CPU 卸载。例如,我们支持高效的 < a herf=" https://github.com/Mozilla-Ocho/llamafile/tree/main" > Llamafile< /a> 和< a herf=" https://github.com/IST-DASLab/marlin" > Marlin< /a> 内核,分别用于 CPU 和 GPU。 更多详细信息可以在这里找到 < a herf=" doc/en/operators/llamafile.md" > 这里< /a> 。
109+ 鉴于 vLLM 已经是一个用于大规模部署优化的优秀框架,KTransformers 特别关注受资源限制的本地部署。我们特别关注异构计算时机,例如量化模型的 GPU/CPU 卸载。例如,我们支持高效的 <a herf =" https://github.com/Mozilla-Ocho/llamafile/tree/main " >Llamafile</a > 和<a herf =" https://github.com/IST-DASLab/marlin " >Marlin</a > 内核,分别用于 CPU 和 GPU。 更多详细信息可以在 <a herf =" doc/en/operators/llamafile.md " >这里</a >找到 。
324110
325111
326112<h3 >示例用法</h3 >
@@ -340,7 +126,7 @@ generated = prefill_and_generate(model, tokenizer, input_tensor.cuda(), max_new_
340126
341127<h3 >如何自定义您的模型</h3 >
342128
343- 一个详细的使用 DeepSeek-V2 作为示例的注入和 multi-GPU 教程在这里给出 [这里](doc/en/injection_tutorial.md)。
129+ 一个详细的使用 DeepSeek-V2 作为示例的注入和 multi-GPU 教程在 [ 这里] ( doc/en/injection_tutorial.md ) 。
344130
345131以下是一个将所有原始 Linear 模块替换为 Marlin 的 YAML 模板示例,Marlin 是一个高级的 4 位量化内核。
346132
0 commit comments