Instructions to use RWKV/RWKV7-1.5B-20260805 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use RWKV/RWKV7-1.5B-20260805 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="RWKV/RWKV7-1.5B-20260805") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("RWKV/RWKV7-1.5B-20260805", device_map="auto") - RWKV
How to use RWKV/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 RWKV/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 "RWKV/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": "RWKV/RWKV7-1.5B-20260805", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/RWKV/RWKV7-1.5B-20260805
- SGLang
How to use RWKV/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 "RWKV/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": "RWKV/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 "RWKV/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": "RWKV/RWKV7-1.5B-20260805", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use RWKV/RWKV7-1.5B-20260805 with Docker Model Runner:
docker model run hf.co/RWKV/RWKV7-1.5B-20260805
Upload folder using huggingface_hub
Browse files- .gitattributes +3 -35
- LICENSE +201 -0
- NOTICE +3 -0
- README.md +203 -0
- chat_template.jinja +56 -0
- config.json +26 -0
- generation_config.json +6 -0
- inference/generate.py +217 -0
- inference/kernel.py +0 -0
- inference/model_loader.py +178 -0
- inference/requirements.txt +5 -0
- inference/runtime.py +0 -0
- model.safetensors +3 -0
- release-manifest.json +282 -0
- tokenizer.json +0 -0
- tokenizer_config.json +19 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,3 @@
|
|
| 1 |
-
*.
|
| 2 |
-
*.
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LICENSE
ADDED
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and do not
|
| 117 |
+
modify the License. You may add Your own attribution notices
|
| 118 |
+
within Derivative Works that You distribute, alongside or as an
|
| 119 |
+
addendum to the NOTICE text from the Work, provided that such
|
| 120 |
+
additional attribution notices cannot be construed as modifying
|
| 121 |
+
the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer, and
|
| 167 |
+
charge a fee for, acceptance of support, warranty, indemnity, or
|
| 168 |
+
other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
NOTICE
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
RWKV-7 model release
|
| 2 |
+
Source: rwkv7-g1i-1.5b-20260805-ctx16384.pth
|
| 3 |
+
Exported inference bundle licensed under Apache-2.0.
|
README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 15 |
+
---
|
| 16 |
+
|
| 17 |
+
<!-- markdownlint-disable first-line-h1 -->
|
| 18 |
+
<!-- markdownlint-disable html -->
|
| 19 |
+
|
| 20 |
+
<div align="center">
|
| 21 |
+
<a href="https://www.rwkv.com/">
|
| 22 |
+
<img src="https://www.rwkv.com/images/avatar.png" width="140" alt="RWKV logo" />
|
| 23 |
+
</a>
|
| 24 |
+
<h1>RWKV7-1.5B-20260805</h1>
|
| 25 |
+
<p><strong>RWKV-7 “Goose” · constant-state recurrent language modeling</strong></p>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
<div align="center">
|
| 29 |
+
<a href="https://www.rwkv.com/"><img alt="Website" src="https://img.shields.io/badge/Website-RWKV-16a7c9" /></a>
|
| 30 |
+
<a href="https://huggingface.co/BlinkDL"><img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-BlinkDL-ffc107" /></a>
|
| 31 |
+
<a href="https://github.com/BlinkDL/RWKV-LM"><img alt="GitHub" src="https://img.shields.io/badge/GitHub-RWKV--LM-181717?logo=github" /></a>
|
| 32 |
+
<a href="https://arxiv.org/abs/2503.14456v2"><img alt="RWKV-7 paper" src="https://img.shields.io/badge/Paper-arXiv%3A2503.14456-b31b1b" /></a>
|
| 33 |
+
<img alt="Weight license metadata" src="https://img.shields.io/badge/Weight%20license-other-lightgrey" />
|
| 34 |
+
</div>
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
## Model introduction
|
| 39 |
+
|
| 40 |
+
This is an official BlinkDL release of **RWKV-7 Goose** in Hugging Face
|
| 41 |
+
Transformers format. RWKV-7 is an attention-free recurrent architecture with a
|
| 42 |
+
constant-size recurrent state and constant inference work per generated token.
|
| 43 |
+
Training remains parallelizable.
|
| 44 |
+
|
| 45 |
+
This is an unregistered checkpoint. The publisher does not assert its training corpus, language coverage, or post-training status; consult the source owner before use.
|
| 46 |
+
|
| 47 |
+
The Transformers integration, conversion, release packaging, Fast Tokenizer, and
|
| 48 |
+
optional TileLang inference implementation are distributed with this release.
|
| 49 |
+
|
| 50 |
+
## Highlights
|
| 51 |
+
|
| 52 |
+
- **Constant recurrent state:** memory does not grow like an attention KV cache.
|
| 53 |
+
- **Native Transformers layout:** standard config, sharded safetensors, generation,
|
| 54 |
+
recurrent cache continuation, training, and LoRA workflows.
|
| 55 |
+
- **Exact Fast Tokenizer:** self-contained Rust-backed `tokenizer.json`, generated
|
| 56 |
+
from the canonical RWKV World byte vocabulary during conversion.
|
| 57 |
+
- **Chat-ready:** `chat_template.jinja` supports system, multi-turn, thinking, and
|
| 58 |
+
strict model-generated tool-call prompts.
|
| 59 |
+
- **Optional optimized runtime:** the isolated [`inference/`](inference/) bundle
|
| 60 |
+
provides PyTorch fallback and TileLang acceleration without changing the
|
| 61 |
+
standard model root.
|
| 62 |
+
|
| 63 |
+
## Model overview
|
| 64 |
+
|
| 65 |
+
| Field | Value |
|
| 66 |
+
| --- | --- |
|
| 67 |
+
| Repository | `BlinkDL/RWKV7-1.5B-20260805` |
|
| 68 |
+
| Architecture class | `Rwkv7ForCausalLM` |
|
| 69 |
+
| Public size label | `1.5`B |
|
| 70 |
+
| Source parameters | `1,527,668,736` |
|
| 71 |
+
| Serialized parameters | `1,527,668,736` |
|
| 72 |
+
| Synthesized compatibility tensors | `0` |
|
| 73 |
+
| Layers | `24` |
|
| 74 |
+
| Hidden / FFN size | `2048` / `8192` |
|
| 75 |
+
| Heads / head size | `32` / `64` |
|
| 76 |
+
| Vocabulary | `65536` |
|
| 77 |
+
| Training context | `not declared` |
|
| 78 |
+
| Weight dtype | `bfloat16` |
|
| 79 |
+
| Numerical conversion | `source dtype preserved` |
|
| 80 |
+
| Metadata profile | `none` |
|
| 81 |
+
| Metadata provenance | `none` |
|
| 82 |
+
| Source checkpoint | `rwkv7-g1i-1.5b-20260805-ctx16384.pth` (unregistered local source) |
|
| 83 |
+
| Source SHA-256 | `32ef7b5bf4dc8bde843cf26dfad809a1f527e2e76a9e790e7d406e71bcd785da` |
|
| 84 |
+
|
| 85 |
+
## Transformers quickstart
|
| 86 |
+
|
| 87 |
+
Native `rwkv7` auto-class registration requires Transformers 5.15 or a current
|
| 88 |
+
source checkout until that release is available.
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
import torch
|
| 92 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 93 |
+
|
| 94 |
+
model_id = "BlinkDL/RWKV7-1.5B-20260805"
|
| 95 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 96 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16)
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
The recurrent cache returned by the model can be passed back for incremental
|
| 100 |
+
decoding. Use an `attention_mask` for padded batches.
|
| 101 |
+
|
| 102 |
+
## Chat quickstart
|
| 103 |
+
|
| 104 |
+
```python
|
| 105 |
+
import torch
|
| 106 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 107 |
+
|
| 108 |
+
model_id = "BlinkDL/RWKV7-1.5B-20260805"
|
| 109 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 110 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 111 |
+
model_id,
|
| 112 |
+
dtype=torch.bfloat16,
|
| 113 |
+
).to("cuda")
|
| 114 |
+
|
| 115 |
+
messages = [{"role": "user", "content": "Explain why RWKV uses constant state."}]
|
| 116 |
+
input_ids = tokenizer.apply_chat_template(
|
| 117 |
+
messages,
|
| 118 |
+
tokenize=True,
|
| 119 |
+
add_generation_prompt=True,
|
| 120 |
+
thinking=False,
|
| 121 |
+
return_tensors="pt",
|
| 122 |
+
).to(model.device)
|
| 123 |
+
|
| 124 |
+
output = model.generate(
|
| 125 |
+
input_ids,
|
| 126 |
+
max_new_tokens=256,
|
| 127 |
+
do_sample=True,
|
| 128 |
+
temperature=1.0,
|
| 129 |
+
top_p=0.5,
|
| 130 |
+
eos_token_id=0,
|
| 131 |
+
pad_token_id=0,
|
| 132 |
+
)
|
| 133 |
+
print(tokenizer.decode(output[0, input_ids.shape[1]:], skip_special_tokens=True))
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
Set `thinking=True` for the RWKV thinking prefix. The intentional generation
|
| 137 |
+
prefixes are `Assistant: <think></think` and `Assistant: <think`; do not append a
|
| 138 |
+
closing `>` to them. Reference stops are token ID `0` and `\n\nUser:`.
|
| 139 |
+
|
| 140 |
+
Strip trailing spaces from user input. The official RWKV prompt guide is available
|
| 141 |
+
in [`RWKV7-G1x-templates.txt`](https://github.com/BlinkDL/RWKV-LM/blob/main/RWKV-v7/RWKV7-G1x-templates.txt).
|
| 142 |
+
|
| 143 |
+
## Optimized local inference
|
| 144 |
+
|
| 145 |
+
Install the versions listed in `inference/requirements.txt`, then run the bundled
|
| 146 |
+
interactive chat:
|
| 147 |
+
|
| 148 |
+
```bash
|
| 149 |
+
python inference/generate.py --model BlinkDL/RWKV7-1.5B-20260805 --backend auto --interactive
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
Or independent prompts separated by blank lines:
|
| 153 |
+
|
| 154 |
+
```bash
|
| 155 |
+
python inference/generate.py \
|
| 156 |
+
--model BlinkDL/RWKV7-1.5B-20260805 \
|
| 157 |
+
--backend auto \
|
| 158 |
+
--input-file prompts.txt
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
`--backend auto` uses validated exact optimized boundaries and otherwise falls
|
| 162 |
+
back to PyTorch. Full explicit TileLang execution can change floating-point
|
| 163 |
+
operation order and requires checkpoint-, dtype-, shape-, and device-specific
|
| 164 |
+
parity validation.
|
| 165 |
+
|
| 166 |
+
## Tokenizer
|
| 167 |
+
|
| 168 |
+
The model root contains one self-contained tokenizer artifact: `tokenizer.json`.
|
| 169 |
+
Textual `vocab.json` and `rwkv_vocab_v20230424.txt` files are intentionally omitted
|
| 170 |
+
because they would duplicate the tokenizer used by Transformers.
|
| 171 |
+
|
| 172 |
+
## Intended use and limitations
|
| 173 |
+
|
| 174 |
+
- This is a base causal language model. Quality, instruction following, and
|
| 175 |
+
language behavior depend on the checkpoint and downstream prompting or
|
| 176 |
+
post-training.
|
| 177 |
+
- Assisted or speculative decoding that requires recurrent-cache rollback is not
|
| 178 |
+
supported without retaining prior state snapshots.
|
| 179 |
+
- Optimized support depends on GPU architecture, dtype, batch, and shape.
|
| 180 |
+
Unsupported `auto` configurations fall back to pure PyTorch.
|
| 181 |
+
- Explicit full TileLang execution can change floating-point operation order and
|
| 182 |
+
requires checkpoint-, dtype-, shape-, and device-specific parity validation.
|
| 183 |
+
- No safety, bias, toxicity, factuality, or high-stakes-use evaluation is claimed
|
| 184 |
+
by this model card.
|
| 185 |
+
|
| 186 |
+
## License and provenance
|
| 187 |
+
|
| 188 |
+
The exported inference bundle is licensed under [Apache-2.0](LICENSE). This publisher does not assert a license for the unregistered model weights. See [`NOTICE`](NOTICE) and the source checkpoint link above for
|
| 189 |
+
provenance.
|
| 190 |
+
|
| 191 |
+
## Citation
|
| 192 |
+
|
| 193 |
+
```bibtex
|
| 194 |
+
@misc{peng2025250314456,
|
| 195 |
+
title = {RWKV-7 "Goose" with Expressive Dynamic State Evolution},
|
| 196 |
+
author = {Bo Peng and Ruichong Zhang and Daniel Goldstein and Eric Alcaide and Xingjian Du and Haowen Hou and Jiaju Lin and Jiaxing Liu and Janna Lu and William Merrill and Guangyu Song and Kaifeng Tan and Saiteja Utpala and Nathan Wilce and Johan S. Wind and Tianyi Wu and Daniel Wuttke and Christian Zhou-Zheng},
|
| 197 |
+
year = {2025},
|
| 198 |
+
eprint = {2503.14456v2},
|
| 199 |
+
archivePrefix = {arXiv},
|
| 200 |
+
primaryClass = {cs.CL},
|
| 201 |
+
url = {https://arxiv.org/abs/2503.14456v2},
|
| 202 |
+
}
|
| 203 |
+
```
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- set add_generation_prompt = add_generation_prompt | default(true) -%}
|
| 2 |
+
{%- set thinking = thinking | default(false) -%}
|
| 3 |
+
{%- set bos_token = bos_token | default('', true) -%}
|
| 4 |
+
{%- set tools = tools | default([], true) -%}
|
| 5 |
+
{%- set ns = namespace(system_prompt='') -%}
|
| 6 |
+
{%- for message in messages -%}
|
| 7 |
+
{%- if message.role == 'system' -%}
|
| 8 |
+
{%- set ns.system_prompt = message.content | trim -%}
|
| 9 |
+
{%- endif -%}
|
| 10 |
+
{%- endfor -%}
|
| 11 |
+
{{- bos_token -}}
|
| 12 |
+
{%- if ns.system_prompt or tools | length > 0 -%}
|
| 13 |
+
{{ 'System: ' }}{{ ns.system_prompt }}
|
| 14 |
+
{%- if tools | length > 0 -%}
|
| 15 |
+
{%- if ns.system_prompt %}{{ '\n' }}{%- endif -%}
|
| 16 |
+
{{ 'Tools:\n' -}}
|
| 17 |
+
{{ tools | tojson }}
|
| 18 |
+
{{ '\nWhen using a tool, return only a compact JSON function call in a ```json block, like {"name":"calculator","arguments":{"expression":"2+2"}}. The `name` field must be top-level, never inside `arguments`. Do not copy the tool schema into arguments. Otherwise answer normally.' }}
|
| 19 |
+
{%- endif -%}
|
| 20 |
+
{{ '\n\n' }}
|
| 21 |
+
{%- endif -%}
|
| 22 |
+
{%- for message in messages -%}
|
| 23 |
+
{%- if message.role == 'user' -%}
|
| 24 |
+
{{ 'User: ' ~ (message.content | trim) ~ '\n\n' }}
|
| 25 |
+
{%- elif message.role == 'assistant' -%}
|
| 26 |
+
{%- set content = message.content | default('', true) | trim -%}
|
| 27 |
+
{{ 'Assistant:' }}
|
| 28 |
+
{%- if message.tool_calls is defined and message.tool_calls | length > 0 -%}
|
| 29 |
+
{%- if content %}{{ ' ' ~ content ~ '\n' }}{%- endif -%}
|
| 30 |
+
{%- for tool_call in message.tool_calls -%}
|
| 31 |
+
{%- if tool_call.function is defined -%}
|
| 32 |
+
{%- set name = tool_call.function.name | default('') -%}
|
| 33 |
+
{%- set args = tool_call.function.arguments | default({}, true) -%}
|
| 34 |
+
{%- else -%}
|
| 35 |
+
{%- set name = tool_call.name | default('') -%}
|
| 36 |
+
{%- set args = tool_call.arguments | default({}, true) -%}
|
| 37 |
+
{%- endif -%}
|
| 38 |
+
{{ ' ```json\n' -}}
|
| 39 |
+
{{ '{"name": ' }}{{ name | tojson }}{{ ', "arguments": ' }}{% if args is string %}{{ args }}{% else %}{{ args | tojson }}{% endif %}{{ '}\n' -}}
|
| 40 |
+
{{ '```' }}{{ '\n' if not loop.last else '' }}
|
| 41 |
+
{%- endfor -%}
|
| 42 |
+
{%- elif content -%}
|
| 43 |
+
{{ ' ' ~ content }}
|
| 44 |
+
{%- endif -%}
|
| 45 |
+
{{ '\n\n' }}
|
| 46 |
+
{%- elif message.role == 'tool' -%}
|
| 47 |
+
{{ 'User: Function output:\n' ~ (message.content | trim) ~ '\n\n' }}
|
| 48 |
+
{%- endif -%}
|
| 49 |
+
{%- endfor -%}
|
| 50 |
+
{%- if add_generation_prompt -%}
|
| 51 |
+
{%- if thinking -%}
|
| 52 |
+
{{ 'Assistant: <think' }}
|
| 53 |
+
{%- else -%}
|
| 54 |
+
{{ 'Assistant: <think></think' }}
|
| 55 |
+
{%- endif -%}
|
| 56 |
+
{%- endif -%}
|
config.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"a_low_rank_dim": 96,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"Rwkv7ForCausalLM"
|
| 5 |
+
],
|
| 6 |
+
"bos_token_id": 0,
|
| 7 |
+
"decay_low_rank_dim": 96,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"eos_token_id": 0,
|
| 10 |
+
"gate_low_rank_dim": 256,
|
| 11 |
+
"head_dim": 64,
|
| 12 |
+
"hidden_size": 2048,
|
| 13 |
+
"intermediate_size": 8192,
|
| 14 |
+
"model_type": "rwkv7",
|
| 15 |
+
"norm_bias": true,
|
| 16 |
+
"norm_eps": 1e-05,
|
| 17 |
+
"num_heads": 32,
|
| 18 |
+
"num_hidden_layers": 24,
|
| 19 |
+
"pad_token_id": 0,
|
| 20 |
+
"tie_word_embeddings": false,
|
| 21 |
+
"use_cache": true,
|
| 22 |
+
"v_low_rank_dim": 64,
|
| 23 |
+
"vocab_size": 65536,
|
| 24 |
+
"wkv_implementation": "eager",
|
| 25 |
+
"wkv_state_dtype": "float32"
|
| 26 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 0,
|
| 3 |
+
"eos_token_id": 0,
|
| 4 |
+
"pad_token_id": 0,
|
| 5 |
+
"use_cache": true
|
| 6 |
+
}
|
inference/generate.py
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import importlib
|
| 5 |
+
import os
|
| 6 |
+
import re
|
| 7 |
+
import sys
|
| 8 |
+
from types import ModuleType
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
import torch
|
| 13 |
+
from transformers import StoppingCriteria, StoppingCriteriaList
|
| 14 |
+
|
| 15 |
+
if __package__ in {None, ""}:
|
| 16 |
+
package_name = "_rwkv7_release_inference"
|
| 17 |
+
package = ModuleType(package_name)
|
| 18 |
+
package.__package__ = package_name
|
| 19 |
+
package.__path__ = [str(Path(__file__).resolve().parent)]
|
| 20 |
+
sys.modules[package_name] = package
|
| 21 |
+
load_model_and_tokenizer = importlib.import_module(
|
| 22 |
+
f"{package_name}.model_loader"
|
| 23 |
+
).load_model_and_tokenizer
|
| 24 |
+
else:
|
| 25 |
+
from .model_loader import load_model_and_tokenizer
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
DTYPES = {
|
| 29 |
+
"bfloat16": torch.bfloat16,
|
| 30 |
+
"float16": torch.float16,
|
| 31 |
+
"float32": torch.float32,
|
| 32 |
+
}
|
| 33 |
+
STOP_TEXT = "\n\nUser:"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class StopOnText(StoppingCriteria):
|
| 37 |
+
def __init__(self, tokenizer: Any, prompt_length: int, stop_text: str) -> None:
|
| 38 |
+
self.tokenizer = tokenizer
|
| 39 |
+
self.prompt_length = prompt_length
|
| 40 |
+
self.stop_text = stop_text
|
| 41 |
+
|
| 42 |
+
def __call__(
|
| 43 |
+
self,
|
| 44 |
+
input_ids: torch.LongTensor,
|
| 45 |
+
scores: torch.FloatTensor,
|
| 46 |
+
**kwargs: Any,
|
| 47 |
+
) -> bool:
|
| 48 |
+
del scores, kwargs
|
| 49 |
+
completion = self.tokenizer.decode(
|
| 50 |
+
input_ids[0, self.prompt_length :],
|
| 51 |
+
skip_special_tokens=False,
|
| 52 |
+
)
|
| 53 |
+
return self.stop_text in completion
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _prompt_ids(tokenizer: Any, messages: list[dict[str, str]], thinking: bool):
|
| 57 |
+
tokens = tokenizer.apply_chat_template(
|
| 58 |
+
messages,
|
| 59 |
+
tokenize=True,
|
| 60 |
+
add_generation_prompt=True,
|
| 61 |
+
thinking=thinking,
|
| 62 |
+
return_tensors="pt",
|
| 63 |
+
)
|
| 64 |
+
if hasattr(tokens, "input_ids"):
|
| 65 |
+
tokens = tokens.input_ids
|
| 66 |
+
elif isinstance(tokens, dict):
|
| 67 |
+
tokens = tokens["input_ids"]
|
| 68 |
+
if tokens.ndim == 1:
|
| 69 |
+
tokens = tokens.unsqueeze(0)
|
| 70 |
+
return tokens
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
@torch.inference_mode()
|
| 74 |
+
def generate_completion(
|
| 75 |
+
model: Any,
|
| 76 |
+
tokenizer: Any,
|
| 77 |
+
messages: list[dict[str, str]],
|
| 78 |
+
*,
|
| 79 |
+
device: str,
|
| 80 |
+
max_new_tokens: int,
|
| 81 |
+
temperature: float,
|
| 82 |
+
top_p: float,
|
| 83 |
+
thinking: bool,
|
| 84 |
+
) -> str:
|
| 85 |
+
input_ids = _prompt_ids(tokenizer, messages, thinking).to(device)
|
| 86 |
+
prompt_length = input_ids.shape[1]
|
| 87 |
+
generation: dict[str, Any] = {
|
| 88 |
+
"input_ids": input_ids,
|
| 89 |
+
"attention_mask": torch.ones_like(input_ids),
|
| 90 |
+
"max_new_tokens": max_new_tokens,
|
| 91 |
+
"do_sample": temperature > 0,
|
| 92 |
+
"eos_token_id": 0,
|
| 93 |
+
"pad_token_id": 0,
|
| 94 |
+
"stopping_criteria": StoppingCriteriaList(
|
| 95 |
+
[StopOnText(tokenizer, prompt_length, STOP_TEXT)]
|
| 96 |
+
),
|
| 97 |
+
}
|
| 98 |
+
if temperature > 0:
|
| 99 |
+
generation["temperature"] = temperature
|
| 100 |
+
generation["top_p"] = top_p
|
| 101 |
+
output = model.generate(**generation)
|
| 102 |
+
completion_ids = output[0, prompt_length:]
|
| 103 |
+
completion = tokenizer.decode(completion_ids, skip_special_tokens=True)
|
| 104 |
+
if STOP_TEXT in completion:
|
| 105 |
+
completion = completion.split(STOP_TEXT, 1)[0]
|
| 106 |
+
return completion.strip()
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def _interactive(
|
| 110 |
+
model: Any,
|
| 111 |
+
tokenizer: Any,
|
| 112 |
+
args: argparse.Namespace,
|
| 113 |
+
) -> None:
|
| 114 |
+
messages: list[dict[str, str]] = []
|
| 115 |
+
print("RWKV-7 Goose — /clear resets the conversation, /exit quits.")
|
| 116 |
+
while True:
|
| 117 |
+
try:
|
| 118 |
+
prompt = input(">>> ")
|
| 119 |
+
except EOFError:
|
| 120 |
+
break
|
| 121 |
+
if prompt == "/exit":
|
| 122 |
+
break
|
| 123 |
+
if prompt == "/clear":
|
| 124 |
+
messages.clear()
|
| 125 |
+
continue
|
| 126 |
+
prompt = prompt.strip()
|
| 127 |
+
if not prompt:
|
| 128 |
+
continue
|
| 129 |
+
messages.append({"role": "user", "content": prompt})
|
| 130 |
+
completion = generate_completion(
|
| 131 |
+
model,
|
| 132 |
+
tokenizer,
|
| 133 |
+
messages,
|
| 134 |
+
device=args.device,
|
| 135 |
+
max_new_tokens=args.max_new_tokens,
|
| 136 |
+
temperature=args.temperature,
|
| 137 |
+
top_p=args.top_p,
|
| 138 |
+
thinking=args.thinking,
|
| 139 |
+
)
|
| 140 |
+
print(completion)
|
| 141 |
+
messages.append({"role": "assistant", "content": completion})
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def _file_prompts(
|
| 145 |
+
model: Any,
|
| 146 |
+
tokenizer: Any,
|
| 147 |
+
args: argparse.Namespace,
|
| 148 |
+
) -> None:
|
| 149 |
+
text = Path(args.input_file).read_text(encoding="utf-8")
|
| 150 |
+
prompts = [prompt.strip() for prompt in re.split(r"\n\s*\n", text) if prompt.strip()]
|
| 151 |
+
if not prompts:
|
| 152 |
+
raise ValueError("input file contains no prompts")
|
| 153 |
+
for prompt in prompts:
|
| 154 |
+
completion = generate_completion(
|
| 155 |
+
model,
|
| 156 |
+
tokenizer,
|
| 157 |
+
[{"role": "user", "content": prompt}],
|
| 158 |
+
device=args.device,
|
| 159 |
+
max_new_tokens=args.max_new_tokens,
|
| 160 |
+
temperature=args.temperature,
|
| 161 |
+
top_p=args.top_p,
|
| 162 |
+
thinking=args.thinking,
|
| 163 |
+
)
|
| 164 |
+
print(f"Prompt: {prompt}")
|
| 165 |
+
print(f"Completion: {completion}")
|
| 166 |
+
print()
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def parse_args() -> argparse.Namespace:
|
| 170 |
+
parser = argparse.ArgumentParser(description="Generate with RWKV-7 Goose")
|
| 171 |
+
parser.add_argument("--model", required=True, help="Hub repo ID or local model directory")
|
| 172 |
+
mode = parser.add_mutually_exclusive_group(required=True)
|
| 173 |
+
mode.add_argument("--interactive", action="store_true")
|
| 174 |
+
mode.add_argument("--input-file")
|
| 175 |
+
parser.add_argument("--device", default="cuda")
|
| 176 |
+
parser.add_argument("--dtype", choices=("auto", *DTYPES), default="auto")
|
| 177 |
+
parser.add_argument("--state-dtype", choices=DTYPES, default="float32")
|
| 178 |
+
parser.add_argument("--backend", choices=("auto", "torch", "tilelang"), default="auto")
|
| 179 |
+
parser.add_argument("--max-new-tokens", type=int, default=300)
|
| 180 |
+
parser.add_argument("--temperature", type=float, default=1.0)
|
| 181 |
+
parser.add_argument("--top-p", type=float, default=0.5)
|
| 182 |
+
parser.add_argument("--seed", type=int, default=33377335)
|
| 183 |
+
parser.add_argument("--thinking", action="store_true")
|
| 184 |
+
return parser.parse_args()
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def main() -> None:
|
| 188 |
+
args = parse_args()
|
| 189 |
+
if int(os.getenv("WORLD_SIZE", "1")) != 1:
|
| 190 |
+
raise RuntimeError("the bundled runtime supports one process and one GPU")
|
| 191 |
+
if int(os.getenv("RANK", "0")) != 0 or int(os.getenv("LOCAL_RANK", "0")) != 0:
|
| 192 |
+
raise RuntimeError("RANK and LOCAL_RANK must be zero")
|
| 193 |
+
if args.max_new_tokens <= 0:
|
| 194 |
+
raise ValueError("max-new-tokens must be positive")
|
| 195 |
+
if args.temperature < 0:
|
| 196 |
+
raise ValueError("temperature must be non-negative")
|
| 197 |
+
if not 0 < args.top_p <= 1:
|
| 198 |
+
raise ValueError("top-p must be in (0, 1]")
|
| 199 |
+
torch.manual_seed(args.seed)
|
| 200 |
+
model, tokenizer = load_model_and_tokenizer(
|
| 201 |
+
args.model,
|
| 202 |
+
device=args.device,
|
| 203 |
+
dtype=None if args.dtype == "auto" else DTYPES[args.dtype],
|
| 204 |
+
backend=args.backend,
|
| 205 |
+
state_dtype=args.state_dtype,
|
| 206 |
+
)
|
| 207 |
+
model.set_kernel_backend(args.backend)
|
| 208 |
+
if args.backend == "tilelang":
|
| 209 |
+
model.prepare_inference_weights()
|
| 210 |
+
if args.interactive:
|
| 211 |
+
_interactive(model, tokenizer, args)
|
| 212 |
+
else:
|
| 213 |
+
_file_prompts(model, tokenizer, args)
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
if __name__ == "__main__":
|
| 217 |
+
main()
|
inference/kernel.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
inference/model_loader.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
import torch
|
| 7 |
+
from huggingface_hub import snapshot_download
|
| 8 |
+
from safetensors.torch import load_file
|
| 9 |
+
from transformers import AutoTokenizer, PreTrainedConfig
|
| 10 |
+
|
| 11 |
+
from .runtime import RWKV7Config, RWKV7ForCausalLM
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
SQUEEZE_MARKERS = (
|
| 15 |
+
".x_",
|
| 16 |
+
".k_",
|
| 17 |
+
"att.r",
|
| 18 |
+
"att.w",
|
| 19 |
+
"att.v0",
|
| 20 |
+
"att.v1",
|
| 21 |
+
"att.v2",
|
| 22 |
+
"att.a",
|
| 23 |
+
"att.g",
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _resolve_model(model: str) -> tuple[Path, bool]:
|
| 28 |
+
local = Path(model).expanduser()
|
| 29 |
+
if local.is_dir():
|
| 30 |
+
return local.resolve(), False
|
| 31 |
+
return Path(snapshot_download(model)), True
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _optimized_config(native: dict, backend: str, state_dtype: str) -> RWKV7Config:
|
| 35 |
+
return RWKV7Config(
|
| 36 |
+
vocab_size=native["vocab_size"],
|
| 37 |
+
hidden_size=native["hidden_size"],
|
| 38 |
+
num_hidden_layers=native["num_hidden_layers"],
|
| 39 |
+
head_size=native["head_dim"],
|
| 40 |
+
intermediate_size=native["intermediate_size"],
|
| 41 |
+
decay_lora_rank=native["decay_low_rank_dim"],
|
| 42 |
+
a_lora_rank=native["a_low_rank_dim"],
|
| 43 |
+
gate_lora_rank=native["gate_low_rank_dim"],
|
| 44 |
+
value_lora_rank=native["v_low_rank_dim"],
|
| 45 |
+
layer_norm_epsilon=native.get("norm_eps", 1e-5),
|
| 46 |
+
use_cache=native.get("use_cache", True),
|
| 47 |
+
kernel_backend=backend,
|
| 48 |
+
recurrent_state_dtype=state_dtype,
|
| 49 |
+
tie_word_embeddings=native.get("tie_word_embeddings", False),
|
| 50 |
+
bos_token_id=native.get("bos_token_id"),
|
| 51 |
+
eos_token_id=native.get("eos_token_id", 0),
|
| 52 |
+
pad_token_id=native.get("pad_token_id", 0),
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _native_key_to_optimized(key: str) -> str:
|
| 57 |
+
return key.removeprefix("rwkv7.")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _native_tensor_to_optimized(key: str, tensor: torch.Tensor) -> torch.Tensor:
|
| 61 |
+
return tensor.squeeze() if any(marker in key for marker in SQUEEZE_MARKERS) else tensor
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _checked_weight(path: Path, *, hub_snapshot: bool) -> Path:
|
| 65 |
+
if path.is_symlink():
|
| 66 |
+
if not hub_snapshot:
|
| 67 |
+
raise RuntimeError(f"local safetensor must not be a symlink: {path.name}")
|
| 68 |
+
path = path.resolve(strict=True)
|
| 69 |
+
if not path.is_file():
|
| 70 |
+
raise RuntimeError(f"safetensor must be a regular file: {path.name}")
|
| 71 |
+
return path
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _weight_plan(
|
| 75 |
+
model_dir: Path, *, hub_snapshot: bool
|
| 76 |
+
) -> list[tuple[Path, set[str] | None]]:
|
| 77 |
+
present = sorted(model_dir.glob("model*.safetensors"))
|
| 78 |
+
if not present:
|
| 79 |
+
raise FileNotFoundError(f"no safetensors found in {model_dir}")
|
| 80 |
+
checked = {
|
| 81 |
+
path.name: _checked_weight(path, hub_snapshot=hub_snapshot) for path in present
|
| 82 |
+
}
|
| 83 |
+
index_path = model_dir / "model.safetensors.index.json"
|
| 84 |
+
if not index_path.is_file():
|
| 85 |
+
if [path.name for path in present] != ["model.safetensors"]:
|
| 86 |
+
raise RuntimeError("multiple safetensors require model.safetensors.index.json")
|
| 87 |
+
return [(checked["model.safetensors"], None)]
|
| 88 |
+
|
| 89 |
+
index = json.loads(index_path.read_text(encoding="utf-8"))
|
| 90 |
+
weight_map = index.get("weight_map")
|
| 91 |
+
if not isinstance(weight_map, dict) or not weight_map:
|
| 92 |
+
raise RuntimeError("model.safetensors.index.json has no weight_map")
|
| 93 |
+
keys_by_file: dict[str, set[str]] = {}
|
| 94 |
+
for key, filename in weight_map.items():
|
| 95 |
+
if not isinstance(key, str) or not isinstance(filename, str):
|
| 96 |
+
raise RuntimeError("invalid weight_map entry")
|
| 97 |
+
keys_by_file.setdefault(filename, set()).add(key)
|
| 98 |
+
if set(keys_by_file) != {path.name for path in present}:
|
| 99 |
+
raise RuntimeError("indexed and present safetensors files differ")
|
| 100 |
+
return [(checked[filename], keys_by_file[filename]) for filename in sorted(keys_by_file)]
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def _load_native_model(
|
| 104 |
+
model_dir: Path,
|
| 105 |
+
native_config: dict,
|
| 106 |
+
backend: str,
|
| 107 |
+
state_dtype: str,
|
| 108 |
+
*,
|
| 109 |
+
hub_snapshot: bool,
|
| 110 |
+
) -> RWKV7ForCausalLM:
|
| 111 |
+
config = _optimized_config(native_config, backend, state_dtype)
|
| 112 |
+
with torch.device("meta"):
|
| 113 |
+
model = RWKV7ForCausalLM(config)
|
| 114 |
+
expected = set(model.state_dict())
|
| 115 |
+
seen: set[str] = set()
|
| 116 |
+
for weight_file, indexed_keys in _weight_plan(
|
| 117 |
+
model_dir, hub_snapshot=hub_snapshot
|
| 118 |
+
):
|
| 119 |
+
native_shard = load_file(weight_file, device="cpu")
|
| 120 |
+
if indexed_keys is not None and set(native_shard) != indexed_keys:
|
| 121 |
+
raise RuntimeError(f"tensor keys in {weight_file.name} do not match the index")
|
| 122 |
+
shard = {}
|
| 123 |
+
for native_key, tensor in native_shard.items():
|
| 124 |
+
optimized_key = _native_key_to_optimized(native_key)
|
| 125 |
+
if optimized_key in seen or optimized_key in shard:
|
| 126 |
+
raise RuntimeError(f"duplicate optimized tensor key: {optimized_key}")
|
| 127 |
+
shard[optimized_key] = _native_tensor_to_optimized(optimized_key, tensor)
|
| 128 |
+
unexpected = sorted(set(shard) - expected)
|
| 129 |
+
if unexpected:
|
| 130 |
+
raise RuntimeError(f"native checkpoint has unexpected keys: {unexpected}")
|
| 131 |
+
model.load_state_dict(shard, strict=False, assign=True)
|
| 132 |
+
seen.update(shard)
|
| 133 |
+
missing = sorted(expected - seen)
|
| 134 |
+
if missing:
|
| 135 |
+
raise RuntimeError(f"native checkpoint is missing optimized runtime keys: {missing}")
|
| 136 |
+
return model
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _load_tokenizer(model_dir: Path):
|
| 140 |
+
return AutoTokenizer.from_pretrained(
|
| 141 |
+
model_dir,
|
| 142 |
+
config=PreTrainedConfig(),
|
| 143 |
+
local_files_only=True,
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def load_model_and_tokenizer(
|
| 148 |
+
model: str,
|
| 149 |
+
*,
|
| 150 |
+
device: str,
|
| 151 |
+
dtype: torch.dtype | None,
|
| 152 |
+
backend: str,
|
| 153 |
+
state_dtype: str,
|
| 154 |
+
):
|
| 155 |
+
model_dir, hub_snapshot = _resolve_model(model)
|
| 156 |
+
native_config = json.loads((model_dir / "config.json").read_text(encoding="utf-8"))
|
| 157 |
+
architectures = set(native_config.get("architectures", []))
|
| 158 |
+
if architectures != {"Rwkv7ForCausalLM"}:
|
| 159 |
+
raise ValueError(f"unsupported RWKV-7 architecture: {sorted(architectures)}")
|
| 160 |
+
loaded = _load_native_model(
|
| 161 |
+
model_dir,
|
| 162 |
+
native_config,
|
| 163 |
+
backend,
|
| 164 |
+
state_dtype,
|
| 165 |
+
hub_snapshot=hub_snapshot,
|
| 166 |
+
)
|
| 167 |
+
if dtype is None:
|
| 168 |
+
dtype_name = str(native_config.get("dtype", "bfloat16")).removeprefix("torch.")
|
| 169 |
+
try:
|
| 170 |
+
dtype = {
|
| 171 |
+
"bfloat16": torch.bfloat16,
|
| 172 |
+
"float16": torch.float16,
|
| 173 |
+
"float32": torch.float32,
|
| 174 |
+
}[dtype_name]
|
| 175 |
+
except KeyError as error:
|
| 176 |
+
raise ValueError(f"unsupported model dtype: {dtype_name}") from error
|
| 177 |
+
loaded = loaded.to(device=device, dtype=dtype).eval()
|
| 178 |
+
return loaded, _load_tokenizer(model_dir)
|
inference/requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers>=5.0,<6
|
| 2 |
+
huggingface-hub>=0.34
|
| 3 |
+
safetensors>=0.5
|
| 4 |
+
jinja2>=3.1,<4
|
| 5 |
+
tilelang==0.1.12
|
inference/runtime.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:84ccbb857c84e00cefc48b233937ada79c411e491df25fb21aed23237f39a14f
|
| 3 |
+
size 3055418240
|
release-manifest.json
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"builder": {
|
| 3 |
+
"asset_set": "2026.08.06-r1",
|
| 4 |
+
"assets_sha256": "6d8637e951d8ea83e0ba5bdb70ef0c378f629e4f3aecd1689dd68146807ab8a9",
|
| 5 |
+
"version": "0.2.0"
|
| 6 |
+
},
|
| 7 |
+
"conversion": {
|
| 8 |
+
"explicit_cast": false,
|
| 9 |
+
"serialized_parameter_count": 1527668736,
|
| 10 |
+
"source_float_dtypes": [
|
| 11 |
+
"bfloat16"
|
| 12 |
+
],
|
| 13 |
+
"source_parameter_count": 1527668736,
|
| 14 |
+
"synthesized_tensors": [],
|
| 15 |
+
"target_float_dtypes": [
|
| 16 |
+
"bfloat16"
|
| 17 |
+
],
|
| 18 |
+
"tensor_count": 798,
|
| 19 |
+
"tensor_map_sha256": "03131ced241e7b0f86869363b3969ead6ef58462f23d9f04e56e26d00565aefc"
|
| 20 |
+
},
|
| 21 |
+
"files": {
|
| 22 |
+
".gitattributes": {
|
| 23 |
+
"role": "metadata",
|
| 24 |
+
"sha256": "964ca37433fb68dd62bc6ef445108229a3baaf5a9905310c1a218505291ddf88",
|
| 25 |
+
"size_bytes": 137
|
| 26 |
+
},
|
| 27 |
+
"LICENSE": {
|
| 28 |
+
"role": "metadata",
|
| 29 |
+
"sha256": "205aa9f1953db0b1a40adb68b1c78d8efd2b5345d77fb67eb88cc019e03efeaf",
|
| 30 |
+
"size_bytes": 11558
|
| 31 |
+
},
|
| 32 |
+
"NOTICE": {
|
| 33 |
+
"role": "metadata",
|
| 34 |
+
"sha256": "06364166275b220e48b6d030bcd81494b2081ab6441ea0ceafb800b1c8e3fbbb",
|
| 35 |
+
"size_bytes": 122
|
| 36 |
+
},
|
| 37 |
+
"README.md": {
|
| 38 |
+
"role": "model_card",
|
| 39 |
+
"sha256": "35de71abe9fd8ecbee48976baf3f87439501daac6ac966d123326cf5734cab62",
|
| 40 |
+
"size_bytes": 7843
|
| 41 |
+
},
|
| 42 |
+
"chat_template.jinja": {
|
| 43 |
+
"role": "tokenizer",
|
| 44 |
+
"sha256": "55b3119550c7fee19d81f6ef5bc08db815f4e0d9cf4cd9722c0bba30151cac37",
|
| 45 |
+
"size_bytes": 2389
|
| 46 |
+
},
|
| 47 |
+
"config.json": {
|
| 48 |
+
"role": "model_config",
|
| 49 |
+
"sha256": "e4e63cfac48f183f9057974df3d4e4b349008d6cb302ca0b7d5763aa57e2d082",
|
| 50 |
+
"size_bytes": 592
|
| 51 |
+
},
|
| 52 |
+
"generation_config.json": {
|
| 53 |
+
"role": "model_config",
|
| 54 |
+
"sha256": "77a6775652e382c1e32d0591b2f92b1ec265976dab4bd29b534a6c2b2912b474",
|
| 55 |
+
"size_bytes": 93
|
| 56 |
+
},
|
| 57 |
+
"inference/generate.py": {
|
| 58 |
+
"role": "inference",
|
| 59 |
+
"sha256": "3689803b876841dc505b4944fe17ad25d24360d7647a04908b76eaee7c827e70",
|
| 60 |
+
"size_bytes": 7187
|
| 61 |
+
},
|
| 62 |
+
"inference/kernel.py": {
|
| 63 |
+
"role": "inference",
|
| 64 |
+
"sha256": "60bd5739597567fce1de9f5eca7c0a7da96cb5960c8f0004d367806dde448485",
|
| 65 |
+
"size_bytes": 165394
|
| 66 |
+
},
|
| 67 |
+
"inference/model_loader.py": {
|
| 68 |
+
"role": "inference",
|
| 69 |
+
"sha256": "c085dbc3cd60134f89b2bbb510f603c71624e8c4b19ae8d3bde0b3cdc820a592",
|
| 70 |
+
"size_bytes": 6630
|
| 71 |
+
},
|
| 72 |
+
"inference/requirements.txt": {
|
| 73 |
+
"role": "inference",
|
| 74 |
+
"sha256": "3a0ae4bcc4eb24026d1f57b478497e71f293f5f9c38d6b2673253f52b031d5c8",
|
| 75 |
+
"size_bytes": 97
|
| 76 |
+
},
|
| 77 |
+
"inference/runtime.py": {
|
| 78 |
+
"role": "inference",
|
| 79 |
+
"sha256": "bcaf18b458d0758f4e81ff224218df04a3206b1d5c616760ab80980fec1871e5",
|
| 80 |
+
"size_bytes": 158229
|
| 81 |
+
},
|
| 82 |
+
"model.safetensors": {
|
| 83 |
+
"role": "weights",
|
| 84 |
+
"sha256": "84ccbb857c84e00cefc48b233937ada79c411e491df25fb21aed23237f39a14f",
|
| 85 |
+
"size_bytes": 3055418240
|
| 86 |
+
},
|
| 87 |
+
"tokenizer.json": {
|
| 88 |
+
"role": "tokenizer",
|
| 89 |
+
"sha256": "1c0bc8e5f355de60a4587a1e9abb9aa4ef65508ff59641344e7f9f10f76feacf",
|
| 90 |
+
"size_bytes": 1580973
|
| 91 |
+
},
|
| 92 |
+
"tokenizer_config.json": {
|
| 93 |
+
"role": "tokenizer",
|
| 94 |
+
"sha256": "bdff25092e1b40e063569af50ccc6775ba2785a18d1a29d0a80c029d4556f9ee",
|
| 95 |
+
"size_bytes": 458
|
| 96 |
+
}
|
| 97 |
+
},
|
| 98 |
+
"identity": {
|
| 99 |
+
"parameter_label": "1.5",
|
| 100 |
+
"release_date": "20260805",
|
| 101 |
+
"training_context_length": null
|
| 102 |
+
},
|
| 103 |
+
"metadata": {
|
| 104 |
+
"context_length": null,
|
| 105 |
+
"datasets": [],
|
| 106 |
+
"languages": [],
|
| 107 |
+
"license": null,
|
| 108 |
+
"profile": null,
|
| 109 |
+
"provenance": "none"
|
| 110 |
+
},
|
| 111 |
+
"profile": {
|
| 112 |
+
"checkpoint": null,
|
| 113 |
+
"family": null
|
| 114 |
+
},
|
| 115 |
+
"runtime": {
|
| 116 |
+
"files": {
|
| 117 |
+
"kernel.py": {
|
| 118 |
+
"sha256": "88379d8979b908a01af1f06b89d8fc624d332796db6044ec4a027d7cecab1cb6"
|
| 119 |
+
},
|
| 120 |
+
"runtime.py": {
|
| 121 |
+
"sha256": "064c53ce5dfe811ea873ad9976f8f0839b55e515e604adf3c3e28fd4c02de784"
|
| 122 |
+
}
|
| 123 |
+
},
|
| 124 |
+
"format_version": 4,
|
| 125 |
+
"kernel": {
|
| 126 |
+
"format_version": 3,
|
| 127 |
+
"output": "inference/kernel.py",
|
| 128 |
+
"output_sha256": "88379d8979b908a01af1f06b89d8fc624d332796db6044ec4a027d7cecab1cb6",
|
| 129 |
+
"sources": {
|
| 130 |
+
"kernel_tilelang_decode.py": {
|
| 131 |
+
"exports": [
|
| 132 |
+
"Any",
|
| 133 |
+
"_HEAD_SIZE",
|
| 134 |
+
"_NEXP_HALF_LOG2_E",
|
| 135 |
+
"_NLOG2_E",
|
| 136 |
+
"_ROTATOR1_SIGNED",
|
| 137 |
+
"_TWO_NEG_41",
|
| 138 |
+
"_build_cmix_add_layernorm_mix_program",
|
| 139 |
+
"_build_cmix_binned_finalize_program",
|
| 140 |
+
"_build_cmix_finalize_program",
|
| 141 |
+
"_build_cmix_layernorm_mix_program",
|
| 142 |
+
"_build_cmix_sparse_atomic_program",
|
| 143 |
+
"_build_cmix_sparse_binned_program",
|
| 144 |
+
"_build_cmix_sparse_split_program",
|
| 145 |
+
"_build_cmix_value_program",
|
| 146 |
+
"_build_ffn_program",
|
| 147 |
+
"_build_gemv_program",
|
| 148 |
+
"_build_key_gate_program",
|
| 149 |
+
"_build_post_state_program",
|
| 150 |
+
"_build_rankout_program",
|
| 151 |
+
"_build_rankout_reduced_program",
|
| 152 |
+
"_build_rkv_program",
|
| 153 |
+
"_build_tmix_layernorm_mix6_program",
|
| 154 |
+
"_build_wkv_program",
|
| 155 |
+
"_build_wkv_w0_t1_program",
|
| 156 |
+
"_cmix_value_out",
|
| 157 |
+
"_compiled_cmix_add_layernorm_mix",
|
| 158 |
+
"_compiled_cmix_binned_finalize",
|
| 159 |
+
"_compiled_cmix_finalize",
|
| 160 |
+
"_compiled_cmix_layernorm_mix",
|
| 161 |
+
"_compiled_cmix_sparse_atomic",
|
| 162 |
+
"_compiled_cmix_sparse_binned",
|
| 163 |
+
"_compiled_cmix_sparse_split",
|
| 164 |
+
"_compiled_cmix_value",
|
| 165 |
+
"_compiled_ffn",
|
| 166 |
+
"_compiled_gemv",
|
| 167 |
+
"_compiled_key_gate",
|
| 168 |
+
"_compiled_post_state",
|
| 169 |
+
"_compiled_rankout",
|
| 170 |
+
"_compiled_rankout_reduced",
|
| 171 |
+
"_compiled_rkv",
|
| 172 |
+
"_compiled_tmix_layernorm_mix6",
|
| 173 |
+
"_compiled_wkv",
|
| 174 |
+
"_compiled_wkv_w0_t1",
|
| 175 |
+
"_dtype_name",
|
| 176 |
+
"_ffn_out",
|
| 177 |
+
"_post_state_out",
|
| 178 |
+
"_rankout_out",
|
| 179 |
+
"_require_contiguous_cuda",
|
| 180 |
+
"_rkv_out",
|
| 181 |
+
"_wkv_kernel_out",
|
| 182 |
+
"_wkv_out",
|
| 183 |
+
"_wkv_precise_out",
|
| 184 |
+
"_wkv_w0_t1_out",
|
| 185 |
+
"clear_tilelang_kernel_caches",
|
| 186 |
+
"cuda_arch_key",
|
| 187 |
+
"lru_cache",
|
| 188 |
+
"torch"
|
| 189 |
+
],
|
| 190 |
+
"namespace": "decode",
|
| 191 |
+
"sha256": "b582151a6d2bd345cc5f87415543370e027c8f943a4dfe57a18300f08560bd73"
|
| 192 |
+
},
|
| 193 |
+
"kernel_tilelang_state.py": {
|
| 194 |
+
"exports": [
|
| 195 |
+
"Any",
|
| 196 |
+
"BFLOAT16",
|
| 197 |
+
"CUDA_GET_DEVICE_CAPABILITY",
|
| 198 |
+
"EXACT_FUSED_STATE_PROJECTION_CAPABILITIES",
|
| 199 |
+
"FLOAT16",
|
| 200 |
+
"FLOAT32",
|
| 201 |
+
"IS_GRAD_ENABLED",
|
| 202 |
+
"TORCH_STACK",
|
| 203 |
+
"TORCH_WHERE",
|
| 204 |
+
"TORCH_ZEROS_LIKE",
|
| 205 |
+
"_compiled_backward_kernel",
|
| 206 |
+
"_compiled_fast_state_scan",
|
| 207 |
+
"_compiled_fused_state_update",
|
| 208 |
+
"_compiled_kernel",
|
| 209 |
+
"_compiled_low_precision_state_kernel",
|
| 210 |
+
"_compiled_post_state",
|
| 211 |
+
"_compiled_state_projection",
|
| 212 |
+
"_compiled_x_mix",
|
| 213 |
+
"_dtype_name",
|
| 214 |
+
"_require_exact_fused_state_projection",
|
| 215 |
+
"build_fast_state_scan_program",
|
| 216 |
+
"build_fused_state_update_program",
|
| 217 |
+
"build_low_precision_state_program",
|
| 218 |
+
"build_post_state_program",
|
| 219 |
+
"build_state_backward_program",
|
| 220 |
+
"build_state_program",
|
| 221 |
+
"build_state_projection_program",
|
| 222 |
+
"build_x_mix_program",
|
| 223 |
+
"clear_tilelang_state_kernel_caches",
|
| 224 |
+
"cuda_arch_key",
|
| 225 |
+
"exact_fused_state_projection_supported",
|
| 226 |
+
"lru_cache",
|
| 227 |
+
"tilelang_fast_state_scan",
|
| 228 |
+
"tilelang_fused_state_update",
|
| 229 |
+
"tilelang_low_precision_state_finalize",
|
| 230 |
+
"tilelang_post_state",
|
| 231 |
+
"tilelang_state_finalize",
|
| 232 |
+
"tilelang_state_finalize_backward",
|
| 233 |
+
"tilelang_state_projection",
|
| 234 |
+
"tilelang_state_scan",
|
| 235 |
+
"tilelang_state_update",
|
| 236 |
+
"tilelang_x_mix",
|
| 237 |
+
"torch",
|
| 238 |
+
"torch_state_scan",
|
| 239 |
+
"torch_state_update"
|
| 240 |
+
],
|
| 241 |
+
"namespace": "state",
|
| 242 |
+
"sha256": "a3597160cb8d7317151200d05b241af7edcad2928c3731687764d914c28bf21a"
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
},
|
| 246 |
+
"transforms": {
|
| 247 |
+
"configuration_rwkv7.py": {
|
| 248 |
+
"output_sha256": "60a060199526f5a6c4d5a2436520eed97e9f21f2ea3cb6e6584d9b5fcb6f21f4",
|
| 249 |
+
"source_sha256": "60a060199526f5a6c4d5a2436520eed97e9f21f2ea3cb6e6584d9b5fcb6f21f4"
|
| 250 |
+
},
|
| 251 |
+
"custom_ops.py": {
|
| 252 |
+
"output_sha256": "8240d4eebc9decbd5ebf8fbcc3abc0ee6441b0eb4854b8d7bc18172cd2babf17",
|
| 253 |
+
"source_sha256": "fb86e5c9dfc9deb5a1be821ce02c3a390ce5c95ff55feded6add2422f0dc3623"
|
| 254 |
+
},
|
| 255 |
+
"kernel_dispatch.py": {
|
| 256 |
+
"output_sha256": "0290559437016ba4e2c2a26f7c7a0985b6fbab991535b7ae65ba18eb421fa9e1",
|
| 257 |
+
"source_sha256": "0290559437016ba4e2c2a26f7c7a0985b6fbab991535b7ae65ba18eb421fa9e1"
|
| 258 |
+
},
|
| 259 |
+
"modeling_rwkv7.py": {
|
| 260 |
+
"output_sha256": "ad7f8c981d21a3b0361cd26a2c68234a1bfbacc31fe52b49c3fe9d79e5b32844",
|
| 261 |
+
"source_sha256": "7e1e57a4516efe78a74f971ada0fe58cb71c87102479ed7516b6d3585964ca21"
|
| 262 |
+
},
|
| 263 |
+
"state.py": {
|
| 264 |
+
"output_sha256": "d13d81af6a301a70024494f03b95006bf5f2471ba0b57fd7f1f94bd54f70f2ef",
|
| 265 |
+
"source_sha256": "d13d81af6a301a70024494f03b95006bf5f2471ba0b57fd7f1f94bd54f70f2ef"
|
| 266 |
+
},
|
| 267 |
+
"tilelang_decode.py": {
|
| 268 |
+
"output_sha256": "313120b38178642c17ef16531c4510de87dc0f0d79d80f70b6ade8818b4dfbe7",
|
| 269 |
+
"source_sha256": "fe63e6332037cacbd0400d82f65fd6f1c282e31d92906c5f34d39eb9e83eb642"
|
| 270 |
+
}
|
| 271 |
+
}
|
| 272 |
+
},
|
| 273 |
+
"schema_version": 4,
|
| 274 |
+
"source": {
|
| 275 |
+
"filename": "rwkv7-g1i-1.5b-20260805-ctx16384.pth",
|
| 276 |
+
"kind": "local",
|
| 277 |
+
"reference": null,
|
| 278 |
+
"revision": null,
|
| 279 |
+
"sha256": "32ef7b5bf4dc8bde843cf26dfad809a1f527e2e76a9e790e7d406e71bcd785da",
|
| 280 |
+
"size_bytes": 3055444605
|
| 281 |
+
}
|
| 282 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "<|endoftext|>",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
}
|
| 11 |
+
},
|
| 12 |
+
"backend": "tokenizers",
|
| 13 |
+
"bos_token": "<|endoftext|>",
|
| 14 |
+
"eos_token": "<|endoftext|>",
|
| 15 |
+
"pad_token": "<|endoftext|>",
|
| 16 |
+
"padding_side": "left",
|
| 17 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 18 |
+
"unk_token": "<|endoftext|>"
|
| 19 |
+
}
|