Update README_zh.md
#2
by
sixsixcoder
- opened
- README_zh.md +35 -1
README_zh.md
CHANGED
@@ -69,7 +69,7 @@ GLM-4-9B 是智谱 AI 推出的最新一代预训练模型 GLM-4 系列中的开
|
|
69 |
|
70 |
**请严格按照[依赖](https://github.com/THUDM/GLM-4/blob/main/basic_demo/requirements.txt)安装,否则无法正常运行。**
|
71 |
|
72 |
-
### Transformers 推理代码
|
73 |
|
74 |
```python
|
75 |
|
@@ -108,6 +108,40 @@ print(tokenizer.decode(out[0][input_len:], skip_special_tokens=True))
|
|
108 |
|
109 |
```
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
## 协议
|
112 |
|
113 |
GLM-4 模型的权重的使用则需要遵循 [LICENSE](LICENSE)。
|
|
|
69 |
|
70 |
**请严格按照[依赖](https://github.com/THUDM/GLM-4/blob/main/basic_demo/requirements.txt)安装,否则无法正常运行。**
|
71 |
|
72 |
+
### Transformers 推理代码 (需要版本号大于等于4.46.0)
|
73 |
|
74 |
```python
|
75 |
|
|
|
108 |
|
109 |
```
|
110 |
|
111 |
+
### vLLM 推理代码 (需要版本号大于等于0.6.4)
|
112 |
+
```Python
|
113 |
+
|
114 |
+
|
115 |
+
from transformers import AutoTokenizer
|
116 |
+
from vllm import LLM, SamplingParams
|
117 |
+
|
118 |
+
# GLM-4-9B-Chat-1M
|
119 |
+
# max_model_len, tp_size = 1048576, 4
|
120 |
+
# 如果遇见 OOM 现象,建议减少max_model_len,或者增加tp_size
|
121 |
+
max_model_len, tp_size = 131072, 1
|
122 |
+
model_name = "THUDM/glm-4-9b-chat-hf"
|
123 |
+
prompt = [{"role": "user", "content": "你好"}]
|
124 |
+
|
125 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
126 |
+
llm = LLM(
|
127 |
+
model=model_name,
|
128 |
+
tensor_parallel_size=tp_size,
|
129 |
+
max_model_len=max_model_len,
|
130 |
+
trust_remote_code=True,
|
131 |
+
enforce_eager=True,
|
132 |
+
# GLM-4-9B-Chat-1M 如果遇见 OOM 现象,建议开启下述参数
|
133 |
+
# enable_chunked_prefill=True,
|
134 |
+
# max_num_batched_tokens=8192
|
135 |
+
)
|
136 |
+
stop_token_ids = [151329, 151336, 151338]
|
137 |
+
sampling_params = SamplingParams(temperature=0.95, max_tokens=1024, stop_token_ids=stop_token_ids)
|
138 |
+
|
139 |
+
inputs = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
|
140 |
+
outputs = llm.generate(prompts=inputs, sampling_params=sampling_params)
|
141 |
+
|
142 |
+
print(outputs[0].outputs[0].text)
|
143 |
+
```
|
144 |
+
|
145 |
## 协议
|
146 |
|
147 |
GLM-4 模型的权重的使用则需要遵循 [LICENSE](LICENSE)。
|