kernels-bot commited on
Commit
eaf0f88
·
verified ·
1 Parent(s): ffc2322

Uploaded using `kernel-builder`.

Browse files
Files changed (34) hide show
  1. .gitattributes +9 -0
  2. build/torch210-cxx11-cu126-aarch64-linux/_ops.py +3 -3
  3. build/torch210-cxx11-cu126-aarch64-linux/{_rwkv_cuda_86f75d9.abi3.so → _rwkv_cuda_dfdeb22.abi3.so} +1 -1
  4. build/torch210-cxx11-cu126-aarch64-linux/metadata.json +1 -1
  5. build/torch210-cxx11-cu128-aarch64-linux/_ops.py +3 -3
  6. build/{torch211-cxx11-cu128-aarch64-linux/_rwkv_cuda_86f75d9.abi3.so → torch210-cxx11-cu128-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so} +1 -1
  7. build/torch210-cxx11-cu128-aarch64-linux/metadata.json +1 -1
  8. build/torch210-cxx11-cu130-aarch64-linux/_ops.py +3 -3
  9. build/{torch211-cxx11-cu130-aarch64-linux/_rwkv_cuda_86f75d9.abi3.so → torch210-cxx11-cu130-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so} +1 -1
  10. build/torch210-cxx11-cu130-aarch64-linux/metadata.json +1 -1
  11. build/torch211-cxx11-cu126-aarch64-linux/_ops.py +3 -3
  12. build/torch211-cxx11-cu126-aarch64-linux/{_rwkv_cuda_86f75d9.abi3.so → _rwkv_cuda_dfdeb22.abi3.so} +1 -1
  13. build/torch211-cxx11-cu126-aarch64-linux/metadata.json +1 -1
  14. build/torch211-cxx11-cu128-aarch64-linux/_ops.py +3 -3
  15. build/{torch210-cxx11-cu128-aarch64-linux/_rwkv_cuda_86f75d9.abi3.so → torch211-cxx11-cu128-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so} +1 -1
  16. build/torch211-cxx11-cu128-aarch64-linux/metadata.json +1 -1
  17. build/torch211-cxx11-cu130-aarch64-linux/_ops.py +3 -3
  18. build/{torch210-cxx11-cu130-aarch64-linux/_rwkv_cuda_86f75d9.abi3.so → torch211-cxx11-cu130-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so} +1 -1
  19. build/torch211-cxx11-cu130-aarch64-linux/metadata.json +1 -1
  20. build/torch212-cxx11-cu126-aarch64-linux/__init__.py +170 -0
  21. build/torch212-cxx11-cu126-aarch64-linux/_ops.py +9 -0
  22. build/torch212-cxx11-cu126-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so +3 -0
  23. build/torch212-cxx11-cu126-aarch64-linux/metadata.json +15 -0
  24. build/torch212-cxx11-cu126-aarch64-linux/rwkv/__init__.py +26 -0
  25. build/torch212-cxx11-cu130-aarch64-linux/__init__.py +170 -0
  26. build/torch212-cxx11-cu130-aarch64-linux/_ops.py +9 -0
  27. build/torch212-cxx11-cu130-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so +3 -0
  28. build/torch212-cxx11-cu130-aarch64-linux/metadata.json +17 -0
  29. build/torch212-cxx11-cu130-aarch64-linux/rwkv/__init__.py +26 -0
  30. build/torch212-cxx11-cu132-aarch64-linux/__init__.py +170 -0
  31. build/torch212-cxx11-cu132-aarch64-linux/_ops.py +9 -0
  32. build/torch212-cxx11-cu132-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so +3 -0
  33. build/torch212-cxx11-cu132-aarch64-linux/metadata.json +17 -0
  34. build/torch212-cxx11-cu132-aarch64-linux/rwkv/__init__.py +26 -0
.gitattributes CHANGED
@@ -159,3 +159,12 @@ build/torch211-cxx11-cu130-x86_64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs di
159
  build/torch212-cxx11-cu126-x86_64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
160
  build/torch212-cxx11-cu130-x86_64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
161
  build/torch212-cxx11-cu132-x86_64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
159
  build/torch212-cxx11-cu126-x86_64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
160
  build/torch212-cxx11-cu130-x86_64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
161
  build/torch212-cxx11-cu132-x86_64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
162
+ build/torch210-cxx11-cu126-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
163
+ build/torch210-cxx11-cu128-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
164
+ build/torch210-cxx11-cu130-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
165
+ build/torch211-cxx11-cu126-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
166
+ build/torch211-cxx11-cu128-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
167
+ build/torch211-cxx11-cu130-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
168
+ build/torch212-cxx11-cu126-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
169
+ build/torch212-cxx11-cu130-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
170
+ build/torch212-cxx11-cu132-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so filter=lfs diff=lfs merge=lfs -text
build/torch210-cxx11-cu126-aarch64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _rwkv_cuda_86f75d9
3
- ops = torch.ops._rwkv_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_rwkv_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _rwkv_cuda_dfdeb22
3
+ ops = torch.ops._rwkv_cuda_dfdeb22
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_rwkv_cuda_dfdeb22::{op_name}"
build/torch210-cxx11-cu126-aarch64-linux/{_rwkv_cuda_86f75d9.abi3.so → _rwkv_cuda_dfdeb22.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:db4d37ddbafb2f617859098993d32d43db0fc9db93e98505efa79b4bd282a030
3
  size 2232072
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a0a87c0d1d20d0268d41ce17fc2956188dc741d477c88c3a3b097663b974079a
3
  size 2232072
build/torch210-cxx11-cu126-aarch64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "rwkv",
3
- "id": "_rwkv_cuda_86f75d9",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
1
  {
2
  "name": "rwkv",
3
+ "id": "_rwkv_cuda_dfdeb22",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
build/torch210-cxx11-cu128-aarch64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _rwkv_cuda_86f75d9
3
- ops = torch.ops._rwkv_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_rwkv_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _rwkv_cuda_dfdeb22
3
+ ops = torch.ops._rwkv_cuda_dfdeb22
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_rwkv_cuda_dfdeb22::{op_name}"
build/{torch211-cxx11-cu128-aarch64-linux/_rwkv_cuda_86f75d9.abi3.so → torch210-cxx11-cu128-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2bb5666854e7d30a79b3665bdb4dc1b414e1e99e0f9b6c6b830bb5e040c4723e
3
  size 2428792
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:57c5971cfc8211061308e458b61b1cca798fe240f9d9b764207e45962b9f9649
3
  size 2428792
build/torch210-cxx11-cu128-aarch64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "rwkv",
3
- "id": "_rwkv_cuda_86f75d9",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
1
  {
2
  "name": "rwkv",
3
+ "id": "_rwkv_cuda_dfdeb22",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
build/torch210-cxx11-cu130-aarch64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _rwkv_cuda_86f75d9
3
- ops = torch.ops._rwkv_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_rwkv_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _rwkv_cuda_dfdeb22
3
+ ops = torch.ops._rwkv_cuda_dfdeb22
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_rwkv_cuda_dfdeb22::{op_name}"
build/{torch211-cxx11-cu130-aarch64-linux/_rwkv_cuda_86f75d9.abi3.so → torch210-cxx11-cu130-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:35da2e270b6779a634d2e41b07f385952e3689b8d5aa66da14f70c029388b3f3
3
  size 2433400
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:63f96928ddcb5057297d6fa3fb938752f76630ee104589a2e0c79634ac332769
3
  size 2433400
build/torch210-cxx11-cu130-aarch64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "rwkv",
3
- "id": "_rwkv_cuda_86f75d9",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
1
  {
2
  "name": "rwkv",
3
+ "id": "_rwkv_cuda_dfdeb22",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
build/torch211-cxx11-cu126-aarch64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _rwkv_cuda_86f75d9
3
- ops = torch.ops._rwkv_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_rwkv_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _rwkv_cuda_dfdeb22
3
+ ops = torch.ops._rwkv_cuda_dfdeb22
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_rwkv_cuda_dfdeb22::{op_name}"
build/torch211-cxx11-cu126-aarch64-linux/{_rwkv_cuda_86f75d9.abi3.so → _rwkv_cuda_dfdeb22.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:da8acbdf94af9a4245064830b237dbb79a5ed61f66bf5baec9753257c0269d60
3
  size 2232072
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d91f9c8ef6e83975d97417e1e63e78fd04009ca2ce6a4bae673e4814585d9fc0
3
  size 2232072
build/torch211-cxx11-cu126-aarch64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "rwkv",
3
- "id": "_rwkv_cuda_86f75d9",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
1
  {
2
  "name": "rwkv",
3
+ "id": "_rwkv_cuda_dfdeb22",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
build/torch211-cxx11-cu128-aarch64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _rwkv_cuda_86f75d9
3
- ops = torch.ops._rwkv_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_rwkv_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _rwkv_cuda_dfdeb22
3
+ ops = torch.ops._rwkv_cuda_dfdeb22
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_rwkv_cuda_dfdeb22::{op_name}"
build/{torch210-cxx11-cu128-aarch64-linux/_rwkv_cuda_86f75d9.abi3.so → torch211-cxx11-cu128-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6e06058a91fcd84154ad74740166945559d8d1a02b3cadef47149d0bf5dc673a
3
  size 2428792
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65811a3820a7cbb2846cc83c4e670739c90433c44fa8a7346b69de0c3469591f
3
  size 2428792
build/torch211-cxx11-cu128-aarch64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "rwkv",
3
- "id": "_rwkv_cuda_86f75d9",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
1
  {
2
  "name": "rwkv",
3
+ "id": "_rwkv_cuda_dfdeb22",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
build/torch211-cxx11-cu130-aarch64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _rwkv_cuda_86f75d9
3
- ops = torch.ops._rwkv_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_rwkv_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _rwkv_cuda_dfdeb22
3
+ ops = torch.ops._rwkv_cuda_dfdeb22
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_rwkv_cuda_dfdeb22::{op_name}"
build/{torch210-cxx11-cu130-aarch64-linux/_rwkv_cuda_86f75d9.abi3.so → torch211-cxx11-cu130-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:be9f74b4a43cafcd2c41f7424dc65f63825654fc0ad077f8b3d5ce0ba146eede
3
  size 2433400
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f3b59a8b28fe59c6778e9c3f46c0854ed4b770fbc57fa2a2e9648ff66de0db30
3
  size 2433400
build/torch211-cxx11-cu130-aarch64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "rwkv",
3
- "id": "_rwkv_cuda_86f75d9",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
1
  {
2
  "name": "rwkv",
3
+ "id": "_rwkv_cuda_dfdeb22",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
build/torch212-cxx11-cu126-aarch64-linux/__init__.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ._ops import ops
2
+ from typing import Tuple, Any
3
+
4
+ # Use a broad Tensor alias to avoid importing torch at import time.
5
+ from torch import Tensor
6
+
7
+ def forward(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor) -> None:
8
+ """RWKV WKV forward pass (float32).
9
+
10
+ Runs the CUDA kernel and writes the result into ``y`` in-place.
11
+
12
+ Args:
13
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
14
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
15
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
16
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
17
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.float32`` (written in-place).
18
+
19
+ Notes:
20
+ - All tensors must be on the same CUDA device.
21
+ - Shapes must agree on ``B``, ``T`` and ``C``.
22
+ """
23
+ _validate_device_match((w, u, k, v, y))
24
+ ops.forward(w, u, k, v, y)
25
+
26
+
27
+ def forward_bf16(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor) -> None:
28
+ """RWKV WKV forward pass (bfloat16 inputs/outputs, float32 ``w``).
29
+
30
+ Runs the CUDA kernel and writes the result into ``y`` in-place.
31
+
32
+ Args:
33
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
34
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
35
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
36
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
37
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16`` (written in-place).
38
+
39
+ Notes:
40
+ - All tensors must be on the same CUDA device.
41
+ - Shapes must agree on ``B``, ``T`` and ``C``.
42
+ """
43
+ _validate_device_match((w, u, k, v, y))
44
+ ops.forward_bf16(w, u, k, v, y)
45
+
46
+
47
+ def forward_with_state(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor, s: Tensor) -> None:
48
+ """RWKV WKV forward pass with persistent state (float32).
49
+
50
+ Runs the CUDA kernel using and updating state ``s`` and writes the result into ``y``.
51
+
52
+ Args:
53
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
54
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
55
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
56
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
57
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.float32`` (written in-place).
58
+ s: Stateful tensor, shape ``[B, C]``, dtype ``torch.float32`` (updated in-place).
59
+
60
+ Notes:
61
+ - All tensors must be on the same CUDA device.
62
+ - Shapes must agree on ``B`` and ``C``; ``y`` shares ``[B, T, C]`` with inputs.
63
+ """
64
+ _validate_device_match((w, u, k, v, y, s))
65
+ ops.forward_with_state(w, u, k, v, y, s)
66
+
67
+
68
+ def forward_with_state_bf16(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor, s: Tensor) -> None:
69
+ """RWKV WKV forward pass with persistent state (bfloat16 inputs/outputs, float32 ``w`` and ``s``).
70
+
71
+ Runs the CUDA kernel using and updating state ``s`` and writes the result into ``y``.
72
+
73
+ Args:
74
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
75
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
76
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
77
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
78
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16`` (written in-place).
79
+ s: Stateful tensor, shape ``[B, C]``, dtype ``torch.float32`` (updated in-place).
80
+
81
+ Notes:
82
+ - All tensors must be on the same CUDA device.
83
+ - Shapes must agree on ``B`` and ``C``; ``y`` shares ``[B, T, C]`` with inputs.
84
+ """
85
+ _validate_device_match((w, u, k, v, y, s))
86
+ ops.forward_with_state_bf16(w, u, k, v, y, s)
87
+
88
+
89
+ def backward(
90
+ w: Tensor,
91
+ u: Tensor,
92
+ k: Tensor,
93
+ v: Tensor,
94
+ y: Tensor,
95
+ gy: Tensor,
96
+ gw: Tensor,
97
+ gu: Tensor,
98
+ gk: Tensor,
99
+ gv: Tensor,
100
+ ) -> None:
101
+ """RWKV WKV backward pass (float32).
102
+
103
+ Writes gradients into the provided tensors in-place.
104
+
105
+ Args:
106
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
107
+ u, k, v, y: Forward-pass tensors, shape ``[B, T, C]``, dtype ``torch.float32``.
108
+ gy: Gradient of ``y``, shape ``[B, T, C]``, dtype ``torch.float32``.
109
+ gw: Gradient for ``w``, shape ``[C]``, dtype ``torch.float32`` (written in-place).
110
+ gu, gk, gv: Gradients for ``u``, ``k``, ``v`` respectively, shape ``[B, T, C]``, dtype ``torch.float32`` (written in-place).
111
+
112
+ Notes:
113
+ - All tensors must be on the same CUDA device.
114
+ - Shapes must agree on ``B``, ``T`` and ``C``.
115
+ """
116
+ _validate_device_match((w, u, k, v, y, gy, gw, gu, gk, gv))
117
+ ops.backward(w, u, k, v, y, gy, gw, gu, gk, gv)
118
+
119
+
120
+ def backward_bf16(
121
+ w: Tensor,
122
+ u: Tensor,
123
+ k: Tensor,
124
+ v: Tensor,
125
+ y: Tensor,
126
+ gy: Tensor,
127
+ gw: Tensor,
128
+ gu: Tensor,
129
+ gk: Tensor,
130
+ gv: Tensor,
131
+ ) -> None:
132
+ """RWKV WKV backward pass (bfloat16 inputs/outputs/gradients, float32 ``w``).
133
+
134
+ Writes gradients into the provided tensors in-place.
135
+
136
+ Args:
137
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
138
+ u, k, v, y: Forward-pass tensors, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
139
+ gy: Gradient of ``y``, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
140
+ gw: Gradient for ``w``, shape ``[C]``, dtype ``torch.bfloat16`` (written in-place).
141
+ gu, gk, gv: Gradients for ``u``, ``k``, ``v`` respectively, shape ``[B, T, C]``, dtype ``torch.bfloat16`` (written in-place).
142
+
143
+ Notes:
144
+ - All tensors must be on the same CUDA device.
145
+ - Shapes must agree on ``B``, ``T`` and ``C``.
146
+ """
147
+ _validate_device_match((w, u, k, v, y, gy, gw, gu, gk, gv))
148
+ ops.backward_bf16(w, u, k, v, y, gy, gw, gu, gk, gv)
149
+
150
+
151
+ def _validate_device_match(tensors: Tuple[Tensor, ...]) -> None:
152
+ """Minimal runtime validation that all tensors live on the same CUDA device."""
153
+ if not tensors:
154
+ return
155
+ device = tensors[0].device
156
+ if not device.type == "cuda":
157
+ raise RuntimeError("RWKV CUDA ops require CUDA tensors")
158
+ for t in tensors[1:]:
159
+ if t.device != device:
160
+ raise RuntimeError("All tensors must be on the same CUDA device")
161
+
162
+
163
+ __all__ = [
164
+ "forward",
165
+ "forward_bf16",
166
+ "forward_with_state",
167
+ "forward_with_state_bf16",
168
+ "backward",
169
+ "backward_bf16",
170
+ ]
build/torch212-cxx11-cu126-aarch64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rwkv_cuda_dfdeb22
3
+ ops = torch.ops._rwkv_cuda_dfdeb22
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rwkv_cuda_dfdeb22::{op_name}"
build/torch212-cxx11-cu126-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02c639b66eb5ef2f4384c0680d86f1fe160b1c9a8963d521cba10083b250a07a
3
+ size 2232120
build/torch212-cxx11-cu126-aarch64-linux/metadata.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "rwkv",
3
+ "id": "_rwkv_cuda_dfdeb22",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "8.0",
11
+ "8.9",
12
+ "9.0"
13
+ ]
14
+ }
15
+ }
build/torch212-cxx11-cu126-aarch64-linux/rwkv/__init__.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ctypes
2
+ import importlib.util
3
+ import sys
4
+ from pathlib import Path
5
+ from types import ModuleType
6
+
7
+
8
+ def _import_from_path(file_path: Path) -> ModuleType:
9
+ # We cannot use the module name as-is, after adding it to `sys.modules`,
10
+ # it would also be used for other imports. So, we make a module name that
11
+ # depends on the path for it to be unique using the hex-encoded hash of
12
+ # the path.
13
+ path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
14
+ module_name = path_hash
15
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
16
+ if spec is None:
17
+ raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
18
+ module = importlib.util.module_from_spec(spec)
19
+ if module is None:
20
+ raise ImportError(f"Cannot load module {module_name} from spec")
21
+ sys.modules[module_name] = module
22
+ spec.loader.exec_module(module) # type: ignore
23
+ return module
24
+
25
+
26
+ globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
build/torch212-cxx11-cu130-aarch64-linux/__init__.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ._ops import ops
2
+ from typing import Tuple, Any
3
+
4
+ # Use a broad Tensor alias to avoid importing torch at import time.
5
+ from torch import Tensor
6
+
7
+ def forward(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor) -> None:
8
+ """RWKV WKV forward pass (float32).
9
+
10
+ Runs the CUDA kernel and writes the result into ``y`` in-place.
11
+
12
+ Args:
13
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
14
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
15
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
16
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
17
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.float32`` (written in-place).
18
+
19
+ Notes:
20
+ - All tensors must be on the same CUDA device.
21
+ - Shapes must agree on ``B``, ``T`` and ``C``.
22
+ """
23
+ _validate_device_match((w, u, k, v, y))
24
+ ops.forward(w, u, k, v, y)
25
+
26
+
27
+ def forward_bf16(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor) -> None:
28
+ """RWKV WKV forward pass (bfloat16 inputs/outputs, float32 ``w``).
29
+
30
+ Runs the CUDA kernel and writes the result into ``y`` in-place.
31
+
32
+ Args:
33
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
34
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
35
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
36
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
37
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16`` (written in-place).
38
+
39
+ Notes:
40
+ - All tensors must be on the same CUDA device.
41
+ - Shapes must agree on ``B``, ``T`` and ``C``.
42
+ """
43
+ _validate_device_match((w, u, k, v, y))
44
+ ops.forward_bf16(w, u, k, v, y)
45
+
46
+
47
+ def forward_with_state(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor, s: Tensor) -> None:
48
+ """RWKV WKV forward pass with persistent state (float32).
49
+
50
+ Runs the CUDA kernel using and updating state ``s`` and writes the result into ``y``.
51
+
52
+ Args:
53
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
54
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
55
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
56
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
57
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.float32`` (written in-place).
58
+ s: Stateful tensor, shape ``[B, C]``, dtype ``torch.float32`` (updated in-place).
59
+
60
+ Notes:
61
+ - All tensors must be on the same CUDA device.
62
+ - Shapes must agree on ``B`` and ``C``; ``y`` shares ``[B, T, C]`` with inputs.
63
+ """
64
+ _validate_device_match((w, u, k, v, y, s))
65
+ ops.forward_with_state(w, u, k, v, y, s)
66
+
67
+
68
+ def forward_with_state_bf16(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor, s: Tensor) -> None:
69
+ """RWKV WKV forward pass with persistent state (bfloat16 inputs/outputs, float32 ``w`` and ``s``).
70
+
71
+ Runs the CUDA kernel using and updating state ``s`` and writes the result into ``y``.
72
+
73
+ Args:
74
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
75
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
76
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
77
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
78
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16`` (written in-place).
79
+ s: Stateful tensor, shape ``[B, C]``, dtype ``torch.float32`` (updated in-place).
80
+
81
+ Notes:
82
+ - All tensors must be on the same CUDA device.
83
+ - Shapes must agree on ``B`` and ``C``; ``y`` shares ``[B, T, C]`` with inputs.
84
+ """
85
+ _validate_device_match((w, u, k, v, y, s))
86
+ ops.forward_with_state_bf16(w, u, k, v, y, s)
87
+
88
+
89
+ def backward(
90
+ w: Tensor,
91
+ u: Tensor,
92
+ k: Tensor,
93
+ v: Tensor,
94
+ y: Tensor,
95
+ gy: Tensor,
96
+ gw: Tensor,
97
+ gu: Tensor,
98
+ gk: Tensor,
99
+ gv: Tensor,
100
+ ) -> None:
101
+ """RWKV WKV backward pass (float32).
102
+
103
+ Writes gradients into the provided tensors in-place.
104
+
105
+ Args:
106
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
107
+ u, k, v, y: Forward-pass tensors, shape ``[B, T, C]``, dtype ``torch.float32``.
108
+ gy: Gradient of ``y``, shape ``[B, T, C]``, dtype ``torch.float32``.
109
+ gw: Gradient for ``w``, shape ``[C]``, dtype ``torch.float32`` (written in-place).
110
+ gu, gk, gv: Gradients for ``u``, ``k``, ``v`` respectively, shape ``[B, T, C]``, dtype ``torch.float32`` (written in-place).
111
+
112
+ Notes:
113
+ - All tensors must be on the same CUDA device.
114
+ - Shapes must agree on ``B``, ``T`` and ``C``.
115
+ """
116
+ _validate_device_match((w, u, k, v, y, gy, gw, gu, gk, gv))
117
+ ops.backward(w, u, k, v, y, gy, gw, gu, gk, gv)
118
+
119
+
120
+ def backward_bf16(
121
+ w: Tensor,
122
+ u: Tensor,
123
+ k: Tensor,
124
+ v: Tensor,
125
+ y: Tensor,
126
+ gy: Tensor,
127
+ gw: Tensor,
128
+ gu: Tensor,
129
+ gk: Tensor,
130
+ gv: Tensor,
131
+ ) -> None:
132
+ """RWKV WKV backward pass (bfloat16 inputs/outputs/gradients, float32 ``w``).
133
+
134
+ Writes gradients into the provided tensors in-place.
135
+
136
+ Args:
137
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
138
+ u, k, v, y: Forward-pass tensors, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
139
+ gy: Gradient of ``y``, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
140
+ gw: Gradient for ``w``, shape ``[C]``, dtype ``torch.bfloat16`` (written in-place).
141
+ gu, gk, gv: Gradients for ``u``, ``k``, ``v`` respectively, shape ``[B, T, C]``, dtype ``torch.bfloat16`` (written in-place).
142
+
143
+ Notes:
144
+ - All tensors must be on the same CUDA device.
145
+ - Shapes must agree on ``B``, ``T`` and ``C``.
146
+ """
147
+ _validate_device_match((w, u, k, v, y, gy, gw, gu, gk, gv))
148
+ ops.backward_bf16(w, u, k, v, y, gy, gw, gu, gk, gv)
149
+
150
+
151
+ def _validate_device_match(tensors: Tuple[Tensor, ...]) -> None:
152
+ """Minimal runtime validation that all tensors live on the same CUDA device."""
153
+ if not tensors:
154
+ return
155
+ device = tensors[0].device
156
+ if not device.type == "cuda":
157
+ raise RuntimeError("RWKV CUDA ops require CUDA tensors")
158
+ for t in tensors[1:]:
159
+ if t.device != device:
160
+ raise RuntimeError("All tensors must be on the same CUDA device")
161
+
162
+
163
+ __all__ = [
164
+ "forward",
165
+ "forward_bf16",
166
+ "forward_with_state",
167
+ "forward_with_state_bf16",
168
+ "backward",
169
+ "backward_bf16",
170
+ ]
build/torch212-cxx11-cu130-aarch64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rwkv_cuda_dfdeb22
3
+ ops = torch.ops._rwkv_cuda_dfdeb22
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rwkv_cuda_dfdeb22::{op_name}"
build/torch212-cxx11-cu130-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1fd38632d1a9c1b1ec491840e0f3b6862be3b376441b69404a4cc1c01d4321c
3
+ size 2433408
build/torch212-cxx11-cu130-aarch64-linux/metadata.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "rwkv",
3
+ "id": "_rwkv_cuda_dfdeb22",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "10.0",
11
+ "12.0",
12
+ "8.0",
13
+ "8.9",
14
+ "9.0"
15
+ ]
16
+ }
17
+ }
build/torch212-cxx11-cu130-aarch64-linux/rwkv/__init__.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ctypes
2
+ import importlib.util
3
+ import sys
4
+ from pathlib import Path
5
+ from types import ModuleType
6
+
7
+
8
+ def _import_from_path(file_path: Path) -> ModuleType:
9
+ # We cannot use the module name as-is, after adding it to `sys.modules`,
10
+ # it would also be used for other imports. So, we make a module name that
11
+ # depends on the path for it to be unique using the hex-encoded hash of
12
+ # the path.
13
+ path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
14
+ module_name = path_hash
15
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
16
+ if spec is None:
17
+ raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
18
+ module = importlib.util.module_from_spec(spec)
19
+ if module is None:
20
+ raise ImportError(f"Cannot load module {module_name} from spec")
21
+ sys.modules[module_name] = module
22
+ spec.loader.exec_module(module) # type: ignore
23
+ return module
24
+
25
+
26
+ globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
build/torch212-cxx11-cu132-aarch64-linux/__init__.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ._ops import ops
2
+ from typing import Tuple, Any
3
+
4
+ # Use a broad Tensor alias to avoid importing torch at import time.
5
+ from torch import Tensor
6
+
7
+ def forward(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor) -> None:
8
+ """RWKV WKV forward pass (float32).
9
+
10
+ Runs the CUDA kernel and writes the result into ``y`` in-place.
11
+
12
+ Args:
13
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
14
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
15
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
16
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
17
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.float32`` (written in-place).
18
+
19
+ Notes:
20
+ - All tensors must be on the same CUDA device.
21
+ - Shapes must agree on ``B``, ``T`` and ``C``.
22
+ """
23
+ _validate_device_match((w, u, k, v, y))
24
+ ops.forward(w, u, k, v, y)
25
+
26
+
27
+ def forward_bf16(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor) -> None:
28
+ """RWKV WKV forward pass (bfloat16 inputs/outputs, float32 ``w``).
29
+
30
+ Runs the CUDA kernel and writes the result into ``y`` in-place.
31
+
32
+ Args:
33
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
34
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
35
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
36
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
37
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16`` (written in-place).
38
+
39
+ Notes:
40
+ - All tensors must be on the same CUDA device.
41
+ - Shapes must agree on ``B``, ``T`` and ``C``.
42
+ """
43
+ _validate_device_match((w, u, k, v, y))
44
+ ops.forward_bf16(w, u, k, v, y)
45
+
46
+
47
+ def forward_with_state(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor, s: Tensor) -> None:
48
+ """RWKV WKV forward pass with persistent state (float32).
49
+
50
+ Runs the CUDA kernel using and updating state ``s`` and writes the result into ``y``.
51
+
52
+ Args:
53
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
54
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
55
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
56
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.float32``.
57
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.float32`` (written in-place).
58
+ s: Stateful tensor, shape ``[B, C]``, dtype ``torch.float32`` (updated in-place).
59
+
60
+ Notes:
61
+ - All tensors must be on the same CUDA device.
62
+ - Shapes must agree on ``B`` and ``C``; ``y`` shares ``[B, T, C]`` with inputs.
63
+ """
64
+ _validate_device_match((w, u, k, v, y, s))
65
+ ops.forward_with_state(w, u, k, v, y, s)
66
+
67
+
68
+ def forward_with_state_bf16(w: Tensor, u: Tensor, k: Tensor, v: Tensor, y: Tensor, s: Tensor) -> None:
69
+ """RWKV WKV forward pass with persistent state (bfloat16 inputs/outputs, float32 ``w`` and ``s``).
70
+
71
+ Runs the CUDA kernel using and updating state ``s`` and writes the result into ``y``.
72
+
73
+ Args:
74
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
75
+ u: Input tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
76
+ k: Key tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
77
+ v: Value tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
78
+ y: Output tensor, shape ``[B, T, C]``, dtype ``torch.bfloat16`` (written in-place).
79
+ s: Stateful tensor, shape ``[B, C]``, dtype ``torch.float32`` (updated in-place).
80
+
81
+ Notes:
82
+ - All tensors must be on the same CUDA device.
83
+ - Shapes must agree on ``B`` and ``C``; ``y`` shares ``[B, T, C]`` with inputs.
84
+ """
85
+ _validate_device_match((w, u, k, v, y, s))
86
+ ops.forward_with_state_bf16(w, u, k, v, y, s)
87
+
88
+
89
+ def backward(
90
+ w: Tensor,
91
+ u: Tensor,
92
+ k: Tensor,
93
+ v: Tensor,
94
+ y: Tensor,
95
+ gy: Tensor,
96
+ gw: Tensor,
97
+ gu: Tensor,
98
+ gk: Tensor,
99
+ gv: Tensor,
100
+ ) -> None:
101
+ """RWKV WKV backward pass (float32).
102
+
103
+ Writes gradients into the provided tensors in-place.
104
+
105
+ Args:
106
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
107
+ u, k, v, y: Forward-pass tensors, shape ``[B, T, C]``, dtype ``torch.float32``.
108
+ gy: Gradient of ``y``, shape ``[B, T, C]``, dtype ``torch.float32``.
109
+ gw: Gradient for ``w``, shape ``[C]``, dtype ``torch.float32`` (written in-place).
110
+ gu, gk, gv: Gradients for ``u``, ``k``, ``v`` respectively, shape ``[B, T, C]``, dtype ``torch.float32`` (written in-place).
111
+
112
+ Notes:
113
+ - All tensors must be on the same CUDA device.
114
+ - Shapes must agree on ``B``, ``T`` and ``C``.
115
+ """
116
+ _validate_device_match((w, u, k, v, y, gy, gw, gu, gk, gv))
117
+ ops.backward(w, u, k, v, y, gy, gw, gu, gk, gv)
118
+
119
+
120
+ def backward_bf16(
121
+ w: Tensor,
122
+ u: Tensor,
123
+ k: Tensor,
124
+ v: Tensor,
125
+ y: Tensor,
126
+ gy: Tensor,
127
+ gw: Tensor,
128
+ gu: Tensor,
129
+ gk: Tensor,
130
+ gv: Tensor,
131
+ ) -> None:
132
+ """RWKV WKV backward pass (bfloat16 inputs/outputs/gradients, float32 ``w``).
133
+
134
+ Writes gradients into the provided tensors in-place.
135
+
136
+ Args:
137
+ w: Decay weights, shape ``[C]``, dtype ``torch.float32``.
138
+ u, k, v, y: Forward-pass tensors, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
139
+ gy: Gradient of ``y``, shape ``[B, T, C]``, dtype ``torch.bfloat16``.
140
+ gw: Gradient for ``w``, shape ``[C]``, dtype ``torch.bfloat16`` (written in-place).
141
+ gu, gk, gv: Gradients for ``u``, ``k``, ``v`` respectively, shape ``[B, T, C]``, dtype ``torch.bfloat16`` (written in-place).
142
+
143
+ Notes:
144
+ - All tensors must be on the same CUDA device.
145
+ - Shapes must agree on ``B``, ``T`` and ``C``.
146
+ """
147
+ _validate_device_match((w, u, k, v, y, gy, gw, gu, gk, gv))
148
+ ops.backward_bf16(w, u, k, v, y, gy, gw, gu, gk, gv)
149
+
150
+
151
+ def _validate_device_match(tensors: Tuple[Tensor, ...]) -> None:
152
+ """Minimal runtime validation that all tensors live on the same CUDA device."""
153
+ if not tensors:
154
+ return
155
+ device = tensors[0].device
156
+ if not device.type == "cuda":
157
+ raise RuntimeError("RWKV CUDA ops require CUDA tensors")
158
+ for t in tensors[1:]:
159
+ if t.device != device:
160
+ raise RuntimeError("All tensors must be on the same CUDA device")
161
+
162
+
163
+ __all__ = [
164
+ "forward",
165
+ "forward_bf16",
166
+ "forward_with_state",
167
+ "forward_with_state_bf16",
168
+ "backward",
169
+ "backward_bf16",
170
+ ]
build/torch212-cxx11-cu132-aarch64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rwkv_cuda_dfdeb22
3
+ ops = torch.ops._rwkv_cuda_dfdeb22
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rwkv_cuda_dfdeb22::{op_name}"
build/torch212-cxx11-cu132-aarch64-linux/_rwkv_cuda_dfdeb22.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16a4fe19a41f0d5b06690c2cca4965a35cd78f6503c5bda15ded23929b70bb8a
3
+ size 2501256
build/torch212-cxx11-cu132-aarch64-linux/metadata.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "rwkv",
3
+ "id": "_rwkv_cuda_dfdeb22",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "10.0",
11
+ "12.0",
12
+ "8.0",
13
+ "8.9",
14
+ "9.0"
15
+ ]
16
+ }
17
+ }
build/torch212-cxx11-cu132-aarch64-linux/rwkv/__init__.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ctypes
2
+ import importlib.util
3
+ import sys
4
+ from pathlib import Path
5
+ from types import ModuleType
6
+
7
+
8
+ def _import_from_path(file_path: Path) -> ModuleType:
9
+ # We cannot use the module name as-is, after adding it to `sys.modules`,
10
+ # it would also be used for other imports. So, we make a module name that
11
+ # depends on the path for it to be unique using the hex-encoded hash of
12
+ # the path.
13
+ path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
14
+ module_name = path_hash
15
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
16
+ if spec is None:
17
+ raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
18
+ module = importlib.util.module_from_spec(spec)
19
+ if module is None:
20
+ raise ImportError(f"Cannot load module {module_name} from spec")
21
+ sys.modules[module_name] = module
22
+ spec.loader.exec_module(module) # type: ignore
23
+ return module
24
+
25
+
26
+ globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))