zR
commited on
Commit
·
a22a67d
1
Parent(s):
9b501ef
test
Browse files- README.md +25 -7
- README_zh.md +53 -0
- modeling_glm.py +1 -1
README.md
CHANGED
@@ -2,16 +2,30 @@
|
|
2 |
frameworks:
|
3 |
- Pytorch
|
4 |
license: other
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
-
|
|
|
|
|
10 |
---
|
11 |
|
12 |
# GLM-Edge-V-5B
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
```python
|
17 |
import torch
|
@@ -48,4 +62,8 @@ generate_kwargs = {
|
|
48 |
output = model.generate(**generate_kwargs, max_new_tokens=100)
|
49 |
print(tokenizer.decode(output[0][len(inputs["input_ids"][0]):], skip_special_tokens=True))
|
50 |
|
51 |
-
```
|
|
|
|
|
|
|
|
|
|
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-V-5B
|
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 |
import torch
|
|
|
62 |
output = model.generate(**generate_kwargs, max_new_tokens=100)
|
63 |
print(tokenizer.decode(output[0][len(inputs["input_ids"][0]):], skip_special_tokens=True))
|
64 |
|
65 |
+
```
|
66 |
+
|
67 |
+
## License
|
68 |
+
|
69 |
+
The usage of this model’s weights is subject to the terms outlined in the [LICENSE](LICENSE).
|
README_zh.md
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# GLM-Edge-V-5B
|
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 |
+
import torch
|
16 |
+
from PIL import Image
|
17 |
+
from transformers import (
|
18 |
+
AutoTokenizer,
|
19 |
+
AutoImageProcessor,
|
20 |
+
AutoModelForCausalLM,
|
21 |
+
)
|
22 |
+
|
23 |
+
url = "img.png"
|
24 |
+
messages = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "describe this image"}]}]
|
25 |
+
image = Image.open(url)
|
26 |
+
|
27 |
+
model_dir = "THUDM/glm-edge-v-5b"
|
28 |
+
|
29 |
+
processor = AutoImageProcessor.from_pretrained(model_dir, trust_remote_code=True)
|
30 |
+
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
|
31 |
+
model = AutoModelForCausalLM.from_pretrained(
|
32 |
+
model_dir,
|
33 |
+
torch_dtype=torch.bfloat16,
|
34 |
+
device_map="auto",
|
35 |
+
trust_remote_code=True,
|
36 |
+
)
|
37 |
+
|
38 |
+
inputs = tokenizer.apply_chat_template(
|
39 |
+
messages, add_generation_prompt=True, return_dict=True, tokenize=True, return_tensors="pt"
|
40 |
+
).to(next(model.parameters()).device)
|
41 |
+
|
42 |
+
generate_kwargs = {
|
43 |
+
**inputs,
|
44 |
+
"pixel_values": torch.tensor(processor(image).pixel_values).to(next(model.parameters()).device),
|
45 |
+
}
|
46 |
+
output = model.generate(**generate_kwargs, max_new_tokens=100)
|
47 |
+
print(tokenizer.decode(output[0][len(inputs["input_ids"][0]):], skip_special_tokens=True))
|
48 |
+
|
49 |
+
```
|
50 |
+
|
51 |
+
## 协议
|
52 |
+
|
53 |
+
本模型的权重的使用则需要遵循 [LICENSE](LICENSE)。
|
modeling_glm.py
CHANGED
@@ -31,7 +31,7 @@ from .configuration_glm import GlmConfig
|
|
31 |
|
32 |
logger = logging.get_logger(__name__)
|
33 |
|
34 |
-
_CHECKPOINT_FOR_DOC = "THUDM/glm-
|
35 |
_CONFIG_FOR_DOC = "GlmConfig"
|
36 |
|
37 |
|
|
|
31 |
|
32 |
logger = logging.get_logger(__name__)
|
33 |
|
34 |
+
_CHECKPOINT_FOR_DOC = "THUDM/glm-edge-5b"
|
35 |
_CONFIG_FOR_DOC = "GlmConfig"
|
36 |
|
37 |
|