Downloads · 30 days
0
AnshulRanjan2004/MicroRWKV
MicroRWKV is a text generation model from AnshulRanjan2004. Use it when you need the model to write or continue text. The card lists the license as gpl-3.0.
This is a custom architecture for the nanoRWKV project from RWKV-v4neo. The architecture is based on the original nanoRWKV architecture, but with some modifications.
Downloads · 30 days
0
Access
Public
Updated Aug 24, 2025
Repo size
3.2 MB
Likes
3
Public
Click a slice to open those files.
.gif3.8 MB · 64%
From the Hugging Face model README
This is a custom architecture for the nanoRWKV project from RWKV-v4neo. The architecture is based on the original nanoRWKV architecture, but with some modifications.

This is RWKV "x051a" which does not require custom CUDA kernel to train, so it works for any GPU / CPU.

The nanoGPT-style implementation of RWKV Language Model - an RNN with GPT-level LLM performance.
Dataset used - TinyStories

RWKV is essentially an RNN with unrivaled advantage when doing inference. Here we benchmark the speed and space occupation of RWKV, along with its Transformer counterpart (code could be found here). We could easily find:

Before kicking off this project, make sure you are familiar with the following concepts:
RWKV_TimeMix -> RWKV_ChannelMix -> Sliding Window Attention -> GroupedQAttention -> TinyMoE
Here is a brief description of each component:
time_maa_k, time_maa_v, time_maa_r, and time_maa_g, to control the mixing process.
The module also applies a time-decay mechanism using the time_decay parameter, which allows the model to give more importance to recent inputs.
The output of this module is then passed through a series of linear layers, including the receptance, key, value, and gate layers.
time_maa_k and time_maa_r, to control the mixing process.
The module applies a key, value, and receptance linear layers to the mixed input, and the output is then passed through a sigmoid activation function.
Sliding Window Attention: This attention mechanism operates on a sliding window of the input, enabling the model to efficiently capture both local and global dependencies. The module computes the query, key, and value matrices using a linear layer, and then applies a sliding window attention operation to the input. The output of the sliding window attention is then passed through a final linear layer to produce the final output.
GroupedQAttention: This attention module applies a grouped approach to the query, key, and value computations, improving the model's ability to capture multi-headed attention. The module first computes the query, key, value, and weight matrices using a single linear layer, and then splits these matrices into groups. The attention computation is then performed on each group, and the results are concatenated and passed through a final linear layer.
TinyMoE: The Tiny Mixture of Experts (TinyMoE) layer is a lightweight and efficient implementation of a Mixture of Experts (MoE) mechanism, which can help the model learn specialized representations. The module computes attention scores using a linear layer, and then applies these scores to a set of expert networks to produce the final output. The module also includes an auxiliary loss term that encourages the experts to learn diverse representations, improving the overall performance of the model.
To use this model for inference, you can follow these steps:
out directory.block_size, vocab_size, etc from the table into the class GPTConfig in generate.py.python generate.py --prompt="One day" --max_num_tokens=50 --model_name="ckpt-500"
Explain:
This command will generate text based on the input prompt "One day" using the model weights stored in the out directory. The max_num_tokens parameter specifies the maximum number of tokens to generate, and the model_name parameter specifies the name of the model weights file to load. For model_name, you can specify the name of the model weights file without the extension, like "ckpt-500" or "ckpt-1000" or only "ckpt".
| name_model | BLOCK_SIZE | VOCAB_SIZE | N_LAYER | N_HEAD | N_EMBD | NUM_EXPERTS | NUM_ACTIVE_EXPERTS | EXPERT_DIM | DIM | DROPOUT | BIAS | DATASET |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ckpt-500.pth | 1024 | 50304 | 8 | 8 | 768 | 4 | 4 | 512 | 768 | 0.0 | False | tinystories_15k |
Prompt: One day
Generated text: One day: Sharing positive bought Isabel a rainbow hug. Her name was an vitamins, so only one favorite thing to cheer she were.
Lily picked up a hay and proudly went to a small portion. She was very happened. When Tommy said it
Generated text length: 227 | Inference time: 3 seconds
We got the results as follows
| model | params | train loss | val loss |
|---|---|---|---|
| GPT-2 | 124M | 2.82 | 2.86 |
| RWKV | 130M | 2.85 | 2.88 |
Existing OpenAI GPT-2 checkpoints and RWKV checkpoints allow us to get some baselines in place for openwebtext. We can get the numbers as follows:
python train.py config/eval_rwkv4_{169m|430m|1b5|3b|7b|14b}.py
python train.py config/eval_gpt2{|_medium|_large|_xl}.py
and observe the following losses on val set:
| model | RWKV | GPT-2 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| parameters | 169M | 430M | 1.5B | 3B | 7B | 14B | 124M | 350M | 774M | 1.5B |
| val loss | 3.11 | 2.79 | 2.54 | 2.42 | 2.32 | 2.23 | 3.11 | 2.82 | 2.66 | 2.56 |
Notice that both models are not trained in the openwebtext (RWKV in The Pile and OpenAI GPT-2 in private WebText), so they could be further improved due to dataset domain gap.
The MicroRWKV model is a custom neural network architecture that combines several cutting-edge techniques, such as time-based and channel-based mixing, sliding window attention, grouped attention, and a Tiny Mixture of Experts (TinyMoE) layer. These components work together to enhance the model's ability to capture both local and global dependencies, as well as to learn specialized representations. The combination of these techniques results in a powerful and efficient model that can be used for a variety of natural language processing tasks.
Here are some useful references (offering my sincerest gratitude):