Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
datasets:
|
| 3 |
+
- EleutherAI/pile
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+

|
| 7 |
+
|
| 8 |
+
# Model card for RWKV-4 | 7B parameters chat version (Raven)
|
| 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 |
+
The "Raven" models needs to be prompted in a specific way, learn more about that [in the integration blogpost](https://huggingface.co/blog/rwkv).
|
| 42 |
+
|
| 43 |
+
### Running the model on a CPU
|
| 44 |
+
|
| 45 |
+
<details>
|
| 46 |
+
<summary> Click to expand </summary>
|
| 47 |
+
|
| 48 |
+
```python
|
| 49 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 50 |
+
|
| 51 |
+
model = AutoModelForCausalLM.from_pretrained("RWKV/rwkv-raven-7b")
|
| 52 |
+
tokenizer = AutoTokenizer.from_pretrained("RWKV/rwkv-raven-7b")
|
| 53 |
+
|
| 54 |
+
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."
|
| 55 |
+
|
| 56 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 57 |
+
output = model.generate(inputs["input_ids"], max_new_tokens=40)
|
| 58 |
+
print(tokenizer.decode(output[0].tolist(), skip_special_tokens=True))
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
### Running the model on a single GPU
|
| 63 |
+
|
| 64 |
+
<details>
|
| 65 |
+
<summary> Click to expand </summary>
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 69 |
+
|
| 70 |
+
model = AutoModelForCausalLM.from_pretrained("RWKV/rwkv-raven-7b").to(0)
|
| 71 |
+
tokenizer = AutoTokenizer.from_pretrained("RWKV/rwkv-raven-7b")
|
| 72 |
+
|
| 73 |
+
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."
|
| 74 |
+
|
| 75 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(0)
|
| 76 |
+
output = model.generate(inputs["input_ids"], max_new_tokens=40)
|
| 77 |
+
print(tokenizer.decode(output[0].tolist(), skip_special_tokens=True))
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
</details>
|
| 81 |
+
|
| 82 |
+
</details>
|
| 83 |
+
|
| 84 |
+
### Running the model in half-precision, on GPU
|
| 85 |
+
|
| 86 |
+
<details>
|
| 87 |
+
<summary> Click to expand </summary>
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
import torch
|
| 91 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 92 |
+
|
| 93 |
+
model = AutoModelForCausalLM.from_pretrained("RWKV/rwkv-raven-7b", torch_dtype=torch.float16).to(0)
|
| 94 |
+
tokenizer = AutoTokenizer.from_pretrained("RWKV/rwkv-raven-7b")
|
| 95 |
+
|
| 96 |
+
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."
|
| 97 |
+
|
| 98 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(0)
|
| 99 |
+
output = model.generate(inputs["input_ids"], max_new_tokens=40)
|
| 100 |
+
print(tokenizer.decode(output[0].tolist(), skip_special_tokens=True))
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
</details>
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
### Running the model multiple GPUs
|
| 107 |
+
<details>
|
| 108 |
+
<summary> Click to expand </summary>
|
| 109 |
+
|
| 110 |
+
```python
|
| 111 |
+
# pip install accelerate
|
| 112 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 113 |
+
|
| 114 |
+
model = AutoModelForCausalLM.from_pretrained("RWKV/rwkv-raven-7b", device_map="auto")
|
| 115 |
+
tokenizer = AutoTokenizer.from_pretrained("RWKV/rwkv-raven-7b")
|
| 116 |
+
|
| 117 |
+
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."
|
| 118 |
+
|
| 119 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(0)
|
| 120 |
+
output = model.generate(inputs["input_ids"], max_new_tokens=40)
|
| 121 |
+
print(tokenizer.decode(output[0].tolist(), skip_special_tokens=True))
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
</details>
|
| 125 |
+
|
| 126 |
+
## Citation
|
| 127 |
+
|
| 128 |
+
If you use this model, please consider citing the original work, from the original repo [here](https://github.com/BlinkDL/ChatRWKV/)
|