ybelkada commited on
Commit
7fdda3c
1 Parent(s): ba1ea3c

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +127 -0
README.md ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - EleutherAI/pile
4
+ ---
5
+
6
+ ![RWKlogo.png](https://s3.amazonaws.com/moonup/production/uploads/62441d1d9fdefb55a0b7d12c/UWpP-lGRZJJDaEx_uUlDv.png)
7
+
8
+ # Model card for RWKV-4 | 3B parameters trained on Pile dataset
9
+
10
+ RWKV is a project led by [Bo Peng](https://github.com/BlinkDL). Learn more about the model architecture in the blogposts from Johan Wind [here](https://johanwind.github.io/2023/03/23/rwkv_overview.html) and [here](https://johanwind.github.io/2023/03/23/rwkv_details.html). Learn more about the project by joining the [RWKV discord server](https://discordapp.com/users/468093332535640064).
11
+
12
+ # Table of contents
13
+
14
+ 0. [TL;DR](#TL;DR)
15
+ 1. [Model Details](#model-details)
16
+ 2. [Usage](#usage)
17
+ 3. [Citation](#citation)
18
+
19
+ ## TL;DR
20
+
21
+ Below is the description from the [original repository](https://github.com/BlinkDL/RWKV-LM)
22
+ > RWKV is an RNN with transformer-level LLM performance. It can be directly trained like a GPT (parallelizable). It's combining the best of RNN and transformer - great performance, fast inference, saves VRAM, fast training, "infinite" ctx_len, and free sentence embedding.
23
+
24
+ ## Model Details
25
+
26
+ The details of the architecture can be found on the blogpost mentioned above and the Hugging Face blogpost of the integration.
27
+
28
+ ## Usage
29
+
30
+ ### Convert the raw weights to the HF format
31
+
32
+ You can use the [`convert_rwkv_checkpoint_to_hf.py`](https://github.com/huggingface/transformers/tree/main/src/transformers/models/rwkv/convert_rwkv_checkpoint_to_hf.py) script by specifying the repo_id of the original weights, the filename and the output directory. You can also optionally directly push the converted model on the Hub by passing `--push_to_hub` flag and `--model_name` argument to specify where to push the converted weights.
33
+
34
+ ```bash
35
+ python convert_rwkv_checkpoint_to_hf.py --repo_id RAW_HUB_REPO --checkpoint_file RAW_FILE --output_dir OUTPUT_DIR --push_to_hub --model_name dummy_user/converted-rwkv
36
+ ```
37
+
38
+ ### Generate text
39
+
40
+ You can use the `AutoModelForCausalLM` and `AutoTokenizer` classes to generate texts from the model. Expand the sections below to understand how to run the model in different scenarios:
41
+
42
+ ### Running the model on a CPU
43
+
44
+ <details>
45
+ <summary> Click to expand </summary>
46
+
47
+ ```python
48
+ from transformers import AutoModelForCausalLM, AutoTokenizer
49
+
50
+ model = AutoModelForCausalLM.from_pretrained("RWKV/rwkv-4-3b-pile")
51
+ tokenizer = AutoTokenizer.from_pretrained("RWKV/rwkv-4-3b-pile")
52
+
53
+ prompt = "\nIn a shocking finding, scientist discovered a herd of dragons living in a remote, previously unexplored valley, in Tibet. Even more surprising to the researchers was the fact that the dragons spoke perfect Chinese."
54
+
55
+ inputs = tokenizer(prompt, return_tensors="pt")
56
+ output = model.generate(inputs["input_ids"], max_new_tokens=40)
57
+ print(tokenizer.decode(output[0].tolist(), skip_special_tokens=True))
58
+ ```
59
+
60
+
61
+ ### Running the model on a single GPU
62
+
63
+ <details>
64
+ <summary> Click to expand </summary>
65
+
66
+ ```python
67
+ from transformers import AutoModelForCausalLM, AutoTokenizer
68
+
69
+ model = AutoModelForCausalLM.from_pretrained("RWKV/rwkv-4-3b-pile").to(0)
70
+ tokenizer = AutoTokenizer.from_pretrained("RWKV/rwkv-4-3b-pile")
71
+
72
+ prompt = "\nIn a shocking finding, scientist discovered a herd of dragons living in a remote, previously unexplored valley, in Tibet. Even more surprising to the researchers was the fact that the dragons spoke perfect Chinese."
73
+
74
+ inputs = tokenizer(prompt, return_tensors="pt").to(0)
75
+ output = model.generate(inputs["input_ids"], max_new_tokens=40)
76
+ print(tokenizer.decode(output[0].tolist(), skip_special_tokens=True))
77
+ ```
78
+
79
+ </details>
80
+
81
+ </details>
82
+
83
+ ### Running the model in half-precision, on GPU
84
+
85
+ <details>
86
+ <summary> Click to expand </summary>
87
+
88
+ ```python
89
+ import torch
90
+ from transformers import AutoModelForCausalLM, AutoTokenizer
91
+
92
+ model = AutoModelForCausalLM.from_pretrained("RWKV/rwkv-4-3b-pile", torch_dtype=torch.float16).to(0)
93
+ tokenizer = AutoTokenizer.from_pretrained("RWKV/rwkv-4-3b-pile")
94
+
95
+ prompt = "\nIn a shocking finding, scientist discovered a herd of dragons living in a remote, previously unexplored valley, in Tibet. Even more surprising to the researchers was the fact that the dragons spoke perfect Chinese."
96
+
97
+ inputs = tokenizer(prompt, return_tensors="pt").to(0)
98
+ output = model.generate(inputs["input_ids"], max_new_tokens=40)
99
+ print(tokenizer.decode(output[0].tolist(), skip_special_tokens=True))
100
+ ```
101
+
102
+ </details>
103
+
104
+
105
+ ### Running the model multiple GPUs
106
+ <details>
107
+ <summary> Click to expand </summary>
108
+
109
+ ```python
110
+ # pip install accelerate
111
+ from transformers import AutoModelForCausalLM, AutoTokenizer
112
+
113
+ model = AutoModelForCausalLM.from_pretrained("RWKV/rwkv-4-3b-pile", device_map="auto")
114
+ tokenizer = AutoTokenizer.from_pretrained("RWKV/rwkv-4-3b-pile")
115
+
116
+ prompt = "\nIn a shocking finding, scientist discovered a herd of dragons living in a remote, previously unexplored valley, in Tibet. Even more surprising to the researchers was the fact that the dragons spoke perfect Chinese."
117
+
118
+ inputs = tokenizer(prompt, return_tensors="pt").to(0)
119
+ output = model.generate(inputs["input_ids"], max_new_tokens=40)
120
+ print(tokenizer.decode(output[0].tolist(), skip_special_tokens=True))
121
+ ```
122
+
123
+ </details>
124
+
125
+ ## Citation
126
+
127
+ If you use this model, please consider citing the original work, from the original repo [here](https://github.com/BlinkDL/ChatRWKV/)