derek33125
commited on
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
- zh
|
5 |
+
library_name: transformers
|
6 |
+
pipeline_tag: text-generation
|
7 |
+
---
|
8 |
+
# Update
|
9 |
+
**The model is now following the update from GLM-4-9B-Chat and now requires `transformers>=4.44.0`. Please update your dependencies accordingly.**
|
10 |
+
**Also follow the [dependencies](https://github.com/THUDM/GLM-4/blob/main/basic_demo/requirements.txt) it before using**
|
11 |
+
|
12 |
+
# Introduction
|
13 |
+
This model is [GLM-4-9B-Chat](https://huggingface.co/THUDM/glm-4-9b-chat/tree/main), fine-tuned with the [Smile dataset](https://github.com/qiuhuachuan/smile) to focus on mental health care.
|
14 |
+
|
15 |
+
Since it is fine-tuned with a Chinese dataset, please use it in Chinese, even though the base model supports English text.
|
16 |
+
|
17 |
+
# Use the following method to quickly call the GLM-4-9B-Chat language model
|
18 |
+
Use the transformers backend for inference:
|
19 |
+
```python
|
20 |
+
import torch
|
21 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
22 |
+
device = "cuda"
|
23 |
+
tokenizer = AutoTokenizer.from_pretrained("derek33125/project-angel-chatglm4", trust_remote_code=True)
|
24 |
+
query = "我感到很悲伤"
|
25 |
+
inputs = tokenizer.apply_chat_template([{"role": "user", "content": query}],
|
26 |
+
add_generation_prompt=True,
|
27 |
+
tokenize=True,
|
28 |
+
return_tensors="pt",
|
29 |
+
return_dict=True
|
30 |
+
)
|
31 |
+
inputs = inputs.to(device)
|
32 |
+
model = AutoModelForCausalLM.from_pretrained(
|
33 |
+
"derek33125/project-angel-chatglm4",
|
34 |
+
torch_dtype=torch.bfloat16,
|
35 |
+
low_cpu_mem_usage=True,
|
36 |
+
trust_remote_code=True
|
37 |
+
).to(device).eval()
|
38 |
+
gen_kwargs = {"max_length": 2500, "do_sample": True, "top_k": 1}
|
39 |
+
with torch.no_grad():
|
40 |
+
outputs = model.generate(**inputs, **gen_kwargs)
|
41 |
+
outputs = outputs[:, inputs['input_ids'].shape[1]:]
|
42 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
43 |
+
```
|
44 |
+
|
45 |
+
It also supports [VLLM](https://github.com/THUDM/GLM-4/blob/main/basic_demo/openai_api_server.py) and [LangChain](https://python.langchain.com/v0.2/docs/integrations/llms/huggingface_pipelines/) .
|
46 |
+
|
47 |
+
|