Craigz commited on
Commit
cd03e37
·
verified ·
1 Parent(s): 7bf8334

Upload 58 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. README.md +257 -3
  2. docs/Makefile +20 -0
  3. docs/locales/zh_CN/LC_MESSAGES/deployment/vllm.mo +0 -0
  4. docs/locales/zh_CN/LC_MESSAGES/deployment/vllm.po +159 -0
  5. docs/locales/zh_CN/LC_MESSAGES/getting_started/installation.mo +0 -0
  6. docs/locales/zh_CN/LC_MESSAGES/getting_started/installation.po +47 -0
  7. docs/locales/zh_CN/LC_MESSAGES/getting_started/quickstart.mo +0 -0
  8. docs/locales/zh_CN/LC_MESSAGES/getting_started/quickstart.po +121 -0
  9. docs/locales/zh_CN/LC_MESSAGES/index.mo +0 -0
  10. docs/locales/zh_CN/LC_MESSAGES/index.po +138 -0
  11. docs/locales/zh_CN/LC_MESSAGES/inference/chat.mo +0 -0
  12. docs/locales/zh_CN/LC_MESSAGES/inference/chat.po +85 -0
  13. docs/locales/zh_CN/LC_MESSAGES/quantization/awq.mo +0 -0
  14. docs/locales/zh_CN/LC_MESSAGES/quantization/awq.po +109 -0
  15. docs/locales/zh_CN/LC_MESSAGES/quantization/gguf.mo +0 -0
  16. docs/locales/zh_CN/LC_MESSAGES/quantization/gguf.po +108 -0
  17. docs/locales/zh_CN/LC_MESSAGES/quantization/gptq.mo +0 -0
  18. docs/locales/zh_CN/LC_MESSAGES/quantization/gptq.po +109 -0
  19. docs/locales/zh_CN/LC_MESSAGES/run_locally/llama.cpp.mo +0 -0
  20. docs/locales/zh_CN/LC_MESSAGES/run_locally/llama.cpp.po +144 -0
  21. docs/locales/zh_CN/LC_MESSAGES/run_locally/ollama.mo +0 -0
  22. docs/locales/zh_CN/LC_MESSAGES/run_locally/ollama.po +89 -0
  23. docs/locales/zh_CN/LC_MESSAGES/training/SFT/example.mo +0 -0
  24. docs/locales/zh_CN/LC_MESSAGES/training/SFT/example.po +305 -0
  25. docs/locales/zh_CN/LC_MESSAGES/training/SFT/index.mo +0 -0
  26. docs/locales/zh_CN/LC_MESSAGES/training/SFT/index.po +21 -0
  27. docs/locales/zh_CN/LC_MESSAGES/training/SFT/llama_factory.mo +0 -0
  28. docs/locales/zh_CN/LC_MESSAGES/training/SFT/llama_factory.po +181 -0
  29. docs/locales/zh_CN/LC_MESSAGES/web_ui/text_generation_webui.mo +0 -0
  30. docs/locales/zh_CN/LC_MESSAGES/web_ui/text_generation_webui.po +113 -0
  31. docs/make.bat +35 -0
  32. docs/requirements-docs.txt +4 -0
  33. docs/source/assets/.DS_Store +0 -0
  34. docs/source/assets/logo/.DS_Store +0 -0
  35. docs/source/assets/logo/qwen1.5.png +0 -0
  36. docs/source/conf.py +112 -0
  37. docs/source/deployment/vllm.rst +206 -0
  38. docs/source/framework/function_call.rst +131 -0
  39. docs/source/framework/qwen_agent.rst +93 -0
  40. docs/source/getting_started/installation.rst +24 -0
  41. docs/source/getting_started/quickstart.rst +146 -0
  42. docs/source/index.rst +93 -0
  43. docs/source/inference/chat.rst +115 -0
  44. docs/source/quantization/awq.rst +172 -0
  45. docs/source/quantization/gguf.rst +87 -0
  46. docs/source/quantization/gptq.rst +189 -0
  47. docs/source/run_locally/llama.cpp.rst +113 -0
  48. docs/source/run_locally/ollama.rst +71 -0
  49. docs/source/training/SFT/example.rst +572 -0
  50. docs/source/training/SFT/index.rst +8 -0
README.md CHANGED
@@ -1,3 +1,257 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Qwen1.5
2
+
3
+ <p align="center">
4
+ <img src="https://qianwen-res.oss-accelerate.aliyuncs.com/assets/blog/qwen1.5/logo_qwen1.5.jpg" width="400"/>
5
+ <p>
6
+
7
+ <p align="center">
8
+ 🤗 <a href="https://huggingface.co/Qwen">Hugging Face</a>&nbsp&nbsp | &nbsp&nbsp🤖 <a href="https://modelscope.cn/organization/qwen">ModelScope</a>&nbsp&nbsp | &nbsp&nbsp 📑 <a href="https://qwenlm.github.io">Blog</a> &nbsp&nbsp | &nbsp&nbsp📖 <a href="https://qwen.readthedocs.io/">Documentation</a>
9
+ <br>
10
+ 🖥️ <a href="https://huggingface.co/spaces/Qwen/Qwen1.5-72B-Chat">Demo</a>&nbsp&nbsp | &nbsp&nbsp💬 <a href="https://github.com/QwenLM/Qwen/blob/main/assets/wechat.png">WeChat (微信)</a>&nbsp&nbsp | &nbsp&nbsp🫨 <a href="https://discord.gg/CV4E9rpNSD">Discord</a>&nbsp&nbsp
11
+ </p>
12
+
13
+
14
+ Visit our Hugging Face or ModelScope organization (click links above), search checkpoints with names starting with `Qwen1.5-`, and you will find all you need! Enjoy!
15
+
16
+
17
+
18
+ ## Introduction
19
+ This time, we upgrade Qwen to Qwen1.5, the beta version of Qwen2. Similar to Qwen, it is still a decoder-only transformer model with SwiGLU activation, RoPE, multi-head attention. At this moment, we have achieved:
20
+ * 6 model sizes: 0.5B, 1.8B, 4B, 7B, 14B, and 72B;
21
+ * Significant model quality improvements in chat models;
22
+ * Strengthened multilingual capabilities in both base and chat models;
23
+ * All models support the context length of `32768` tokens;
24
+ * System prompts enabled for all models, which means roleplay is possible.
25
+ * No need of `trust_remote_code` anymore.
26
+
27
+ We have not integrated GQA and mixture of SWA and full attention in this version and we will add the features in the future version.
28
+
29
+
30
+ ## News
31
+ * 2024.02.05: We released the Qwen1.5 series.
32
+
33
+ ## Performance
34
+ Detailed evaluation results are reported in this <a href="https://qwenlm.github.io"> 📑 blog</a>.
35
+
36
+
37
+ ## Requirements
38
+ * `transformers>=4.37.0`.
39
+
40
+ > [!Warning]
41
+ > <div align="center">
42
+ > <b>
43
+ > 🚨 This is a must because `transformers` integrated Qwen2 codes since `4.37.0`.
44
+ > </b>
45
+ > </div>
46
+
47
+ ## Quickstart
48
+
49
+ ### 🤗 Hugging Face Transformers
50
+
51
+ Here we show a code snippet to show you how to use the chat model with `transformers`:
52
+
53
+ ```python
54
+ from transformers import AutoModelForCausalLM, AutoTokenizer
55
+ device = "cuda" # the device to load the model onto
56
+
57
+ model = AutoModelForCausalLM.from_pretrained(
58
+ "Qwen/Qwen1.5-72B-Chat",
59
+ torch_dtype="auto",
60
+ device_map="auto"
61
+ )
62
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-72B-Chat")
63
+
64
+ prompt = "Give me a short introduction to large language model."
65
+ messages = [
66
+ {"role": "system", "content": "You are a helpful assistant."},
67
+ {"role": "user", "content": prompt}
68
+ ]
69
+ text = tokenizer.apply_chat_template(
70
+ messages,
71
+ tokenize=False,
72
+ add_generation_prompt=True
73
+ )
74
+ model_inputs = tokenizer([text], return_tensors="pt").to(device)
75
+
76
+ generated_ids = model.generate(
77
+ model_inputs.input_ids,
78
+ max_new_tokens=512
79
+ )
80
+ generated_ids = [
81
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
82
+ ]
83
+
84
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
85
+ ```
86
+
87
+ For quantized models, we advise you to use the GPTQ and AWQ correspondents, namely `Qwen1.5-7B-Chat-GPTQ-Int8`, `Qwen1.5-7B-Chat-AWQ`.
88
+
89
+ ### 🤖 ModelScope
90
+ We strongly advise users especially those in mainland China to use ModelScope. `snapshot_download` can help you solve issues concerning downloading checkpoints.
91
+
92
+ ### 💻 Run locally
93
+
94
+ #### Ollama
95
+
96
+ > [!NOTE]
97
+ > <div align="center">
98
+ > Ollama provides an <a href="https://github.com/ollama/ollama/blob/main/docs/openai.md">OpenAI-compatible API</a>, which however does NOT support <b>function calling</b>. For tool use capabilities, consider using <a href="https://github.com/QwenLM/Qwen-Agent">Qwen-Agent</a>, which offers a wrapper for function calling over the API.
99
+ > </div>
100
+
101
+ After [installing ollama](https://github.com/ollama/ollama/blob/main/README.md), you can initiate the ollama service with the following command:
102
+ ```shell
103
+ ollama serve
104
+ # You need to keep this service running whenever you are using ollama
105
+ ```
106
+
107
+ To pull a model checkpoint and run the model, use the `ollama run` command. You can specify a model size by adding a suffix to `qwen`, such as `:0.5b`, `:1.8b`, `:4b`, `:7b`, `:14b`, or `:72b`:
108
+ ```shell
109
+ ollama run qwen:4b
110
+ # To exit, type "/bye" and press ENTER
111
+ ```
112
+
113
+ You can also access the ollama service via its OpenAI-compatible API. Please note that you need to (1) keep `ollama serve` running while using the API, and (2) execute `ollama run qwen:4b` before utilizing this API to ensure that the model checkpoint is prepared.
114
+ ```py
115
+ from openai import OpenAI
116
+ client = OpenAI(
117
+ base_url='http://localhost:11434/v1/',
118
+ api_key='ollama', # required but ignored
119
+ )
120
+ chat_completion = client.chat.completions.create(
121
+ messages=[
122
+ {
123
+ 'role': 'user',
124
+ 'content': 'Say this is a test',
125
+ }
126
+ ],
127
+ model='qwen:4b',
128
+ )
129
+ ```
130
+
131
+ For additional details, please visit [ollama.ai](https://ollama.ai/).
132
+
133
+ #### llama.cpp
134
+ Download our provided GGUF files or create them by yourself, and you can directly use them with the latest [`llama.cpp`](https://github.com/ggerganov/llama.cpp) with a one-line command:
135
+ ```shell
136
+ ./main -m <path-to-file> -n 512 --color -i -cml -f prompts/chat-with-qwen.txt
137
+ ```
138
+
139
+ #### LMStudio
140
+ Qwen1.5 has already been supported by [lmstudio.ai](https://lmstudio.ai/). You can directly use LMStudio with our GGUF files.
141
+
142
+ #### OpenVINO
143
+ Qwen1.5 has already been supported by [OpenVINO toolkit](https://github.com/openvinotoolkit). You can install and run this [example notebook](https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/254-llm-chatbot) with Intel CPU, integrated GPU or discrete GPU.
144
+
145
+
146
+ ## Web UI
147
+
148
+ #### Text generation web UI
149
+ You can directly use [`text-generation-webui`](https://github.com/oobabooga/text-generation-webui) for creating a web UI demo. If you use GGUF, remember to install the latest wheel of `llama.cpp` with the support of Qwen1.5.
150
+
151
+
152
+ #### llamafile
153
+ Clone [`llamafile`](https://github.com/Mozilla-Ocho/llamafile), run source install, and then create your own llamafile with the GGUF file following the guide [here](https://github.com/Mozilla-Ocho/llamafile?tab=readme-ov-file#creating-llamafiles). You are able to run one line of command, say `./qwen.llamafile`, to create a demo.
154
+
155
+
156
+ ## Deployment
157
+ Now, Qwen1.5 is supported by multiple inference frameworks. Here we demonstrate the usage of `vLLM` and `SGLang`.
158
+
159
+ > [!Warning]
160
+ > <div align="center">
161
+ > The OpenAI-compatible APIs provided by vLLM and SGLang currently do NOT support <b>function calling</b>. For tool use capabilities, <a href="https://github.com/QwenLM/Qwen-Agent">Qwen-Agent</a> provides a wrapper around these APIs to support function calling.
162
+ > </div>
163
+
164
+ ### vLLM
165
+ We advise you to use `vLLM>=0.3.0` to build OpenAI-compatible API service. Start the server with a chat model, e.g. `Qwen1.5-7B-Chat`:
166
+ ```shell
167
+ python -m vllm.entrypoints.openai.api_server --served-model-name Qwen1.5-7B-Chat --model Qwen/Qwen1.5-7B-Chat
168
+ ```
169
+
170
+ Then use the chat API as demonstrated below:
171
+
172
+ ```shell
173
+ curl http://localhost:8000/v1/chat/completions \
174
+ -H "Content-Type: application/json" \
175
+ -d '{
176
+ "model": "Qwen1.5-7B-Chat",
177
+ "messages": [
178
+ {"role": "system", "content": "You are a helpful assistant."},
179
+ {"role": "user", "content": "Tell me something about large language models."}
180
+ ]
181
+ }'
182
+ ```
183
+ ```python
184
+ from openai import OpenAI
185
+ # Set OpenAI's API key and API base to use vLLM's API server.
186
+ openai_api_key = "EMPTY"
187
+ openai_api_base = "http://localhost:8000/v1"
188
+
189
+ client = OpenAI(
190
+ api_key=openai_api_key,
191
+ base_url=openai_api_base,
192
+ )
193
+
194
+ chat_response = client.chat.completions.create(
195
+ model="Qwen1.5-7B-Chat",
196
+ messages=[
197
+ {"role": "system", "content": "You are a helpful assistant."},
198
+ {"role": "user", "content": "Tell me something about large language models."},
199
+ ]
200
+ )
201
+ print("Chat response:", chat_response)
202
+ ```
203
+
204
+ ### SGLang
205
+ Please install `SGLang` from source. Similar to `vLLM`, you need to launch a server and use OpenAI-compatible API service. Start the server first:
206
+ ```shell
207
+ python -m sglang.launch_server --model-path Qwen/Qwen1.5-7B-Chat --port 30000
208
+ ```
209
+ You can use it in Python as shown below:
210
+ ```python
211
+ from sglang import function, system, user, assistant, gen, set_default_backend, RuntimeEndpoint
212
+
213
+ @function
214
+ def multi_turn_question(s, question_1, question_2):
215
+ s += system("You are a helpful assistant.")
216
+ s += user(question_1)
217
+ s += assistant(gen("answer_1", max_tokens=256))
218
+ s += user(question_2)
219
+ s += assistant(gen("answer_2", max_tokens=256))
220
+
221
+ set_default_backend(RuntimeEndpoint("http://localhost:30000"))
222
+
223
+ state = multi_turn_question.run(
224
+ question_1="What is the capital of China?",
225
+ question_2="List two local attractions.",
226
+ )
227
+
228
+ for m in state.messages():
229
+ print(m["role"], ":", m["content"])
230
+
231
+ print(state["answer_1"])
232
+ ```
233
+
234
+ ## Finetuning
235
+ We advise you to use training frameworks, including [Axolotl](https://github.com/OpenAccess-AI-Collective/axolotl), [Llama-Factory](https://github.com/hiyouga/LLaMA-Factory), [Swift](https://github.com/modelscope/swift), etc., to finetune your models with SFT, DPO, PPO, etc.
236
+
237
+ ## API
238
+ Qwen1.5 models are now deployed on both [DashScope](https://dashscope.aliyun.com/) and [Together](https://api.together.ai/). Check [this](https://api.together.xyz/playground/chat/Qwen/Qwen1.5-72B-Chat) out and have fun with Qwen1.5-72B-Chat!
239
+
240
+ ## License Agreement
241
+ Check the license of each model inside its HF repo. It is NOT necessary for you to submit a request for commercial usage.
242
+
243
+ ## Citation
244
+ If you find our work helpful, feel free to give us a cite.
245
+
246
+ ```
247
+ @article{qwen,
248
+ title={Qwen Technical Report},
249
+ author={Jinze Bai and Shuai Bai and Yunfei Chu and Zeyu Cui and Kai Dang and Xiaodong Deng and Yang Fan and Wenbin Ge and Yu Han and Fei Huang and Binyuan Hui and Luo Ji and Mei Li and Junyang Lin and Runji Lin and Dayiheng Liu and Gao Liu and Chengqiang Lu and Keming Lu and Jianxin Ma and Rui Men and Xingzhang Ren and Xuancheng Ren and Chuanqi Tan and Sinan Tan and Jianhong Tu and Peng Wang and Shijie Wang and Wei Wang and Shengguang Wu and Benfeng Xu and Jin Xu and An Yang and Hao Yang and Jian Yang and Shusheng Yang and Yang Yao and Bowen Yu and Hongyi Yuan and Zheng Yuan and Jianwei Zhang and Xingxuan Zhang and Yichang Zhang and Zhenru Zhang and Chang Zhou and Jingren Zhou and Xiaohuan Zhou and Tianhang Zhu},
250
+ journal={arXiv preprint arXiv:2309.16609},
251
+ year={2023}
252
+ }
253
+ ```
254
+
255
+ ## Contact Us
256
+ If you are interested to leave a message to either our research team or product team, join our [Discord](https://discord.gg/z3GAxXZ9Ce) or [WeChat groups](assets/wechat.png)!
257
+
docs/Makefile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line, and also
5
+ # from the environment for the first two.
6
+ SPHINXOPTS ?=
7
+ SPHINXBUILD ?= sphinx-build
8
+ SOURCEDIR = source
9
+ BUILDDIR = build
10
+
11
+ # Put it first so that "make" without argument is like "make help".
12
+ help:
13
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
+
15
+ .PHONY: help Makefile
16
+
17
+ # Catch-all target: route all unknown targets to Sphinx using the new
18
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
+ %: Makefile
20
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
docs/locales/zh_CN/LC_MESSAGES/deployment/vllm.mo ADDED
Binary file (7.44 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/deployment/vllm.po ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/deployment/vllm.rst:2 c78a51ede5ef46d182efb0495820be10
19
+ msgid "vLLM"
20
+ msgstr "vLLM"
21
+
22
+ #: ../../source/deployment/vllm.rst:4 39eba3f4176443e3bea91397e9ede435
23
+ msgid ""
24
+ "We recommend you trying with `vLLM <https://github.com/vllm-"
25
+ "project/vllm>`__ for your deployement of Qwen. It is simple to use, and "
26
+ "it is fast with state-of-the-art serving throughtput, efficienct "
27
+ "management of attention key value memory with PagedAttention, continuous "
28
+ "batching of input requests, optimized CUDA kernels, etc. To learn more "
29
+ "about vLLM, please refer to the `paper "
30
+ "<https://arxiv.org/abs/2309.06180>`__ and `documentation "
31
+ "<https://vllm.readthedocs.io/>`__."
32
+ msgstr "我们建议您在部署Qwen时尝试使用 `vLLM <https://github.com/vllm-project/vllm>`__ 。它易于使用,且具有最先进的服务吞吐量、高效的注意力键值内存管理(通过PagedAttention实现)、连续批处理输入请求、优化的CUDA内核等功能。要了解更多关于vLLM的信息,请参阅 `论文 <https://arxiv.org/abs/2309.06180>`__ 和 `文档 <https://vllm.readthedocs.io/>`__ 。"
33
+
34
+ #: ../../source/deployment/vllm.rst:14 824e70bf8dff4879bbb0eb51c038b6d6
35
+ msgid "Installation"
36
+ msgstr "安装"
37
+
38
+ #: ../../source/deployment/vllm.rst:16 5f1f51379ca84bb7a5b5362b7e7d9e82
39
+ msgid ""
40
+ "By default, you can install ``vLLM`` by pip: ``pip install vLLM>=0.3.0``,"
41
+ " but if you are using CUDA 11.8, check the note in the official document "
42
+ "for installation (`link "
43
+ "<https://docs.vllm.ai/en/latest/getting_started/installation.html>`__) "
44
+ "for some help. We also advise you to install ray by ``pip install ray`` "
45
+ "for distributed serving."
46
+ msgstr "默认情况下,你可以通过 ``pip`` 来安装vLLM :``pip install vLLM>=0.3.0`` , 但如果你正在使用 CUDA 11.8,请查看官方文档中的注意事项 以获取有关安装的帮助( `链接 <https://docs.vllm.ai/en/latest/getting_started/installation.html>`__ )。 我们也建议你通过 ``pip install ray`` 安装ray, 以便支持分布式服务。"
47
+
48
+ #: ../../source/deployment/vllm.rst:24 b7cda8f24f53482b89940ec7ea1b747f
49
+ msgid "Offline Batched Inference"
50
+ msgstr "离线推理"
51
+
52
+ #: ../../source/deployment/vllm.rst:26 2aeda0988c284b4083e64fb11ac48472
53
+ msgid ""
54
+ "Models supported by Qwen2 codes, e.g., Qwen1.5, are supported by vLLM. "
55
+ "The simplest usage of vLLM is offline batched inference as demonstrated "
56
+ "below."
57
+ msgstr "Qwen2代码支持的模型,例如Qwen1.5,都被vLLM所支持。 vLLM最简单的使用方式是通过以下演示进行离线批量推理。"
58
+
59
+ #: ../../source/deployment/vllm.rst:63 f79753fdb5aa4b0686e2457925ed83ba
60
+ msgid "OpenAI-API Compatible API Service"
61
+ msgstr "适配OpenAI-API的API服务"
62
+
63
+ #: ../../source/deployment/vllm.rst:65 8418e661aa044763b45a114d6231ca12
64
+ msgid ""
65
+ "It is easy to build an OpenAI-API compatible API service with vLLM, which"
66
+ " can be deployed as a server that implements OpenAI API protocol. By "
67
+ "default, it starts the server at ``http://localhost:8000``. You can "
68
+ "specify the address with ``--host`` and ``--port`` arguments. Run the "
69
+ "command as shown below:"
70
+ msgstr "借助vLLM,构建一个与OpenAI API兼容的API服务十分简便,该服务可以作为实现OpenAI API协议的服务器进行部署。默认情况下,它将在 `http://localhost:8000 <http://localhost:8000>`__ 启动服务器。您可以通过 ``--host`` 和 ``--port`` 参数来自定义地址。请按照以下所示运行命令:"
71
+
72
+ #: ../../source/deployment/vllm.rst:76 671f946fbe424b2086e1dcce4df7d156
73
+ msgid ""
74
+ "You don’t need to worry about chat template as it by default uses the "
75
+ "chat template provided by the tokenizer."
76
+ msgstr "你无需担心chat模板,因为它默认会使用由tokenizer提供的chat模板。"
77
+
78
+ #: ../../source/deployment/vllm.rst:79 9ac8c5901cae46d0b406fdd7f2da6feb
79
+ msgid ""
80
+ "Then, you can use the `create chat interface "
81
+ "<https://platform.openai.com/docs/api-"
82
+ "reference/chat/completions/create>`__ to communicate with Qwen:"
83
+ msgstr "然后,您可以利用 `create chat interface <https://platform.openai.com/docs/api-reference/chat/completions/create>`__ 来与Qwen进行对话:"
84
+
85
+ #: ../../source/deployment/vllm.rst:93 72eaebe10a8d4769a9ce15f68f5aaef5
86
+ msgid ""
87
+ "or you can use python client with ``openai`` python package as shown "
88
+ "below:"
89
+ msgstr "或者您可以如下面所示使用 ``openai`` Python 包中的 Python 客户端:"
90
+
91
+ #: ../../source/deployment/vllm.rst:118 3d91f5241559497b92f1215723526ce5
92
+ msgid "Multi-GPU Distributred Serving"
93
+ msgstr "多卡分布式部署"
94
+
95
+ #: ../../source/deployment/vllm.rst:120 de0f6109c6c54ec498dad7572dbc03bb
96
+ msgid ""
97
+ "To scale up your serving throughputs, distributed serving helps you by "
98
+ "leveraging more GPU devices. Besides, for large models like ``Qwen1.5"
99
+ "-72B-Chat``, it is impossible to serve it on a single GPU. Here, we "
100
+ "demonstrate how to run ``Qwen1.5-72B-Chat`` with tensor parallelism just "
101
+ "by passing in the argument ``tensor_parallel_size``:"
102
+ msgstr "要提高模型的处理吞吐量,分布式服务可以通过利用更多的GPU设备来帮助您。特别是对于像 ``Qwen1.5-72B-Chat`` 这样的大模型,单个GPU无法支撑其在线服务。在这里,我们通过演示如何仅通过传入参数 ``tensor_parallel_size`` ,来使用张量并行来运行 ``Qwen1.5-72B-Chat`` 模型:"
103
+
104
+ #: ../../source/deployment/vllm.rst:131 8a8342a0388e4e6e9af7e67d1b664049
105
+ msgid ""
106
+ "You can run multi-GPU serving by passing in the argument ``--tensor-"
107
+ "parallel-size``:"
108
+ msgstr "您可以通过传递参数 ``--tensor-parallel-size`` 来运行多GPU服务:"
109
+
110
+ #: ../../source/deployment/vllm.rst:141 1b322fc6beda485d85073871e8d79009
111
+ msgid "Serving Quantized Models"
112
+ msgstr "部署量化模型"
113
+
114
+ #: ../../source/deployment/vllm.rst:143 f78f39a1d50e428b8f9a46880afc33db
115
+ msgid ""
116
+ "vLLM supports different types of quantized models, including AWQ, GPTQ, "
117
+ "SqueezeLLM, etc. Here we show how to deploy AWQ and GPTQ models. The "
118
+ "usage is almost the same as above except for an additional argument for "
119
+ "quantization. For example, to run an AWQ model. e.g., ``Qwen1.5-7B-Chat-"
120
+ "AWQ``:"
121
+ msgstr "vLLM 支持多种类型的量化模型,例如 AWQ、GPTQ、SqueezeLLM 等。这里我们将展示如何部署 AWQ 和 GPTQ 模型。使用方法与上述基本相同,只不过需要额外指定一个量化参数。例如,要运行一个 AWQ 模型,例如 ``Qwen1.5-7B-Chat-AWQ`` :"
122
+
123
+ #: ../../source/deployment/vllm.rst:154 828cb96a6d4543aba4145552c9b0c5b2
124
+ msgid "or GPTQ models like ``Qwen1.5-7B-Chat-GPTQ-Int8``:"
125
+ msgstr "或者是GPTQ模型比如 ``Qwen1.5-7B-Chat-GPTQ-Int8`` :"
126
+
127
+ #: ../../source/deployment/vllm.rst:160 7869bd5c2bb542f393215ab5f85315f3
128
+ msgid ""
129
+ "Similarly, you can run serving adding the argument ``--quantization`` as "
130
+ "shown below:"
131
+ msgstr "同样地,您可以在运行服务时添加 ``--quantization`` 参数,如下所示:"
132
+
133
+ #: ../../source/deployment/vllm.rst:169 dca42b48bef043cf81c89efa5ed2663c
134
+ msgid "or"
135
+ msgstr "或者"
136
+
137
+ #: ../../source/deployment/vllm.rst:177 27cc85ab1f474328bbd863413ba83883
138
+ msgid ""
139
+ "Additionally, vLLM supports the combination of AWQ or GPTQ models with KV"
140
+ " cache quantization, namely FP8 E5M2 KV Cache. For example:"
141
+ msgstr "此外,vLLM支持将AWQ或GPTQ模型与KV缓存量化相结合,即FP8 E5M2 KV Cache方案。例如:"
142
+
143
+ #: ../../source/deployment/vllm.rst:192 fa4a78593b0347d89685a3317e382560
144
+ msgid "Troubleshooting"
145
+ msgstr "常见问题"
146
+
147
+ #: ../../source/deployment/vllm.rst:194 303b60dd7fa14134aa8bc2db5d2d2a19
148
+ msgid ""
149
+ "You may encounter OOM issues that are pretty annoying. We recommend two "
150
+ "arguments for you to make some fix. The first one is ``--max-model-len``."
151
+ " Our provided default ``max_postiion_embedding`` is ``32768`` and thus "
152
+ "the maximum length for the serving is also this value, leading to higher "
153
+ "requirements of memory. Reducing it to a proper length for yourself often"
154
+ " helps with the OOM issue. Another argument you can pay attention to is "
155
+ "``--gpu-memory-utilization``. By default it is ``0.9`` and you can level "
156
+ "it up to tackle the OOM problem. This is also why you find a vLLM service"
157
+ " always takes so much memory."
158
+ msgstr "您可能会遇到令人烦恼的OOM(内存溢出)问题。我们推荐您尝试两个参数进行修复。第一个参数是 ``--max-model-len`` 。我们提供的默认最大位置嵌入(max_position_embedding)为32768,因此服务时的最大长度也是这个值,这会导致更高的内存需求。将此值适当减小通常有助于解决OOM问题。另一个您可以关注的参数是 ``--gpu-memory-utilization`` 。默认情况下,该值为 ``0.9`` ,您可以将其调高以应对OOM问题。这也是为什么您发现一个大型语言模型服务总是占用大量内存的原因。"
159
+
docs/locales/zh_CN/LC_MESSAGES/getting_started/installation.mo ADDED
Binary file (1.32 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/getting_started/installation.po ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/getting_started/installation.rst:2
19
+ #: deb8f437f6fa43f58a37268ecf29e339
20
+ msgid "Installation"
21
+ msgstr "安装"
22
+
23
+ #: ../../source/getting_started/installation.rst:4
24
+ #: 522d89ca22b3435382fbb514205c2dcd
25
+ msgid ""
26
+ "To get a quick start with Qwen1.5, you can install the ``transformers`` "
27
+ "library from Hugging Face and use models in the `Qwen1.5 collection "
28
+ "<https://huggingface.co/collections/Qwen/qwen15-65c0a2f577b1ecb76d786524>`__."
29
+ " We advise you to install the latest ``transformers`` or at least version"
30
+ " 4.37.0."
31
+ msgstr "要快速上手Qwen1.5,您可以从Hugging Face安装 ``transformers`` 库,并使用 `Qwen1.5 Collection <https://huggingface.co/collections/Qwen/qwen15-65c0a2f577b1ecb76d786524>`__ 中的模型。我们建议您安装最新版本的 ``transformers`` 库,或者至少安装4.37.0版本。"
32
+
33
+ #: ../../source/getting_started/installation.rst:11
34
+ #: 514b20d297d345ebaaf16381b6ce1d4e
35
+ msgid "Install with Pip"
36
+ msgstr "Pip安装"
37
+
38
+ #: ../../source/getting_started/installation.rst:18
39
+ #: 892ae185130049779862b4b91425d9de
40
+ msgid "Install with Conda"
41
+ msgstr "Conda安装"
42
+
43
+ #: ../../source/getting_started/installation.rst:24
44
+ #: a7db48bd0a4f49e3b24a7a44cca4defd
45
+ msgid "We advise you to use Python 3.8 or higher, and Pytorch 2.0 or higher."
46
+ msgstr "我们建议您使用Python3.8及以上版本和Pytorch 2.0及以上版本。"
47
+
docs/locales/zh_CN/LC_MESSAGES/getting_started/quickstart.mo ADDED
Binary file (4.43 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/getting_started/quickstart.po ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/getting_started/quickstart.rst:2
19
+ #: 0d59f700095e438687bc5ef12625a233
20
+ msgid "Quickstart"
21
+ msgstr "快速开始"
22
+
23
+ #: ../../source/getting_started/quickstart.rst:4
24
+ #: 34c301da60d148e391e99560081c476f
25
+ msgid ""
26
+ "This guide helps you quickly start using Qwen1.5. We provide examples of "
27
+ "`Hugging Face Transformers "
28
+ "<https://github.com/huggingface/transformers>`__ as well as `ModelScope "
29
+ "<https://github.com/modelscope/modelscope>`__, and `vLLM "
30
+ "<https://github.com/vllm-project/vllm>`__ for deployment."
31
+ msgstr "本指南帮助您快速上手Qwen1.5的使用,并提供了如下示例: `Hugging Face Transformers <https://github.com/huggingface/transformers>`__ 以及 `ModelScope <https://github.com/modelscope/modelscope>`__ 和 `vLLM <https://github.com/vllm-project/vllm>`__ 在部署时的应用实例。"
32
+
33
+ #: ../../source/getting_started/quickstart.rst:10
34
+ #: 4a4d501b6a8243348c451132208ff369
35
+ msgid "Hugging Face Transformers & ModelScope"
36
+ msgstr "Hugging Face Transformers & ModelScope"
37
+
38
+ #: ../../source/getting_started/quickstart.rst:12
39
+ #: 73463ba21bec4384bd2db9e3deb03ec9
40
+ msgid ""
41
+ "To get a quick start with Qwen1.5, we advise you to try with the "
42
+ "inference with ``transformers`` first. Make sure that you have installed "
43
+ "``transformers>=4.37.0``. The following is a very simple code snippet "
44
+ "showing how to run Qwen1.5-Chat, with an example of Qwen1.5-7B-Chat:"
45
+ msgstr "要快速上手Qwen1.5,我们建议您首先尝试使用transformers进行推理。请确保已安装了 ``transformers>=4.37.0`` 版本。以下是一个非常简单的代码片段示例,展示如何运行Qwen1.5-Chat模型,其中包含 ``Qwen1.5-7B-Chat`` 的实例:"
46
+
47
+ #: ../../source/getting_started/quickstart.rst:56
48
+ #: 02d8873c2f4944bd8e555b1a7ca0bd83
49
+ msgid ""
50
+ "Previously, we use ``model.chat()`` (see ``modeling_qwen.py`` in previous"
51
+ " Qwen models for more information). Now, we follow the practice of "
52
+ "``transformers`` and directly use ``model.generate()`` with "
53
+ "``apply_chat_template()`` in tokenizer."
54
+ msgstr "以前,我们使用 ``model.chat()`` (有关更多详细信息,请参阅先前Qwen模型中的 ``modeling_qwen.py`` )。现在,我们遵循 ``transformers`` 的实践,直接使用 ``model.generate()`` 配合tokenizer中的 ``apply_chat_template()`` 方法。"
55
+
56
+ #: ../../source/getting_started/quickstart.rst:61
57
+ #: 69a7184639c842a3b3036eb4ed564746
58
+ msgid ""
59
+ "To tackle with downloading issues, we advise you to try with from "
60
+ "ModelScope, just changing the first line of code above to the following:"
61
+ msgstr "为了解决下载问题,我们建议您尝试从 ModelScope 进行下载,只需将上述代码的第一行更改为以下内容:"
62
+
63
+ #: ../../source/getting_started/quickstart.rst:68
64
+ #: 74ec66c1e58444509705de8097aa3f93
65
+ msgid ""
66
+ "Streaming mode for model chat is simple with the help of "
67
+ "``TextStreamer``. Below we show you an example of how to use it:"
68
+ msgstr "借助 ``TextStreamer`` ,chat的流式模式变得非常简单。下面我们将展示一个如何使用它的示例:"
69
+
70
+ #: ../../source/getting_started/quickstart.rst:84
71
+ #: fedfd60540414413ba87cdc77dde4f3a
72
+ msgid "vLLM for Deployment"
73
+ msgstr "使用vLLM部署"
74
+
75
+ #: ../../source/getting_started/quickstart.rst:86
76
+ #: 0306956b41b04d2a9c349942abd29743
77
+ msgid ""
78
+ "To deploy Qwen1.5, we advise you to use vLLM. vLLM is a fast and easy-to-"
79
+ "use framework for LLM inference and serving. In the following, we "
80
+ "demonstrate how to build a OpenAI-API compatible API service with vLLM."
81
+ msgstr "要部署Qwen1.5,我们建议您使用vLLM。vLLM是一个用于LLM推理和服务的快速且易于使用的框架。以下,我们将展示如何使用vLLM构建一个与OpenAI API兼容的API服务。"
82
+
83
+ #: ../../source/getting_started/quickstart.rst:91
84
+ #: ea047884429444f69cf13fa20a9a1226
85
+ msgid "First, make sure you have installed ``vLLM>=0.3.0``:"
86
+ msgstr "首先,确保你已经安装 ``vLLM>=0.3.0`` :"
87
+
88
+ #: ../../source/getting_started/quickstart.rst:97
89
+ #: fa3653a7e100405a9150d61cbc7aa0bf
90
+ msgid ""
91
+ "Run the following code to build up a vllm service. Here we take Qwen1.5"
92
+ "-7B-Chat as an example:"
93
+ msgstr "运行以下代码以构建vllm服务。此处我们以Qwen1.5-7B-Chat为例:"
94
+
95
+ #: ../../source/getting_started/quickstart.rst:104
96
+ #: 3ca1e2527a2f4f359ca353cf02e394c5
97
+ msgid ""
98
+ "Then, you can use the `create chat interface "
99
+ "<https://platform.openai.com/docs/api-"
100
+ "reference/chat/completions/create>`__ to communicate with Qwen:"
101
+ msgstr "然后,您可以使用 `create chat interface <https://platform.openai.com/docs/api-reference/chat/completions/create>`__ 来与Qwen进行交流:"
102
+
103
+ #: ../../source/getting_started/quickstart.rst:118
104
+ #: 903bf1697ebc472fa96655cd6eefaf94
105
+ msgid ""
106
+ "or you can use python client with ``openai`` python package as shown "
107
+ "below:"
108
+ msgstr "或者您可以按照下面所示的方式,使用 ``openai`` Python 包中的Python 客户端:"
109
+
110
+ #: ../../source/getting_started/quickstart.rst:143
111
+ #: 930fecfab8b64a33ab1807427ca1ffe9
112
+ msgid "Next Step"
113
+ msgstr "下一步"
114
+
115
+ #: ../../source/getting_started/quickstart.rst:145
116
+ #: dc8967f0befe41f781a22ada80e0a361
117
+ msgid ""
118
+ "Now, you can have fun with Qwen models. Would love to know more about its"
119
+ " usages? Feel free to check other documents in this documentation."
120
+ msgstr "现在,您可以尽情探索Qwen模型的各种用途。若想了解更多,请随时查阅本文档中的其他内容。"
121
+
docs/locales/zh_CN/LC_MESSAGES/index.mo ADDED
Binary file (2.75 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/index.po ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-03-04 15:21+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
12
+ "Language: zh_CN\n"
13
+ "Language-Team: zh_CN <LL@li.org>\n"
14
+ "Plural-Forms: nplurals=1; plural=0;\n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=utf-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "Generated-By: Babel 2.14.0\n"
19
+
20
+ #: ../../source/index.rst:42
21
+ msgid "Getting Started"
22
+ msgstr "快速开始"
23
+
24
+ #: ../../source/index.rst:49
25
+ msgid "Inference"
26
+ msgstr "推理"
27
+
28
+ #: ../../source/index.rst:55
29
+ msgid "Run Locally"
30
+ msgstr "本地运行"
31
+
32
+ #: ../../source/index.rst:62
33
+ msgid "Web UI"
34
+ msgstr "Web UI"
35
+
36
+ #: ../../source/index.rst:68
37
+ msgid "Quantization"
38
+ msgstr "量化"
39
+
40
+ #: ../../source/index.rst:76
41
+ msgid "Deployment"
42
+ msgstr "部署"
43
+
44
+ #: ../../source/index.rst:82
45
+ msgid "Training"
46
+ msgstr "训练"
47
+
48
+ #: ../../source/index.rst:7 2d3747ef5e9a463ebdd4f47fa4fd614b
49
+ msgid "Welcome to Qwen!"
50
+ msgstr "欢迎来到Qwen"
51
+
52
+ #: ../../source/index.rst:-1 261ac6a5ed984af08f173e4e317239f0
53
+ msgid "Qwen"
54
+ msgstr ""
55
+
56
+ #: ../../source/index.rst:16 a75ccce7dbae42528044bd349bec2406
57
+ #, fuzzy
58
+ msgid ""
59
+ "Qwen is the large language model and large multimodal model series of the"
60
+ " Qwen Team, Alibaba Group. Now the large language models have been "
61
+ "upgraded to Qwen1.5. Both language models and multimodal models are "
62
+ "pretrained on large-scale multilingual and multimodal data and post-"
63
+ "trained on quality data for aligning to human preferences. Qwen is "
64
+ "capable of natural language understanding, text generation, vision "
65
+ "understanding, audio understanding, tool use, role play, playing as AI "
66
+ "agent, etc."
67
+ msgstr ""
68
+ "Qwen是阿里巴巴集团Qwen团队研发的大语言模型和大型多模态模型系列。目前,大语言模型已升级至Qwen1.5版本。无论是语言模型还是多模态模型,均在大规模多语言和多模态数据上进行预训练,并通过高质量数据进行后期微调以贴近人类偏好。Qwen具备自然语言理解、文本生成、视觉理解、音频理解、工具使用、角色扮演、作为AI"
69
+ " Agent进行互动等多种能力。"
70
+
71
+ #: ../../source/index.rst:19 3491cf32758549fb9178f7f6ec74c568
72
+ msgid "The latest version, Qwen1.5, has the following features:"
73
+ msgstr "最新版本Qwen1.5有以下特点:"
74
+
75
+ #: ../../source/index.rst:21 31a2e69fd9894077b1121a7112b219a2
76
+ msgid "6 model sizes, including 0.5B, 1.8B, 4B, 7B, 14B, and 72B;"
77
+ msgstr "6种模型规模,包括0.5B、1.8B、4B、7B、14B和72B;"
78
+
79
+ #: ../../source/index.rst:22 eb837bd71db8400792a68d6ca470ac3a
80
+ msgid ""
81
+ "Base and chat models for each size, with the chat models aligned for "
82
+ "human preferences;"
83
+ msgstr "针对每种尺寸提供基础模型和Chat模型,并确保聊天模型按照人类偏好进行校准;"
84
+
85
+ #: ../../source/index.rst:23 0d1bfd621aac4df6a53213d90492c39b
86
+ msgid "Multilingual support of both base and chat models;"
87
+ msgstr "对基础模型和Chat模型的多语言支持"
88
+
89
+ #: ../../source/index.rst:24 7ff10a8a6e724630b7a92d32c84566d3
90
+ msgid "Stable support of 32K context length for models of all sizes"
91
+ msgstr "基础模型和聊天模型都支持多种语言;"
92
+
93
+ #: ../../source/index.rst:25 9ab7e4b426d445a0bd59a7560ec98475
94
+ msgid "Supporting tool use, RAG, role play, and playing as AI agent;"
95
+ msgstr "支持工具调用、RAG(检索增强文本生成)、角色扮演、AI Agent等;"
96
+
97
+ #: ../../source/index.rst:27 c6fc5c5e004644daba19e91be5da82cc
98
+ msgid "For more information, please visit our:"
99
+ msgstr "想了解更多信息,欢迎访问:"
100
+
101
+ #: ../../source/index.rst:29 99d292a28a794301b7cb202e0f928db7
102
+ msgid "`Blog <https://qwenlm.github.io/>`__"
103
+ msgstr "`博客 <https://qwenlm.github.io/>`__"
104
+
105
+ #: ../../source/index.rst:30 0ca51a3b64c94734af59c09a69f1456b
106
+ msgid "`GitHub <https://github.com/QwenLM>`__"
107
+ msgstr "`GitHub <https://github.com/QwenLM>`__"
108
+
109
+ #: ../../source/index.rst:31 836732175cf0403da8537a94ad181757
110
+ msgid "`Hugging Face <https://huggingface.co/Qwen>`__"
111
+ msgstr "`Hugging Face <https://huggingface.co/Qwen>`__"
112
+
113
+ #: ../../source/index.rst:32 bea79b7409ad42bc9b555ab671bce948
114
+ msgid "`ModelScope <https://modelscope.cn/organization/qwen>`__"
115
+ msgstr "`ModelScope <https://modelscope.cn/organization/qwen>`__"
116
+
117
+ #: ../../source/index.rst:33 e304df6f68b44519b8ae3df43f939c5b
118
+ msgid ""
119
+ "`Qwen1.5 Collection "
120
+ "<https://huggingface.co/collections/Qwen/qwen15-65c0a2f577b1ecb76d786524>`__"
121
+ msgstr ""
122
+ "`Qwen1.5 Collection "
123
+ "<https://huggingface.co/collections/Qwen/qwen15-65c0a2f577b1ecb76d786524>`__"
124
+
125
+ #: ../../source/index.rst:35 ec007374bc394c24a365c4459d9b0021
126
+ msgid ""
127
+ "Join our community by joining our `Discord "
128
+ "<https://discord.gg/yPEP2vHTu4>`__ and `WeChat "
129
+ "<https://github.com/QwenLM/Qwen/blob/main/assets/wechat.png>`__ group. We"
130
+ " are looking forward to seeing you there!"
131
+ msgstr ""
132
+ "加入社区,加入 `Discord <https://discord.gg/yPEP2vHTu4>`__ 和 `微信群 "
133
+ "<https://github.com/QwenLM/Qwen/blob/main/assets/wechat.png>`__ 。很期待见到你们!"
134
+
135
+ #: ../../source/index.rst:40 5659ef68386e4ec392fde8f9e276e5d0
136
+ msgid "Documentation"
137
+ msgstr "文档"
138
+
docs/locales/zh_CN/LC_MESSAGES/inference/chat.mo ADDED
Binary file (4.34 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/inference/chat.po ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/inference/chat.rst:2 3d10dc3916e94e8da08d26f3cec394e8
19
+ msgid "Using Transformers to Chat"
20
+ msgstr "使用Transformers实现Chat"
21
+
22
+ #: ../../source/inference/chat.rst:4 ae560ca3c52141a2b7f62c37c2ef620a
23
+ msgid ""
24
+ "The most significant but also the simplest usage of Qwen1.5 is to chat "
25
+ "with it using the ``transformers`` library. In this document, we show how"
26
+ " to chat with ``Qwen1.5-7B-Chat``, in either streaming mode or not."
27
+ msgstr "Qwen1.5 最重要同时也最简单的用途是通过transformers库实现Chat功能。在本文档中,我们将展示如何在流式模式或非流式模式下与Qwen1.5-7B-Chat进行对话。"
28
+
29
+ #: ../../source/inference/chat.rst:9 0b04962cd6f94353ad675ee83fdaa2a0
30
+ msgid "Basic Usage"
31
+ msgstr "基本用法"
32
+
33
+ #: ../../source/inference/chat.rst:11 cff73f0ce0bd4c53b18ff8be21a2ad4a
34
+ msgid ""
35
+ "You can just write several lines of code with ``transformers`` to chat "
36
+ "with Qwen1.5-Chat. Essentially, we build the tokenizer and the model with"
37
+ " ``from_pretrained`` method, and we use ``generate`` method to perform "
38
+ "chatting with the help of chat template provided by the tokenizer. Below "
39
+ "is an example of how to chat with Qwen1.5-7B-Chat:"
40
+ msgstr "你只需借助 ``transformers`` 库编写几行代码,就能与Qwen1.5-Chat进行对话。实质上,我们通过from_pretrained方法构建tokenizer和模型,然后利用 ``generate`` 方法,在tokenizer提供的chat template的辅助下进行chat。以下是一个如何与Qwen1.5-7B-Chat进行对话的示例:"
41
+
42
+ #: ../../source/inference/chat.rst:56 804addcd484b4988a72f67e272294c4b
43
+ msgid ""
44
+ "Note that the previous method in the original Qwen repo ``chat()`` is now"
45
+ " replaced by ``generate()``. The ``apply_chat_template()`` function is "
46
+ "used to convert the messages into a format that the model can understand."
47
+ " The ``add_generation_prompt`` argument is used to add a generation "
48
+ "prompt, which refers to ``<|im_start|>assistant\\n`` to the input. Notably,"
49
+ " we apply ChatML template for chat models following our previous "
50
+ "practice. The ``max_new_tokens`` argument is used to set the maximum "
51
+ "length of the response. The ``tokenizer.batch_decode()`` function is used"
52
+ " to decode the response. In terms of the input, the above ``messages`` is"
53
+ " an example to show how to format your dialog history and system prompt. "
54
+ "By default, if you do not specify system prompt, we directly use ``You "
55
+ "are a helpful assistant.``."
56
+ msgstr "请注意,原Qwen仓库中的旧方法 ``chat()`` 现在已被 ``generate()`` 方法替代。这里使用了 ``apply_chat_template()`` 函数将消息转换为模型能够理解的格式。其中的 ``add_generation_prompt`` 参数用于在输入中添加生成提示,该提示指向 ``<|im_start|>assistant\\n`` 。尤其需要注意的是,我们遵循先前实践,对chat模型应用ChatML模板。而 ``max_new_tokens`` 参数则用于设置响应的最大长度。此外,通过 ``tokenizer.batch_decode()`` 函数对响应进行解码。关于输入部分,上述的 ``messages`` 是一个示例,展示了如何格式化对话历史记录和系统提示。默认情况下,如果您没有指定系统提示,我们将直接使用 ``You are a helpful assistant.`` 作为系统提示。"
57
+
58
+ #: ../../source/inference/chat.rst:70 97b15b98fc784700bad1298d1604e8dd
59
+ msgid "Streaming Mode"
60
+ msgstr "流式输出"
61
+
62
+ #: ../../source/inference/chat.rst:72 3b1052923dd141b8b7b49451c2fa53db
63
+ msgid ""
64
+ "With the help of ``TextStreamer``, you can modify your chatting with Qwen"
65
+ " to streaming mode. Below we show you an example of how to use it:"
66
+ msgstr "借助 ``TextStreamer`` ,您可以将与Qwen的对话切换到流式传输模式。下面是一个关于如何使用它的示例:"
67
+
68
+ #: ../../source/inference/chat.rst:89 95d10848cede405f884341ed0379849b
69
+ msgid ""
70
+ "Besides using ``TextStreamer``, we can also use ``TextIteratorStreamer`` "
71
+ "which stores print-ready text in a queue, to be used by a downstream "
72
+ "application as an iterator:"
73
+ msgstr "除了使用 ``TextStreamer`` 之外,我们还可以使用 ``TextIteratorStreamer`` ,它将可打印的文本存储在一个队列中,以便下游应用程序作为迭代器来使用:"
74
+
75
+ #: ../../source/inference/chat.rst:111 910e04c17dd04c8e91691aff386fff2b
76
+ msgid "Next Step"
77
+ msgstr "下一步"
78
+
79
+ #: ../../source/inference/chat.rst:113 3df342c8e1af454994600742e06e7bc9
80
+ msgid ""
81
+ "Now you can chat with Qwen1.5 in either streaming mode or not. Continue "
82
+ "to read the documentation and try to figure out more advanced usages of "
83
+ "model inference!"
84
+ msgstr "现在,你可以选择流式模式或非流式模式与Qwen1.5进行对话。继续阅读文档,并尝试探索模型推理的更多高级用法!""
85
+
docs/locales/zh_CN/LC_MESSAGES/quantization/awq.mo ADDED
Binary file (5.44 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/quantization/awq.po ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/quantization/awq.rst:2 bab75f352096428a9dee89930ab02e7a
19
+ msgid "AWQ"
20
+ msgstr "AWQ"
21
+
22
+ #: ../../source/quantization/awq.rst:4 517d6f4ca69247f7b08087dd995cf1a6
23
+ msgid ""
24
+ "For quantized models, one of our recommendations is the usage of `AWQ "
25
+ "<https://arxiv.org/abs/2306.00978>`__ with `AutoAWQ <https://github.com"
26
+ "/casper-hansen/AutoAWQ>`__. AWQ refers to Activation-aware Weight "
27
+ "Quantization, a hardware-friendly approach for LLM low-bit weight-only "
28
+ "quantization. AutoAWQ is an easy-to-use package for 4-bit quantized "
29
+ "models. AutoAWQ speeds up models by 3x and reduces memory requirements by"
30
+ " 3x compared to FP16. AutoAWQ implements the Activation-aware Weight "
31
+ "Quantization (AWQ) algorithm for quantizing LLMs. In this document, we "
32
+ "show you how to use the quantized model with Transformers and also how to"
33
+ " quantize your own model."
34
+ msgstr "对于量化模型,我们推荐使用 `AWQ <https://arxiv.org/abs/2306.00978>`__ 结合 `AutoAWQ <https://github.com/casper-hansen/AutoAWQ>`__ 。AWQ即激活感知权重量化,是一种针对LLM的低比特权重量化的硬件友好方法。而AutoAWQ是一个易于使用的工具包,专门用于4比特量化模型。相较于FP16,AutoAWQ能够将模型的运行速度提升3倍,并将内存需求降低至原来的1/3。AutoAWQ实现了激活感知权重量化(AWQ)算法,可用于LLM的量化处理。在本文档中,我们将向您展示如何在Transformers框架下使用量化模型,以及如何对您自己的模型进行量化。"
35
+
36
+ #: ../../source/quantization/awq.rst:16 4f843dc502354b71ba29fdc918bdff73
37
+ msgid "Usage of AWQ Quantized Models with Transformers"
38
+ msgstr "如何在Transformers中使用AWQ量化模型"
39
+
40
+ #: ../../source/quantization/awq.rst:18 0984fc07bb83453ba4dcfe68e7e4ff76
41
+ msgid ""
42
+ "Now, Transformers has officially supported AutoAWQ, which means that you "
43
+ "can directly use the quantized model with Transformers. The following is "
44
+ "a very simple code snippet showing how to run ``Qwen1.5-7B-Chat-AWQ`` "
45
+ "with the quantized model:"
46
+ msgstr "现在,Transformers已经正式支持AutoAWQ,这意味着您可以直接在Transformers中使用量化模型。以下是一个非常简单的代码片段,展示如何运行量化模型 ``Qwen1.5-7B-Chat-AWQ`` :"
47
+
48
+ #: ../../source/quantization/awq.rst:57 e0eb738bce98432ea115745392b5e826
49
+ msgid "Usage of AWQ Quantized Models with vLLM"
50
+ msgstr "如何在vLLM中使用AWQ量化模型"
51
+
52
+ #: ../../source/quantization/awq.rst:59 9e96a6878cda41ef935fe77629492c60
53
+ msgid ""
54
+ "vLLM has supported AWQ, which means that you can directly use our "
55
+ "provided AWQ models or those trained with ``AutoAWQ`` with vLLM. "
56
+ "Actually, the usage is the same with the basic usage of vLLM. We provide "
57
+ "a simple example of how to launch OpenAI-API compatible API with vLLM and"
58
+ " ``Qwen1.5-7B-Chat-AWQ``:"
59
+ msgstr "vLLM 已经支持了AWQ,这意味着您可以直接使用我们提供的AWQ模型,或者是通过AutoAWQ训练得到的与vLLM兼容的模型。实际上,其用法与vLLM的基本用法相同。我们提供了一个简单的示例,展示了如何通过vLLM启动与OpenAI API兼容的接口,并使用 ``Qwen1.5-7B-Chat-AWQ`` 模型:"
60
+
61
+ #: ../../source/quantization/awq.rst:79 4143e0d33e5044ee9cb5f712c6fa0b3a
62
+ msgid ""
63
+ "or you can use python client with ``openai`` python package as shown "
64
+ "below:"
65
+ msgstr "或者你可以按照下面所示的方式,使用 ``openai`` Python包中的Python客户端:"
66
+
67
+ #: ../../source/quantization/awq.rst:104 6a6eb6b49b864b9483b8b7e75a644eaa
68
+ msgid "Quantize Your Own Model with AutoAWQ"
69
+ msgstr "使用AutoAWQ量化你的模型"
70
+
71
+ #: ../../source/quantization/awq.rst:106 883826b500fe44c2bf8cfe1c6e817f85
72
+ msgid ""
73
+ "If you want to quantize your own model to AWQ quantized models, we advise"
74
+ " you to use AutoAWQ. It is suggested installing the latest version of the"
75
+ " package by installing from source code:"
76
+ msgstr "如果您希望将自定义模型量化为AWQ量化模型,我们建议您使用AutoAWQ。推荐通过安装源代码来获取并安装该工具包的最新版本:"
77
+
78
+ #: ../../source/quantization/awq.rst:116 b70a51920b4444abac3843c56f0b1a6a
79
+ msgid ""
80
+ "Suppose you have finetuned a model based on ``Qwen1.5-7B``, which is "
81
+ "named ``Qwen1.5-7B-finetuned``, with your own dataset, e.g., Alpaca. To "
82
+ "build your own AWQ quantized model, you need to use the training data for"
83
+ " calibration. Below, we provide a simple demonstration for you to run:"
84
+ msgstr "假设你已经基于 ``Qwen1.5-7B`` 模型进行了微调,并将其命名为 ``Qwen1.5-7B-finetuned`` ,且使用的是你自己的数据集,比如Alpaca。若要构建你自己的AWQ量化模型,你需要使用训练数据进行校准。以下,我们将为你提供一个简单的演示示例以便运行:"
85
+
86
+ #: ../../source/quantization/awq.rst:136 d9f8d6987a2e436d8a50d57ff36cfa30
87
+ msgid ""
88
+ "Then you need to prepare your data for calibaration. What you need to do "
89
+ "is just put samples into a list, each of which is a text. As we directly "
90
+ "use our finetuning data for calibration, we first format it with ChatML "
91
+ "template. For example:"
92
+ msgstr "接下来,您需要准备数据以进行校准。您需要做的就是将样本放入一个列表中,其中每个样本都是一段文本。由于我们直接使用微调数据来进行校准,所以我们首先使用ChatML模板对其进行格式化。例如:"
93
+
94
+ #: ../../source/quantization/awq.rst:149 635319f729684f319b0ec092ad8e40d6
95
+ msgid "where each ``msg`` is a typical chat message as shown below:"
96
+ msgstr "其中每个 ``msg`` 是一个典型的聊天消息,如下所示:"
97
+
98
+ #: ../../source/quantization/awq.rst:159 b324715402c94122a01cacbb1b312d88
99
+ msgid "Then just run the calibration process by one line of code:"
100
+ msgstr "然后只需通过一行代码运行校准过程:"
101
+
102
+ #: ../../source/quantization/awq.rst:165 e5d0fe0d78fa4ee3933913c9d8fb004c
103
+ msgid "Finally, save the quantized model:"
104
+ msgstr "最后,保存量化模型:"
105
+
106
+ #: ../../source/quantization/awq.rst:172 4de18a17e5c548bcb9aa6b464ce5a473
107
+ msgid "Then you can obtain your own AWQ quantized model for deployment. Enjoy!"
108
+ msgstr "然后你就可以得到一个可以用于部署的AWQ量化模型。玩得开心!"
109
+
docs/locales/zh_CN/LC_MESSAGES/quantization/gguf.mo ADDED
Binary file (6.14 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/quantization/gguf.po ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/quantization/gguf.rst:2 79e40c40b83d4f6d9bb98c1dd1b1ef71
19
+ msgid "GGUF"
20
+ msgstr "GGUF"
21
+
22
+ #: ../../source/quantization/gguf.rst:4 14be5842d732404796a6f550f14a7bdd
23
+ msgid ""
24
+ "Recently, running LLMs locally is popular in the community, and running "
25
+ "GGUF files with llama.cpp is a typical example. With llama.cpp, you can "
26
+ "not only build GGUF files for your models but also perform low-bit "
27
+ "quantization. In GGUF, you can directly quantize your models without "
28
+ "calibration, or apply the AWQ scale for better quality, or use imatrix "
29
+ "with calibration data. In this document, we demonstrate the simplest way "
30
+ "to quantize your model as well as the way to apply AWQ scale to your Qwen"
31
+ " model quantization."
32
+ msgstr "最近,在社区中本地运行LLM变得越来越流行,其中使用llama.cpp处理GGUF文件是一个典型的例子。通过llama.cpp,您不仅可以为自己的模型构建GGUF文件,还可以进行低比特量化操作。在GGUF格式下,您可以直接对模型进行量化而无需校准过程,或者为了获得更好的量化效果应用AWQ scale,亦或是结合校准数据使用imatrix工具。在这篇文档中,我们将展示最简便的模型量化方法,以及如何在对Qwen模型进行量化时应用AWQ比例以优化其质量。"
33
+
34
+ #: ../../source/quantization/gguf.rst:14 80a49bd4e8be44c0a76fba918f1ec373
35
+ msgid "Quantize Your Models and Make GGUF Files"
36
+ msgstr "量化你的模型并生成GGUF文件"
37
+
38
+ #: ../../source/quantization/gguf.rst:16 dccc5a60aeea4bb49045d4b5f37fc8ec
39
+ msgid ""
40
+ "Before you move to quantization, make sure you have followed the "
41
+ "instruction and started to use llama.cpp. The following guidance will NOT"
42
+ " provide instructions about installation and building. Now, suppose you "
43
+ "would like to quantize ``Qwen1.5-7B-Chat``. You need to first make a GGUF"
44
+ " file for the fp16 model as shown below:"
45
+ msgstr "在进行量化操作之前,请确保你已经按照指导开始使用llama.cpp。以下指引将不会提供有关安装和构建的步骤。现在,假设你要对 ``Qwen1.5-7B-Chat`` 模型进行量化,首先需要按照如下所示的方式为fp16模型创建一个GGUF文件:"
46
+
47
+ #: ../../source/quantization/gguf.rst:26 0f97df4b989e4cea92ec0fe41f8dbd0b
48
+ msgid ""
49
+ "where the first argument refers to the path to the HF model directory or "
50
+ "the HF model name, and the second argument refers to the path of your "
51
+ "output GGUF file (here I just put it under the directory ``models/7B``. "
52
+ "Remember to create the directory before you run the command). In this "
53
+ "way, you have generated a GGUF file for your fp16 model, and you then "
54
+ "need to quantize it to low bits based on your requirements. An example of"
55
+ " quantizing the model to 4 bits is shown below:"
56
+ msgstr ""其中,第一个参数指代的是预训练模型所在的路径或者HF模型的名称,第二个参数则指的是你想要生成的GGUF文件的路径(此处我将其置于 ``models/7B`` 目录下)。请记住,在运行命令之前,需要先创建这个目录。通过这种方式,你已经为你的fp16模型生成了一个GGUF文件,接下来你需要根据实际需求将其量化至低比特位。以下是一个将模型量化至4位的具体示例:""
57
+
58
+ #: ../../source/quantization/gguf.rst:38 65e715f3392c4fd58ce4884f54da40c5
59
+ msgid ""
60
+ "where we use ``q4_0`` for the 4-bit quantization. Until now, you have "
61
+ "finished quantizing a model to 4 bits and putting it into a GGUF file, "
62
+ "which can be run directly with llama.cpp."
63
+ msgstr "到现在为止,您已经完成了将模型量化为4比特,并将其放入GGUF文件中。这里的 ``q4_0`` 表示4比特量化。现在,这个量化后的模型可以直接通过llama.cpp运行。"
64
+
65
+ #: ../../source/quantization/gguf.rst:43 4dcc797b636f486da31d32535fdc9f6d
66
+ msgid "Quantize Your Models With AWQ Scales"
67
+ msgstr "利用AWQ scales来量化你的模型"
68
+
69
+ #: ../../source/quantization/gguf.rst:45 8b17749b06b54091bf660ffb88974e8e
70
+ msgid ""
71
+ "To improve the quality of your quantized models, one possible solution is"
72
+ " to apply the AWQ scale, following `this script <https://github.com"
73
+ "/casper-hansen/AutoAWQ/blob/main/docs/examples.md>`__. First of all, when"
74
+ " you run ``model.quantize()`` with AutoAWQ, remember to add "
75
+ "``export_compatible=True`` as shown below:"
76
+ msgstr "要提升量化模型的质量,一种可能的解决方案是应用AWQ scales。具体操作步骤如下:首先,在使用AutoAWQ运行model.quantize()时,请务必记得添加 ``export_compatible=True`` 参数,如下所示:"
77
+
78
+ #: ../../source/quantization/gguf.rst:62 9bc945e98396439c9c2eeafef825d2fd
79
+ msgid ""
80
+ "With ``model.save_quantzed()`` as shown above, a fp16 model with AWQ "
81
+ "scales is saved. Then, when you run ``convert-hf-to-gguf.py``, remember "
82
+ "to replace the model path with the path to the fp16 model with AWQ "
83
+ "scales, e.g.,"
84
+ msgstr "通过上述的 model.save_quantized(),一个带有AWQ scales的fp16模型将被保存。然后,当你运行 ``convert-hf-to-gguf.py`` 脚本时,请记得将模型路径替换为带有AWQ scales的fp16模型的路径,例如:"
85
+
86
+ #: ../../source/quantization/gguf.rst:71 384fbacfe6984c95b3cbcd68cd3dcd5d
87
+ msgid ""
88
+ "In this way, you can apply the AWQ scales to your quantized models in "
89
+ "GGUF formats, which helps improving the model quality."
90
+ msgstr "通过这种方式,您可以在GGUF格式的量化模型中应用AWQ scales,这有助于提升模型的质量。"
91
+
92
+ #: ../../source/quantization/gguf.rst:74 b492d0f21b6b44d2b17cafaef752177f
93
+ msgid ""
94
+ "We usually quantize the fp16 model to 2, 3, 4, 5, 6, and 8-bit models. To"
95
+ " perform different low-bit quantization, just replace the quantization "
96
+ "method in your command. For example, if you want to quantize your model "
97
+ "to 2-bit model, you can replace ``q4_0`` to ``q2_k`` as demonstrated "
98
+ "below:"
99
+ msgstr "我们通常将fp16模型量化为2、3、4、5、6和8位模型。要执行不同低比特的量化,只需在命令中替换量化方法即可。例如,如果你想将你的模型量化为2位模型,你可以按照下面所示,将 ``q4_0`` 替换为 ``q2_k`` :"
100
+
101
+ #: ../../source/quantization/gguf.rst:84 9b51095b2c6f4b258bf5aec039471953
102
+ msgid ""
103
+ "We now provide GGUF models in the following quantization levels: "
104
+ "``q2_k``, ``q3_k_m``, ``q4_0``, ``q4_k_m``, ``q5_0``, ``q5_k_m``, "
105
+ "``q6_k``, and ``q8_0``. For more information, please visit `llama.cpp "
106
+ "<https://github.com/ggerganov/llama.cpp>`__."
107
+ msgstr "我们现在提供了以下量化级别的GGUF模型: ``q2_k`` 、 ``q3_k_m`` 、 ``q4_0`` 、 ``q4_k_m`` 、 ``q5_0`` 、 ``q5_k_m`` 、 ``q6_k`` 和 ``q8_0`` 。 欲了解更多信息,请访问 `llama.cpp <https://github.com/ggerganov/llama.cpp>`__ 。"
108
+
docs/locales/zh_CN/LC_MESSAGES/quantization/gptq.mo ADDED
Binary file (5.63 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/quantization/gptq.po ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/quantization/gptq.rst:2 41077c7d75ad44bba5cff56fef7a54bd
19
+ msgid "GPTQ"
20
+ msgstr "GPTQ"
21
+
22
+ #: ../../source/quantization/gptq.rst:4 c291d8c4012b4ac58b42b37c04ac3f05
23
+ msgid ""
24
+ "`GPTQ <https://arxiv.org/abs/2210.17323>`__ is a quantization method for "
25
+ "GPT-like LLMs, which uses one-shot weight quantization based on "
26
+ "approximate second-order information. In this document, we show you how "
27
+ "to use the quantized model with transformers and also how to quantize "
28
+ "your own model with `AutoGPTQ <https://github.com/AutoGPTQ/AutoGPTQ>`__."
29
+ msgstr "`GPTQ <https://arxiv.org/abs/2210.17323>`__ 是一种针对类GPT大型语言模型的量化方法,它基于近似二阶信息进行一次性权重量化。在本文档中,我们将向您展示如何使用 ``transformers`` 库加载并应用量化后的模型,同时也会指导您如何通过 `AutoGPTQ <https://github.com/AutoGPTQ/AutoGPTQ>`__ 来对您自己的模型进行量化处理。"
30
+
31
+ #: ../../source/quantization/gptq.rst:11 ba8f325751ea460b8d3b9d8665f82e7c
32
+ msgid "Usage of GPTQ Models with Transformers"
33
+ msgstr "在Transformers中使用GPTQ模型"
34
+
35
+ #: ../../source/quantization/gptq.rst:13 290140b39fd24e9698933f1a4b3e140f
36
+ msgid ""
37
+ "Now, Transformers has officially supported AutoGPTQ, which means that you"
38
+ " can directly use the quantized model with Transformers. The following is"
39
+ " a very simple code snippet showing how to run ``Qwen1.5-7B-Chat-GPTQ-"
40
+ "Int8`` (note that for each size of Qwen1.5, we provide both Int4 and Int8"
41
+ " quantized models) with the quantized model:"
42
+ msgstr "现在,Transformers 正式支持了AutoGPTQ,这意味着您能够直接在Transformers中使用量化后的模型。以下是一个非常简单的代码片段示例,展示如何运行 ``Qwen1.5-7B-Chat-GPTQ-Int8`` (请注意,对于每种大小的Qwen1.5模型,我们都提供了Int4和Int8两种量化版本):"
43
+
44
+ #: ../../source/quantization/gptq.rst:53 fea96fa1c4344b37a5492a2136f38667
45
+ msgid "Usage of GPTQ Quantized Models with vLLM"
46
+ msgstr "在vLLM中使用GPTQ量化模型"
47
+
48
+ #: ../../source/quantization/gptq.rst:55 0f8eee84b4664c6db0e2383b44f92ca1
49
+ msgid ""
50
+ "vLLM has supported GPTQ, which means that you can directly use our "
51
+ "provided GPTQ models or those trained with ``AutoGPTQ`` with vLLM. "
52
+ "Actually, the usage is the same with the basic usage of vLLM. We provide "
53
+ "a simple example of how to launch OpenAI-API compatible API with vLLM and"
54
+ " ``Qwen1.5-7B-Chat-GPTQ-Int8``:"
55
+ msgstr "vLLM 已经支持了GPTQ,这意味着您可以直接使用我们提供的GPTQ模型,或者那些通过AutoGPTQ训练得到的模型与vLLM结合使用。实际上,其用法与vLLM的基本用法相同。我们提供了一个简单的示例,展示了如何使用vLLM以及 ``Qwen1.5-7B-Chat-GPTQ-Int8`` 模型启动与OpenAI API兼容的API:"
56
+
57
+ #: ../../source/quantization/gptq.rst:75 66259f71f06f437d83e467853aad4e91
58
+ msgid ""
59
+ "or you can use python client with ``openai`` python package as shown "
60
+ "below:"
61
+ msgstr "或者你可以按照下面所示的方式,使用 ``openai`` Python包中的Python客户端:"
62
+
63
+ #: ../../source/quantization/gptq.rst:100 ebb1ebce02da4f78aa2d9dbce73a92d5
64
+ msgid "Quantize Your Own Model with AutoGPTQ"
65
+ msgstr "使用AutoGPTQ量化你的模型"
66
+
67
+ #: ../../source/quantization/gptq.rst:102 e0e9185eec504db59ae92b48cbb5f039
68
+ msgid ""
69
+ "If you want to quantize your own model to GPTQ quantized models, we "
70
+ "advise you to use AutoGPTQ. It is suggested installing the latest version"
71
+ " of the package by installing from source code:"
72
+ msgstr "如果你想将自定义模型量化为GPTQ量化模型,我们建议你使用AutoGPTQ工具。推荐通过安装源代码的方式获取并安装最新版本的该软件包。"
73
+
74
+ #: ../../source/quantization/gptq.rst:112 2f85adf755994b5c8566acdcd9b40bdb
75
+ msgid ""
76
+ "Suppose you have finetuned a model based on ``Qwen1.5-7B``, which is "
77
+ "named ``Qwen1.5-7B-finetuned``, with your own dataset, e.g., Alpaca. To "
78
+ "build your own GPTQ quantized model, you need to use the training data "
79
+ "for calibration. Below, we provide a simple demonstration for you to run:"
80
+ msgstr "假设你已经基于 ``Qwen1.5-7B`` 模型进行了微调,并将该微调后的模型命名为 ``Qwen1.5-7B-finetuned`` ,且使用的是自己的数据集,比如Alpaca。要构建你自己的GPTQ量化模型,你需要使用训练数据进行校准。以下是一个简单的演示示例,供你参考运行:"
81
+
82
+ #: ../../source/quantization/gptq.rst:143 1a0c345f405c44c7b59710cafa099951
83
+ msgid ""
84
+ "Then you need to prepare your data for calibaration. What you need to do "
85
+ "is just put samples into a list, each of which is a text. As we directly "
86
+ "use our finetuning data for calibration, we first format it with ChatML "
87
+ "template. For example:"
88
+ msgstr "接下来,你需要准备数据进行校准。你需要做的是将样本放入一个列表中,其中每个样本都是一段文本。由于我们直接使用微调数据进行校准,所以我们首先使用ChatML模板对它进行格式化处理。例如:"
89
+
90
+ #: ../../source/quantization/gptq.rst:158 58188538413049bcbe47270f9eb40d68
91
+ msgid "where each ``msg`` is a typical chat message as shown below:"
92
+ msgstr "接下来,你需要准备数据以进行校准。你需要做的就是将样本放入一个列表中,其中每个样本都是文本。由于我们直接使用微调数据来进行校准,所以我们首先使用ChatML模板来格式化它。例如:"
93
+
94
+ #: ../../source/quantization/gptq.rst:168 e42b03c4aeeb41caac04a7fbfd2e5925
95
+ msgid "Then just run the calibration process by one line of code:"
96
+ msgstr "然后只需通过一行代码运行校准过程:"
97
+
98
+ #: ../../source/quantization/gptq.rst:177 edcb18775f864566b47befa8e03b6277
99
+ msgid "Finally, save the quantized model:"
100
+ msgstr "最后,保存量化模型:"
101
+
102
+ #: ../../source/quantization/gptq.rst:184 ea6f6d3200904260b4e67cf5e7b29467
103
+ msgid ""
104
+ "It is unfortunate that the ``save_quantized`` method does not support "
105
+ "sharding. For sharding, you need to load the model and use "
106
+ "``save_pretrained`` from transformers to save and shard the model. Except"
107
+ " for this, everything is so simple. Enjoy!"
108
+ msgstr "很遗憾, ``save_quantized`` 方法不支持模型分片。若要实现模型分片,您需要先加载模型,然后使用来自 ``transformers`` 库的 ``save_pretrained`` 方法来保存并分片模型。除此之外,一切操作都非常简单。祝您使用愉快!"
109
+
docs/locales/zh_CN/LC_MESSAGES/run_locally/llama.cpp.mo ADDED
Binary file (4.95 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/run_locally/llama.cpp.po ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-03-04 15:21+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/run_locally/llama.cpp.rst:2 9295ae9f5a5f45bfab93b7e8518e8f08
19
+ msgid "llama.cpp"
20
+ msgstr "llama.cpp"
21
+
22
+ #: ../../source/run_locally/llama.cpp.rst:4 b13bc91c8a9a4571839cb73e37761d1d
23
+ msgid ""
24
+ "`llama.cpp <https://github.com/ggerganov/llama.cpp>`__ is a C++ library "
25
+ "for LLM inference with mimimal setup. It enables running Qwen on your "
26
+ "local machine. It is a plain C/C++ implementation without dependencies, "
27
+ "and it has AVX, AVX2 and AVX512 support for x86 architectures. It "
28
+ "provides 2, 3, 4, 5, 6, and 8-bit quantization for faster inference and "
29
+ "reduced memory footprint. CPU+GPU hybrid inference to partially "
30
+ "accelerate models larger than the total VRAM capacity is also supported. "
31
+ "Essentially, the usage of llama.cpp is to run the GGUF (GPT-Generated "
32
+ "Unified Format ) models. For more information, please refer to the "
33
+ "official GitHub repo. Here we demonstrate how to run Qwen with llama.cpp."
34
+ msgstr ""
35
+ "`llama.cpp <https://github.com/ggerganov/llama.cpp>`__ "
36
+ "是一个C++库,用于简化LLM推理的设置。它使得在本地机器上运行Qwen成为可能。该库是一个纯C/C++实现,不依赖任何外部库,并且针对x86架构提供了AVX、AVX2和AVX512加速支持。此外,它还提供了2、3、4、5、6以及8位量化功能,以加快推理速度并减少内存占用。对于大于总VRAM容量的大规模模型,该库还支持CPU+GPU混合推理模式进行部分加速。本质上,llama.cpp的用途在于运行GGUF(由GPT生成的统一格式)模型。欲了解更多详情,请参阅官方GitHub仓库。以下我们将演示如何使用llama.cpp运行Qwen。"
37
+
38
+ #: ../../source/run_locally/llama.cpp.rst:17 7296806f5b8f469387080e1658c355ed
39
+ msgid "Prerequisites"
40
+ msgstr "准备"
41
+
42
+ #: ../../source/run_locally/llama.cpp.rst:19 33c80a9748744bfe8580b781834fe204
43
+ msgid ""
44
+ "This example is for the usage on Linux or MacOS. For the first step, "
45
+ "clone the repo and enter the directory:"
46
+ msgstr "这个示例适用于Linux或MacOS系统。第一步操作是: “克隆仓库并进入该目录:"
47
+
48
+ #: ../../source/run_locally/llama.cpp.rst:27 023579e4d3e948fbaf2a2e358cc71d59
49
+ msgid "Then use ``make``:"
50
+ msgstr "然后运行 ``make`` 命令:"
51
+
52
+ #: ../../source/run_locally/llama.cpp.rst:33 513bfba9842b483687c4e1b4e5b2a092
53
+ msgid "Then you can run GGUF files with ``llama.cpp``."
54
+ msgstr "然后你就能使用 ``llama.cpp`` 运行GGUF文件。"
55
+
56
+ #: ../../source/run_locally/llama.cpp.rst:36 ffbbe87d16bc4205aa246fcf1216a9b7
57
+ msgid "Running Qwen GGUF Files"
58
+ msgstr "运行Qwen的GGUF文件"
59
+
60
+ #: ../../source/run_locally/llama.cpp.rst:38 06afbf066c6442c68f45d1a90bd68b7c
61
+ msgid ""
62
+ "We provide a series of GGUF models in our Hugging Face organization, and "
63
+ "to search for what you need you can search the repo names with ``-GGUF``."
64
+ " Download the GGUF model that you want with ``huggingface-cli`` (you need"
65
+ " to install it first with ``pip install huggingface_hub``):"
66
+ msgstr ""
67
+ "我们在Hugging Face组织中提供了一系列GGUF模型,为了找到您需要的模型,您可以搜索仓库名称中包含 ``-GGUF`` "
68
+ "的部分。要下载所需的GGUF模型,请使用 ``huggingface-cli`` (首先需要通过命令 ``pip install "
69
+ "huggingface_hub`` 安装它):"
70
+
71
+ #: ../../source/run_locally/llama.cpp.rst:48 4f94dc408d9641e686d64d0508cb7d3f
72
+ msgid "for example:"
73
+ msgstr "比如:"
74
+
75
+ #: ../../source/run_locally/llama.cpp.rst:54 3333b60028d74c5ea09d3fa42c22af4c
76
+ msgid "Then you can run the model with the following command:"
77
+ msgstr "然后你可以用如下命令运行模型:"
78
+
79
+ #: ../../source/run_locally/llama.cpp.rst:60 1dd4d5e214df4b4a8c4b4236d2b40caa
80
+ msgid ""
81
+ "where ``-n`` refers to the maximum number of tokens to generate. There "
82
+ "are other hyperparameters for you to choose and you can run"
83
+ msgstr "``-n`` 指的是要生成的最大token数量。这里还有其他超参数供你选择,并且你可以运行"
84
+
85
+ #: ../../source/run_locally/llama.cpp.rst:67 1418c6357ce942a7880167048985755d
86
+ msgid "to figure them out."
87
+ msgstr "以了解它们。"
88
+
89
+ #: ../../source/run_locally/llama.cpp.rst:70 688ee9f001ec4085b4d93caea7aeb036
90
+ msgid "Make Your GGUF Files"
91
+ msgstr "生成你的GGUF文件"
92
+
93
+ #: ../../source/run_locally/llama.cpp.rst:72 404521aabf484cb2aa304a78f23a63db
94
+ #, fuzzy
95
+ msgid ""
96
+ "We introduce the method of creating and quantizing GGUF files in "
97
+ "`quantization/llama.cpp <../quantization/gguf.html>`__. You can refer to "
98
+ "that document for more information."
99
+ msgstr ""
100
+ "我们在 `quantization/llama.cpp <../quantization/gguf.html>`__ "
101
+ "中介绍了创建和量化GGUF文件的方法。您可以参考该文档获取更多信息。"
102
+
103
+ #: ../../source/run_locally/llama.cpp.rst:77 524dc22e5deb490b9191b674281d2bd9
104
+ msgid "Perplexity Evaluation"
105
+ msgstr "PPL评测"
106
+
107
+ #: ../../source/run_locally/llama.cpp.rst:79 c2df95294edf4f0b8de7f92c4e63b604
108
+ msgid ""
109
+ "``llama.cpp`` provides methods for us to evaluate the perplexity "
110
+ "performance of the GGUF models. To do this, you need to prepare the "
111
+ "dataset, say \"wiki test\". Here we demonstrate an example to run the "
112
+ "test."
113
+ msgstr "llama.cpp为我们提供了评估GGUF模型PPL性能的方法。为了实现这一点,你需要准备一个数据集,比如“wiki测试”。这里我们展示了一个运行测试的例子。"
114
+
115
+ #: ../../source/run_locally/llama.cpp.rst:84 2b96c26557914be28d5d246775b657cd
116
+ msgid "For the first step, download the dataset:"
117
+ msgstr "第一步,下载数据集:"
118
+
119
+ #: ../../source/run_locally/llama.cpp.rst:91 fb0bc11477524f07b6e195757f152d92
120
+ msgid "Then you can run the test with the following command:"
121
+ msgstr "然后你可以用如下命令运行测试:"
122
+
123
+ #: ../../source/run_locally/llama.cpp.rst:97 6822a2aaaa5141ea9be44c569b4a440f
124
+ msgid "where the output is like"
125
+ msgstr "输出如下所示"
126
+
127
+ #: ../../source/run_locally/llama.cpp.rst:105 cca21a6ce70d445fbb23ca92cafc574d
128
+ msgid "Wait for some time and you will get the perplexity of the model."
129
+ msgstr "稍等一段时间你将得到模型的PPL评测结果。"
130
+
131
+ #: ../../source/run_locally/llama.cpp.rst:108 f3df6de18c0d4b78ad29738580cab53a
132
+ msgid "Use GGUF with LM Studio"
133
+ msgstr "在LM Studio使用GGUF"
134
+
135
+ #: ../../source/run_locally/llama.cpp.rst:110 e901df85221a4887b98a3a5c540f010a
136
+ msgid ""
137
+ "If you still find it difficult to use ``llama.cpp``, I advise you to play"
138
+ " with `LM Studio <https://lmstudio.ai/>`__, which is a platform for your "
139
+ "to search and run local LLMs. Qwen1.5 has already been officially part of"
140
+ " LM Studio. Have fun!"
141
+ msgstr ""
142
+ "如果你仍然觉得使用llama.cpp有困难,我建议你尝试一下 `LM Studio <https://lmstudio.ai/>`__ "
143
+ "这个平台,它允许你搜索和运行本地的大规模语言模型。Qwen1.5已经正式成为LM Studio的一部分。祝你使用愉快!"
144
+
docs/locales/zh_CN/LC_MESSAGES/run_locally/ollama.mo ADDED
Binary file (2.57 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/run_locally/ollama.po ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/run_locally/ollama.rst:2 5dbfc8ae09a24c89964f37ebd4ca66bd
19
+ msgid "Ollama"
20
+ msgstr "Ollama"
21
+
22
+ #: ../../source/run_locally/ollama.rst:4 ba8364b5fce64dedabeb7cfbcf677675
23
+ msgid ""
24
+ "`Ollama <https://ollama.com/>`__ helps you run LLMs locally with only a "
25
+ "few commands. It is available at MacOS, Linux, and Windows. Now, Qwen1.5 "
26
+ "is officially on Ollama, and you can run it with one command:"
27
+ msgstr "`Ollama <https://ollama.com/>`__ 帮助您通过少量命令即可在本地运行LLM。它适用于MacOS、Linux和Windows操作系统。现在,Qwen1.5正式上线Ollama,您只需一条命令即可运行它:"
28
+
29
+ #: ../../source/run_locally/ollama.rst:12 93533ba6809b42c19a936440d86df528
30
+ msgid "Next, we introduce more detailed usages of Ollama for running Qwen models."
31
+ msgstr "接着,我们介绍在Ollama使用Qwen模型的更多用法"
32
+
33
+ #: ../../source/run_locally/ollama.rst:16 a972d55b2d0e4ec1b9046258d7342d09
34
+ msgid "Quickstart"
35
+ msgstr "快速开始"
36
+
37
+ #: ../../source/run_locally/ollama.rst:18 494ac69706fb4581b63e8eb81b91148b
38
+ msgid ""
39
+ "Visit the official website `Ollama <https://ollama.com/>`__ and click "
40
+ "download to install Ollama on your device. You can also search models in "
41
+ "the website, where you can find the Qwen1.5 models. Except for the "
42
+ "default one, you can choose to run Qwen1.5-Chat models of different sizes"
43
+ " by:"
44
+ msgstr "访问官方网站 `Ollama <https://ollama.com/>`__ ”,点击 ``Download`` 以在您的设备上安装Ollama。您还可以在网站上搜索模型,在这里您可以找到Qwen1.5系列模型。除了默认模型之外,您可以通过以下方式选择运行不同大小的Qwen1.5-Chat模型:"
45
+
46
+ #: ../../source/run_locally/ollama.rst:24 2aa16e7c8f2144958e5682603c54729c
47
+ msgid "``ollama run qwen:0.5b``"
48
+ msgstr ""
49
+
50
+ #: ../../source/run_locally/ollama.rst:25 e409605f90f64c9383f2fd7401b51b69
51
+ msgid "``ollama run qwen:1.8b``"
52
+ msgstr ""
53
+
54
+ #: ../../source/run_locally/ollama.rst:26 eb4a5cd83bd944acb4576566d6ef39ab
55
+ msgid "``ollama run qwen:4b``"
56
+ msgstr ""
57
+
58
+ #: ../../source/run_locally/ollama.rst:27 53dd5fcbf9794c6fa9351ac89c59896f
59
+ msgid "``ollama run qwen:7b``"
60
+ msgstr ""
61
+
62
+ #: ../../source/run_locally/ollama.rst:28 56ed4eb4153643ccae8a59abd9b8cf99
63
+ msgid "``ollama run qwen:14b``"
64
+ msgstr ""
65
+
66
+ #: ../../source/run_locally/ollama.rst:29 b3e49968c75545f7b291dd7ae099fb8b
67
+ msgid "``ollama run qwen:72b``"
68
+ msgstr ""
69
+
70
+ #: ../../source/run_locally/ollama.rst:32 52d43c07a68b428692fbb19ccb6e1813
71
+ msgid "Run Ollama with Your GGUF Files"
72
+ msgstr "在Ollama运行你的GGUF文件"
73
+
74
+ #: ../../source/run_locally/ollama.rst:34 948e45e8c2aa4cadb9246d2a4d94c3f3
75
+ msgid ""
76
+ "Sometimes you don't want to pull models and you just want to use Ollama "
77
+ "with your own GGUF files. Suppose you have a GGUF file of Qwen, ``qwen1_5"
78
+ "-7b-chat-q4_0.gguf``. For the first step, you need to create a file "
79
+ "called ``Modelfile``. The content of the file is shown below:"
80
+ msgstr "有时您可能不想拉取模型,而是希望直接使用自己的GGUF文件来配合Ollama。假设您有一个名为 ``qwen1_5-7b-chat-q4_0.gguf`` 的Qwen的GGUF文件。在第一步中,您需要创建一个名为 ``Modelfile`` 的文件。该文件的内容如下所示:"
81
+
82
+ #: ../../source/run_locally/ollama.rst:61 3843d0ede09345ce8f694bc19399b780
83
+ msgid "Then create the ollama model by running:"
84
+ msgstr "然后通过运行下列命令来创建一个ollama模型"
85
+
86
+ #: ../../source/run_locally/ollama.rst:67 c061968787654e92ae68ef9a8d2a19ed
87
+ msgid "Once it is finished, you can run your ollama model by:"
88
+ msgstr "完成后,你即可运行你的ollama模型:"
89
+
docs/locales/zh_CN/LC_MESSAGES/training/SFT/example.mo ADDED
Binary file (14.8 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/training/SFT/example.po ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/training/SFT/example.rst:2 691e3f2b49604b49a99b0d62c21ab625
19
+ msgid "Example"
20
+ msgstr "示例"
21
+
22
+ #: ../../source/training/SFT/example.rst:4 ad35293ab62442db89b6b6d2334b0415
23
+ msgid ""
24
+ "Here we provide a very simple script for supervised finetuning, which is "
25
+ "revised from the training script in ```Fastchat`` <https://github.com/lm-"
26
+ "sys/FastChat>`__. The script is used to finetune Qwen with Hugging Face "
27
+ "Trainer. You can check the script `here "
28
+ "<https://github.com/QwenLM/Qwen1.5/blob/main/finetune.py>`__. This script"
29
+ " for supervised finetuning (SFT) has the following features:"
30
+ msgstr "在这里,我们提供了一个非常简单的有监督微调脚本,该脚本是基于 `Fastchat <https://github.com/lm-sys/FastChat>`__ 的训练脚本修改而来的。这个脚本用于使用Hugging Face Trainer 对Qwen模型进行微调。你可以在以下链接查看这个脚本: `这里 <https://github.com/QwenLM/Qwen1.5/blob/main/finetune.py>`__ 。这个脚本具有以下特点:"
31
+
32
+ #: ../../source/training/SFT/example.rst:11 d058261c295d4c62ab51212928663d67
33
+ msgid "Support single-GPU and multi-GPU training;"
34
+ msgstr "支持单卡和多卡分布式训练"
35
+
36
+ #: ../../source/training/SFT/example.rst:12 73732e5202a048ad9bd628046779d3a2
37
+ msgid ""
38
+ "Support full-parameter tuning, `LoRA "
39
+ "<https://arxiv.org/abs/2106.09685>`__, and `Q-LoRA "
40
+ "<https://arxiv.org/abs/2305.14314>`__."
41
+ msgstr "支持全参数微调、 `LoRA <https://arxiv.org/abs/2106.09685>`__ 以及 `Q-LoRA <https://arxiv.org/abs/2305.14314>`__ 。"
42
+
43
+ #: ../../source/training/SFT/example.rst:16 4691f21f4b19470ba7c587c0a2c21f49
44
+ msgid "In the following, we introduce more details about the usage of the script."
45
+ msgstr "下面,我们介绍脚本的更多细节。"
46
+
47
+ #: ../../source/training/SFT/example.rst:20 fe662acf1951448c959543a3c74c8417
48
+ msgid "Installation"
49
+ msgstr "安装"
50
+
51
+ #: ../../source/training/SFT/example.rst:22 e412d1f6dda44df3b6792975b6124c10
52
+ msgid "Before you start, make sure you have installed the following packages:"
53
+ msgstr "开始之前,确保你已经安装了以下代码库:"
54
+
55
+ #: ../../source/training/SFT/example.rst:29 4cf9efbe517045778d847fd3adef663a
56
+ msgid "Data Preparation"
57
+ msgstr "准备数据"
58
+
59
+ #: ../../source/training/SFT/example.rst:31 07e875e969504388b10b7ada5b4c3c7d
60
+ msgid ""
61
+ "For data preparation, we advise you to organize the data in a jsonl file,"
62
+ " where each line is a dictionary as demonstrated below:"
63
+ msgstr "我们建议你放在jsonl文件中,每一行是一个如下所示的字典:"
64
+
65
+ #: ../../source/training/SFT/example.rst:76 652ddb9b02594421bde769f553d29a3e
66
+ msgid ""
67
+ "Above are two examples of each data sample in the dataset. Each sample is"
68
+ " a JSON object with the following fields: ``type``, ``messages`` and "
69
+ "``source``. ``messages`` is required while the others are optional for "
70
+ "you to label your data format and data source. The ``messages`` field is "
71
+ "a list of JSON objects, each of which has two fields: ``role`` and "
72
+ "``content``. ``role`` can be ``system``, ``user``, or ``assistant``. "
73
+ "``content`` is the text of the message. ``source`` is the source of the "
74
+ "data, which can be ``self-made``, ``alpaca``, ``open-hermes``, or any "
75
+ "other string."
76
+ msgstr "以上提供了该数据集中的每个样本的两个示例。每个样本都是一个JSON对象,包含以下字段: ``type`` 、 ``messages`` 和 ``source`` 。其中, ``messages`` 是必填字段,而其他字段则是供您标记数据格式和数据来源的可选字段。 ``messages`` 字段是一个JSON对象列表,每个对象都包含两个字段: ``role`` 和 ``content`` 。其中, ``role`` 可以是 ``system`` 、 ``user`` 或 ``assistant`` ,表示消息的角色; ``content`` 则是消息的文本内容。而 ``source`` 字段代表了数据来源,可能包括 ``self-made`` 、 ``alpaca`` 、 ``open-hermes`` 或其他任意字符串。"
77
+
78
+ #: ../../source/training/SFT/example.rst:86 9271b908bb19400d8dfe56f1ef0ce1b5
79
+ msgid ""
80
+ "To make the jsonl file, you can use ``json`` to save a list of "
81
+ "dictionaries to the jsonl file:"
82
+ msgstr "你需要用 ``json`` 将一个字典列表存入jsonl文件中:"
83
+
84
+ #: ../../source/training/SFT/example.rst:98 6c36700445c340bfa6feeadd6c1bdb1c
85
+ msgid "Quickstart"
86
+ msgstr "快速开始"
87
+
88
+ #: ../../source/training/SFT/example.rst:100 0e86c01757e74bdabfc3bca0e4265481
89
+ msgid ""
90
+ "For you to start finetuning quickly, we directly provide a shell script "
91
+ "for you to run without paying attention to details. You need "
92
+ "different hyperparameters for different types of training, e.g., single-"
93
+ "GPU / multi-GPU training, full-parameter tuning, LoRA, or Q-LoRA."
94
+ msgstr "为了让您能够快速开始微调,我们直接提供了一个shell脚本,您可以无需关注具体细节即可运行。针对不同类型的训练(例如单GPU训练、多GPU训练、全参数微调、LoRA或Q-LoRA),您可能需要不同的超参数设置。"
95
+
96
+ #: ../../source/training/SFT/example.rst:113 6967058d5e504f3f87a084f8b6756224
97
+ msgid ""
98
+ "Specify the ``<model_path>`` for your model, ``<data_path>`` for your "
99
+ "data, and ``<config_path>`` for your deepspeed configuration. If you use "
100
+ "LoRA or Q-LoRA, just add ``--use_lora True`` or ``--q_lora True`` based "
101
+ "on your requirements. This is the simplest way to start finetuning. If "
102
+ "you want to change more hyperparameters, you can dive into the script and"
103
+ " modify those parameters."
104
+ msgstr "为您的模型指定 ``<model_path>`` ,为您的数据指定 ``<data_path>`` ,并为您的Deepspeed配置指定 ``<config_path>`` 。如果您使用LoRA或Q-LoRA,只需根据您的需求添加 ``--use_lora True`` 或 ``--q_lora True`` 。这是开始微调的最简单方式。如果您想更改更多超参数,您可以深入脚本并修改这些参数。"
105
+
106
+ #: ../../source/training/SFT/example.rst:122 9ce4446fa109470188c3a6f849c51a23
107
+ msgid "Advanced Usages"
108
+ msgstr "高级用法"
109
+
110
+ #: ../../source/training/SFT/example.rst:124 a5b1894b1348461dae32eafa7193b325
111
+ msgid ""
112
+ "In this section, we introduce the details of the scripts, including the "
113
+ "core python script as well as the corresponding shell script."
114
+ msgstr "在这个部分中,我们介绍python脚本以及shell脚本的相关细节"
115
+
116
+ #: ../../source/training/SFT/example.rst:128 7df17cdd0ceb42eb9d7f1734b317c3b9
117
+ msgid "Shell Script"
118
+ msgstr "Shell脚本"
119
+
120
+ #: ../../source/training/SFT/example.rst:130 9da15ddce8994ea29a9562b498bebb4c
121
+ msgid ""
122
+ "Before we introduce the python code, we provide a brief introduction to "
123
+ "the shell script with commands. We provide some guidance inside the shell"
124
+ " script and here we take ``finetune.sh`` as an example."
125
+ msgstr "在展示Python代码之前,我们先对包含命令的Shell脚本做一个简单的介绍。我们在Shell脚本中提供了一些指南,并且此处将以 ``finetune.sh`` 这个脚本为例进行解释说明。"
126
+
127
+ #: ../../source/training/SFT/example.rst:134 407c05f4ef174a40a986fb9fcc994466
128
+ msgid ""
129
+ "To set up the environment variables for distributed training (or single-"
130
+ "GPU training), specify the following variables: ``GPUS_PER_NODE``, "
131
+ "``NNODES``, ``NODE_RANK``, ``MASTER_ADDR``, and ``MASTER_PORT``. No need "
132
+ "to worry too much about them as we provide the default settings for you. "
133
+ "In the command, you can pass in the argument ``-m`` and ``-d`` to specify"
134
+ " the model path and data path, respectively. You can also pass in the "
135
+ "argument ``--deepspeed`` to specify the deepspeed configuration file. We "
136
+ "provide two configuration files for ZeRO2 and ZeRO3, and you can choose "
137
+ "one based on your requirements. In most cases, we recommend using ZeRO3 "
138
+ "for multi-GPU training except for Q-LoRA, where we recommend using ZeRO2."
139
+ msgstr "要为分布式训练(或单GPU训练)设置环境变量,请指定以下变量: ``GPUS_PER_NODE`` 、 ``NNODES、NODE_RANK`` 、 ``MASTER_ADDR`` 和 ``MASTER_PORT`` 。不必过于担心这些变量,因为我们为您提供了默认设置。在命令行中,您可以通过传入参数 ``-m`` 和 ``-d`` 来分别指定模型路径和数据路径。您还可以通过传入参数 ``--deepspeed`` 来指定Deepspeed配置文件。我们为您提供针对ZeRO2和ZeRO3的两种配置文件,您可以根据需求选择其中之一。在大多数情况下,我们建议在多GPU训练中使用ZeRO3,但针对Q-LoRA,我们推荐使用ZeRO2。"
140
+
141
+ #: ../../source/training/SFT/example.rst:146 3253db51858e4ed9936299f01a35fb8b
142
+ msgid ""
143
+ "There are a series of hyperparameters to tune. Passing in ``--bf16`` or "
144
+ "``--fp16`` to specify the precision for mixed precision training. "
145
+ "The other significant hyperparameters include:"
146
+ msgstr "有一系列需要调节的超参数。您可以向程序传递 ``--bf16`` 或 ``--fp16`` 参数来指定混合精度训练所采用的精度级别。此外,还有其他一些重要的超参数如下:"
147
+
148
+ #: ../../source/training/SFT/example.rst:151 4a971f83ddd140e295c719e1938306b0
149
+ msgid "``--output_dir``: the path of your output models or adapters."
150
+ msgstr " ``--output_dir`` :模型或者adapter的输出路径;."
151
+
152
+ #: ../../source/training/SFT/example.rst:152 e69801659a8c4bcba41cdcdc4a2fd5fc
153
+ msgid "``--num_train_epochs``: the number of training epochs."
154
+ msgstr " ``--num_train_epochs`` : 训练轮数;"
155
+
156
+ #: ../../source/training/SFT/example.rst:153 7c12854b98524812a8b4760588a62776
157
+ msgid ""
158
+ "``--gradient_accumulation_steps``: the number of gradient accumulation "
159
+ "steps."
160
+ msgstr " ``--gradient_accumulation_steps`` :梯度累积;"
161
+
162
+ #: ../../source/training/SFT/example.rst:155 99dce5d00f63497297bcb9f81490803d
163
+ msgid ""
164
+ "``--per_device_train_batch_size``: the batch size per GPU for training, "
165
+ "and the total batch size is equalt to ``per_device_train_batch_size`` "
166
+ ":math:`\\times` ``number_of_gpus`` :math:`\\times` "
167
+ "``gradient_accumulation_steps``."
168
+ msgstr " ``--per_device_train_batch_size`` 参数表示每个GPU在训练时的批次大小,而总批次大小等于 ``per_device_train_batch_size`` 乘以 GPU 的数量,再乘以 ``gradient_accumulation_steps`` ;"
169
+
170
+ #: ../../source/training/SFT/example.rst:159 475e6a55c72243cb99358dcd2c465910
171
+ msgid "``--learning_rate``: the learning rate."
172
+ msgstr " ``--learning_rate`` :学习率;"
173
+
174
+ #: ../../source/training/SFT/example.rst:160 d375b81b4a4b450f8204af76a598f07f
175
+ msgid "``--warmup_steps``: the number of warmup steps."
176
+ msgstr " ``--warmup_steps`` :warmup的步数;"
177
+
178
+ #: ../../source/training/SFT/example.rst:161 315ccca447354e63b97336b9c8439317
179
+ msgid "``--lr_scheduler_type``: the type of learning rate scheduler."
180
+ msgstr " ``--lr_scheduler_type`` :learning rate scheduler类型;"
181
+
182
+ #: ../../source/training/SFT/example.rst:162 338b6abfcb684c87a5c64323712c015e
183
+ msgid "``--weight_decay``: the value of weight decay."
184
+ msgstr " ``--weight_decay``:weight decay的值;"
185
+
186
+ #: ../../source/training/SFT/example.rst:163 092f57e35db9472f80881e60395a6fd9
187
+ msgid "``--adam_beta2``: the value of :math:`\\beta_2` in Adam."
188
+ msgstr " ``--adam_beta2`` :Adam :math:`\\beta_2` "
189
+
190
+ #: ../../source/training/SFT/example.rst:164 1b3dd161a9e74cbb9d5ea69c7e7e027d
191
+ msgid "``--model_max_length``: the maximum sequence length."
192
+ msgstr " ``--model_max_length`` :最大长度;"
193
+
194
+ #: ../../source/training/SFT/example.rst:165 c8679770b7894a28aae2d37f74fe793b
195
+ msgid ""
196
+ "``--use_lora``: whether to use LoRA. Adding ``--q_lora`` can enable "
197
+ "Q-LoRA."
198
+ msgstr " ``--use_lora`` :是否使用LoRA,加上 ``--q_lora`` 即可启用Q-LoRA。""
199
+
200
+ #: ../../source/training/SFT/example.rst:167 19559d935a3a4b5ca489bac858a1a370
201
+ msgid "``--gradient_checkpointing``: whether to use gradient checkpointing."
202
+ msgstr " ``--gradient_checkpointing`` :是否使用gradient checkpointing;"
203
+
204
+ #: ../../source/training/SFT/example.rst:170 1b7c0668912844a8ac5d659cff28a3ca
205
+ msgid "Python Script"
206
+ msgstr "Python脚本"
207
+
208
+ #: ../../source/training/SFT/example.rst:172 56fefe47f8f84599ad5ef2a3a757b6b9
209
+ msgid ""
210
+ "In this script, we mainly use ``trainer`` from HF and ``peft`` to train "
211
+ "our models. We also use ``deepspeed`` to accelerate the training process."
212
+ " The script is very simple and easy to understand."
213
+ msgstr "在本脚本中,我们主要使用来自HF的 ``trainer`` 和 ``peft`` 来训练我们的模型。同时,我们也利用 ``deepspeed`` 来加速训练过程。该脚本非常简洁且易于理解。"
214
+
215
+ #: ../../source/training/SFT/example.rst:228 39088ec5d7014e1388276b552acfba08
216
+ msgid ""
217
+ "The classes for arguments allow you to specify hyperparameters for model,"
218
+ " data, training, and additionally LoRA if you use LoRA or Q-LoRA to train"
219
+ " your model. Specifically, ``model-max-length`` is a key hyperparameter "
220
+ "that determines your maximum sequence length of your training data."
221
+ msgstr "参数类允许你为模型、数据和训练指定超参数,如果使用LoRA或Q-LoRA训练模型,还会包含这两个方法的相关超参数。具体来说, ``model-max-length`` 是一个关键的超参数,它决定了训练数据的最大序列长度。"
222
+
223
+ #: ../../source/training/SFT/example.rst:234 fe78a42c209d43e2bb6bb05eeef07f6a
224
+ msgid "``LoRAArguments`` includes the hyperparameters for LoRA or Q-LoRA:"
225
+ msgstr ""
226
+
227
+ #: ../../source/training/SFT/example.rst:236 1d4398fa2e54447e9ebab4b86d880a40
228
+ msgid "``lora_r``: the rank for LoRA;"
229
+ msgstr " ``LoRAArguments`` 包含了用于LoRA或Q-LoRA的超参数:"
230
+
231
+ #: ../../source/training/SFT/example.rst:237 a885bf1a19ab4d05b3d1727b1fe45f23
232
+ msgid "``lora_alpha``: the alpha value for LoRA;"
233
+ msgstr " `lora_alpha`` :LoRA的alpha值;"
234
+
235
+ #: ../../source/training/SFT/example.rst:238 f77081bd15d440299d74c8fae5b14952
236
+ msgid "``lora_dropout``: the dropout rate for LoRA;"
237
+ msgstr " ``lora_dropout`` :LoRA的Dropout;"
238
+
239
+ #: ../../source/training/SFT/example.rst:239 ed286b58fe1143a88e18430a2e0faa2a
240
+ msgid ""
241
+ "``lora_target_modules``: the target modules for LoRA. By default we tune "
242
+ "all linear layers;"
243
+ msgstr " ``lora_target_modules`` :LoRA的目标模块,默认情况下,我们对所有线性层进行调优;"
244
+
245
+ #: ../../source/training/SFT/example.rst:241 245ff8c677174e4b80486a2b7bc54b1e
246
+ msgid "``lora_weight_path``: the path to the weight file for LoRA;"
247
+ msgstr " ``lora_weight_path``:LoRA的权重路径;"
248
+
249
+ #: ../../source/training/SFT/example.rst:242 441ef87612c647518633090a3889360d
250
+ msgid "``lora_bias``: the bias for LoRA;"
251
+ msgstr " ``lora_bias`` :LoRA的bias"
252
+
253
+ #: ../../source/training/SFT/example.rst:243 95776633d70841efb4187ad9408ffb23
254
+ msgid "``q_lora``: whether to use Q-LoRA."
255
+ msgstr " ``q_lora`` 是否使用Q-LoRA。""
256
+
257
+ #: ../../source/training/SFT/example.rst:301 8842a7bafb2d4d77a63590bdd79195ce
258
+ msgid ""
259
+ "The method ``safe_save_model_for_hf_trainer``, which uses "
260
+ "``get_peft_state_maybe_zero_3``, helps tackle the problems in saving "
261
+ "models trained either with or without ZeRO3."
262
+ msgstr "方法 ``safe_save_model_for_hf_trainer`` 通过使用 ``get_peft_state_maybe_zero_3`` 有助于解决在保存采用或未采用ZeRO3技术训练的模型时遇到的问题。"
263
+
264
+ #: ../../source/training/SFT/example.rst:335 7850340690ee4a4ebc65de95cd04ccd6
265
+ msgid ""
266
+ "For data preprocessing, we use ``preprocess`` to organize the data. "
267
+ "Specifically, we apply our ChatML template to the texts. If you prefer "
268
+ "other chat templates, you can use others, e.g., by still applying "
269
+ "``apply_chat_template()`` with another tokenizer. The chat template is "
270
+ "stored in the ``tokenizer_config.json`` in the HF repo. Additionally, we "
271
+ "pad the sequence of each sample to the maximum length for training."
272
+ msgstr "在数据预处理阶段,我们使用 ``preprocess`` 来整理数据。具体来说,我们应用ChatML模板对文本进行处理。如果您倾向于使用其他chat模板,您也可以选择其他的,例如,仍然通过``apply_chat_template()``函数配合另一个tokenizer进行应用。Chat模板存储在HF仓库中的 ``tokenizer_config.json`` 文件中。此外,我们还将每个样本的序列填充到最大长度,以便于训练。"
273
+
274
+ #: ../../source/training/SFT/example.rst:432 c308fd832bd747a48ac896a9ffaa9804
275
+ msgid ""
276
+ "Then we utilize ``make_supervised_data_module`` by using "
277
+ "``SupervisedDataset`` or ``LazySupervisedDataset`` to build the dataset."
278
+ msgstr "然后我们利用 ``make_supervised_data_module`` ,通过使用 ``SupervisedDataset`` 或 ``LazySupervisedDataset`` 来构建数据集。"
279
+
280
+ #: ../../source/training/SFT/example.rst:555 2245d0d984224d9dbc8ddbb43160c596
281
+ msgid ""
282
+ "The ``train`` method is the key to the training. In general, it loads the"
283
+ " tokenizer and model with ``AutoTokenizer.from_pretrained()`` and "
284
+ "``AutoModelForCausalLM.from_pretrained()``. If we use LoRA, the method "
285
+ "will initialize LoRA configuration with ``LoraConfig``. If we apply "
286
+ "Q-LoRA, we should use ``prepare_model_for_kbit_training``. Note that for "
287
+ "now it still does not support resume for LoRA. Then we leave the "
288
+ "following efforts to ``trainer`` and have a cup of coffee!"
289
+ msgstr "``train`` 方法是训练过程的关键所在。通常情况下,它会通过 ``AutoTokenizer.from_pretrained()`` 和 ``AutoModelForCausalLM.from_pretrained()`` 来加载tokenizer和模型。如果使用了LoRA,该方法将会用 ``LoraConfig`` 初始化LoRA配置。若应用Q-LoRA,则应当采用 ``prepare_model_for_kbit_training`` 。请注意,目前还不支持对LoRA的续训(resume)。接下来的任务就交给trainer处理,此时不妨喝杯咖啡稍作休息!"
290
+
291
+ #: ../../source/training/SFT/example.rst:564 5224efdee6424eec88b1fdf0a99e4694
292
+ msgid "Next Step"
293
+ msgstr "下一步"
294
+
295
+ #: ../../source/training/SFT/example.rst:566 2f2432fcec6e42758b92c50f6c7855bd
296
+ msgid ""
297
+ "Now, you are able to use a very simple script to perform different types "
298
+ "of SFT. Alternatively, you can use more advanced training libraries, such"
299
+ " as `Axolotl <https://github.com/OpenAccess-AI-Collective/axolotl>`__ or "
300
+ "`LLaMA-Factory <https://github.com/hiyouga/LLaMA-Factory>`__, to enjoy "
301
+ "more functionalities. To take a step forward, after SFT, you can consider"
302
+ " RLHF to align your model to human preferences! Stay tuned for our next "
303
+ "tutorial on RLHF!"
304
+ msgstr "现在,您可以使用一个非常简单的脚本来执行不同类型的SFT。另外,您还可以选择使用更高级的训练库,例如 `Axolotl <https://github.com/OpenAccess-AI-Collective/axolotl>`__ 或 `LLaMA-Factory <https://github.com/hiyouga/LLaMA-Factory>`__ ,以享受更多的功能。进一步来说,在完成SFT之后,您可以考虑采用RLHF(强化学习与人类反馈)来使您的模型更好地与人类偏好对齐!请继续关注我们接下来关于RLHF的教程!"
305
+
docs/locales/zh_CN/LC_MESSAGES/training/SFT/index.mo ADDED
Binary file (457 Bytes). View file
 
docs/locales/zh_CN/LC_MESSAGES/training/SFT/index.po ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Plural-Forms: nplurals=1; plural=0;\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/training/SFT/index.rst:2 7c5733b15e73491ca46e02dcd6a501f8
19
+ msgid "SFT"
20
+ msgstr "有监督微调"
21
+
docs/locales/zh_CN/LC_MESSAGES/training/SFT/llama_factory.mo ADDED
Binary file (4.87 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/training/SFT/llama_factory.po ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-03-12 01:42+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
12
+ "Language-Team: LANGUAGE <LL@li.org>\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=utf-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Generated-By: Babel 2.14.0\n"
17
+
18
+ #: ../../source/training/SFT/llama_factory.rst:2
19
+ #: 59f81b6b7fa440c9b569151bd34595fd
20
+ msgid "LLaMA-Factory"
21
+ msgstr ""
22
+
23
+ #: ../../source/training/SFT/llama_factory.rst:4
24
+ #: 1d5a0e9c836a43e984330f7b50e84487
25
+ msgid ""
26
+ "Here we provide a script for supervised finetuning Qwen1.5 with `LLaMA-"
27
+ "Factory <https://github.com/hiyouga/LLaMA-Factory>`__. This script for "
28
+ "supervised finetuning (SFT) has the following features:"
29
+ msgstr "我们将介绍如何使用 `LLaMA-Factory <https://github.com/hiyouga/LLaMA-Factory>`__ 微调模型。本脚本包含如下特点:"
30
+
31
+ #: ../../source/training/SFT/llama_factory.rst:8
32
+ #: ebe5c05bb39346f0b64ef71ec2f2c0a7
33
+ msgid "Support single-GPU and multi-GPU training;"
34
+ msgstr "支持单卡和多卡分布式训练"
35
+
36
+ #: ../../source/training/SFT/llama_factory.rst:10
37
+ #: 28e8b2797a93491591eff4fcb6f1a4ea
38
+ msgid "Support full-parameter tuning, LoRA, Q-LoRA, Dora."
39
+ msgstr "支持全参数微调、LoRA、Q-LoRA 和 DoRA 。"
40
+
41
+ #: ../../source/training/SFT/llama_factory.rst:12
42
+ #: 5705aea24e634555a9c1ac297415c062
43
+ msgid "In the following, we introduce more details about the usage of the script."
44
+ msgstr "下文将介绍更多关于脚本的用法。"
45
+
46
+ #: ../../source/training/SFT/llama_factory.rst:16
47
+ #: a946af86f08044379906c17ecafed11a
48
+ msgid "Installation"
49
+ msgstr "安装"
50
+
51
+ #: ../../source/training/SFT/llama_factory.rst:18
52
+ #: 2c970d53e2e04cdc910f62a0b77ed626
53
+ msgid "Before you start, make sure you have installed the following packages:"
54
+ msgstr "开始之前,确保你已经安装了以下代码库:"
55
+
56
+ #: ../../source/training/SFT/llama_factory.rst:20
57
+ #: 0e3e1ec5879340e98f4e25e4b6d9ded1
58
+ msgid ""
59
+ "Follow the instructions of `LLaMA-Factory <https://github.com/hiyouga"
60
+ "/LLaMA-Factory>`__, and build the environment."
61
+ msgstr ""
62
+ "根据 `LLaMA-Factory <https://github.com/hiyouga/LLaMA-Factory>`__ "
63
+ "官方指引构建好你的环境"
64
+
65
+ #: ../../source/training/SFT/llama_factory.rst:23
66
+ #: 166ac903c6ce4285841641f5f3b5bec0
67
+ msgid "Install these packages (Optional):"
68
+ msgstr "安装下列代码库(可选):"
69
+
70
+ #: ../../source/training/SFT/llama_factory.rst:30
71
+ #: 5092a8b55dba46ca95ac6e177af0fa99
72
+ msgid ""
73
+ "If you want to use `FlashAttention-2 <https://github.com/Dao-AILab/flash-"
74
+ "attention>`__, make sure your CUDA is 11.6 and above."
75
+ msgstr ""
76
+ "如你使用 `FlashAttention-2 <https://github.com/Dao-AILab/flash-attention>`__"
77
+ " ,请确保你的CUDA版本在11.6以上。"
78
+
79
+ #: ../../source/training/SFT/llama_factory.rst:35
80
+ #: ee8e36c067c94af2a4a74238f3d26ac5
81
+ msgid "Data Preparation"
82
+ msgstr "准备数据"
83
+
84
+ #: ../../source/training/SFT/llama_factory.rst:37
85
+ #: bad133d73f4049459f22f7c2cbf0523e
86
+ msgid ""
87
+ "LLaMA-Factory provides several training datasets in ``data`` folder, you "
88
+ "can use it directly. If you are using a custom dataset, please prepare "
89
+ "your dataset as follow."
90
+ msgstr ""
91
+ "LLaMA-Factory 在 ``data`` "
92
+ "文件夹中提供了多个训练数据集,您可以直接使用它们。如果您打算使用自定义数据集,请按照以下方式准备您的数据集。"
93
+
94
+ #: ../../source/training/SFT/llama_factory.rst:41
95
+ #: 6d942c4471c448b9a67a327d67442b34
96
+ msgid ""
97
+ "Organize your data in a **json** file and put your data in ``data`` "
98
+ "folder. LLaMA-Factory supports dataset in ``alpaca`` or ``sharegpt`` "
99
+ "format."
100
+ msgstr ""
101
+ "请将您的数据以 ``json`` 格式进行组织,并将数据放入 data 文件夹中。LLaMA-Factory 支持以 ``alpaca`` 或 "
102
+ "``sharegpt`` 格式的数据集。"
103
+
104
+ #: ../../source/training/SFT/llama_factory.rst:45
105
+ #: c80fd006f8bf481f806582eb000215e8
106
+ msgid "The dataset in ``alpaca`` format should follow the below format:"
107
+ msgstr "``alpaca`` 格式的数据集应遵循以下格式:"
108
+
109
+ #: ../../source/training/SFT/llama_factory.rst:62
110
+ #: 876409cf2a294398926fdcbe355fd4d9
111
+ msgid "The dataset in ``sharegpt`` format should follow the below format:"
112
+ msgstr "``sharegpt`` 格式的数据集应遵循以下格式:"
113
+
114
+ #: ../../source/training/SFT/llama_factory.rst:83
115
+ #: 3731a5252e4749efb1f5b897934094a7
116
+ msgid ""
117
+ "Provide your dataset definition in ``data/dataset_info.json`` in the "
118
+ "following format ."
119
+ msgstr "在 ``data/dataset_info.json`` 文件中提供您的数据集定义,并采用以下格式:"
120
+
121
+ #: ../../source/training/SFT/llama_factory.rst:86
122
+ #: c048531148ff496dba3e8f57feb11e34
123
+ msgid ""
124
+ "For ``alpaca`` format dataset, the columns in ``dataset_info.json`` "
125
+ "should be:"
126
+ msgstr "对于 ``alpaca`` 格式的数据集,其 ``dataset_info.json`` 文件中��列应为:"
127
+
128
+ #: ../../source/training/SFT/llama_factory.rst:102
129
+ #: 6ece984e56c4463a80b71f8af62282fe
130
+ msgid ""
131
+ "For ``sharegpt`` format dataset, the columns in ``dataset_info.json`` "
132
+ "should be:"
133
+ msgstr "对于 ``sharegpt`` 格式的数据集,``dataset_info.json`` 文件中的列应该包括:"
134
+
135
+ #: ../../source/training/SFT/llama_factory.rst:124
136
+ #: 6da6d3f24fcf46ef86a08820e79446dd
137
+ msgid "Training"
138
+ msgstr "训练"
139
+
140
+ #: ../../source/training/SFT/llama_factory.rst:126
141
+ #: f3a81032d0924cb9b7dacdad9b32b4fc
142
+ msgid "Execute the following training command:"
143
+ msgstr "执行下列命令:"
144
+
145
+ #: ../../source/training/SFT/llama_factory.rst:166
146
+ #: fc83cc671a04458db38f7ac6d3fee22b
147
+ msgid ""
148
+ "and enjoy the training process. To make changes to your training, you can"
149
+ " modify the arguments in the training command to adjust the "
150
+ "hyperparameters. One argument to note is ``cutoff_len``, which is the "
151
+ "maximum length of the training data. Control this parameter to avoid OOM "
152
+ "error."
153
+ msgstr ""
154
+ "并享受训练过程。若要调整您的训练,您可以通过修改训练命令中的参数来调整超参数。其中一个需要注意的参数是 ``cutoff_len`` "
155
+ ",它代表训练数据的最大长度。通过控制这个参数,可以避免出现OOM(内存溢出)错误。"
156
+
157
+ #: ../../source/training/SFT/llama_factory.rst:173
158
+ #: 663c9bd983754ac0aa20bd1dbb524598
159
+ msgid "Merge LoRA"
160
+ msgstr "合并LoRA"
161
+
162
+ #: ../../source/training/SFT/llama_factory.rst:175
163
+ #: 845a8a06b9494e589ee21b5c7ebaf22d
164
+ msgid ""
165
+ "If you train your model with LoRA, you probably need to merge adapter "
166
+ "parameters to the main branch. Run the following command to perform the "
167
+ "merging of LoRA adapters."
168
+ msgstr "如果你使用 LoRA 训练模型,可能需要将adapter参数合并到主分支中。请运行以下命令以执行 LoRA adapter 的合并操作。"
169
+
170
+ #: ../../source/training/SFT/llama_factory.rst:191
171
+ #: 03fd595a678f48cabe5b9c6192edc406
172
+ msgid "Conclusion"
173
+ msgstr "结语"
174
+
175
+ #: ../../source/training/SFT/llama_factory.rst:193
176
+ #: 3e566cad14514beaad47a28f282ada51
177
+ msgid ""
178
+ "The above content is the simplest way to use LLaMA-Factory to train Qwen."
179
+ " Feel free to dive into the details by checking the official repo!"
180
+ msgstr "上述内容是使用LLaMA-Factory训练Qwen的最简单方法。 欢迎通过查看官方仓库深入了解详细信息!"
181
+
docs/locales/zh_CN/LC_MESSAGES/web_ui/text_generation_webui.mo ADDED
Binary file (5.77 kB). View file
 
docs/locales/zh_CN/LC_MESSAGES/web_ui/text_generation_webui.po ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2024, Qwen Team, Alibaba Group.
2
+ # This file is distributed under the same license as the Qwen package.
3
+ #
4
+ #, fuzzy
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: Qwen \n"
8
+ "Report-Msgid-Bugs-To: \n"
9
+ "POT-Creation-Date: 2024-02-21 21:08+0800\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Language: zh_CN\n"
12
+ "Language-Team: zh_CN <LL@li.org>\n"
13
+ "Plural-Forms: nplurals=1; plural=0;\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=utf-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Generated-By: Babel 2.14.0\n"
18
+
19
+ #: ../../source/web_ui/text_generation_webui.rst:2
20
+ #: c0f23ae236e54e24af7deef5d7146003
21
+ msgid "Text Generation Web UI"
22
+ msgstr "Text Generation Web UI"
23
+
24
+ #: ../../source/web_ui/text_generation_webui.rst:4
25
+ #: 47af3df3d9ab4729846c3a0d6d0895b5
26
+ msgid ""
27
+ "`Text Generation Web UI <https://github.com/oobabooga/text-generation-"
28
+ "webui>`__ (TGW, or usually referred to “oobabooga”) is a popular web UI "
29
+ "for text generation, similar to `AUTOMATIC1111/stable-diffusion-webui "
30
+ "<https://github.com/AUTOMATIC1111/stable-diffusion-webui>`__. It has "
31
+ "multiple interfaces, and supports multiple model backends, including "
32
+ "`Transformers <https://github.com/huggingface/transformers>`__, "
33
+ "`llama.cpp <https://github.com/ggerganov/llama.cpp>`__ (through `llama-"
34
+ "cpp-python <https://github.com/abetlen/llama-cpp-python>`__), `ExLlamaV2 "
35
+ "<https://github.com/turboderp/exllamav2>`__, `AutoGPTQ "
36
+ "<https://github.com/PanQiWei/AutoGPTQ>`__, `AutoAWQ <https://github.com"
37
+ "/casper-hansen/AutoAWQ>`__, `GPTQ-for-LLaMa "
38
+ "<https://github.com/qwopqwop200/GPTQ-for-LLaMa>`__, `CTransformers "
39
+ "<https://github.com/marella/ctransformers>`__, `QuIP# <https://github.com"
40
+ "/Cornell-RelaxML/quip-sharp>`__. In this section, we introduce how to run"
41
+ " Qwen locally with TGW."
42
+ msgstr "`Text Generation Web UI <https://github.com/oobabooga/text-generation-webui>`__ (简称TGW,通常被称为“oobabooga”)是一款流行的文本生成Web界面工具,类似于 `AUTOMATIC1111/stable-diffusion-webui <https://github.com/AUTOMATIC1111/stable-diffusion-webui>`__ 。它拥有多个交互界面,并支持多种模型后端,包括 `Transformers <https://github.com/huggingface/transformers>`__ 、 `llama.cpp <https://github.com/ggerganov/llama.cpp>`__ (通过 `llama-cpp-python <https://github.com/abetlen/llama-cpp-python>`__ 实现)、 `ExLlamaV2 <https://github.com/turboderp/exllamav2>`__ 、 `AutoGPTQ <https://github.com/PanQiWei/AutoGPTQ>`__ 、 `AutoAWQ <https://github.com/casper-hansen/AutoAWQ>`__ 、 `GPTQ-for-LLaMa <https://github.com/qwopqwop200/GPTQ-for-LLaMa>`__ 、 `CTransformers <https://github.com/marella/ctransformers>`__ 以及 `QuIP# <https://github.com/Cornell-RelaxML/quip-sharp>`__ 。在本节中,我们将介绍如何在本地环境中使用TGW运行Qwen。"
43
+
44
+ #: ../../source/web_ui/text_generation_webui.rst:23
45
+ #: 5e9eb228343a4168b8c1af490096093e
46
+ msgid "Quickstart"
47
+ msgstr "快速开始"
48
+
49
+ #: ../../source/web_ui/text_generation_webui.rst:25
50
+ #: 17dd3e7a101d448c8f382b0f7bc96a63
51
+ msgid ""
52
+ "The simplest way to run TGW is to use the provided shell scripts in the "
53
+ "`repo <https://github.com/oobabooga/text-generation-webui>`__. For the "
54
+ "first step, clone the repo and enter the directory:"
55
+ msgstr "最简单的运行TGW(Text Generation WebUI)的方法是使用 `repo <https://github.com/oobabooga/text-generation-webui>`__ 中提供的Shell脚本。首先,克隆repo并进去文件夹中:"
56
+
57
+ #: ../../source/web_ui/text_generation_webui.rst:34
58
+ #: 009d1688050543bfb6bc4863646e78d3
59
+ msgid ""
60
+ "You can directly run the ``start_linux.sh``, ``start_windows.bat``, "
61
+ "``start_macos.sh``, or ``start_wsl.bat`` script depending on your OS. "
62
+ "Alternatively you can manually install the requirements in your conda "
63
+ "environment. Here I take the practice on MacOS as an example."
64
+ msgstr "你可以根据你的操作系统直接运行相应的脚本,例如在Linux系统上运行 ``start_linux.sh`` ,在Windows系统上运行 ``start_windows.bat`` ,在MacOS系统上运行 ``start_macos.sh`` ,或者在Windows子系统Linux(WSL)上运行 ``start_wsl.bat`` 。另外,你也可以选择手动在conda环境中安装所需的依赖项。这里以MacOS系统为例进行实践操作。"
65
+
66
+ #: ../../source/web_ui/text_generation_webui.rst:45
67
+ #: c8d93c382166438f943c1ae4b9d84be3
68
+ msgid ""
69
+ "Then you can install the requirements by running ``pip install -r`` based"
70
+ " on your OS, e.g.,"
71
+ msgstr "接下来,您可以根据您的操作系统执行 ``pip install -r`` 命令来安装相应的依赖项,例如,"
72
+
73
+ #: ../../source/web_ui/text_generation_webui.rst:52
74
+ #: 52b5cbf125f442b699dc05bf827ecb5f
75
+ msgid ""
76
+ "For ``bitsandbytes`` and ``llama-cpp-python`` inside the requirements, I "
77
+ "advise you to install them through ``pip`` directly. However, temporarily"
78
+ " please do not use GGUF as the performance with TGW is unsatisfactory. "
79
+ "After finishing the installation of required packages, you need to "
80
+ "prepare your models by putting the model files or directories in the "
81
+ "folder ``./models``. For example, you should put the transformers model "
82
+ "directory of ``Qwen1.5-7B-Chat`` in the way shown below:"
83
+ msgstr "对于requirements中的 ``bitsandbytes`` 和 ``llama-cpp-python`` ,我建议您直接通过 ``pip`` 进行安装。但是,暂时请不要使用GGUF,因为其与TGW配合时的性能表现不佳。在完成所需包的安装之后,您需要准备模型,将模型文件或目录放在``./models``文件夹中。例如,您应按照以下方式将``transformers``模型目录 ``Qwen1.5-7B-Chat`` 放置到相应位置。例如,您应该将 ``Qwen1.5-7B-Chat`` 模型的目录结构放入 ``./models`` 文件夹内。"
84
+
85
+ #: ../../source/web_ui/text_generation_webui.rst:76
86
+ #: 3d7582c62c0348cb90d4c221f4b7ad33
87
+ msgid "Then you just need to run"
88
+ msgstr "随后你需要运行"
89
+
90
+ #: ../../source/web_ui/text_generation_webui.rst:82
91
+ #: 040a0472b9d34ef7a9f7854f57f6cd62
92
+ msgid "to launch your web UI service. Please browse to"
93
+ msgstr "来启动你的网页服务。请点击进入"
94
+
95
+ #: ../../source/web_ui/text_generation_webui.rst:88
96
+ #: 8118d325bcee4f1aa52d63cd8208f6a2
97
+ msgid "and enjoy playing with Qwen in a web UI!"
98
+ msgstr "然后享受使用Qwen的Web UI吧!"
99
+
100
+ #: ../../source/web_ui/text_generation_webui.rst:91
101
+ #: 453dec3129ea4a60b6c803dd6c43c251
102
+ msgid "Next Step"
103
+ msgstr "下一步"
104
+
105
+ #: ../../source/web_ui/text_generation_webui.rst:93
106
+ #: cc02078a24ff484b8494356ced5ee451
107
+ msgid ""
108
+ "There are a lot more usages in TGW, where you can even enjoy role play, "
109
+ "use different types of quantized models, train LoRA, incorporate "
110
+ "extensions like stable diffusion and whisper, etc. Go to figure out more "
111
+ "advanced usages and apply them to Qwen models!"
112
+ msgstr "TGW 中包含了许多更多用途,您甚至可以在其中享受角色扮演的乐趣,并使用不同类型的量化模型。您可以训练诸如LoRA这样的算法,并将Stable Diffusion和Whisper等扩展功能纳入其中。赶快去探索更多高级用法,并将它们应用于Qwen模型中吧!"
113
+
docs/make.bat ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @ECHO OFF
2
+
3
+ pushd %~dp0
4
+
5
+ REM Command file for Sphinx documentation
6
+
7
+ if "%SPHINXBUILD%" == "" (
8
+ set SPHINXBUILD=sphinx-build
9
+ )
10
+ set SOURCEDIR=source
11
+ set BUILDDIR=build
12
+
13
+ if "%1" == "" goto help
14
+
15
+ %SPHINXBUILD% >NUL 2>NUL
16
+ if errorlevel 9009 (
17
+ echo.
18
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19
+ echo.installed, then set the SPHINXBUILD environment variable to point
20
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
21
+ echo.may add the Sphinx directory to PATH.
22
+ echo.
23
+ echo.If you don't have Sphinx installed, grab it from
24
+ echo.https://www.sphinx-doc.org/
25
+ exit /b 1
26
+ )
27
+
28
+ %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29
+ goto end
30
+
31
+ :help
32
+ %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33
+
34
+ :end
35
+ popd
docs/requirements-docs.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ sphinx
2
+ sphinx-book-theme
3
+ sphinx-copybutton
4
+ furo
docs/source/assets/.DS_Store ADDED
Binary file (6.15 kB). View file
 
docs/source/assets/logo/.DS_Store ADDED
Binary file (6.15 kB). View file
 
docs/source/assets/logo/qwen1.5.png ADDED
docs/source/conf.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # This file only contains a selection of the most common options. For a full
4
+ # list see the documentation:
5
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
6
+
7
+ # -- Path setup --------------------------------------------------------------
8
+
9
+ # If extensions (or modules to document with autodoc) are in another directory,
10
+ # add these directories to sys.path here. If the directory is relative to the
11
+ # documentation root, use os.path.abspath to make it absolute, like shown here.
12
+
13
+ import os
14
+ import sys
15
+ from sphinx.ext import autodoc
16
+ import logging
17
+
18
+ sys.path.insert(0, os.path.abspath(os.path.join('..', '..')))
19
+
20
+ logger = logging.getLogger(__name__)
21
+
22
+ # -- Project information -----------------------------------------------------
23
+
24
+ project = 'Qwen'
25
+ copyright = '2024, Qwen Team'
26
+ author = 'Qwen Team'
27
+
28
+ # -- General configuration ---------------------------------------------------
29
+
30
+ # Add any Sphinx extension module names here, as strings. They can be
31
+ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32
+ # ones.
33
+ extensions = [
34
+ "sphinx.ext.napoleon",
35
+ "sphinx.ext.viewcode",
36
+ "sphinx.ext.intersphinx",
37
+ # "sphinx_copybutton",
38
+ "sphinx.ext.autodoc",
39
+ "sphinx.ext.autosummary",
40
+ ]
41
+
42
+ # Add any paths that contain templates here, relative to this directory.
43
+ templates_path = ['_templates']
44
+
45
+ # List of patterns, relative to source directory, that match files and
46
+ # directories to ignore when looking for source files.
47
+ # This pattern also affects html_static_path and html_extra_path.
48
+ exclude_patterns = []
49
+
50
+ # Exclude the prompt "$" when copying code
51
+ copybutton_prompt_text = r"\$ "
52
+ copybutton_prompt_is_regexp = True
53
+
54
+ # -- Options for HTML output -------------------------------------------------
55
+
56
+ # The theme to use for HTML and HTML Help pages. See the documentation for
57
+ # a list of builtin themes.
58
+ #
59
+ html_title = project
60
+ html_theme = 'furo'
61
+ # html_logo = 'assets/logo/qwen.png'
62
+ # html_theme_options = {
63
+ # 'path_to_docs': 'docs/source',
64
+ # 'repository_url': 'https://github.com/QwenLM/Qwen1.5',
65
+ # # 'use_repository_button': True,
66
+ # }
67
+ html_sidebars = {
68
+ "**": [
69
+ "sidebar/scroll-start.html",
70
+ "sidebar/brand.html",
71
+ "sidebar/navigation.html",
72
+ "sidebar/ethical-ads.html",
73
+ "sidebar/scroll-end.html",
74
+ ]
75
+ }
76
+
77
+ # multi-language docs
78
+ language = 'en'
79
+ locale_dirs = ['../locales/'] # path is example but recommended.
80
+ gettext_compact = False # optional.
81
+ gettext_uuid = True # optional.
82
+
83
+ # Add any paths that contain custom static files (such as style sheets) here,
84
+ # relative to this directory. They are copied after the builtin static files,
85
+ # so a file named "default.css" will overwrite the builtin "default.css".
86
+ # html_static_path = ['_static']
87
+
88
+ # Mock out external dependencies here.
89
+ autodoc_mock_imports = [
90
+ "torch", "transformers"
91
+ ]
92
+
93
+ for mock_target in autodoc_mock_imports:
94
+ if mock_target in sys.modules:
95
+ logger.info(
96
+ f"Potentially problematic mock target ({mock_target}) found; "
97
+ "autodoc_mock_imports cannot mock modules that have already "
98
+ "been loaded into sys.modules when the sphinx build starts.")
99
+
100
+
101
+ class MockedClassDocumenter(autodoc.ClassDocumenter):
102
+ """Remove note about base class when a class is derived from object."""
103
+
104
+ def add_line(self, line: str, source: str, *lineno: int) -> None:
105
+ if line == " Bases: :py:class:`object`":
106
+ return
107
+ super().add_line(line, source, *lineno)
108
+
109
+
110
+ autodoc.ClassDocumenter = MockedClassDocumenter
111
+
112
+ navigation_with_keys = False
docs/source/deployment/vllm.rst ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ vLLM
2
+ =====================
3
+
4
+ We recommend you trying with
5
+ `vLLM <https://github.com/vllm-project/vllm>`__ for your deployement
6
+ of Qwen. It is simple to use, and it is fast with state-of-the-art
7
+ serving throughtput, efficienct management of attention key value memory
8
+ with PagedAttention, continuous batching of input requests, optimized
9
+ CUDA kernels, etc. To learn more about vLLM, please refer to the
10
+ `paper <https://arxiv.org/abs/2309.06180>`__ and
11
+ `documentation <https://vllm.readthedocs.io/>`__.
12
+
13
+ Installation
14
+ ------------
15
+
16
+ By default, you can install ``vLLM`` by pip:
17
+ ``pip install vLLM>=0.3.0``, but if you are using CUDA 11.8, check the
18
+ note in the official document for installation
19
+ (`link <https://docs.vllm.ai/en/latest/getting_started/installation.html>`__)
20
+ for some help. We also advise you to install ray by ``pip install ray``
21
+ for distributed serving.
22
+
23
+ Offline Batched Inference
24
+ -------------------------
25
+
26
+ Models supported by Qwen2 codes, e.g., Qwen1.5, are supported by vLLM.
27
+ The simplest usage of vLLM is offline batched inference as demonstrated
28
+ below.
29
+
30
+ .. code:: python
31
+
32
+ from transformers import AutoTokenizer
33
+ from vllm import LLM, SamplingParams
34
+
35
+ # Initialize the tokenizer
36
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-7B-Chat")
37
+
38
+ # Pass the default decoding hyperparameters of Qwen1.5-7B-Chat
39
+ # max_tokens is for the maximum length for generation.
40
+ sampling_params = SamplingParams(temperature=0.7, top_p=0.8, repetition_penalty=1.05, max_tokens=512)
41
+
42
+ # Input the model name or path. Can be GPTQ or AWQ models.
43
+ llm = LLM(model="Qwen/Qwen1.5-7B-Chat")
44
+
45
+ # Prepare your prompts
46
+ prompt = "Tell me something about large language models."
47
+ messages = [
48
+ {"role": "system", "content": "You are a helpful assistant."},
49
+ {"role": "user", "content": prompt}
50
+ ]
51
+ text = tokenizer.apply_chat_template(
52
+ messages,
53
+ tokenize=False,
54
+ add_generation_prompt=True
55
+ )
56
+
57
+ # generate outputs
58
+ outputs = llm.generate([text], sampling_params)
59
+
60
+ # Print the outputs.
61
+ for output in outputs:
62
+ prompt = output.prompt
63
+ generated_text = output.outputs[0].text
64
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
65
+
66
+ OpenAI-API Compatible API Service
67
+ ---------------------------------
68
+
69
+ It is easy to build an OpenAI-API compatible API service with vLLM,
70
+ which can be deployed as a server that implements OpenAI API protocol.
71
+ By default, it starts the server at ``http://localhost:8000``. You can
72
+ specify the address with ``--host`` and ``--port`` arguments. Run the
73
+ command as shown below:
74
+
75
+ .. code:: bash
76
+
77
+ python -m vllm.entrypoints.openai.api_server \
78
+ --model Qwen/Qwen1.5-7B-Chat
79
+
80
+ You don’t need to worry about chat template as it by default uses the
81
+ chat template provided by the tokenizer.
82
+
83
+ Then, you can use the `create chat
84
+ interface <https://platform.openai.com/docs/api-reference/chat/completions/create>`__
85
+ to communicate with Qwen:
86
+
87
+ .. code:: bash
88
+
89
+ curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
90
+ "model": "Qwen/Qwen1.5-7B-Chat",
91
+ "messages": [
92
+ {"role": "system", "content": "You are a helpful assistant."},
93
+ {"role": "user", "content": "Tell me something about large language models."}
94
+ ]
95
+ }'
96
+
97
+ or you can use python client with ``openai`` python package as shown
98
+ below:
99
+
100
+ .. code:: python
101
+
102
+ from openai import OpenAI
103
+ # Set OpenAI's API key and API base to use vLLM's API server.
104
+ openai_api_key = "EMPTY"
105
+ openai_api_base = "http://localhost:8000/v1"
106
+
107
+ client = OpenAI(
108
+ api_key=openai_api_key,
109
+ base_url=openai_api_base,
110
+ )
111
+
112
+ chat_response = client.chat.completions.create(
113
+ model="Qwen/Qwen1.5-7B-Chat",
114
+ messages=[
115
+ {"role": "system", "content": "You are a helpful assistant."},
116
+ {"role": "user", "content": "Tell me something about large language models."},
117
+ ]
118
+ )
119
+ print("Chat response:", chat_response)
120
+
121
+ Multi-GPU Distributred Serving
122
+ ------------------------------
123
+
124
+ To scale up your serving throughputs, distributed serving helps you by
125
+ leveraging more GPU devices. Besides, for large models like
126
+ ``Qwen1.5-72B-Chat``, it is impossible to serve it on a single GPU.
127
+ Here, we demonstrate how to run ``Qwen1.5-72B-Chat`` with tensor
128
+ parallelism just by passing in the argument ``tensor_parallel_size``:
129
+
130
+ .. code:: python
131
+
132
+ from vllm import LLM, SamplingParams
133
+ llm = LLM(model="Qwen/Qwen1.5-72B-Chat", tensor_parallel_size=4)
134
+
135
+ You can run multi-GPU serving by passing in the argument
136
+ ``--tensor-parallel-size``:
137
+
138
+ .. code:: bash
139
+
140
+ python -m vllm.entrypoints.api_server \
141
+ --model Qwen/Qwen1.5-72B-Chat \
142
+ --tensor-parallel-size 4
143
+
144
+ Serving Quantized Models
145
+ ------------------------
146
+
147
+ vLLM supports different types of quantized models, including AWQ, GPTQ,
148
+ SqueezeLLM, etc. Here we show how to deploy AWQ and GPTQ models. The
149
+ usage is almost the same as above except for an additional argument for
150
+ quantization. For example, to run an AWQ model. e.g.,
151
+ ``Qwen1.5-7B-Chat-AWQ``:
152
+
153
+ .. code:: python
154
+
155
+ from vllm import LLM, SamplingParams
156
+ llm = LLM(model="Qwen/Qwen1.5-7B-Chat-AWQ", quantization="awq")
157
+
158
+ or GPTQ models like ``Qwen1.5-7B-Chat-GPTQ-Int8``:
159
+
160
+ .. code:: python
161
+
162
+ llm = LLM(model="Qwen/Qwen1.5-7B-Chat-GPTQ-Int4", quantization="gptq")
163
+
164
+ Similarly, you can run serving adding the argument ``--quantization`` as
165
+ shown below:
166
+
167
+ .. code:: bash
168
+
169
+ python -m vllm.entrypoints.openai.api_server \
170
+ --model Qwen/Qwen1.5-7B-Chat-AWQ \
171
+ --quantization awq
172
+
173
+ or
174
+
175
+ .. code:: bash
176
+
177
+ python -m vllm.entrypoints.openai.api_server \
178
+ --model Qwen/Qwen1.5-7B-Chat-GPTQ-Int8 \
179
+ --quantization gptq
180
+
181
+ Additionally, vLLM supports the combination of AWQ or GPTQ models with
182
+ KV cache quantization, namely FP8 E5M2 KV Cache. For example:
183
+
184
+ .. code:: python
185
+
186
+ llm = LLM(model="Qwen/Qwen1.5-7B-Chat-GPTQ-Int8", quantization="gptq", kv_cache_dtype="fp8_e5m2")
187
+
188
+ .. code:: bash
189
+
190
+ python -m vllm.entrypoints.openai.api_server \
191
+ --model Qwen/Qwen1.5-7B-Chat-GPTQ-Int8 \
192
+ --quantization gptq \
193
+ --kv-cache-dtype fp8_e5m2
194
+
195
+ Troubleshooting
196
+ ---------------
197
+
198
+ You may encounter OOM issues that are pretty annoying. We recommend two
199
+ arguments for you to make some fix. The first one is
200
+ ``--max-model-len``. Our provided default ``max_postiion_embedding`` is
201
+ ``32768`` and thus the maximum length for the serving is also this
202
+ value, leading to higher requirements of memory. Reducing it to a proper
203
+ length for yourself often helps with the OOM issue. Another argument you
204
+ can pay attention to is ``--gpu-memory-utilization``. By default it is
205
+ ``0.9`` and you can level it up to tackle the OOM problem. This is also
206
+ why you find a vLLM service always takes so much memory.
docs/source/framework/function_call.rst ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Function Calling
2
+ ================
3
+
4
+ We offer a wrapper for function calling over the dashscope API and the
5
+ OpenAI API in `Qwen-Agent <https://github.com/QwenLM/Qwen-Agent>`__.
6
+
7
+ Use Case
8
+ --------
9
+
10
+ .. code:: py
11
+
12
+ import json
13
+ import os
14
+ from qwen_agent.llm import get_chat_model
15
+
16
+
17
+ # Example dummy function hard coded to return the same weather
18
+ # In production, this could be your backend API or an external API
19
+ def get_current_weather(location, unit='fahrenheit'):
20
+ """Get the current weather in a given location"""
21
+ if 'tokyo' in location.lower():
22
+ return json.dumps({
23
+ 'location': 'Tokyo',
24
+ 'temperature': '10',
25
+ 'unit': 'celsius'
26
+ })
27
+ elif 'san francisco' in location.lower():
28
+ return json.dumps({
29
+ 'location': 'San Francisco',
30
+ 'temperature': '72',
31
+ 'unit': 'fahrenheit'
32
+ })
33
+ elif 'paris' in location.lower():
34
+ return json.dumps({
35
+ 'location': 'Paris',
36
+ 'temperature': '22',
37
+ 'unit': 'celsius'
38
+ })
39
+ else:
40
+ return json.dumps({'location': location, 'temperature': 'unknown'})
41
+
42
+
43
+ def test():
44
+ llm = get_chat_model({
45
+ # Use the model service provided by DashScope:
46
+ 'model': 'qwen-max',
47
+ 'model_server': 'dashscope',
48
+ 'api_key': os.getenv('DASHSCOPE_API_KEY'),
49
+
50
+ # Use the model service provided by Together.AI:
51
+ # 'model': 'Qwen/Qwen1.5-14B-Chat',
52
+ # 'model_server': 'https://api.together.xyz', # api_base
53
+ # 'api_key': os.getenv('TOGETHER_API_KEY'),
54
+
55
+ # Use your own model service compatible with OpenAI API:
56
+ # 'model': 'Qwen/Qwen1.5-72B-Chat',
57
+ # 'model_server': 'http://localhost:8000/v1', # api_base
58
+ # 'api_key': 'EMPTY',
59
+ })
60
+
61
+ # Step 1: send the conversation and available functions to the model
62
+ messages = [{
63
+ 'role': 'user',
64
+ 'content': "What's the weather like in San Francisco?"
65
+ }]
66
+ functions = [{
67
+ 'name': 'get_current_weather',
68
+ 'description': 'Get the current weather in a given location',
69
+ 'parameters': {
70
+ 'type': 'object',
71
+ 'properties': {
72
+ 'location': {
73
+ 'type': 'string',
74
+ 'description':
75
+ 'The city and state, e.g. San Francisco, CA',
76
+ },
77
+ 'unit': {
78
+ 'type': 'string',
79
+ 'enum': ['celsius', 'fahrenheit']
80
+ },
81
+ },
82
+ 'required': ['location'],
83
+ },
84
+ }]
85
+
86
+ print('# Assistant Response 1:')
87
+ responses = []
88
+ for responses in llm.chat(messages=messages,
89
+ functions=functions,
90
+ stream=True):
91
+ print(responses)
92
+
93
+ messages.extend(responses) # extend conversation with assistant's reply
94
+
95
+ # Step 2: check if the model wanted to call a function
96
+ last_response = messages[-1]
97
+ if last_response.get('function_call', None):
98
+
99
+ # Step 3: call the function
100
+ # Note: the JSON response may not always be valid; be sure to handle errors
101
+ available_functions = {
102
+ 'get_current_weather': get_current_weather,
103
+ } # only one function in this example, but you can have multiple
104
+ function_name = last_response['function_call']['name']
105
+ function_to_call = available_functions[function_name]
106
+ function_args = json.loads(last_response['function_call']['arguments'])
107
+ function_response = function_to_call(
108
+ location=function_args.get('location'),
109
+ unit=function_args.get('unit'),
110
+ )
111
+ print('# Function Response:')
112
+ print(function_response)
113
+
114
+ # Step 4: send the info for each function call and function response to the model
115
+ messages.append({
116
+ 'role': 'function',
117
+ 'name': function_name,
118
+ 'content': function_response,
119
+ }) # extend conversation with function response
120
+
121
+ print('# Assistant Response 2:')
122
+ for responses in llm.chat(
123
+ messages=messages,
124
+ functions=functions,
125
+ stream=True,
126
+ ): # get a new response from the model where it can see the function response
127
+ print(responses)
128
+
129
+
130
+ if __name__ == '__main__':
131
+ test()
docs/source/framework/qwen_agent.rst ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Qwen-Agent
2
+ ==========
3
+
4
+ `Qwen-Agent <https://github.com/QwenLM/Qwen-Agent>`__ is a framework for
5
+ developing LLM applications based on the instruction following, tool
6
+ usage, planning, and memory capabilities of Qwen. It also comes with
7
+ example applications such as Browser Assistant, Code Interpreter, and
8
+ Custom Assistant.
9
+
10
+ Installation
11
+ ------------
12
+
13
+ .. code:: bash
14
+
15
+ git clone https://github.com/QwenLM/Qwen-Agent.git
16
+ cd Qwen-Agent
17
+ pip install -e ./
18
+
19
+ Developing Your Own Agent
20
+ -------------------------
21
+
22
+ Qwen-Agent provides atomic components such as LLMs and prompts, as well
23
+ as high-level components such as Agents. The example below uses the
24
+ Assistant component as an illustration, demonstrating how to add custom
25
+ tools and quickly develop an agent that uses tools.
26
+
27
+ .. code:: py
28
+
29
+ import json
30
+ import os
31
+
32
+ import json5
33
+ import urllib.parse
34
+ from qwen_agent.agents import Assistant
35
+ from qwen_agent.tools.base import BaseTool, register_tool
36
+
37
+ llm_cfg = {
38
+ # Use the model service provided by DashScope:
39
+ 'model': 'qwen-max',
40
+ 'model_server': 'dashscope',
41
+ # 'api_key': 'YOUR_DASHSCOPE_API_KEY',
42
+ # It will use the `DASHSCOPE_API_KEY' environment variable if 'api_key' is not set here.
43
+
44
+ # Use your own model service compatible with OpenAI API:
45
+ # 'model': 'Qwen/Qwen1.5-72B-Chat',
46
+ # 'model_server': 'http://localhost:8000/v1', # api_base
47
+ # 'api_key': 'EMPTY',
48
+
49
+ # (Optional) LLM hyperparameters for generation:
50
+ 'generate_cfg': {
51
+ 'top_p': 0.8
52
+ }
53
+ }
54
+ system = 'According to the user\'s request, you first draw a picture and then automatically run code to download the picture ' + \
55
+ 'and select an image operation from the given document to process the image'
56
+
57
+ # Add a custom tool named my_image_gen:
58
+ @register_tool('my_image_gen')
59
+ class MyImageGen(BaseTool):
60
+ description = 'AI painting (image generation) service, input text description, and return the image URL drawn based on text information.'
61
+ parameters = [{
62
+ 'name': 'prompt',
63
+ 'type': 'string',
64
+ 'description': 'Detailed description of the desired image content, in English',
65
+ 'required': True
66
+ }]
67
+
68
+ def call(self, params: str, **kwargs) -> str:
69
+ prompt = json5.loads(params)['prompt']
70
+ prompt = urllib.parse.quote(prompt)
71
+ return json.dumps(
72
+ {'image_url': f'https://image.pollinations.ai/prompt/{prompt}'},
73
+ ensure_ascii=False)
74
+
75
+
76
+ tools = ['my_image_gen', 'code_interpreter'] # code_interpreter is a built-in tool in Qwen-Agent
77
+ bot = Assistant(llm=llm_cfg,
78
+ system_message=system,
79
+ function_list=tools,
80
+ files=[os.path.abspath('doc.pdf')])
81
+
82
+ messages = []
83
+ while True:
84
+ query = input('user question: ')
85
+ messages.append({'role': 'user', 'content': query})
86
+ response = []
87
+ for response in bot.run(messages=messages):
88
+ print('bot response:', response)
89
+ messages.extend(response)
90
+
91
+ The framework also provides more atomic components for developers to
92
+ combine. For additional showcases, please refer to
93
+ `examples <https://github.com/QwenLM/Qwen-Agent/tree/main/examples>`__.
docs/source/getting_started/installation.rst ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Installation
2
+ ============
3
+
4
+ To get a quick start with Qwen1.5, you can install the ``transformers``
5
+ library from Hugging Face and use models in the `Qwen1.5
6
+ collection <https://huggingface.co/collections/Qwen/qwen15-65c0a2f577b1ecb76d786524>`__.
7
+ We advise you to install the latest ``transformers`` or at least version
8
+ 4.37.0.
9
+
10
+ Install with Pip
11
+ ~~~~~~~~~~~~~~~~
12
+
13
+ .. code:: bash
14
+
15
+ pip install transformers
16
+
17
+ Install with Conda
18
+ ~~~~~~~~~~~~~~~~~~
19
+
20
+ .. code:: bash
21
+
22
+ conda install conda-forge::transformers
23
+
24
+ We advise you to use Python 3.8 or higher, and Pytorch 2.0 or higher.
docs/source/getting_started/quickstart.rst ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Quickstart
2
+ ==========
3
+
4
+ This guide helps you quickly start using Qwen1.5. We provide examples of
5
+ `Hugging Face Transformers <https://github.com/huggingface/transformers>`__
6
+ as well as `ModelScope <https://github.com/modelscope/modelscope>`__, and
7
+ `vLLM <https://github.com/vllm-project/vllm>`__ for deployment.
8
+
9
+ Hugging Face Transformers & ModelScope
10
+ --------------------------------------
11
+
12
+ To get a quick start with Qwen1.5, we advise you to try with the
13
+ inference with ``transformers`` first. Make sure that you have installed
14
+ ``transformers>=4.37.0``. The following is a very simple code snippet
15
+ showing how to run Qwen1.5-Chat, with an example of Qwen1.5-7B-Chat:
16
+
17
+ .. code:: python
18
+
19
+ from transformers import AutoModelForCausalLM, AutoTokenizer
20
+ device = "cuda" # the device to load the model onto
21
+
22
+ # Now you do not need to add "trust_remote_code=True"
23
+ model = AutoModelForCausalLM.from_pretrained(
24
+ "Qwen/Qwen1.5-7B-Chat",
25
+ torch_dtype="auto",
26
+ device_map="auto"
27
+ )
28
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-7B-Chat")
29
+
30
+ # Instead of using model.chat(), we directly use model.generate()
31
+ # But you need to use tokenizer.apply_chat_template() to format your inputs as shown below
32
+ prompt = "Give me a short introduction to large language model."
33
+ messages = [
34
+ {"role": "system", "content": "You are a helpful assistant."},
35
+ {"role": "user", "content": prompt}
36
+ ]
37
+ text = tokenizer.apply_chat_template(
38
+ messages,
39
+ tokenize=False,
40
+ add_generation_prompt=True
41
+ )
42
+ model_inputs = tokenizer([text], return_tensors="pt").to(device)
43
+
44
+ # Directly use generate() and tokenizer.decode() to get the output.
45
+ # Use `max_new_tokens` to control the maximum output length.
46
+ generated_ids = model.generate(
47
+ model_inputs.input_ids,
48
+ max_new_tokens=512
49
+ )
50
+ generated_ids = [
51
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
52
+ ]
53
+
54
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
55
+
56
+ Previously, we use ``model.chat()`` (see ``modeling_qwen.py`` in
57
+ previous Qwen models for more information). Now, we follow the practice
58
+ of ``transformers`` and directly use ``model.generate()`` with
59
+ ``apply_chat_template()`` in tokenizer.
60
+
61
+ To tackle with downloading issues, we advise you to try with from
62
+ ModelScope, just changing the first line of code above to the following:
63
+
64
+ .. code:: python
65
+
66
+ from modelscope import AutoModelForCausalLM, AutoTokenizer
67
+
68
+ Streaming mode for model chat is simple with the help of
69
+ ``TextStreamer``. Below we show you an example of how to use it:
70
+
71
+ .. code:: python
72
+
73
+ ...
74
+ # Reuse the code before `model.generate()` in the last code snippet
75
+ from transformers import TextStreamer
76
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
77
+ generated_ids = model.generate(
78
+ model_inputs.input_ids,
79
+ max_new_tokens=512,
80
+ streamer=streamer,
81
+ )
82
+
83
+ vLLM for Deployment
84
+ -------------------
85
+
86
+ To deploy Qwen1.5, we advise you to use vLLM. vLLM is a fast
87
+ and easy-to-use framework for LLM inference and serving. In the
88
+ following, we demonstrate how to build a OpenAI-API compatible API
89
+ service with vLLM.
90
+
91
+ First, make sure you have installed ``vLLM>=0.3.0``:
92
+
93
+ .. code:: bash
94
+
95
+ pip install vllm
96
+
97
+ Run the following code to build up a vllm service. Here we take
98
+ Qwen1.5-7B-Chat as an example:
99
+
100
+ .. code:: bash
101
+
102
+ python -m vllm.entrypoints.openai.api_server --model Qwen/Qwen1.5-7B-Chat
103
+
104
+ Then, you can use the `create chat
105
+ interface <https://platform.openai.com/docs/api-reference/chat/completions/create>`__
106
+ to communicate with Qwen:
107
+
108
+ .. code:: bash
109
+
110
+ curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
111
+ "model": "Qwen/Qwen1.5-7B-Chat",
112
+ "messages": [
113
+ {"role": "system", "content": "You are a helpful assistant."},
114
+ {"role": "user", "content": "Tell me something about large language models."}
115
+ ],
116
+ }'
117
+
118
+ or you can use python client with ``openai`` python package as shown
119
+ below:
120
+
121
+ .. code:: python
122
+
123
+ from openai import OpenAI
124
+ # Set OpenAI's API key and API base to use vLLM's API server.
125
+ openai_api_key = "EMPTY"
126
+ openai_api_base = "http://localhost:8000/v1"
127
+
128
+ client = OpenAI(
129
+ api_key=openai_api_key,
130
+ base_url=openai_api_base,
131
+ )
132
+
133
+ chat_response = client.chat.completions.create(
134
+ model="Qwen/Qwen1.5-7B-Chat",
135
+ messages=[
136
+ {"role": "system", "content": "You are a helpful assistant."},
137
+ {"role": "user", "content": "Tell me something about large language models."},
138
+ ]
139
+ )
140
+ print("Chat response:", chat_response)
141
+
142
+ Next Step
143
+ ---------
144
+
145
+ Now, you can have fun with Qwen models. Would love to know more about
146
+ its usages? Feel free to check other documents in this documentation.
docs/source/index.rst ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. Qwen documentation master file, created by
2
+ sphinx-quickstart on Tue Feb 20 21:16:41 2024.
3
+ You can adapt this file completely to your liking, but it should at least
4
+ contain the root `toctree` directive.
5
+
6
+ Welcome to Qwen!
7
+ ================
8
+
9
+ .. figure:: ./assets/logo/qwen1.5.png
10
+ :width: 60%
11
+ :align: center
12
+ :alt: Qwen
13
+ :class: no-scaled-link
14
+
15
+
16
+ Qwen is the large language model and large multimodal model series of the Qwen Team, Alibaba Group. Now the large language models have been upgraded to Qwen1.5. Both language models and multimodal models are pretrained on large-scale multilingual and multimodal data and post-trained on quality data for aligning to human preferences.
17
+ Qwen is capable of natural language understanding, text generation, vision understanding, audio understanding, tool use, role play, playing as AI agent, etc.
18
+
19
+ The latest version, Qwen1.5, has the following features:
20
+
21
+ * 6 model sizes, including 0.5B, 1.8B, 4B, 7B, 14B, and 72B;
22
+ * Base and chat models for each size, with the chat models aligned for human preferences;
23
+ * Multilingual support of both base and chat models;
24
+ * Stable support of 32K context length for models of all sizes
25
+ * Supporting tool use, RAG, role play, and playing as AI agent;
26
+
27
+ For more information, please visit our:
28
+
29
+ * `Blog <https://qwenlm.github.io/>`__
30
+ * `GitHub <https://github.com/QwenLM>`__
31
+ * `Hugging Face <https://huggingface.co/Qwen>`__
32
+ * `ModelScope <https://modelscope.cn/organization/qwen>`__
33
+ * `Qwen1.5 Collection <https://huggingface.co/collections/Qwen/qwen15-65c0a2f577b1ecb76d786524>`__
34
+
35
+ Join our community by joining our `Discord <https://discord.gg/yPEP2vHTu4>`__ and `WeChat <https://github.com/QwenLM/Qwen/blob/main/assets/wechat.png>`__ group. We are looking forward to seeing you there!
36
+
37
+
38
+
39
+ Documentation
40
+ -------------
41
+
42
+ .. toctree::
43
+ :maxdepth: 1
44
+ :caption: Getting Started
45
+
46
+ getting_started/installation
47
+ getting_started/quickstart
48
+
49
+ .. toctree::
50
+ :maxdepth: 1
51
+ :caption: Inference
52
+
53
+ inference/chat
54
+
55
+ .. toctree::
56
+ :maxdepth: 1
57
+ :caption: Run Locally
58
+
59
+ run_locally/llama.cpp
60
+ run_locally/ollama
61
+
62
+ .. toctree::
63
+ :maxdepth: 1
64
+ :caption: Web UI
65
+
66
+ web_ui/text_generation_webui
67
+
68
+ .. toctree::
69
+ :maxdepth: 1
70
+ :caption: Quantization
71
+
72
+ quantization/awq
73
+ quantization/gptq
74
+ quantization/gguf
75
+
76
+ .. toctree::
77
+ :maxdepth: 1
78
+ :caption: Deployment
79
+
80
+ deployment/vllm
81
+
82
+ .. toctree::
83
+ :maxdepth: 2
84
+ :caption: Training
85
+
86
+ training/SFT/index
87
+
88
+ .. toctree::
89
+ :maxdepth: 1
90
+ :caption: Framework
91
+
92
+ framework/qwen_agent
93
+ framework/function_call
docs/source/inference/chat.rst ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Using Transformers to Chat
2
+ ==========================
3
+
4
+ The most significant but also the simplest usage of Qwen1.5 is to chat
5
+ with it using the ``transformers`` library. In this document, we show
6
+ how to chat with ``Qwen1.5-7B-Chat``, in either streaming mode or not.
7
+
8
+ Basic Usage
9
+ -----------
10
+
11
+ You can just write several lines of code with ``transformers`` to chat with
12
+ Qwen1.5-Chat. Essentially, we build the tokenizer and the model with
13
+ ``from_pretrained`` method, and we use ``generate`` method to perform
14
+ chatting with the help of chat template provided by the tokenizer.
15
+ Below is an example of how to chat with Qwen1.5-7B-Chat:
16
+
17
+ .. code:: python
18
+
19
+ from transformers import AutoModelForCausalLM, AutoTokenizer
20
+ device = "cuda" # the device to load the model onto
21
+
22
+ # Now you do not need to add "trust_remote_code=True"
23
+ model = AutoModelForCausalLM.from_pretrained(
24
+ "Qwen/Qwen1.5-7B-Chat",
25
+ torch_dtype="auto",
26
+ device_map="auto"
27
+ )
28
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-7B-Chat")
29
+
30
+ # Instead of using model.chat(), we directly use model.generate()
31
+ # But you need to use tokenizer.apply_chat_template() to format your inputs as shown below
32
+ prompt = "Give me a short introduction to large language model."
33
+ messages = [
34
+ {"role": "system", "content": "You are a helpful assistant."},
35
+ {"role": "user", "content": prompt}
36
+ ]
37
+ text = tokenizer.apply_chat_template(
38
+ messages,
39
+ tokenize=False,
40
+ add_generation_prompt=True
41
+ )
42
+ model_inputs = tokenizer([text], return_tensors="pt").to(device)
43
+
44
+ # Directly use generate() and tokenizer.decode() to get the output.
45
+ # Use `max_new_tokens` to control the maximum output length.
46
+ generated_ids = model.generate(
47
+ model_inputs.input_ids,
48
+ max_new_tokens=512
49
+ )
50
+ generated_ids = [
51
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
52
+ ]
53
+
54
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
55
+
56
+ Note that the previous method in the original Qwen repo ``chat()`` is
57
+ now replaced by ``generate()``. The ``apply_chat_template()`` function
58
+ is used to convert the messages into a format that the model can
59
+ understand. The ``add_generation_prompt`` argument is used to add a
60
+ generation prompt, which refers to ``<|im_start|>assistant\n`` to the input.
61
+ Notably, we apply ChatML template for chat models following our previous
62
+ practice. The ``max_new_tokens`` argument is used to set the maximum length
63
+ of the response. The ``tokenizer.batch_decode()`` function is used to
64
+ decode the response. In terms of the input, the above ``messages`` is an
65
+ example to show how to format your dialog history and system prompt. By
66
+ default, if you do not specify system prompt, we directly use ``You are
67
+ a helpful assistant.``.
68
+
69
+ Streaming Mode
70
+ --------------
71
+
72
+ With the help of ``TextStreamer``, you can modify your chatting with
73
+ Qwen to streaming mode. Below we show you an example of how to use it:
74
+
75
+ .. code:: python
76
+
77
+ # Repeat the code above before model.generate()
78
+ # Starting here, we add streamer for text generation.
79
+ from transformers import TextStreamer
80
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
81
+
82
+ # This will print the output in the streaming mode.
83
+ generated_ids = model.generate(
84
+ model_inputs,
85
+ max_new_tokens=512,
86
+ streamer=streamer,
87
+ )
88
+
89
+ Besides using ``TextStreamer``, we can also use ``TextIteratorStreamer``
90
+ which stores print-ready text in a queue, to be used by a downstream
91
+ application as an iterator:
92
+
93
+ .. code:: python
94
+
95
+ # Repeat the code above before model.generate()
96
+ # Starting here, we add streamer for text generation.
97
+ from transformers import TextIteratorStreamer
98
+ streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
99
+
100
+ from threading import Thread
101
+ generation_kwargs = dict(model_inputs, streamer=streamer, max_new_tokens=512)
102
+ thread = Thread(target=model.generate, kwargs=generation_kwargs)
103
+
104
+ thread.start()
105
+ generated_text = ""
106
+ for new_text in streamer:
107
+ generated_text += new_text
108
+ print(generated_text)
109
+
110
+ Next Step
111
+ ---------
112
+
113
+ Now you can chat with Qwen1.5 in either streaming mode or not. Continue
114
+ to read the documentation and try to figure out more advanced usages of
115
+ model inference!
docs/source/quantization/awq.rst ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ AWQ
2
+ =====================
3
+
4
+ For quantized models, one of our recommendations is the usage of
5
+ `AWQ <https://arxiv.org/abs/2306.00978>`__ with
6
+ `AutoAWQ <https://github.com/casper-hansen/AutoAWQ>`__. AWQ refers to
7
+ Activation-aware Weight Quantization, a hardware-friendly approach for
8
+ LLM low-bit weight-only quantization. AutoAWQ is an easy-to-use package
9
+ for 4-bit quantized models. AutoAWQ speeds up models by 3x and reduces
10
+ memory requirements by 3x compared to FP16. AutoAWQ implements the
11
+ Activation-aware Weight Quantization (AWQ) algorithm for quantizing
12
+ LLMs. In this document, we show you how to use the quantized model with
13
+ Transformers and also how to quantize your own model.
14
+
15
+ Usage of AWQ Quantized Models with Transformers
16
+ -----------------------------------------------
17
+
18
+ Now, Transformers has officially supported AutoAWQ, which means that you
19
+ can directly use the quantized model with Transformers. The following is
20
+ a very simple code snippet showing how to run ``Qwen1.5-7B-Chat-AWQ``
21
+ with the quantized model:
22
+
23
+ .. code:: python
24
+
25
+ from transformers import AutoModelForCausalLM, AutoTokenizer
26
+ device = "cuda" # the device to load the model onto
27
+
28
+ model = AutoModelForCausalLM.from_pretrained(
29
+ "Qwen/Qwen1.5-7B-Chat-AWQ", # the quantized model
30
+ device_map="auto"
31
+ )
32
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-7B-Chat-AWQ")
33
+
34
+ prompt = "Give me a short introduction to large language model."
35
+ messages = [
36
+ {"role": "system", "content": "You are a helpful assistant."},
37
+ {"role": "user", "content": prompt}
38
+ ]
39
+ text = tokenizer.apply_chat_template(
40
+ messages,
41
+ tokenize=False,
42
+ add_generation_prompt=True
43
+ )
44
+ model_inputs = tokenizer([text], return_tensors="pt").to(device)
45
+
46
+ generated_ids = model.generate(
47
+ model_inputs.input_ids,
48
+ max_new_tokens=512
49
+ )
50
+ generated_ids = [
51
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
52
+ ]
53
+
54
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
55
+
56
+ Usage of AWQ Quantized Models with vLLM
57
+ ---------------------------------------
58
+
59
+ vLLM has supported AWQ, which means that you can directly use our
60
+ provided AWQ models or those trained with ``AutoAWQ`` with vLLM.
61
+ Actually, the usage is the same with the basic usage of vLLM. We provide
62
+ a simple example of how to launch OpenAI-API compatible API with vLLM
63
+ and ``Qwen1.5-7B-Chat-AWQ``:
64
+
65
+ .. code:: bash
66
+
67
+ python -m vllm.entrypoints.openai.api_server --model Qwen/Qwen1.5-7B-Chat-AWQ
68
+
69
+ .. code:: bash
70
+
71
+ curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
72
+ "model": "Qwen/Qwen1.5-7B-Chat-AWQ",
73
+ "messages": [
74
+ {"role": "system", "content": "You are a helpful assistant."},
75
+ {"role": "user", "content": "Tell me something about large language models."}
76
+ ],
77
+ }'
78
+
79
+ or you can use python client with ``openai`` python package as shown
80
+ below:
81
+
82
+ .. code:: python
83
+
84
+ from openai import OpenAI
85
+ # Set OpenAI's API key and API base to use vLLM's API server.
86
+ openai_api_key = "EMPTY"
87
+ openai_api_base = "http://localhost:8000/v1"
88
+
89
+ client = OpenAI(
90
+ api_key=openai_api_key,
91
+ base_url=openai_api_base,
92
+ )
93
+
94
+ chat_response = client.chat.completions.create(
95
+ model="Qwen/Qwen1.5-7B-Chat-AWQ",
96
+ messages=[
97
+ {"role": "system", "content": "You are a helpful assistant."},
98
+ {"role": "user", "content": "Tell me something about large language models."},
99
+ ]
100
+ )
101
+ print("Chat response:", chat_response)
102
+
103
+ Quantize Your Own Model with AutoAWQ
104
+ ------------------------------------
105
+
106
+ If you want to quantize your own model to AWQ quantized models, we
107
+ advise you to use AutoAWQ. It is suggested installing the latest version
108
+ of the package by installing from source code:
109
+
110
+ .. code:: bash
111
+
112
+ git clone https://github.com/casper-hansen/AutoAWQ.git
113
+ cd AutoAWQ
114
+ pip install -e .
115
+
116
+ Suppose you have finetuned a model based on ``Qwen1.5-7B``, which is
117
+ named ``Qwen1.5-7B-finetuned``, with your own dataset, e.g., Alpaca. To
118
+ build your own AWQ quantized model, you need to use the training data
119
+ for calibration. Below, we provide a simple demonstration for you to
120
+ run:
121
+
122
+ .. code:: python
123
+
124
+ from awq import AutoAWQForCausalLM
125
+ from transformers import AutoTokenizer
126
+
127
+ # Specify paths and hyperparameters for quantization
128
+ model_path = "your_model_path"
129
+ quant_path = "your_quantized_model_path"
130
+ quant_config = { "zero_point": True, "q_group_size": 128, "w_bit": 4, "version": "GEMM" }
131
+
132
+ # Load your tokenizer and model with AutoAWQ
133
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
134
+ model = AutoAWQForCausalLM.from_pretrained(model_path, device_map="auto", safetensors=True)
135
+
136
+ Then you need to prepare your data for calibaration. What you need to do
137
+ is just put samples into a list, each of which is a text. As we directly
138
+ use our finetuning data for calibration, we first format it with ChatML
139
+ template. For example:
140
+
141
+ .. code:: python
142
+
143
+ data = []
144
+ for msg in messages:
145
+ msg = c['messages']
146
+ text = tokenizer.apply_chat_template(msg, tokenize=False, add_generation_prompt=False)
147
+ data.append(text.strip())
148
+
149
+ where each ``msg`` is a typical chat message as shown below:
150
+
151
+ .. code:: json
152
+
153
+ [
154
+ {"role": "system", "content": "You are a helpful assistant."},
155
+ {"role": "user", "content": "Tell me who you are."},
156
+ {"role": "assistant", "content": "I am a large language model named Qwen..."}
157
+ ]
158
+
159
+ Then just run the calibration process by one line of code:
160
+
161
+ .. code:: python
162
+
163
+ model.quantize(tokenizer, quant_config=quant_config, calib_data=data)
164
+
165
+ Finally, save the quantized model:
166
+
167
+ .. code:: python
168
+
169
+ model.save_quantized(quant_path, safetensors=True, shard_size="4GB")
170
+ tokenizer.save_pretrained(quant_path)
171
+
172
+ Then you can obtain your own AWQ quantized model for deployment. Enjoy!
docs/source/quantization/gguf.rst ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GGUF
2
+ ===========================
3
+
4
+ Recently, running LLMs locally is popular in the community, and running
5
+ GGUF files with llama.cpp is a typical example. With llama.cpp, you can
6
+ not only build GGUF files for your models but also perform low-bit
7
+ quantization. In GGUF, you can directly quantize your models without
8
+ calibration, or apply the AWQ scale for better quality, or use imatrix
9
+ with calibration data. In this document, we demonstrate the simplest way
10
+ to quantize your model as well as the way to apply AWQ scale to your
11
+ Qwen model quantization.
12
+
13
+ Quantize Your Models and Make GGUF Files
14
+ ----------------------------------------
15
+
16
+ Before you move to quantization, make sure you have followed the
17
+ instruction and started to use llama.cpp. The following guidance will
18
+ NOT provide instructions about installation and building. Now, suppose
19
+ you would like to quantize ``Qwen1.5-7B-Chat``. You need to first make a
20
+ GGUF file for the fp16 model as shown below:
21
+
22
+ .. code:: bash
23
+
24
+ python convert-hf-to-gguf.py Qwen/Qwen1.5-7B-Chat --outfile models/7B/qwen1_5-7b-chat-fp16.gguf
25
+
26
+ where the first argument refers to the path to the HF model directory or
27
+ the HF model name, and the second argument refers to the path of your
28
+ output GGUF file (here I just put it under the directory ``models/7B``.
29
+ Remember to create the directory before you run the command). In this
30
+ way, you have generated a GGUF file for your fp16 model, and you then
31
+ need to quantize it to low bits based on your requirements. An example
32
+ of quantizing the model to 4 bits is shown below:
33
+
34
+ .. code:: bash
35
+
36
+ ./quantize models/7B/qwen1_5-7b-chat-fp16.gguf models/7B/qwen1_5-7b-chat-q4_0.gguf q4_0
37
+
38
+ where we use ``q4_0`` for the 4-bit quantization. Until now, you have
39
+ finished quantizing a model to 4 bits and putting it into a GGUF file,
40
+ which can be run directly with llama.cpp.
41
+
42
+ Quantize Your Models With AWQ Scales
43
+ ------------------------------------
44
+
45
+ To improve the quality of your quantized models, one possible solution
46
+ is to apply the AWQ scale, following `this
47
+ script <https://github.com/casper-hansen/AutoAWQ/blob/main/docs/examples.md>`__.
48
+ First of all, when you run ``model.quantize()`` with AutoAWQ, remember
49
+ to add ``export_compatible=True`` as shown below:
50
+
51
+ .. code:: python
52
+
53
+ ...
54
+ model.quantize(
55
+ tokenizer,
56
+ quant_config=quant_config,
57
+ export_compatible=True
58
+ )
59
+ model.save_pretrained(quant_path)
60
+ ...
61
+
62
+ With ``model.save_quantzed()`` as shown above, a fp16 model with AWQ
63
+ scales is saved. Then, when you run ``convert-hf-to-gguf.py``, remember
64
+ to replace the model path with the path to the fp16 model with AWQ
65
+ scales, e.g.,
66
+
67
+ .. code:: bash
68
+
69
+ python convert-hf-to-gguf.py ${quant_path} --outfile models/7B/qwen1_5-7b-chat-fp16-awq.gguf
70
+
71
+ In this way, you can apply the AWQ scales to your quantized models in
72
+ GGUF formats, which helps improving the model quality.
73
+
74
+ We usually quantize the fp16 model to 2, 3, 4, 5, 6, and 8-bit models.
75
+ To perform different low-bit quantization, just replace the quantization
76
+ method in your command. For example, if you want to quantize your model
77
+ to 2-bit model, you can replace ``q4_0`` to ``q2_k`` as demonstrated
78
+ below:
79
+
80
+ .. code:: bash
81
+
82
+ ./quantize models/7B/qwen1_5-7b-chat-fp16.gguf models/7B/qwen1_5-7b-chat-q2_k.gguf q2_k
83
+
84
+ We now provide GGUF models in the following quantization levels:
85
+ ``q2_k``, ``q3_k_m``, ``q4_0``, ``q4_k_m``, ``q5_0``, ``q5_k_m``,
86
+ ``q6_k``, and ``q8_0``. For more information, please visit
87
+ `llama.cpp <https://github.com/ggerganov/llama.cpp>`__.
docs/source/quantization/gptq.rst ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GPTQ
2
+ ======================
3
+
4
+ `GPTQ <https://arxiv.org/abs/2210.17323>`__ is a quantization method for
5
+ GPT-like LLMs, which uses one-shot weight quantization based on
6
+ approximate second-order information. In this document, we show you how
7
+ to use the quantized model with transformers and also how to quantize
8
+ your own model with `AutoGPTQ <https://github.com/AutoGPTQ/AutoGPTQ>`__.
9
+
10
+ Usage of GPTQ Models with Transformers
11
+ --------------------------------------
12
+
13
+ Now, Transformers has officially supported AutoGPTQ, which means that
14
+ you can directly use the quantized model with Transformers. The
15
+ following is a very simple code snippet showing how to run
16
+ ``Qwen1.5-7B-Chat-GPTQ-Int8`` (note that for each size of Qwen1.5, we
17
+ provide both Int4 and Int8 quantized models) with the quantized model:
18
+
19
+ .. code:: python
20
+
21
+ from transformers import AutoModelForCausalLM, AutoTokenizer
22
+ device = "cuda" # the device to load the model onto
23
+
24
+ model = AutoModelForCausalLM.from_pretrained(
25
+ "Qwen/Qwen1.5-7B-Chat-GPTQ-Int8", # the quantized model
26
+ device_map="auto"
27
+ )
28
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-7B-Chat-GPTQ-Int8")
29
+
30
+ prompt = "Give me a short introduction to large language model."
31
+ messages = [
32
+ {"role": "system", "content": "You are a helpful assistant."},
33
+ {"role": "user", "content": prompt}
34
+ ]
35
+ text = tokenizer.apply_chat_template(
36
+ messages,
37
+ tokenize=False,
38
+ add_generation_prompt=True
39
+ )
40
+ model_inputs = tokenizer([text], return_tensors="pt").to(device)
41
+
42
+ generated_ids = model.generate(
43
+ model_inputs.input_ids,
44
+ max_new_tokens=512
45
+ )
46
+ generated_ids = [
47
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
48
+ ]
49
+
50
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
51
+
52
+ Usage of GPTQ Quantized Models with vLLM
53
+ ----------------------------------------
54
+
55
+ vLLM has supported GPTQ, which means that you can directly use our
56
+ provided GPTQ models or those trained with ``AutoGPTQ`` with vLLM.
57
+ Actually, the usage is the same with the basic usage of vLLM. We provide
58
+ a simple example of how to launch OpenAI-API compatible API with vLLM
59
+ and ``Qwen1.5-7B-Chat-GPTQ-Int8``:
60
+
61
+ .. code:: bash
62
+
63
+ python -m vllm.entrypoints.openai.api_server --model Qwen/Qwen1.5-7B-Chat-GPTQ-Int8
64
+
65
+ .. code:: bash
66
+
67
+ curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
68
+ "model": "Qwen/Qwen1.5-7B-Chat-GPTQ-Int8",
69
+ "messages": [
70
+ {"role": "system", "content": "You are a helpful assistant."},
71
+ {"role": "user", "content": "Tell me something about large language models."}
72
+ ],
73
+ }'
74
+
75
+ or you can use python client with ``openai`` python package as shown
76
+ below:
77
+
78
+ .. code:: python
79
+
80
+ from openai import OpenAI
81
+ # Set OpenAI's API key and API base to use vLLM's API server.
82
+ openai_api_key = "EMPTY"
83
+ openai_api_base = "http://localhost:8000/v1"
84
+
85
+ client = OpenAI(
86
+ api_key=openai_api_key,
87
+ base_url=openai_api_base,
88
+ )
89
+
90
+ chat_response = client.chat.completions.create(
91
+ model="Qwen/Qwen1.5-7B-Chat-GPTQ-Int8",
92
+ messages=[
93
+ {"role": "system", "content": "You are a helpful assistant."},
94
+ {"role": "user", "content": "Tell me something about large language models."},
95
+ ]
96
+ )
97
+ print("Chat response:", chat_response)
98
+
99
+ Quantize Your Own Model with AutoGPTQ
100
+ -------------------------------------
101
+
102
+ If you want to quantize your own model to GPTQ quantized models, we
103
+ advise you to use AutoGPTQ. It is suggested installing the latest
104
+ version of the package by installing from source code:
105
+
106
+ .. code:: bash
107
+
108
+ git clone https://github.com/AutoGPTQ/AutoGPTQ
109
+ cd AutoGPTQ
110
+ pip install -e .
111
+
112
+ Suppose you have finetuned a model based on ``Qwen1.5-7B``, which is
113
+ named ``Qwen1.5-7B-finetuned``, with your own dataset, e.g., Alpaca. To
114
+ build your own GPTQ quantized model, you need to use the training data
115
+ for calibration. Below, we provide a simple demonstration for you to
116
+ run:
117
+
118
+ .. code:: python
119
+
120
+ from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
121
+ from transformers import AutoTokenizer
122
+
123
+ # Specify paths and hyperparameters for quantization
124
+ model_path = "your_model_path"
125
+ quant_path = "your_quantized_model_path"
126
+ quantize_config = BaseQuantizeConfig(
127
+ bits=8, # 4 or 8
128
+ group_size=128,
129
+ damp_percent=0.01,
130
+ desc_act=False, # set to False can significantly speed up inference but the perplexity may slightly bad
131
+ static_groups=False,
132
+ sym=True,
133
+ true_sequential=True,
134
+ model_name_or_path=None,
135
+ model_file_base_name="model"
136
+ )
137
+ max_len = 8192
138
+
139
+ # Load your tokenizer and model with AutoGPTQ
140
+ # To learn about loading model to multiple GPUs,
141
+ # visit https://github.com/AutoGPTQ/AutoGPTQ/blob/main/docs/tutorial/02-Advanced-Model-Loading-and-Best-Practice.md
142
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
143
+ model = AutoGPTQForCausalLM.from_pretrained(model_path, safetensors=True)
144
+
145
+ Then you need to prepare your data for calibaration. What you need to do
146
+ is just put samples into a list, each of which is a text. As we directly
147
+ use our finetuning data for calibration, we first format it with ChatML
148
+ template. For example:
149
+
150
+ .. code:: python
151
+
152
+ data = []
153
+ for msg in messages:
154
+ msg = c['messages']
155
+ text = tokenizer.apply_chat_template(msg, tokenize=False, add_generation_prompt=False)
156
+ model_inputs = tokenizer([text])
157
+ input_ids = torch.tensor(model_inputs.input_ids[:max_len], dtype=torch.int)
158
+ data.append(dict(input_ids=input_ids, attention_mask=input_ids.ne(tokenizer.pad_token_id)))
159
+
160
+ where each ``msg`` is a typical chat message as shown below:
161
+
162
+ .. code:: json
163
+
164
+ [
165
+ {"role": "system", "content": "You are a helpful assistant."},
166
+ {"role": "user", "content": "Tell me who you are."},
167
+ {"role": "assistant", "content": "I am a large language model named Qwen..."}
168
+ ]
169
+
170
+ Then just run the calibration process by one line of code:
171
+
172
+ .. code:: python
173
+
174
+ logging.basicConfig(
175
+ format="%(asctime)s %(levelname)s [%(name)s] %(message)s", level=logging.INFO, datefmt="%Y-%m-%d %H:%M:%S"
176
+ )
177
+ model.quantize(data, cache_examples_on_gpu=False)
178
+
179
+ Finally, save the quantized model:
180
+
181
+ .. code:: python
182
+
183
+ model.save_quantized(quant_path, use_safetensors=True)
184
+ tokenizer.save_pretrained(quant_path)
185
+
186
+ It is unfortunate that the ``save_quantized`` method does not support
187
+ sharding. For sharding, you need to load the model and use
188
+ ``save_pretrained`` from transformers to save and shard the model.
189
+ Except for this, everything is so simple. Enjoy!
docs/source/run_locally/llama.cpp.rst ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ llama.cpp
2
+ ===========================
3
+
4
+ `llama.cpp <https://github.com/ggerganov/llama.cpp>`__ is a C++ library
5
+ for LLM inference with mimimal setup. It enables running Qwen on your
6
+ local machine. It is a plain C/C++ implementation without dependencies,
7
+ and it has AVX, AVX2 and AVX512 support for x86 architectures. It
8
+ provides 2, 3, 4, 5, 6, and 8-bit quantization for faster inference and
9
+ reduced memory footprint. CPU+GPU hybrid inference to partially
10
+ accelerate models larger than the total VRAM capacity is also supported.
11
+ Essentially, the usage of llama.cpp is to run the GGUF (GPT-Generated
12
+ Unified Format ) models. For more information, please refer to the
13
+ official GitHub repo. Here we demonstrate how to run Qwen with
14
+ llama.cpp.
15
+
16
+ Prerequisites
17
+ -------------
18
+
19
+ This example is for the usage on Linux or MacOS. For the first step,
20
+ clone the repo and enter the directory:
21
+
22
+ .. code:: bash
23
+
24
+ git clone https://github.com/ggerganov/llama.cpp
25
+ cd llama.cpp
26
+
27
+ Then use ``make``:
28
+
29
+ .. code:: bash
30
+
31
+ make
32
+
33
+ Then you can run GGUF files with ``llama.cpp``.
34
+
35
+ Running Qwen GGUF Files
36
+ -----------------------
37
+
38
+ We provide a series of GGUF models in our Hugging Face organization, and
39
+ to search for what you need you can search the repo names with
40
+ ``-GGUF``. Download the GGUF model that you want with
41
+ ``huggingface-cli`` (you need to install it first with
42
+ ``pip install huggingface_hub``):
43
+
44
+ .. code:: bash
45
+
46
+ huggingface-cli download <model_repo> <gguf_file> --local-dir <local_dir> --local-dir-use-symlinks False
47
+
48
+ for example:
49
+
50
+ .. code:: bash
51
+
52
+ huggingface-cli download Qwen/Qwen1.5-7B-Chat-GGUF qwen1_5-7b-chat-q5_k_m.gguf --local-dir . --local-dir-use-symlinks False
53
+
54
+ Then you can run the model with the following command:
55
+
56
+ .. code:: bash
57
+
58
+ ./main -m qwen1_5-7b-chat-q5_k_m.gguf -n 512 --color -i -cml -f prompts/chat-with-qwen.txt
59
+
60
+ where ``-n`` refers to the maximum number of tokens to generate. There
61
+ are other hyperparameters for you to choose and you can run
62
+
63
+ .. code:: bash
64
+
65
+ ./main -h
66
+
67
+ to figure them out.
68
+
69
+ Make Your GGUF Files
70
+ --------------------
71
+
72
+ We introduce the method of creating and quantizing GGUF files in
73
+ `quantization/llama.cpp <../quantization/gguf.html>`__. You can refer
74
+ to that document for more information.
75
+
76
+ Perplexity Evaluation
77
+ ---------------------
78
+
79
+ ``llama.cpp`` provides methods for us to evaluate the perplexity
80
+ performance of the GGUF models. To do this, you need to prepare the
81
+ dataset, say "wiki test". Here we demonstrate an example to run the
82
+ test.
83
+
84
+ For the first step, download the dataset:
85
+
86
+ .. code:: bash
87
+
88
+ wget https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-raw-v1.zip?ref=salesforce-research -O wikitext-2-raw-v1.zip
89
+ unzip wikitext-2-raw-v1.zip
90
+
91
+ Then you can run the test with the following command:
92
+
93
+ .. code:: bash
94
+
95
+ ./perplexity -m models/7B/ggml-model-q4_0.gguf -f wiki.test.raw
96
+
97
+ where the output is like
98
+
99
+ .. code:: text
100
+
101
+ perplexity : calculating perplexity over 655 chunks
102
+ 24.43 seconds per pass - ETA 4.45 hours
103
+ [1]4.5970,[2]5.1807,[3]6.0382,...
104
+
105
+ Wait for some time and you will get the perplexity of the model.
106
+
107
+ Use GGUF with LM Studio
108
+ -----------------------
109
+
110
+ If you still find it difficult to use ``llama.cpp``, I advise you to
111
+ play with `LM Studio <https://lmstudio.ai/>`__, which is a platform
112
+ for your to search and run local LLMs. Qwen1.5 has already been
113
+ officially part of LM Studio. Have fun!
docs/source/run_locally/ollama.rst ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Ollama
2
+ ===========================
3
+
4
+ `Ollama <https://ollama.com/>`__ helps you run LLMs locally with only a
5
+ few commands. It is available at MacOS, Linux, and Windows. Now, Qwen1.5
6
+ is officially on Ollama, and you can run it with one command:
7
+
8
+ .. code:: bash
9
+
10
+ ollama run qwen
11
+
12
+ Next, we introduce more detailed usages of Ollama for running Qwen
13
+ models.
14
+
15
+ Quickstart
16
+ ----------
17
+
18
+ Visit the official website `Ollama <https://ollama.com/>`__ and click
19
+ download to install Ollama on your device. You can also search models in
20
+ the website, where you can find the Qwen1.5 models. Except for the
21
+ default one, you can choose to run Qwen1.5-Chat models of different
22
+ sizes by:
23
+
24
+ - ``ollama run qwen:0.5b``
25
+ - ``ollama run qwen:1.8b``
26
+ - ``ollama run qwen:4b``
27
+ - ``ollama run qwen:7b``
28
+ - ``ollama run qwen:14b``
29
+ - ``ollama run qwen:72b``
30
+
31
+ Run Ollama with Your GGUF Files
32
+ -------------------------------
33
+
34
+ Sometimes you don't want to pull models and you just want to use Ollama
35
+ with your own GGUF files. Suppose you have a GGUF file of Qwen,
36
+ ``qwen1_5-7b-chat-q4_0.gguf``. For the first step, you need to create a
37
+ file called ``Modelfile``. The content of the file is shown below:
38
+
39
+ .. code:: text
40
+
41
+ FROM qwen1_5-7b-chat-q4_0.gguf
42
+
43
+ # set the temperature to 1 [higher is more creative, lower is more coherent]
44
+ PARAMETER temperature 0.7
45
+ PARAMETER top_p 0.8
46
+ PARAMETER repeat_penalty 1.05
47
+ PARAMETER top_k 20
48
+
49
+ TEMPLATE """{{ if and .First .System }}<|im_start|>system
50
+ {{ .System }}<|im_end|>
51
+ {{ end }}<|im_start|>user
52
+ {{ .Prompt }}<|im_end|>
53
+ <|im_start|>assistant
54
+ {{ .Response }}"""
55
+
56
+ # set the system message
57
+ SYSTEM """
58
+ You are a helpful assistant.
59
+ """
60
+
61
+ Then create the ollama model by running:
62
+
63
+ .. code:: bash
64
+
65
+ ollama create qwen7b -f Modelfile
66
+
67
+ Once it is finished, you can run your ollama model by:
68
+
69
+ .. code:: bash
70
+
71
+ ollama run qwen7b
docs/source/training/SFT/example.rst ADDED
@@ -0,0 +1,572 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Example
2
+ ====================================================
3
+
4
+ Here we provide a very simple script for supervised finetuning, which is revised from the training
5
+ script in ```Fastchat`` <https://github.com/lm-sys/FastChat>`__. The
6
+ script is used to finetune Qwen with Hugging Face Trainer. You can check
7
+ the script
8
+ `here <https://github.com/QwenLM/Qwen1.5/blob/main/finetune.py>`__. This
9
+ script for supervised finetuning (SFT) has the following features:
10
+
11
+ - Support single-GPU and multi-GPU training;
12
+ - Support full-parameter tuning,
13
+ `LoRA <https://arxiv.org/abs/2106.09685>`__, and
14
+ `Q-LoRA <https://arxiv.org/abs/2305.14314>`__.
15
+
16
+ In the following, we introduce more details about the usage of the
17
+ script.
18
+
19
+ Installation
20
+ ------------
21
+
22
+ Before you start, make sure you have installed the following packages:
23
+
24
+ .. code:: bash
25
+
26
+ pip install peft deepspeed optimum accelerate
27
+
28
+ Data Preparation
29
+ ----------------
30
+
31
+ For data preparation, we advise you to organize the data in a jsonl
32
+ file, where each line is a dictionary as demonstrated below:
33
+
34
+ .. code:: json
35
+
36
+ {
37
+ "type": "chatml",
38
+ "messages": [
39
+ {
40
+ "role": "system",
41
+ "content": "You are a helpful assistant."
42
+ },
43
+ {
44
+ "role": "user",
45
+ "content": "Tell me something about large language models."
46
+ },
47
+ {
48
+ "role": "assistant",
49
+ "content": "Large language models are a type of language model that is trained on a large corpus of text data. They are capable of generating human-like text and are used in a variety of natural language processing tasks..."
50
+ }
51
+ ],
52
+ "source": "unknown"
53
+ }
54
+
55
+ .. code:: json
56
+
57
+ {
58
+ "type": "chatml",
59
+ "messages": [
60
+ {
61
+ "role": "system",
62
+ "content": "You are a helpful assistant."
63
+ },
64
+ {
65
+ "role": "user",
66
+ "content": "What is your name?"
67
+ },
68
+ {
69
+ "role": "assistant",
70
+ "content": "My name is Qwen."
71
+ }
72
+ ],
73
+ "source": "self-made"
74
+ }
75
+
76
+ Above are two examples of each data sample in the dataset. Each sample
77
+ is a JSON object with the following fields: ``type``, ``messages`` and
78
+ ``source``. ``messages`` is required while the others are optional for
79
+ you to label your data format and data source. The ``messages`` field is
80
+ a list of JSON objects, each of which has two fields: ``role`` and
81
+ ``content``. ``role`` can be ``system``, ``user``, or ``assistant``.
82
+ ``content`` is the text of the message. ``source`` is the source of the
83
+ data, which can be ``self-made``, ``alpaca``, ``open-hermes``, or any
84
+ other string.
85
+
86
+ To make the jsonl file, you can use ``json`` to save a list of
87
+ dictionaries to the jsonl file:
88
+
89
+ .. code:: python
90
+
91
+ import json
92
+
93
+ with open('data.jsonl', 'w') as f:
94
+ for sample in samples:
95
+ f.write(json.dumps(sample) + '\n')
96
+
97
+ Quickstart
98
+ ----------
99
+
100
+ For you to start finetuning quickly, we directly provide a shell script
101
+ for you to run without paying attention to details. You need
102
+ different hyperparameters for different types of training, e.g.,
103
+ single-GPU / multi-GPU training, full-parameter tuning, LoRA, or Q-LoRA.
104
+
105
+
106
+
107
+ .. code:: bash
108
+
109
+ cd examples/sft
110
+ bash finetune.sh -m <model_path> -d <data_path> --deepspeed <config_path> [--use_lora True] [--q_lora True]
111
+
112
+
113
+ Specify the ``<model_path>`` for your model, ``<data_path>`` for your
114
+ data, and ``<config_path>`` for your deepspeed configuration.
115
+ If you use LoRA or Q-LoRA, just add ``--use_lora True`` or
116
+ ``--q_lora True`` based on your requirements.
117
+ This is the simplest way to start finetuning. If you want to change more
118
+ hyperparameters, you can dive into the script and modify those
119
+ parameters.
120
+
121
+ Advanced Usages
122
+ ---------------
123
+
124
+ In this section, we introduce the details of the scripts, including the
125
+ core python script as well as the corresponding shell script.
126
+
127
+ Shell Script
128
+ ~~~~~~~~~~~~~
129
+
130
+ Before we introduce the python code, we provide a brief introduction to
131
+ the shell script with commands. We provide some guidance inside the
132
+ shell script and here we take ``finetune.sh`` as an example.
133
+
134
+ To set up the environment variables for distributed training (or
135
+ single-GPU training), specify the following variables:
136
+ ``GPUS_PER_NODE``, ``NNODES``, ``NODE_RANK``, ``MASTER_ADDR``, and
137
+ ``MASTER_PORT``. No need to worry too much about them as we provide the
138
+ default settings for you. In the command, you can pass in the argument
139
+ ``-m`` and ``-d`` to specify the model path and data path, respectively.
140
+ You can also pass in the argument ``--deepspeed`` to specify the
141
+ deepspeed configuration file. We provide two configuration files for
142
+ ZeRO2 and ZeRO3, and you can choose one based on your requirements. In
143
+ most cases, we recommend using ZeRO3 for multi-GPU training except for
144
+ Q-LoRA, where we recommend using ZeRO2.
145
+
146
+ There are a series of hyperparameters to tune. Passing in ``--bf16`` or
147
+ ``--fp16`` to specify the precision for mixed precision training.
148
+ The other significant hyperparameters include:
149
+
150
+ - ``--output_dir``: the path of your output models or adapters.
151
+ - ``--num_train_epochs``: the number of training epochs.
152
+ - ``--gradient_accumulation_steps``: the number of gradient
153
+ accumulation steps.
154
+ - ``--per_device_train_batch_size``: the batch size per GPU for
155
+ training, and the total batch size is equalt to
156
+ ``per_device_train_batch_size`` :math:`\times` ``number_of_gpus``
157
+ :math:`\times` ``gradient_accumulation_steps``.
158
+ - ``--learning_rate``: the learning rate.
159
+ - ``--warmup_steps``: the number of warmup steps.
160
+ - ``--lr_scheduler_type``: the type of learning rate scheduler.
161
+ - ``--weight_decay``: the value of weight decay.
162
+ - ``--adam_beta2``: the value of :math:`\beta_2` in Adam.
163
+ - ``--model_max_length``: the maximum sequence length.
164
+ - ``--use_lora``: whether to use LoRA. Adding ``--q_lora`` can enable
165
+ Q-LoRA.
166
+ - ``--gradient_checkpointing``: whether to use gradient checkpointing.
167
+
168
+ Python Script
169
+ ~~~~~~~~~~~~~
170
+
171
+ In this script, we mainly use ``trainer`` from HF and ``peft`` to train
172
+ our models. We also use ``deepspeed`` to accelerate the training
173
+ process. The script is very simple and easy to understand.
174
+
175
+ .. code:: python
176
+
177
+ @dataclass
178
+ @dataclass
179
+ class ModelArguments:
180
+ model_name_or_path: Optional[str] = field(default="Qwen/Qwen-7B")
181
+
182
+
183
+ @dataclass
184
+ class DataArguments:
185
+ data_path: str = field(
186
+ default=None, metadata={"help": "Path to the training data."}
187
+ )
188
+ eval_data_path: str = field(
189
+ default=None, metadata={"help": "Path to the evaluation data."}
190
+ )
191
+ lazy_preprocess: bool = False
192
+
193
+
194
+ @dataclass
195
+ class TrainingArguments(transformers.TrainingArguments):
196
+ cache_dir: Optional[str] = field(default=None)
197
+ optim: str = field(default="adamw_torch")
198
+ model_max_length: int = field(
199
+ default=8192,
200
+ metadata={
201
+ "help": "Maximum sequence length. Sequences will be right padded (and possibly truncated)."
202
+ },
203
+ )
204
+ use_lora: bool = False
205
+
206
+
207
+ @dataclass
208
+ class LoraArguments:
209
+ lora_r: int = 64
210
+ lora_alpha: int = 16
211
+ lora_dropout: float = 0.05
212
+ lora_target_modules: List[str] = field(
213
+ default_factory=lambda: [
214
+ "q_proj",
215
+ "k_proj",
216
+ "v_proj",
217
+ "o_proj",
218
+ "up_proj",
219
+ "gate_proj",
220
+ "down_proj",
221
+ ]
222
+ )
223
+ lora_weight_path: str = ""
224
+ lora_bias: str = "none"
225
+ q_lora: bool = False
226
+
227
+ The classes for arguments allow you to specify hyperparameters for
228
+ model, data, training, and additionally LoRA if you use LoRA or Q-LoRA
229
+ to train your model. Specifically, ``model-max-length`` is a key
230
+ hyperparameter that determines your maximum sequence length of your
231
+ training data.
232
+
233
+ ``LoRAArguments`` includes the hyperparameters for LoRA or Q-LoRA:
234
+
235
+ - ``lora_r``: the rank for LoRA;
236
+ - ``lora_alpha``: the alpha value for LoRA;
237
+ - ``lora_dropout``: the dropout rate for LoRA;
238
+ - ``lora_target_modules``: the target modules for LoRA. By default we
239
+ tune all linear layers;
240
+ - ``lora_weight_path``: the path to the weight file for LoRA;
241
+ - ``lora_bias``: the bias for LoRA;
242
+ - ``q_lora``: whether to use Q-LoRA.
243
+
244
+
245
+ .. code:: python
246
+
247
+ def maybe_zero_3(param):
248
+ if hasattr(param, "ds_id"):
249
+ assert param.ds_status == ZeroParamStatus.NOT_AVAILABLE
250
+ with zero.GatheredParameters([param]):
251
+ param = param.data.detach().cpu().clone()
252
+ else:
253
+ param = param.detach().cpu().clone()
254
+ return param
255
+
256
+
257
+ # Borrowed from peft.utils.get_peft_model_state_dict
258
+ def get_peft_state_maybe_zero_3(named_params, bias):
259
+ if bias == "none":
260
+ to_return = {k: t for k, t in named_params if "lora_" in k}
261
+ elif bias == "all":
262
+ to_return = {k: t for k, t in named_params if "lora_" in k or "bias" in k}
263
+ elif bias == "lora_only":
264
+ to_return = {}
265
+ maybe_lora_bias = {}
266
+ lora_bias_names = set()
267
+ for k, t in named_params:
268
+ if "lora_" in k:
269
+ to_return[k] = t
270
+ bias_name = k.split("lora_")[0] + "bias"
271
+ lora_bias_names.add(bias_name)
272
+ elif "bias" in k:
273
+ maybe_lora_bias[k] = t
274
+ for k, t in maybe_lora_bias:
275
+ if bias_name in lora_bias_names:
276
+ to_return[bias_name] = t
277
+ else:
278
+ raise NotImplementedError
279
+ to_return = {k: maybe_zero_3(v) for k, v in to_return.items()}
280
+ return to_return
281
+
282
+
283
+ def safe_save_model_for_hf_trainer(
284
+ trainer: transformers.Trainer, output_dir: str, bias="none"
285
+ ):
286
+ """Collects the state dict and dump to disk."""
287
+ # check if zero3 mode enabled
288
+ if deepspeed.is_deepspeed_zero3_enabled():
289
+ state_dict = trainer.model_wrapped._zero3_consolidated_16bit_state_dict()
290
+ else:
291
+ if trainer.args.use_lora:
292
+ state_dict = get_peft_state_maybe_zero_3(
293
+ trainer.model.named_parameters(), bias
294
+ )
295
+ else:
296
+ state_dict = trainer.model.state_dict()
297
+ if trainer.args.should_save and trainer.args.local_rank == 0:
298
+ trainer._save(output_dir, state_dict=state_dict)
299
+
300
+ The method ``safe_save_model_for_hf_trainer``, which uses
301
+ ``get_peft_state_maybe_zero_3``, helps tackle the problems in saving
302
+ models trained either with or without ZeRO3.
303
+
304
+ .. code:: python
305
+
306
+ def preprocess(
307
+ messages,
308
+ tokenizer: transformers.PreTrainedTokenizer,
309
+ max_len: int,
310
+ ) -> Dict:
311
+ """Preprocesses the data for supervised fine-tuning."""
312
+
313
+ texts = []
314
+ for i, msg in enumerate(messages):
315
+ texts.append(
316
+ tokenizer.apply_chat_template(
317
+ msg,
318
+ tokenize=True,
319
+ add_generation_prompt=False,
320
+ padding=True,
321
+ max_length=max_len,
322
+ truncation=True,
323
+ )
324
+ )
325
+ input_ids = torch.tensor(texts, dtype=torch.int)
326
+ target_ids = input_ids.clone()
327
+ target_ids[target_ids == tokenizer.pad_token_id] = IGNORE_TOKEN_ID
328
+ attention_mask = input_ids.ne(tokenizer.pad_token_id)
329
+
330
+ return dict(
331
+ input_ids=input_ids, target_ids=target_ids, attention_mask=attention_mask
332
+ )
333
+
334
+ For data preprocessing, we use ``preprocess`` to organize the data.
335
+ Specifically, we apply our ChatML template to the texts. If you prefer
336
+ other chat templates, you can use others, e.g., by still applying
337
+ ``apply_chat_template()`` with another tokenizer. The chat template is
338
+ stored in the ``tokenizer_config.json`` in the HF repo. Additionally, we
339
+ pad the sequence of each sample to the maximum length for training.
340
+
341
+ .. code:: python
342
+
343
+ class SupervisedDataset(Dataset):
344
+ """Dataset for supervised fine-tuning."""
345
+
346
+ def __init__(
347
+ self, raw_data, tokenizer: transformers.PreTrainedTokenizer, max_len: int
348
+ ):
349
+ super(SupervisedDataset, self).__init__()
350
+
351
+ rank0_print("Formatting inputs...")
352
+ messages = [example["messages"] for example in raw_data]
353
+ data_dict = preprocess(messages, tokenizer, max_len)
354
+
355
+ self.input_ids = data_dict["input_ids"]
356
+ self.target_ids = data_dict["target_ids"]
357
+ self.attention_mask = data_dict["attention_mask"]
358
+
359
+ def __len__(self):
360
+ return len(self.input_ids)
361
+
362
+ def __getitem__(self, i) -> Dict[str, torch.Tensor]:
363
+ return dict(
364
+ input_ids=self.input_ids[i],
365
+ labels=self.labels[i],
366
+ attention_mask=self.attention_mask[i],
367
+ )
368
+
369
+
370
+ class LazySupervisedDataset(Dataset):
371
+ """Dataset for supervised fine-tuning."""
372
+
373
+ def __init__(
374
+ self, raw_data, tokenizer: transformers.PreTrainedTokenizer, max_len: int
375
+ ):
376
+ super(LazySupervisedDataset, self).__init__()
377
+ self.tokenizer = tokenizer
378
+ self.max_len = max_len
379
+
380
+ rank0_print("Formatting inputs...Skip in lazy mode")
381
+ self.tokenizer = tokenizer
382
+ self.raw_data = raw_data
383
+ self.cached_data_dict = {}
384
+
385
+ def __len__(self):
386
+ return len(self.raw_data)
387
+
388
+ def __getitem__(self, i) -> Dict[str, torch.Tensor]:
389
+ if i in self.cached_data_dict:
390
+ return self.cached_data_dict[i]
391
+
392
+ ret = preprocess([self.raw_data[i]["messages"]], self.tokenizer, self.max_len)
393
+ ret = dict(
394
+ input_ids=ret["input_ids"][0],
395
+ labels=ret["target_ids"][0],
396
+ attention_mask=ret["attention_mask"][0],
397
+ )
398
+ self.cached_data_dict[i] = ret
399
+
400
+ return ret
401
+
402
+
403
+ def make_supervised_data_module(
404
+ tokenizer: transformers.PreTrainedTokenizer,
405
+ data_args,
406
+ max_len,
407
+ ) -> Dict:
408
+ """Make dataset and collator for supervised fine-tuning."""
409
+ dataset_cls = (
410
+ LazySupervisedDataset if data_args.lazy_preprocess else SupervisedDataset
411
+ )
412
+ rank0_print("Loading data...")
413
+
414
+ train_data = []
415
+ with open(data_args.data_path, "r") as f:
416
+ for line in f:
417
+ train_data.append(json.loads(line))
418
+ train_dataset = dataset_cls(train_data, tokenizer=tokenizer, max_len=max_len)
419
+
420
+ if data_args.eval_data_path:
421
+ eval_data = []
422
+ with open(data_args.eval_data_path, "r") as f:
423
+ for line in f:
424
+ eval_data.append(json.loads(line))
425
+ eval_dataset = dataset_cls(eval_data, tokenizer=tokenizer, max_len=max_len)
426
+ else:
427
+ eval_dataset = None
428
+
429
+ return dict(train_dataset=train_dataset, eval_dataset=eval_dataset)
430
+
431
+ Then we utilize ``make_supervised_data_module`` by using
432
+ ``SupervisedDataset`` or ``LazySupervisedDataset`` to build the dataset.
433
+
434
+ .. code:: python
435
+
436
+ def train():
437
+ global local_rank
438
+
439
+ parser = transformers.HfArgumentParser(
440
+ (ModelArguments, DataArguments, TrainingArguments, LoraArguments)
441
+ )
442
+ (
443
+ model_args,
444
+ data_args,
445
+ training_args,
446
+ lora_args,
447
+ ) = parser.parse_args_into_dataclasses()
448
+
449
+ # This serves for single-gpu qlora.
450
+ if (
451
+ getattr(training_args, "deepspeed", None)
452
+ and int(os.environ.get("WORLD_SIZE", 1)) == 1
453
+ ):
454
+ training_args.distributed_state.distributed_type = DistributedType.DEEPSPEED
455
+
456
+ local_rank = training_args.local_rank
457
+
458
+ device_map = None
459
+ world_size = int(os.environ.get("WORLD_SIZE", 1))
460
+ ddp = world_size != 1
461
+ if lora_args.q_lora:
462
+ device_map = {"": int(os.environ.get("LOCAL_RANK") or 0)} if ddp else "auto"
463
+ if len(training_args.fsdp) > 0 or deepspeed.is_deepspeed_zero3_enabled():
464
+ logging.warning("FSDP or ZeRO3 is incompatible with QLoRA.")
465
+
466
+ model_load_kwargs = {
467
+ "low_cpu_mem_usage": not deepspeed.is_deepspeed_zero3_enabled(),
468
+ }
469
+
470
+ compute_dtype = (
471
+ torch.float16
472
+ if training_args.fp16
473
+ else (torch.bfloat16 if training_args.bf16 else torch.float32)
474
+ )
475
+
476
+ # Load model and tokenizer
477
+ config = transformers.AutoConfig.from_pretrained(
478
+ model_args.model_name_or_path,
479
+ cache_dir=training_args.cache_dir,
480
+ )
481
+ config.use_cache = False
482
+
483
+ model = AutoModelForCausalLM.from_pretrained(
484
+ model_args.model_name_or_path,
485
+ config=config,
486
+ cache_dir=training_args.cache_dir,
487
+ device_map=device_map,
488
+ quantization_config=BitsAndBytesConfig(
489
+ load_in_4bit=True,
490
+ bnb_4bit_use_double_quant=True,
491
+ bnb_4bit_quant_type="nf4",
492
+ bnb_4bit_compute_dtype=compute_dtype,
493
+ )
494
+ if training_args.use_lora and lora_args.q_lora
495
+ else None,
496
+ **model_load_kwargs,
497
+ )
498
+ tokenizer = AutoTokenizer.from_pretrained(
499
+ model_args.model_name_or_path,
500
+ cache_dir=training_args.cache_dir,
501
+ model_max_length=training_args.model_max_length,
502
+ padding_side="right",
503
+ use_fast=False,
504
+ )
505
+
506
+ if training_args.use_lora:
507
+ lora_config = LoraConfig(
508
+ r=lora_args.lora_r,
509
+ lora_alpha=lora_args.lora_alpha,
510
+ target_modules=lora_args.lora_target_modules,
511
+ lora_dropout=lora_args.lora_dropout,
512
+ bias=lora_args.lora_bias,
513
+ task_type="CAUSAL_LM",
514
+ )
515
+ if lora_args.q_lora:
516
+ model = prepare_model_for_kbit_training(
517
+ model, use_gradient_checkpointing=training_args.gradient_checkpointing
518
+ )
519
+
520
+ model = get_peft_model(model, lora_config)
521
+
522
+ # Print peft trainable params
523
+ model.print_trainable_parameters()
524
+
525
+ if training_args.gradient_checkpointing:
526
+ model.enable_input_require_grads()
527
+
528
+ # Load data
529
+ data_module = make_supervised_data_module(
530
+ tokenizer=tokenizer, data_args=data_args, max_len=training_args.model_max_length
531
+ )
532
+
533
+ # Start trainer
534
+ trainer = Trainer(
535
+ model=model, tokenizer=tokenizer, args=training_args, **data_module
536
+ )
537
+
538
+ # `not training_args.use_lora` is a temporary workaround for the issue that there are problems with
539
+ # loading the checkpoint when using LoRA with DeepSpeed.
540
+ # Check this issue https://github.com/huggingface/peft/issues/746 for more information.
541
+ if (
542
+ list(pathlib.Path(training_args.output_dir).glob("checkpoint-*"))
543
+ and not training_args.use_lora
544
+ ):
545
+ trainer.train(resume_from_checkpoint=True)
546
+ else:
547
+ trainer.train()
548
+ trainer.save_state()
549
+
550
+ safe_save_model_for_hf_trainer(
551
+ trainer=trainer, output_dir=training_args.output_dir, bias=lora_args.lora_bias
552
+ )
553
+
554
+ The ``train`` method is the key to the training. In general, it loads
555
+ the tokenizer and model with ``AutoTokenizer.from_pretrained()`` and
556
+ ``AutoModelForCausalLM.from_pretrained()``. If we use LoRA, the method
557
+ will initialize LoRA configuration with ``LoraConfig``. If we apply
558
+ Q-LoRA, we should use ``prepare_model_for_kbit_training``. Note that for
559
+ now it still does not support resume for LoRA. Then we leave the
560
+ following efforts to ``trainer`` and have a cup of coffee!
561
+
562
+ Next Step
563
+ ---------
564
+
565
+ Now, you are able to use a very simple script to perform different types
566
+ of SFT. Alternatively, you can use more advanced training libraries,
567
+ such as
568
+ `Axolotl <https://github.com/OpenAccess-AI-Collective/axolotl>`__ or
569
+ `LLaMA-Factory <https://github.com/hiyouga/LLaMA-Factory>`__, to enjoy
570
+ more functionalities. To take a step forward, after SFT, you can
571
+ consider RLHF to align your model to human preferences! Stay tuned for
572
+ our next tutorial on RLHF!
docs/source/training/SFT/index.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ SFT
2
+ =================================
3
+
4
+ .. toctree::
5
+ :maxdepth: 1
6
+
7
+ example
8
+ llama_factory