zR
commited on
Commit
·
f655f35
1
Parent(s):
6c84452
test
Browse files- README.md +23 -38
- README_en.md +0 -1
- README_zh.md +44 -0
README.md
CHANGED
|
@@ -2,74 +2,59 @@
|
|
| 2 |
frameworks:
|
| 3 |
- Pytorch
|
| 4 |
license: other
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
- cn
|
| 13 |
-
- en
|
| 14 |
-
|
| 15 |
-
tools:
|
| 16 |
-
- vllm、fastchat、llamacpp、AdaSeq
|
| 17 |
-
|
| 18 |
---
|
| 19 |
-
# GLM-Edge-1.5b-Chat
|
| 20 |
-
|
| 21 |
-
## 模型介绍
|
| 22 |
|
| 23 |
-
GLM-Edge
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
模型部署的简单示例:
|
| 31 |
|
| 32 |
-
|
| 33 |
|
| 34 |
```shell
|
| 35 |
-
pip install
|
| 36 |
```
|
| 37 |
|
| 38 |
-
|
| 39 |
|
| 40 |
```python
|
| 41 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 42 |
|
| 43 |
-
MODEL_PATH =
|
| 44 |
|
| 45 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
| 46 |
model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, device_map="auto")
|
| 47 |
|
| 48 |
-
message = [
|
| 49 |
-
{
|
| 50 |
-
"role": "user",
|
| 51 |
-
"content": "hello!"
|
| 52 |
-
}
|
| 53 |
-
]
|
| 54 |
|
| 55 |
inputs = tokenizer.apply_chat_template(
|
| 56 |
message,
|
| 57 |
-
return_tensors=
|
| 58 |
add_generation_prompt=True,
|
| 59 |
return_dict=True,
|
| 60 |
).to(model.device)
|
| 61 |
|
| 62 |
-
input_len = inputs['input_ids'].shape[1]
|
| 63 |
generate_kwargs = {
|
| 64 |
-
"input_ids": inputs[
|
| 65 |
-
"attention_mask": inputs[
|
| 66 |
"max_new_tokens": 128,
|
| 67 |
"do_sample": False,
|
| 68 |
}
|
| 69 |
out = model.generate(**generate_kwargs)
|
| 70 |
-
print(tokenizer.decode(out[0][
|
|
|
|
| 71 |
```
|
| 72 |
|
| 73 |
-
##
|
| 74 |
|
| 75 |
-
|
|
|
|
| 2 |
frameworks:
|
| 3 |
- Pytorch
|
| 4 |
license: other
|
| 5 |
+
license_name: glm-4
|
| 6 |
+
license_link: LICENSE
|
| 7 |
+
pipeline_tag: image-text-to-text
|
| 8 |
+
tags:
|
| 9 |
+
- glm
|
| 10 |
+
- edge
|
| 11 |
+
inference: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# GLM-Edge-1.5B-Chat
|
| 15 |
|
| 16 |
+
中文阅读, 点击[这里](README_zh.md)
|
| 17 |
|
| 18 |
+
## Inference with Transformers
|
| 19 |
|
| 20 |
+
### Installation
|
|
|
|
| 21 |
|
| 22 |
+
Install the transformers library from the source code:
|
| 23 |
|
| 24 |
```shell
|
| 25 |
+
pip install git+https://github.com/huggingface/transformers.git
|
| 26 |
```
|
| 27 |
|
| 28 |
+
### Inference
|
| 29 |
|
| 30 |
```python
|
| 31 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 32 |
|
| 33 |
+
MODEL_PATH = "THUDM/glm-edge-1.5b-chat"
|
| 34 |
|
| 35 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
| 36 |
model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, device_map="auto")
|
| 37 |
|
| 38 |
+
message = [{"role": "user", "content": "hello!"}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
inputs = tokenizer.apply_chat_template(
|
| 41 |
message,
|
| 42 |
+
return_tensors="pt",
|
| 43 |
add_generation_prompt=True,
|
| 44 |
return_dict=True,
|
| 45 |
).to(model.device)
|
| 46 |
|
|
|
|
| 47 |
generate_kwargs = {
|
| 48 |
+
"input_ids": inputs["input_ids"],
|
| 49 |
+
"attention_mask": inputs["attention_mask"],
|
| 50 |
"max_new_tokens": 128,
|
| 51 |
"do_sample": False,
|
| 52 |
}
|
| 53 |
out = model.generate(**generate_kwargs)
|
| 54 |
+
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
| 55 |
+
|
| 56 |
```
|
| 57 |
|
| 58 |
+
## License
|
| 59 |
|
| 60 |
+
The usage of this model’s weights is subject to the terms outlined in the [LICENSE](LICENSE).
|
README_en.md
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
# GLM-Edge-1.5b-Chat
|
|
|
|
|
|
README_zh.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GLM-Edge-1.5B-Chat
|
| 2 |
+
|
| 3 |
+
## 使用 transformers 库进行推理
|
| 4 |
+
|
| 5 |
+
### 安装
|
| 6 |
+
|
| 7 |
+
请安装源代码的transformers库。
|
| 8 |
+
|
| 9 |
+
```shell
|
| 10 |
+
pip install git+https://github.com/huggingface/transformers.git
|
| 11 |
+
```
|
| 12 |
+
### 推理
|
| 13 |
+
|
| 14 |
+
```python
|
| 15 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 16 |
+
|
| 17 |
+
MODEL_PATH = "THUDM/glm-edge-1.5b-chat"
|
| 18 |
+
|
| 19 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
| 20 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, device_map="auto")
|
| 21 |
+
|
| 22 |
+
message = [{"role": "user", "content": "hello!"}]
|
| 23 |
+
|
| 24 |
+
inputs = tokenizer.apply_chat_template(
|
| 25 |
+
message,
|
| 26 |
+
return_tensors="pt",
|
| 27 |
+
add_generation_prompt=True,
|
| 28 |
+
return_dict=True,
|
| 29 |
+
).to(model.device)
|
| 30 |
+
|
| 31 |
+
generate_kwargs = {
|
| 32 |
+
"input_ids": inputs["input_ids"],
|
| 33 |
+
"attention_mask": inputs["attention_mask"],
|
| 34 |
+
"max_new_tokens": 128,
|
| 35 |
+
"do_sample": False,
|
| 36 |
+
}
|
| 37 |
+
out = model.generate(**generate_kwargs)
|
| 38 |
+
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
| 39 |
+
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
## 协议
|
| 43 |
+
|
| 44 |
+
本模型的权重的使用则需要遵循 [LICENSE](LICENSE)。
|