Text Generation
Transformers
Safetensors
RWKV
English
fwkv
rosa
linear-transformer
recurrent-neural-network
chat
ultrachat
custom-architecture
custom_code
Instructions to use FWKV/FWKV-ROSA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use FWKV/FWKV-ROSA with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="FWKV/FWKV-ROSA", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("FWKV/FWKV-ROSA", trust_remote_code=True, device_map="auto") - RWKV
How to use FWKV/FWKV-ROSA 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 FWKV/FWKV-ROSA with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "FWKV/FWKV-ROSA" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "FWKV/FWKV-ROSA", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/FWKV/FWKV-ROSA
- SGLang
How to use FWKV/FWKV-ROSA 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 "FWKV/FWKV-ROSA" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "FWKV/FWKV-ROSA", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "FWKV/FWKV-ROSA" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "FWKV/FWKV-ROSA", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use FWKV/FWKV-ROSA with Docker Model Runner:
docker model run hf.co/FWKV/FWKV-ROSA
Update README.md
Browse files
README.md
CHANGED
|
@@ -2,82 +2,191 @@
|
|
| 2 |
language: en
|
| 3 |
license: apache-2.0
|
| 4 |
library_name: transformers
|
|
|
|
| 5 |
tags:
|
| 6 |
- fwkv
|
| 7 |
- rosa
|
|
|
|
| 8 |
- linear-transformer
|
| 9 |
- recurrent-neural-network
|
| 10 |
- chat
|
| 11 |
- ultrachat
|
| 12 |
-
-
|
| 13 |
---
|
| 14 |
|
| 15 |
# FWKV-ROSA
|
| 16 |
|
| 17 |
-
A **56M‑parameter**, from‑scratch recurrent language model
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|--------|-------|
|
| 33 |
-
| **Validation perplexity** | 67.78 |
|
| 34 |
-
| **Validation loss** | 4.216 |
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
## How to
|
| 39 |
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
```python
|
| 43 |
-
import torch
|
| 44 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 45 |
|
| 46 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
|
|
|
| 47 |
tokenizer = AutoTokenizer.from_pretrained("FlameF0X/FWKV-ROSA")
|
| 48 |
```
|
| 49 |
|
| 50 |
-
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
```
|
| 53 |
-
<|user|> Your prompt here
|
| 54 |
-
<|assistant|> The model reply <eos>
|
| 55 |
-
```
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
| Hyperparameter | Value |
|
| 62 |
|----------------|-------|
|
| 63 |
-
|
|
| 64 |
-
| Model dim | 512 |
|
| 65 |
-
| Embedding dim | 128 |
|
| 66 |
| FFN multiplier | 4 |
|
| 67 |
-
| WKV decay floor
|
| 68 |
-
| Batch size (per
|
| 69 |
| Gradient accumulation | 4 |
|
| 70 |
-
| Effective batch size
|
| 71 |
-
| Learning rate
|
| 72 |
-
| Weight decay
|
| 73 |
| Gradient clipping | 1.0 |
|
| 74 |
-
|
|
| 75 |
-
|
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
##
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
| 2 |
language: en
|
| 3 |
license: apache-2.0
|
| 4 |
library_name: transformers
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
tags:
|
| 7 |
- fwkv
|
| 8 |
- rosa
|
| 9 |
+
- rwkv
|
| 10 |
- linear-transformer
|
| 11 |
- recurrent-neural-network
|
| 12 |
- chat
|
| 13 |
- ultrachat
|
| 14 |
+
- custom-architecture
|
| 15 |
---
|
| 16 |
|
| 17 |
# FWKV-ROSA
|
| 18 |
|
| 19 |
+
A **56M‑parameter**, from‑scratch recurrent language model that combines a
|
| 20 |
+
**per‑channel leaky integrator (FWKV)** with the **RWKV‑8 ROSA copy‑signal**
|
| 21 |
+
mechanism. It is a research experiment designed to explore how far purely
|
| 22 |
+
recurrent architectures can go on small‑scale, curated conversational data.
|
| 23 |
|
| 24 |
+
The model was chat‑tuned on `HuggingFaceH4/ultrachat_200k` and uses a simple
|
| 25 |
+
two‑role template:
|
| 26 |
|
| 27 |
+
```
|
| 28 |
+
<|user|> Your message
|
| 29 |
+
<|assistant|> Model reply<|endoftext|>
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
## Model Description
|
| 33 |
+
|
| 34 |
+
- **Architecture:** 14 stacked FWKV blocks. Each block replaces the standard attention with a fixed, data‑independent decayed accumulator:
|
| 35 |
+
`stateₜ = W·stateₜ₋₁ + kₜ·vₜ`, where `W = clamp(sigmoid(w), min=0.1)`.
|
| 36 |
+
The recurrence is computed exactly via a vectorised parallel scan (no
|
| 37 |
+
approximations).
|
| 38 |
+
- **ROSA (Rapid Online Suffix Automaton):** A parameter‑free, causal
|
| 39 |
+
predictor that injects the token that historically followed the longest
|
| 40 |
+
matching suffix of the current context. The ROSA signal is embedded and
|
| 41 |
+
added to the input representation of each token.
|
| 42 |
+
- **Factorised embedding/head:** 128‑dimensional embedding space, projected
|
| 43 |
+
to a 512‑dimensional model space, with tied weights.
|
| 44 |
+
- **Context length:** 1024 tokens. No positional embeddings are used, making
|
| 45 |
+
the context window “free” in terms of parameters.
|
| 46 |
+
- **Tokenizer:** GPT‑2 tokenizer extended with the special tokens `<|user|>`
|
| 47 |
+
and `<|assistant|>`.
|
| 48 |
+
|
| 49 |
+
## Uses
|
| 50 |
+
|
| 51 |
+
### Direct Use
|
| 52 |
+
|
| 53 |
+
FWKV-ROSA is intended for **research on efficient language models** and for
|
| 54 |
+
**educational demonstrations** of recurrent architectures. You can chat with
|
| 55 |
+
it in a multi‑turn setting using the template above.
|
| 56 |
+
|
| 57 |
+
### Out‑of‑Scope Use
|
| 58 |
|
| 59 |
+
- This model is **not** suitable for any production or safety‑critical
|
| 60 |
+
application.
|
| 61 |
+
- It has not been aligned with RLHF or other safety methods and may generate
|
| 62 |
+
inappropriate or harmful content.
|
| 63 |
+
- The limited size and training data mean it cannot be relied upon for factual
|
| 64 |
+
knowledge or reasoning.
|
| 65 |
|
| 66 |
+
### Bias, Risks, and Limitations
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
- Trained on a relatively small synthetic dataset, the model can produce
|
| 69 |
+
repetitive or nonsensical output.
|
| 70 |
+
- The ROSA copy mechanism may occasionally copy large chunks of the user’s
|
| 71 |
+
prompt verbatim.
|
| 72 |
+
- Biases present in the original UltraChat data are likely reflected in the
|
| 73 |
+
model’s responses.
|
| 74 |
|
| 75 |
+
## How to Get Started
|
| 76 |
|
| 77 |
+
The model relies on a custom architecture. To load it, you must provide the
|
| 78 |
+
`modeling_fwkv.py` file (found in the repository) and trust the remote code:
|
| 79 |
|
| 80 |
```python
|
|
|
|
| 81 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 82 |
|
| 83 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 84 |
+
"FlameF0X/FWKV-ROSA",
|
| 85 |
+
trust_remote_code=True
|
| 86 |
+
)
|
| 87 |
tokenizer = AutoTokenizer.from_pretrained("FlameF0X/FWKV-ROSA")
|
| 88 |
```
|
| 89 |
|
| 90 |
+
Then format your prompts exactly with the chat tokens:
|
| 91 |
|
| 92 |
+
```python
|
| 93 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 94 |
+
model.to(device).eval()
|
| 95 |
+
|
| 96 |
+
prompt = "<|user|> What is the capital of France?\n<|assistant|>"
|
| 97 |
+
input_ids = tokenizer.encode(prompt)
|
| 98 |
+
# ROSA IDs must be computed – you can import `rosa` from modeling_fwkv
|
| 99 |
+
from modeling_fwkv import rosa
|
| 100 |
+
rosa_ids = torch.tensor([rosa(input_ids)], device=device)
|
| 101 |
+
out = model(input_ids=torch.tensor([input_ids], device=device),
|
| 102 |
+
rosa_ids=rosa_ids, use_cache=True)
|
| 103 |
+
# Continue autoregressive sampling…
|
| 104 |
```
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
For a fully working chat demo, see the Gradio app provided in the repository.
|
| 107 |
+
|
| 108 |
+
## Training Details
|
| 109 |
+
|
| 110 |
+
### Dataset
|
| 111 |
|
| 112 |
+
- **Name:** [UltraChat 200k](https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k)
|
| 113 |
+
- **Splits:** `train_sft` (20,000 examples), `test_sft` (1,000 examples)
|
| 114 |
+
- **Format:** multi‑turn conversations; only assistant tokens contribute to the loss.
|
| 115 |
+
|
| 116 |
+
### Training Procedure
|
| 117 |
|
| 118 |
| Hyperparameter | Value |
|
| 119 |
|----------------|-------|
|
| 120 |
+
| Architecture | 14 FWKV blocks, d_model=512, d_emb=128 |
|
|
|
|
|
|
|
| 121 |
| FFN multiplier | 4 |
|
| 122 |
+
| WKV decay floor| 0.1 |
|
| 123 |
+
| Batch size (per GPU) | 8 |
|
| 124 |
| Gradient accumulation | 4 |
|
| 125 |
+
| Effective batch size | 32 |
|
| 126 |
+
| Learning rate | 3×10⁻⁴ (cosine schedule) |
|
| 127 |
+
| Weight decay | 0.1 |
|
| 128 |
| Gradient clipping | 1.0 |
|
| 129 |
+
| Optimizer | AdamW (fused) |
|
| 130 |
+
| Precision | bfloat16 mixed |
|
| 131 |
+
| Epochs | 2 |
|
| 132 |
+
| Hardware | 1× NVIDIA T4 (15 GB) |
|
| 133 |
+
| Training time | ~2 hours |
|
| 134 |
+
| Speed | ~80,000 tokens/second |
|
| 135 |
+
|
| 136 |
+
Gradient checkpointing was enabled to fit the 1024‑token sequences in memory.
|
| 137 |
+
|
| 138 |
+
## Evaluation
|
| 139 |
+
|
| 140 |
+
| Metric | Value |
|
| 141 |
+
|-----------------------|---------|
|
| 142 |
+
| Validation loss | 4.216 |
|
| 143 |
+
| Validation perplexity | 67.78 |
|
| 144 |
+
|
| 145 |
+
The perplexity is relatively high due to the small model size and limited
|
| 146 |
+
training data. It is comparable to other similarly‑sized recurrent LMs on
|
| 147 |
+
UltraChat.
|
| 148 |
+
|
| 149 |
+
## Environmental Impact
|
| 150 |
+
|
| 151 |
+
The training ran for about **2 hours** on a single **NVIDIA T4** GPU
|
| 152 |
+
(maximum power draw ~70 W), resulting in an estimated **0.14 kWh** of
|
| 153 |
+
electricity consumption and approximately **0.06 kg CO₂eq** (assuming a
|
| 154 |
+
grid carbon intensity of 0.4 kg/kWh). This is a negligible footprint.
|
| 155 |
+
|
| 156 |
+
## Technical Specifications
|
| 157 |
+
|
| 158 |
+
- **Model type:** Recurrent neural network (linear RNN)
|
| 159 |
+
- **Parameters:** 56.2 million
|
| 160 |
+
- Backbone (FWKV blocks + embeddings): ~50M
|
| 161 |
+
- ROSA embedding: ~6.2M
|
| 162 |
+
- **Checkpoint format:** PyTorch `safetensors`
|
| 163 |
+
- **Required files in the repo:**
|
| 164 |
+
- `config.json`
|
| 165 |
+
- `model.safetensors` (or `pytorch_model.bin`)
|
| 166 |
+
- `modeling_fwkv.py`
|
| 167 |
+
- `tokenizer.json` / `vocab.json` / `merges.txt`
|
| 168 |
+
- **Auto‑mapping:** The `config.json` includes
|
| 169 |
+
`"auto_map": { "AutoModelForCausalLM": "modeling_fwkv.FWKVLanguageModel" }`,
|
| 170 |
+
so loading with `trust_remote_code=True` will automatically locate the
|
| 171 |
+
correct class.
|
| 172 |
+
|
| 173 |
+
## Citation
|
| 174 |
+
|
| 175 |
+
If you use FWKV-ROSA in your research, please cite it as:
|
| 176 |
+
|
| 177 |
+
```bibtex
|
| 178 |
+
@misc{fwkv-rosa,
|
| 179 |
+
author = {FlameF0X},
|
| 180 |
+
title = {FWKV-ROSA: A 56M Recurrent Chat LM with RWKV-style Decay and ROSA Copy Signal},
|
| 181 |
+
year = {2025},
|
| 182 |
+
howpublished = {\url{https://huggingface.co/FlameF0X/FWKV-ROSA}},
|
| 183 |
+
}
|
| 184 |
+
```
|
| 185 |
|
| 186 |
+
## Additional Information
|
| 187 |
|
| 188 |
+
This model was built as an experiment to test the combination of a simple
|
| 189 |
+
leaky integrator with the ROSA copy signal on a small, clean conversational
|
| 190 |
+
dataset. It demonstrates that a pure linear RNN can learn to produce
|
| 191 |
+
coherent multi‑turn dialogue without any attention mechanisms. Feedback and
|
| 192 |
+
contributions are welcome!
|