Instructions to use aabbdev/RWKV7-1.5B-20260805 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use aabbdev/RWKV7-1.5B-20260805 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="aabbdev/RWKV7-1.5B-20260805", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("aabbdev/RWKV7-1.5B-20260805", trust_remote_code=True, device_map="auto") - RWKV
How to use aabbdev/RWKV7-1.5B-20260805 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 aabbdev/RWKV7-1.5B-20260805 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "aabbdev/RWKV7-1.5B-20260805" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "aabbdev/RWKV7-1.5B-20260805", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/aabbdev/RWKV7-1.5B-20260805
- SGLang
How to use aabbdev/RWKV7-1.5B-20260805 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 "aabbdev/RWKV7-1.5B-20260805" \ --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": "aabbdev/RWKV7-1.5B-20260805", "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 "aabbdev/RWKV7-1.5B-20260805" \ --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": "aabbdev/RWKV7-1.5B-20260805", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use aabbdev/RWKV7-1.5B-20260805 with Docker Model Runner:
docker model run hf.co/aabbdev/RWKV7-1.5B-20260805
Publish RWKV7-1.5B-20260805
Browse files- README.md +11 -5
- configuration_rwkv7.py +20 -2
- inference/requirements.txt +2 -2
- modeling_rwkv7.py +166 -3
- release-manifest.json +16 -13
README.md
CHANGED
|
@@ -81,7 +81,7 @@ optional TileLang inference implementation are distributed with this release.
|
|
| 81 |
|
| 82 |
| Field | Value |
|
| 83 |
| --- | --- |
|
| 84 |
-
| Repository | `
|
| 85 |
| Architecture class | `Rwkv7ForCausalLM` |
|
| 86 |
| Public size label | `1.5`B |
|
| 87 |
| Source parameters | `1,527,668,736` |
|
|
@@ -101,6 +101,12 @@ optional TileLang inference implementation are distributed with this release.
|
|
| 101 |
|
| 102 |
## Transformers quickstart
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
The repository includes `configuration_rwkv7.py` and `modeling_rwkv7.py`, adapted
|
| 105 |
from the Transformers RWKV-7 integration at commit
|
| 106 |
[`4ad9ed0`](https://github.com/huggingface/transformers/commit/4ad9ed0747ed6ba75c787e8f9040dcd64b166ee2).
|
|
@@ -116,7 +122,7 @@ from transformers import (
|
|
| 116 |
PreTrainedConfig,
|
| 117 |
)
|
| 118 |
|
| 119 |
-
model_id = "
|
| 120 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 121 |
model_id,
|
| 122 |
config=PreTrainedConfig(),
|
|
@@ -153,7 +159,7 @@ def assistant_content(completion, thinking, *, close_incomplete=False):
|
|
| 153 |
return f"{reply.rstrip()}\n</think>".strip()
|
| 154 |
return "" if thinking_block is None else reply[thinking_block.end():].strip()
|
| 155 |
|
| 156 |
-
model_id = "
|
| 157 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 158 |
model_id,
|
| 159 |
config=PreTrainedConfig(),
|
|
@@ -257,14 +263,14 @@ Install the versions listed in `inference/requirements.txt`, then run the bundle
|
|
| 257 |
interactive chat:
|
| 258 |
|
| 259 |
```bash
|
| 260 |
-
python inference/generate.py --model
|
| 261 |
```
|
| 262 |
|
| 263 |
Or independent prompts separated by blank lines:
|
| 264 |
|
| 265 |
```bash
|
| 266 |
python inference/generate.py \
|
| 267 |
-
--model
|
| 268 |
--backend auto \
|
| 269 |
--input-file prompts.txt
|
| 270 |
```
|
|
|
|
| 81 |
|
| 82 |
| Field | Value |
|
| 83 |
| --- | --- |
|
| 84 |
+
| Repository | `aabbdev/RWKV7-1.5B-20260805` |
|
| 85 |
| Architecture class | `Rwkv7ForCausalLM` |
|
| 86 |
| Public size label | `1.5`B |
|
| 87 |
| Source parameters | `1,527,668,736` |
|
|
|
|
| 101 |
|
| 102 |
## Transformers quickstart
|
| 103 |
|
| 104 |
+
Install the supported runtime before loading remote code:
|
| 105 |
+
|
| 106 |
+
```bash
|
| 107 |
+
python -m pip install "transformers>=5.3,<6" "huggingface-hub>=1.5,<2"
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
The repository includes `configuration_rwkv7.py` and `modeling_rwkv7.py`, adapted
|
| 111 |
from the Transformers RWKV-7 integration at commit
|
| 112 |
[`4ad9ed0`](https://github.com/huggingface/transformers/commit/4ad9ed0747ed6ba75c787e8f9040dcd64b166ee2).
|
|
|
|
| 122 |
PreTrainedConfig,
|
| 123 |
)
|
| 124 |
|
| 125 |
+
model_id = "aabbdev/RWKV7-1.5B-20260805"
|
| 126 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 127 |
model_id,
|
| 128 |
config=PreTrainedConfig(),
|
|
|
|
| 159 |
return f"{reply.rstrip()}\n</think>".strip()
|
| 160 |
return "" if thinking_block is None else reply[thinking_block.end():].strip()
|
| 161 |
|
| 162 |
+
model_id = "aabbdev/RWKV7-1.5B-20260805"
|
| 163 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 164 |
model_id,
|
| 165 |
config=PreTrainedConfig(),
|
|
|
|
| 263 |
interactive chat:
|
| 264 |
|
| 265 |
```bash
|
| 266 |
+
python inference/generate.py --model aabbdev/RWKV7-1.5B-20260805 --backend auto --interactive
|
| 267 |
```
|
| 268 |
|
| 269 |
Or independent prompts separated by blank lines:
|
| 270 |
|
| 271 |
```bash
|
| 272 |
python inference/generate.py \
|
| 273 |
+
--model aabbdev/RWKV7-1.5B-20260805 \
|
| 274 |
--backend auto \
|
| 275 |
--input-file prompts.txt
|
| 276 |
```
|
configuration_rwkv7.py
CHANGED
|
@@ -17,6 +17,22 @@ from huggingface_hub.dataclasses import strict
|
|
| 17 |
|
| 18 |
from transformers.configuration_utils import PreTrainedConfig
|
| 19 |
from transformers.utils import auto_docstring
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
@auto_docstring(
|
|
@@ -29,7 +45,7 @@ from transformers.utils import auto_docstring
|
|
| 29 |
(`BlinkDL/RWKV-LM`) rather than a renamed variant.
|
| 30 |
""",
|
| 31 |
)
|
| 32 |
-
@
|
| 33 |
class Rwkv7Config(PreTrainedConfig):
|
| 34 |
r"""
|
| 35 |
vocab_size (`int`, *optional*, defaults to 65536):
|
|
@@ -147,7 +163,9 @@ class Rwkv7Config(PreTrainedConfig):
|
|
| 147 |
f"num_heads must be hidden_size // head_dim = {self.hidden_size // self.head_dim}, "
|
| 148 |
f"got {self.num_heads}"
|
| 149 |
)
|
| 150 |
-
super()
|
|
|
|
|
|
|
| 151 |
|
| 152 |
|
| 153 |
__all__ = ["Rwkv7Config"]
|
|
|
|
| 17 |
|
| 18 |
from transformers.configuration_utils import PreTrainedConfig
|
| 19 |
from transformers.utils import auto_docstring
|
| 20 |
+
from dataclasses import is_dataclass
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _strict_config(cls):
|
| 24 |
+
# Transformers 5.15 makes PreTrainedConfig a dataclass; 5.3 does not. Hub's
|
| 25 |
+
# strict decorator is valid only in the former case. Rwkv7Config still runs its
|
| 26 |
+
# explicit __init__ validation on both branches.
|
| 27 |
+
if is_dataclass(cls):
|
| 28 |
+
return strict(cls)
|
| 29 |
+
|
| 30 |
+
def _legacy_init(self, **kwargs):
|
| 31 |
+
PreTrainedConfig.__init__(self, **kwargs)
|
| 32 |
+
self.__post_init__()
|
| 33 |
+
|
| 34 |
+
cls.__init__ = _legacy_init
|
| 35 |
+
return cls
|
| 36 |
|
| 37 |
|
| 38 |
@auto_docstring(
|
|
|
|
| 45 |
(`BlinkDL/RWKV-LM`) rather than a renamed variant.
|
| 46 |
""",
|
| 47 |
)
|
| 48 |
+
@_strict_config
|
| 49 |
class Rwkv7Config(PreTrainedConfig):
|
| 50 |
r"""
|
| 51 |
vocab_size (`int`, *optional*, defaults to 65536):
|
|
|
|
| 163 |
f"num_heads must be hidden_size // head_dim = {self.hidden_size // self.head_dim}, "
|
| 164 |
f"got {self.num_heads}"
|
| 165 |
)
|
| 166 |
+
parent_post_init = getattr(super(), "__post_init__", None)
|
| 167 |
+
if parent_post_init is not None:
|
| 168 |
+
parent_post_init(**kwargs)
|
| 169 |
|
| 170 |
|
| 171 |
__all__ = ["Rwkv7Config"]
|
inference/requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
transformers>=5.
|
| 2 |
-
huggingface-hub>=
|
| 3 |
safetensors>=0.5
|
| 4 |
jinja2>=3.1,<4
|
| 5 |
tilelang==0.1.12
|
|
|
|
| 1 |
+
transformers>=5.3,<6
|
| 2 |
+
huggingface-hub>=1.5,<2
|
| 3 |
safetensors>=0.5
|
| 4 |
jinja2>=3.1,<4
|
| 5 |
tilelang==0.1.12
|
modeling_rwkv7.py
CHANGED
|
@@ -20,7 +20,135 @@ import torch
|
|
| 20 |
from torch import nn
|
| 21 |
|
| 22 |
from transformers import initialization as init
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
from transformers.generation import GenerationMixin
|
| 25 |
from transformers.modeling_layers import GradientCheckpointingLayer
|
| 26 |
from transformers.modeling_utils import PreTrainedModel
|
|
@@ -749,8 +877,10 @@ class Rwkv7Cache(Cache):
|
|
| 749 |
layer.is_recurrent_states_initialized[slot] = True
|
| 750 |
layer.has_previous_state[slot] = True
|
| 751 |
return
|
|
|
|
|
|
|
| 752 |
for slot, state in states:
|
| 753 |
-
|
| 754 |
|
| 755 |
|
| 756 |
class Rwkv7Block(GradientCheckpointingLayer):
|
|
@@ -834,6 +964,7 @@ class Rwkv7CausalLMOutput(ModelOutput):
|
|
| 834 |
loss: torch.FloatTensor | None = None
|
| 835 |
logits: torch.FloatTensor | None = None
|
| 836 |
state: Rwkv7Cache | None = None
|
|
|
|
| 837 |
hidden_states: tuple[torch.FloatTensor, ...] | None = None
|
| 838 |
attentions: None = None
|
| 839 |
|
|
@@ -1119,6 +1250,26 @@ class Rwkv7ForCausalLM(Rwkv7PreTrainedModel, GenerationMixin):
|
|
| 1119 |
def set_output_embeddings(self, new_embeddings):
|
| 1120 |
self.head = new_embeddings
|
| 1121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1122 |
def prepare_inputs_for_generation(
|
| 1123 |
self,
|
| 1124 |
input_ids,
|
|
@@ -1128,6 +1279,9 @@ class Rwkv7ForCausalLM(Rwkv7PreTrainedModel, GenerationMixin):
|
|
| 1128 |
is_first_iteration=False,
|
| 1129 |
**kwargs,
|
| 1130 |
):
|
|
|
|
|
|
|
|
|
|
| 1131 |
# `state is not None` does not by itself mean decode: callers can provide
|
| 1132 |
# an empty preallocated state for the initial prompt, or a carried state
|
| 1133 |
# followed by a multi-token continuation. GenerationMixin tells us how
|
|
@@ -1165,6 +1319,7 @@ class Rwkv7ForCausalLM(Rwkv7PreTrainedModel, GenerationMixin):
|
|
| 1165 |
position_ids: torch.LongTensor | None = None,
|
| 1166 |
inputs_embeds: torch.FloatTensor | None = None,
|
| 1167 |
state: Rwkv7Cache | None = None,
|
|
|
|
| 1168 |
labels: torch.LongTensor | None = None,
|
| 1169 |
use_cache: bool | None = None,
|
| 1170 |
output_attentions: bool | None = None,
|
|
@@ -1185,6 +1340,8 @@ class Rwkv7ForCausalLM(Rwkv7PreTrainedModel, GenerationMixin):
|
|
| 1185 |
so `generate` declined to pass it and a caller who passed it was quietly
|
| 1186 |
ignored.
|
| 1187 |
"""
|
|
|
|
|
|
|
| 1188 |
if labels is not None and use_cache is None:
|
| 1189 |
use_cache = False
|
| 1190 |
outputs = self.rwkv7(
|
|
@@ -1209,7 +1366,13 @@ class Rwkv7ForCausalLM(Rwkv7PreTrainedModel, GenerationMixin):
|
|
| 1209 |
if labels is not None:
|
| 1210 |
loss = self.loss_function(logits, labels, self.config.vocab_size, **kwargs)
|
| 1211 |
|
| 1212 |
-
return Rwkv7CausalLMOutput(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1213 |
|
| 1214 |
|
| 1215 |
__all__ = ["Rwkv7Cache", "Rwkv7PreTrainedModel", "Rwkv7Model", "Rwkv7ForCausalLM"]
|
|
|
|
| 20 |
from torch import nn
|
| 21 |
|
| 22 |
from transformers import initialization as init
|
| 23 |
+
try:
|
| 24 |
+
from transformers.cache_utils import Cache, LinearAttentionLayer
|
| 25 |
+
except ImportError:
|
| 26 |
+
from transformers.cache_utils import Cache
|
| 27 |
+
|
| 28 |
+
class LinearAttentionLayer:
|
| 29 |
+
"""Backport of the recurrent-only cache surface introduced after Transformers 5.3."""
|
| 30 |
+
|
| 31 |
+
is_compileable = True
|
| 32 |
+
supports_early_init = False
|
| 33 |
+
is_sliding = False
|
| 34 |
+
|
| 35 |
+
def __init__(self, number_of_states: int = 1, **kwargs):
|
| 36 |
+
del kwargs
|
| 37 |
+
self.number_of_states = number_of_states
|
| 38 |
+
self.conv_states = dict.fromkeys(range(number_of_states))
|
| 39 |
+
self.recurrent_states = dict.fromkeys(range(number_of_states))
|
| 40 |
+
self.is_conv_states_initialized = dict.fromkeys(range(number_of_states), False)
|
| 41 |
+
self.is_recurrent_states_initialized = dict.fromkeys(range(number_of_states), False)
|
| 42 |
+
self.has_previous_state = dict.fromkeys(range(number_of_states), False)
|
| 43 |
+
self.conv_kernel_size = dict.fromkeys(range(number_of_states))
|
| 44 |
+
self.device = None
|
| 45 |
+
self.dtype = None
|
| 46 |
+
self.record_past = False
|
| 47 |
+
|
| 48 |
+
def __repr__(self):
|
| 49 |
+
return self.__class__.__name__
|
| 50 |
+
|
| 51 |
+
@property
|
| 52 |
+
def is_initialized(self):
|
| 53 |
+
return all(self.is_recurrent_states_initialized.values())
|
| 54 |
+
|
| 55 |
+
@property
|
| 56 |
+
def max_batch_size(self):
|
| 57 |
+
for state in self.recurrent_states.values():
|
| 58 |
+
if state is not None:
|
| 59 |
+
return state.shape[0]
|
| 60 |
+
return 0
|
| 61 |
+
|
| 62 |
+
@property
|
| 63 |
+
def max_cache_len(self):
|
| 64 |
+
return -1
|
| 65 |
+
|
| 66 |
+
def lazy_initialization(
|
| 67 |
+
self,
|
| 68 |
+
conv_states=None,
|
| 69 |
+
recurrent_states=None,
|
| 70 |
+
state_idx: int = 0,
|
| 71 |
+
conv_kernel_size=None,
|
| 72 |
+
):
|
| 73 |
+
if conv_states is not None:
|
| 74 |
+
if self.device is None:
|
| 75 |
+
self.dtype, self.device = conv_states.dtype, conv_states.device
|
| 76 |
+
size = conv_states.shape[-1] if conv_kernel_size is None else conv_kernel_size
|
| 77 |
+
self.conv_kernel_size[state_idx] = size
|
| 78 |
+
self.conv_states[state_idx] = torch.zeros(
|
| 79 |
+
(*conv_states.shape[:-1], size),
|
| 80 |
+
dtype=conv_states.dtype,
|
| 81 |
+
device=conv_states.device,
|
| 82 |
+
)
|
| 83 |
+
self.is_conv_states_initialized[state_idx] = True
|
| 84 |
+
if recurrent_states is not None:
|
| 85 |
+
if self.device is None:
|
| 86 |
+
self.dtype, self.device = recurrent_states.dtype, recurrent_states.device
|
| 87 |
+
self.recurrent_states[state_idx] = torch.zeros_like(recurrent_states)
|
| 88 |
+
self.is_recurrent_states_initialized[state_idx] = True
|
| 89 |
+
|
| 90 |
+
def update_recurrent_state(self, recurrent_states, state_idx: int = 0, **kwargs):
|
| 91 |
+
del kwargs
|
| 92 |
+
if not self.is_recurrent_states_initialized[state_idx]:
|
| 93 |
+
self.lazy_initialization(recurrent_states=recurrent_states, state_idx=state_idx)
|
| 94 |
+
self.recurrent_states[state_idx].copy_(recurrent_states)
|
| 95 |
+
self.has_previous_state[state_idx] = True
|
| 96 |
+
return self.recurrent_states[state_idx]
|
| 97 |
+
|
| 98 |
+
def update(self, key_states, value_states, cache_kwargs=None):
|
| 99 |
+
del key_states, value_states, cache_kwargs
|
| 100 |
+
raise NotImplementedError("RWKV7 updates recurrent state through update_recurrent_state")
|
| 101 |
+
|
| 102 |
+
def get_seq_length(self):
|
| 103 |
+
return 0
|
| 104 |
+
|
| 105 |
+
def get_mask_sizes(self, cache_position):
|
| 106 |
+
return cache_position.shape[0], 0
|
| 107 |
+
|
| 108 |
+
def get_max_cache_shape(self):
|
| 109 |
+
return -1
|
| 110 |
+
|
| 111 |
+
def reset(self):
|
| 112 |
+
for state_idx in range(self.number_of_states):
|
| 113 |
+
state = self.recurrent_states[state_idx]
|
| 114 |
+
if state is not None:
|
| 115 |
+
state.zero_()
|
| 116 |
+
self.has_previous_state[state_idx] = False
|
| 117 |
+
|
| 118 |
+
def reorder_cache(self, beam_idx):
|
| 119 |
+
for state_idx in range(self.number_of_states):
|
| 120 |
+
state = self.recurrent_states[state_idx]
|
| 121 |
+
if state is not None:
|
| 122 |
+
self.recurrent_states[state_idx] = state.index_select(0, beam_idx.to(state.device))
|
| 123 |
+
|
| 124 |
+
def batch_repeat_interleave(self, repeats: int):
|
| 125 |
+
for state_idx in range(self.number_of_states):
|
| 126 |
+
state = self.recurrent_states[state_idx]
|
| 127 |
+
if state is not None:
|
| 128 |
+
self.recurrent_states[state_idx] = state.repeat_interleave(repeats, dim=0)
|
| 129 |
+
|
| 130 |
+
def batch_select_indices(self, indices):
|
| 131 |
+
for state_idx in range(self.number_of_states):
|
| 132 |
+
state = self.recurrent_states[state_idx]
|
| 133 |
+
if state is not None:
|
| 134 |
+
self.recurrent_states[state_idx] = state[indices, ...]
|
| 135 |
+
|
| 136 |
+
def offload(self):
|
| 137 |
+
for state_idx in range(self.number_of_states):
|
| 138 |
+
state = self.recurrent_states[state_idx]
|
| 139 |
+
if state is not None:
|
| 140 |
+
self.recurrent_states[state_idx] = state.to("cpu", non_blocking=True)
|
| 141 |
+
|
| 142 |
+
def prefetch(self):
|
| 143 |
+
for state_idx in range(self.number_of_states):
|
| 144 |
+
state = self.recurrent_states[state_idx]
|
| 145 |
+
if state is not None and self.device is not None and state.device != self.device:
|
| 146 |
+
self.recurrent_states[state_idx] = state.to(self.device, non_blocking=True)
|
| 147 |
+
|
| 148 |
+
def crop(self, max_length):
|
| 149 |
+
if max_length not in (0, -1):
|
| 150 |
+
raise RuntimeError("RWKV7 recurrent cache does not support rollback")
|
| 151 |
+
|
| 152 |
from transformers.generation import GenerationMixin
|
| 153 |
from transformers.modeling_layers import GradientCheckpointingLayer
|
| 154 |
from transformers.modeling_utils import PreTrainedModel
|
|
|
|
| 877 |
layer.is_recurrent_states_initialized[slot] = True
|
| 878 |
layer.has_previous_state[slot] = True
|
| 879 |
return
|
| 880 |
+
layer = self.layers[layer_idx]
|
| 881 |
+
assert isinstance(layer, Rwkv7CacheLayer)
|
| 882 |
for slot, state in states:
|
| 883 |
+
layer.update_recurrent_state(state, slot)
|
| 884 |
|
| 885 |
|
| 886 |
class Rwkv7Block(GradientCheckpointingLayer):
|
|
|
|
| 964 |
loss: torch.FloatTensor | None = None
|
| 965 |
logits: torch.FloatTensor | None = None
|
| 966 |
state: Rwkv7Cache | None = None
|
| 967 |
+
past_key_values: Rwkv7Cache | None = None
|
| 968 |
hidden_states: tuple[torch.FloatTensor, ...] | None = None
|
| 969 |
attentions: None = None
|
| 970 |
|
|
|
|
| 1250 |
def set_output_embeddings(self, new_embeddings):
|
| 1251 |
self.head = new_embeddings
|
| 1252 |
|
| 1253 |
+
@staticmethod
|
| 1254 |
+
def _expand_inputs_for_generation(
|
| 1255 |
+
expand_size=1,
|
| 1256 |
+
is_encoder_decoder=False,
|
| 1257 |
+
input_ids=None,
|
| 1258 |
+
**model_kwargs,
|
| 1259 |
+
):
|
| 1260 |
+
cache = model_kwargs.get("state")
|
| 1261 |
+
if cache is None:
|
| 1262 |
+
cache = model_kwargs.get("past_key_values")
|
| 1263 |
+
input_ids, model_kwargs = GenerationMixin._expand_inputs_for_generation(
|
| 1264 |
+
expand_size=expand_size,
|
| 1265 |
+
is_encoder_decoder=is_encoder_decoder,
|
| 1266 |
+
input_ids=input_ids,
|
| 1267 |
+
**model_kwargs,
|
| 1268 |
+
)
|
| 1269 |
+
if cache is not None and expand_size > 1:
|
| 1270 |
+
cache.batch_repeat_interleave(expand_size)
|
| 1271 |
+
return input_ids, model_kwargs
|
| 1272 |
+
|
| 1273 |
def prepare_inputs_for_generation(
|
| 1274 |
self,
|
| 1275 |
input_ids,
|
|
|
|
| 1279 |
is_first_iteration=False,
|
| 1280 |
**kwargs,
|
| 1281 |
):
|
| 1282 |
+
legacy_state = kwargs.pop("past_key_values", None)
|
| 1283 |
+
if state is None:
|
| 1284 |
+
state = legacy_state
|
| 1285 |
# `state is not None` does not by itself mean decode: callers can provide
|
| 1286 |
# an empty preallocated state for the initial prompt, or a carried state
|
| 1287 |
# followed by a multi-token continuation. GenerationMixin tells us how
|
|
|
|
| 1319 |
position_ids: torch.LongTensor | None = None,
|
| 1320 |
inputs_embeds: torch.FloatTensor | None = None,
|
| 1321 |
state: Rwkv7Cache | None = None,
|
| 1322 |
+
past_key_values: Rwkv7Cache | None = None,
|
| 1323 |
labels: torch.LongTensor | None = None,
|
| 1324 |
use_cache: bool | None = None,
|
| 1325 |
output_attentions: bool | None = None,
|
|
|
|
| 1340 |
so `generate` declined to pass it and a caller who passed it was quietly
|
| 1341 |
ignored.
|
| 1342 |
"""
|
| 1343 |
+
if state is None:
|
| 1344 |
+
state = past_key_values
|
| 1345 |
if labels is not None and use_cache is None:
|
| 1346 |
use_cache = False
|
| 1347 |
outputs = self.rwkv7(
|
|
|
|
| 1366 |
if labels is not None:
|
| 1367 |
loss = self.loss_function(logits, labels, self.config.vocab_size, **kwargs)
|
| 1368 |
|
| 1369 |
+
return Rwkv7CausalLMOutput(
|
| 1370 |
+
loss=loss,
|
| 1371 |
+
logits=logits,
|
| 1372 |
+
state=outputs.state,
|
| 1373 |
+
past_key_values=outputs.state,
|
| 1374 |
+
hidden_states=outputs.hidden_states,
|
| 1375 |
+
)
|
| 1376 |
|
| 1377 |
|
| 1378 |
__all__ = ["Rwkv7Cache", "Rwkv7PreTrainedModel", "Rwkv7Model", "Rwkv7ForCausalLM"]
|
release-manifest.json
CHANGED
|
@@ -18,6 +18,7 @@
|
|
| 18 |
"tensor_count": 798,
|
| 19 |
"tensor_map_sha256": "03131ced241e7b0f86869363b3969ead6ef58462f23d9f04e56e26d00565aefc"
|
| 20 |
},
|
|
|
|
| 21 |
"files": {
|
| 22 |
".gitattributes": {
|
| 23 |
"role": "metadata",
|
|
@@ -36,8 +37,8 @@
|
|
| 36 |
},
|
| 37 |
"README.md": {
|
| 38 |
"role": "model_card",
|
| 39 |
-
"sha256": "
|
| 40 |
-
"size_bytes":
|
| 41 |
},
|
| 42 |
"chat_template.jinja": {
|
| 43 |
"role": "tokenizer",
|
|
@@ -51,8 +52,8 @@
|
|
| 51 |
},
|
| 52 |
"configuration_rwkv7.py": {
|
| 53 |
"role": "model_code",
|
| 54 |
-
"sha256": "
|
| 55 |
-
"size_bytes":
|
| 56 |
},
|
| 57 |
"generation_config.json": {
|
| 58 |
"role": "model_config",
|
|
@@ -76,8 +77,8 @@
|
|
| 76 |
},
|
| 77 |
"inference/requirements.txt": {
|
| 78 |
"role": "inference",
|
| 79 |
-
"sha256": "
|
| 80 |
-
"size_bytes":
|
| 81 |
},
|
| 82 |
"inference/runtime.py": {
|
| 83 |
"role": "inference",
|
|
@@ -91,8 +92,8 @@
|
|
| 91 |
},
|
| 92 |
"modeling_rwkv7.py": {
|
| 93 |
"role": "model_code",
|
| 94 |
-
"sha256": "
|
| 95 |
-
"size_bytes":
|
| 96 |
},
|
| 97 |
"tokenizer.json": {
|
| 98 |
"role": "tokenizer",
|
|
@@ -139,8 +140,9 @@
|
|
| 139 |
"provenance": "locked-profile"
|
| 140 |
},
|
| 141 |
"model_code": {
|
| 142 |
-
"format_version":
|
| 143 |
"patches": [
|
|
|
|
| 144 |
"layer-zero-value-residual-buffers",
|
| 145 |
"trainer-past-key-values-placeholder",
|
| 146 |
"trl-position-ids-packing-boundaries",
|
|
@@ -151,18 +153,19 @@
|
|
| 151 |
"sources": {
|
| 152 |
"configuration_rwkv7.py": {
|
| 153 |
"asset_path": "model_code/configuration_rwkv7.py",
|
| 154 |
-
"output_sha256": "
|
| 155 |
"repository_path": "src/transformers/models/rwkv7/configuration_rwkv7.py",
|
| 156 |
"source_sha256": "6f5b92c5fe7498ad22b0054a2f735a7ca82e7577436f4ad32f0fc27d1e900fdd"
|
| 157 |
},
|
| 158 |
"modeling_rwkv7.py": {
|
| 159 |
"asset_path": "model_code/modeling_rwkv7.py",
|
| 160 |
-
"output_sha256": "
|
| 161 |
"repository_path": "src/transformers/models/rwkv7/modeling_rwkv7.py",
|
| 162 |
"source_sha256": "3e8e5af7c4eba0b5de1496aef44773d7ac1bb4d96756e6f55efaf29453d67952"
|
| 163 |
}
|
| 164 |
},
|
| 165 |
-
"
|
|
|
|
| 166 |
},
|
| 167 |
"profile": {
|
| 168 |
"checkpoint": "g1i-1.5b-20260805",
|
|
@@ -326,7 +329,7 @@
|
|
| 326 |
}
|
| 327 |
}
|
| 328 |
},
|
| 329 |
-
"schema_version":
|
| 330 |
"source": {
|
| 331 |
"filename": "rwkv7-g1i-1.5b-20260805-ctx16384.pth",
|
| 332 |
"kind": "huggingface",
|
|
|
|
| 18 |
"tensor_count": 798,
|
| 19 |
"tensor_map_sha256": "03131ced241e7b0f86869363b3969ead6ef58462f23d9f04e56e26d00565aefc"
|
| 20 |
},
|
| 21 |
+
"derivation": null,
|
| 22 |
"files": {
|
| 23 |
".gitattributes": {
|
| 24 |
"role": "metadata",
|
|
|
|
| 37 |
},
|
| 38 |
"README.md": {
|
| 39 |
"role": "model_card",
|
| 40 |
+
"sha256": "62d2cfb899bd1ed68bef0c5b51fe26f88937c87f8dbe19482a99f1d35d3f9794",
|
| 41 |
+
"size_bytes": 11597
|
| 42 |
},
|
| 43 |
"chat_template.jinja": {
|
| 44 |
"role": "tokenizer",
|
|
|
|
| 52 |
},
|
| 53 |
"configuration_rwkv7.py": {
|
| 54 |
"role": "model_code",
|
| 55 |
+
"sha256": "2ef125dc431b540ada5fec14e0df16cc9af6c921ece55f13016c7d323ca5f98a",
|
| 56 |
+
"size_bytes": 7933
|
| 57 |
},
|
| 58 |
"generation_config.json": {
|
| 59 |
"role": "model_config",
|
|
|
|
| 77 |
},
|
| 78 |
"inference/requirements.txt": {
|
| 79 |
"role": "inference",
|
| 80 |
+
"sha256": "289e514cb8a38aef51615a254abb514d0eed4556f4901eb910a1191e9e084199",
|
| 81 |
+
"size_bytes": 94
|
| 82 |
},
|
| 83 |
"inference/runtime.py": {
|
| 84 |
"role": "inference",
|
|
|
|
| 92 |
},
|
| 93 |
"modeling_rwkv7.py": {
|
| 94 |
"role": "model_code",
|
| 95 |
+
"sha256": "7134c72d46ca6b6b8b152444d546bc2a129f8ea430279fa3baf6507a101800e5",
|
| 96 |
+
"size_bytes": 65301
|
| 97 |
},
|
| 98 |
"tokenizer.json": {
|
| 99 |
"role": "tokenizer",
|
|
|
|
| 140 |
"provenance": "locked-profile"
|
| 141 |
},
|
| 142 |
"model_code": {
|
| 143 |
+
"format_version": 3,
|
| 144 |
"patches": [
|
| 145 |
+
"transformers-5.3-config-and-cache-compatibility",
|
| 146 |
"layer-zero-value-residual-buffers",
|
| 147 |
"trainer-past-key-values-placeholder",
|
| 148 |
"trl-position-ids-packing-boundaries",
|
|
|
|
| 153 |
"sources": {
|
| 154 |
"configuration_rwkv7.py": {
|
| 155 |
"asset_path": "model_code/configuration_rwkv7.py",
|
| 156 |
+
"output_sha256": "2ef125dc431b540ada5fec14e0df16cc9af6c921ece55f13016c7d323ca5f98a",
|
| 157 |
"repository_path": "src/transformers/models/rwkv7/configuration_rwkv7.py",
|
| 158 |
"source_sha256": "6f5b92c5fe7498ad22b0054a2f735a7ca82e7577436f4ad32f0fc27d1e900fdd"
|
| 159 |
},
|
| 160 |
"modeling_rwkv7.py": {
|
| 161 |
"asset_path": "model_code/modeling_rwkv7.py",
|
| 162 |
+
"output_sha256": "7134c72d46ca6b6b8b152444d546bc2a129f8ea430279fa3baf6507a101800e5",
|
| 163 |
"repository_path": "src/transformers/models/rwkv7/modeling_rwkv7.py",
|
| 164 |
"source_sha256": "3e8e5af7c4eba0b5de1496aef44773d7ac1bb4d96756e6f55efaf29453d67952"
|
| 165 |
}
|
| 166 |
},
|
| 167 |
+
"transformers_max_version": "6",
|
| 168 |
+
"transformers_min_version": "5.3"
|
| 169 |
},
|
| 170 |
"profile": {
|
| 171 |
"checkpoint": "g1i-1.5b-20260805",
|
|
|
|
| 329 |
}
|
| 330 |
}
|
| 331 |
},
|
| 332 |
+
"schema_version": 9,
|
| 333 |
"source": {
|
| 334 |
"filename": "rwkv7-g1i-1.5b-20260805-ctx16384.pth",
|
| 335 |
"kind": "huggingface",
|