zR commited on
Commit
a1817f2
1 Parent(s): 6b3e945
Files changed (3) hide show
  1. README.md +60 -0
  2. README_zh.md +44 -0
  3. generation_config.json +0 -10
README.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ frameworks:
3
+ - Pytorch
4
+ license: other
5
+ license_name: glm-4
6
+ license_link: LICENSE
7
+ pipeline_tag: text-generation
8
+ tags:
9
+ - glm
10
+ - edge
11
+ inference: false
12
+ ---
13
+
14
+ # GLM-Edge-4B-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-4b-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_zh.md ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # GLM-Edge-4B-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-4b-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)。
generation_config.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "_from_model_config": true,
3
- "eos_token_id": [
4
- 59246,
5
- 59253,
6
- 59255
7
- ],
8
- "pad_token_id": 59246,
9
- "transformers_version": "4.47.0.dev0"
10
- }