Text Generation
Transformers
Safetensors
RWKV
English
Chinese
rwkv7
goose
linear-attention
recurrent
conversational
custom_code
Instructions to use Hakureirm/rwkv7-0.1b-hf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Hakureirm/rwkv7-0.1b-hf with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Hakureirm/rwkv7-0.1b-hf", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Hakureirm/rwkv7-0.1b-hf", trust_remote_code=True, device_map="auto") - RWKV
How to use Hakureirm/rwkv7-0.1b-hf with RWKV:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Hakureirm/rwkv7-0.1b-hf with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Hakureirm/rwkv7-0.1b-hf" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Hakureirm/rwkv7-0.1b-hf", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Hakureirm/rwkv7-0.1b-hf
- SGLang
How to use Hakureirm/rwkv7-0.1b-hf with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Hakureirm/rwkv7-0.1b-hf" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Hakureirm/rwkv7-0.1b-hf", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Hakureirm/rwkv7-0.1b-hf" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Hakureirm/rwkv7-0.1b-hf", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Hakureirm/rwkv7-0.1b-hf with Docker Model Runner:
docker model run hf.co/Hakureirm/rwkv7-0.1b-hf
RWKV-7 0.1B, converted from BlinkDL/rwkv-7-world for the in-tree transformers implementation
Browse files- README.md +103 -0
- config.json +33 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- zh
|
| 6 |
+
library_name: transformers
|
| 7 |
+
pipeline_tag: text-generation
|
| 8 |
+
base_model: BlinkDL/rwkv-7-world
|
| 9 |
+
tags:
|
| 10 |
+
- rwkv
|
| 11 |
+
- rwkv7
|
| 12 |
+
- goose
|
| 13 |
+
- linear-attention
|
| 14 |
+
- recurrent
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# RWKV-7 "Goose" 0.1B — converted for the in-tree `transformers` implementation
|
| 18 |
+
|
| 19 |
+
This is **not a new model**. It is a format conversion of
|
| 20 |
+
[`BlinkDL/rwkv-7-world`](https://huggingface.co/BlinkDL/rwkv-7-world) →
|
| 21 |
+
`RWKV-x070-World-0.1B-v2.8-20241210-ctx4096.pth`, laid out as a `transformers`
|
| 22 |
+
directory so that the `rwkv7` implementation can load it with `from_pretrained`.
|
| 23 |
+
All credit for the weights belongs to **BlinkDL / the RWKV project**; they are
|
| 24 |
+
redistributed here under the Apache-2.0 licence they were released under.
|
| 25 |
+
|
| 26 |
+
## Why this exists
|
| 27 |
+
|
| 28 |
+
RWKV-7 weights are published in two layouts, and until now neither loaded into the
|
| 29 |
+
in-tree implementation:
|
| 30 |
+
|
| 31 |
+
- the reference `.pth` — the same parameter names, but a bare `torch.save` of a flat
|
| 32 |
+
dict rather than a `transformers` directory;
|
| 33 |
+
- the `fla` layout — a `transformers` directory, but a `trust_remote_code` repo whose
|
| 34 |
+
modelling code and tensor names come from `flash-linear-attention`, so it loads its
|
| 35 |
+
own implementation.
|
| 36 |
+
|
| 37 |
+
The conversion is a rename, not a transformation. Every one of the 399 tensors in the
|
| 38 |
+
source `.pth` is **bit-identical** here; the only additions are three all-zero
|
| 39 |
+
placeholders for layer 0's value-residual LoRA, which that layer never reads (layer 0
|
| 40 |
+
*produces* `v_first` rather than mixing towards it) and which exist so the state dict
|
| 41 |
+
is rectangular. `bfloat16`, the dtype the source is stored in.
|
| 42 |
+
|
| 43 |
+
## Usage
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
import torch
|
| 47 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 48 |
+
|
| 49 |
+
# The RWKV world tokenizer; this repo ships weights only.
|
| 50 |
+
tokenizer = AutoTokenizer.from_pretrained("RWKV/RWKV7-Goose-World2.8-0.1B-HF", trust_remote_code=True)
|
| 51 |
+
model = AutoModelForCausalLM.from_pretrained("Hakureirm/rwkv7-0.1b-hf", dtype=torch.bfloat16)
|
| 52 |
+
|
| 53 |
+
inputs = tokenizer("The Eiffel Tower is located in the city of", return_tensors="pt")
|
| 54 |
+
print(tokenizer.decode(model.generate(**inputs, max_new_tokens=20)[0]))
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
RWKV-7 is attention-free and fully recurrent: the state is a fixed-size matrix per
|
| 58 |
+
head, so there is no KV cache, memory is constant in context length, and each new
|
| 59 |
+
token costs the same as the first.
|
| 60 |
+
|
| 61 |
+
## Verification
|
| 62 |
+
|
| 63 |
+
Checked against **BlinkDL's own runtime** — the `rwkv` package at `cpu fp32` with
|
| 64 |
+
`RWKV_V7_ON=1`, not against the implementation being loaded here, which would be
|
| 65 |
+
self-certifying, and not against `fla`, whose RWKV layer prints a warning on import
|
| 66 |
+
saying it is potentially buggy and that results should be cross-checked against the
|
| 67 |
+
official repository.
|
| 68 |
+
|
| 69 |
+
Greedy, 20 tokens, from "The Eiffel Tower is located in the city of":
|
| 70 |
+
|
| 71 |
+
| loaded as | tokens matching the reference runtime |
|
| 72 |
+
|---|---|
|
| 73 |
+
| `float32` | **20/20** |
|
| 74 |
+
| `bfloat16` | **20/20** |
|
| 75 |
+
|
| 76 |
+
Both produce `" Paris, France. It is the tallest building in the world and is the world's tallest"`.
|
| 77 |
+
|
| 78 |
+
Logits agree with the reference to `7.06e-05` absolute and `1.97e-06` relative, with
|
| 79 |
+
argmax agreement on every prompt position.
|
| 80 |
+
|
| 81 |
+
0.1B is a useful size to check against for a reason beyond its download: it is 768 wide
|
| 82 |
+
with `head_dim` 64, i.e. twelve heads of width 64, so the head *count* and the head
|
| 83 |
+
*width* differ. At larger widths where both are 64, a quantity indexed by the wrong one
|
| 84 |
+
of them agrees by coincidence.
|
| 85 |
+
|
| 86 |
+
## Reproducing the conversion
|
| 87 |
+
|
| 88 |
+
```bash
|
| 89 |
+
huggingface-cli download BlinkDL/rwkv-7-world RWKV-x070-World-0.1B-v2.8-20241210-ctx4096.pth --local-dir .
|
| 90 |
+
python src/transformers/models/rwkv7/convert_rwkv7_checkpoint_to_hf.py \
|
| 91 |
+
--checkpoint RWKV-x070-World-0.1B-v2.8-20241210-ctx4096.pth \
|
| 92 |
+
--flavour native --dtype bfloat16 --output_dir ./rwkv7-0.1b-hf
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
`--flavour fla` reads the safetensors layout instead. The converter compares the
|
| 96 |
+
checkpoint's tensor shapes against the ones the config implies and refuses a
|
| 97 |
+
disagreement, so a config that names a different model fails rather than producing
|
| 98 |
+
something that loads and generates noise.
|
| 99 |
+
|
| 100 |
+
## Citation
|
| 101 |
+
|
| 102 |
+
The model is RWKV-7 "Goose" by Bo Peng (BlinkDL) and the RWKV community. Reference
|
| 103 |
+
implementation: [BlinkDL/RWKV-LM](https://github.com/BlinkDL/RWKV-LM).
|
config.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"a_low_rank_dim": 64,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"Rwkv7ForCausalLM"
|
| 5 |
+
],
|
| 6 |
+
"bos_token_id": 0,
|
| 7 |
+
"decay_low_rank_dim": 64,
|
| 8 |
+
"deep_embed_size": 768,
|
| 9 |
+
"dtype": "bfloat16",
|
| 10 |
+
"eos_token_id": 0,
|
| 11 |
+
"gate_low_rank_dim": 128,
|
| 12 |
+
"head_dim": 64,
|
| 13 |
+
"hidden_act": "sqrelu",
|
| 14 |
+
"hidden_ratio": 4.0,
|
| 15 |
+
"hidden_size": 768,
|
| 16 |
+
"intermediate_size": 3072,
|
| 17 |
+
"max_position_embeddings": 8192,
|
| 18 |
+
"model_type": "rwkv7",
|
| 19 |
+
"norm_bias": true,
|
| 20 |
+
"norm_eps": 1e-05,
|
| 21 |
+
"num_heads": 12,
|
| 22 |
+
"num_hidden_layers": 12,
|
| 23 |
+
"pad_token_id": 0,
|
| 24 |
+
"sparse_channel_mix": false,
|
| 25 |
+
"tie_word_embeddings": false,
|
| 26 |
+
"transformers_version": "5.15.0.dev0",
|
| 27 |
+
"use_cache": true,
|
| 28 |
+
"use_deep_embed": false,
|
| 29 |
+
"v_low_rank_dim": 32,
|
| 30 |
+
"vocab_size": 65536,
|
| 31 |
+
"wkv_implementation": "eager",
|
| 32 |
+
"wkv_state_dtype": "float32"
|
| 33 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:843e408a28782988b7be383991b49dba632559d85455d0658dfeb522da6b59cc
|
| 3 |
+
size 382208592
|