Build uploaded using `kernels`.
Browse files- .gitattributes +1 -0
- build/torch210-cu128-x86_64-windows/__init__.py +170 -0
- build/torch210-cu128-x86_64-windows/_ops.py +9 -0
- build/torch210-cu128-x86_64-windows/_rwkv_cuda_38ccc47.pyd +3 -0
- build/torch210-cu128-x86_64-windows/metadata.json +15 -0
- build/torch210-cu128-x86_64-windows/rwkv/__init__.py +26 -0
.gitattributes
CHANGED
|
@@ -93,3 +93,4 @@ build/torch210-cxx11-cu130-aarch64-linux/_rwkv_cuda_efd954c.abi3.so filter=lfs d
|
|
| 93 |
build/torch29-cxx11-cu126-aarch64-linux/_rwkv_cuda_efd954c.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 94 |
build/torch29-cxx11-cu128-aarch64-linux/_rwkv_cuda_efd954c.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 95 |
build/torch29-cxx11-cu130-aarch64-linux/_rwkv_cuda_efd954c.abi3.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 93 |
build/torch29-cxx11-cu126-aarch64-linux/_rwkv_cuda_efd954c.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 94 |
build/torch29-cxx11-cu128-aarch64-linux/_rwkv_cuda_efd954c.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 95 |
build/torch29-cxx11-cu130-aarch64-linux/_rwkv_cuda_efd954c.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 96 |
+
build/torch210-cu128-x86_64-windows/_rwkv_cuda_38ccc47.pyd filter=lfs diff=lfs merge=lfs -text
|
build/torch210-cu128-x86_64-windows/__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/torch210-cu128-x86_64-windows/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _rwkv_cuda_38ccc47
|
| 3 |
+
ops = torch.ops._rwkv_cuda_38ccc47
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_rwkv_cuda_38ccc47::{op_name}"
|
build/torch210-cu128-x86_64-windows/_rwkv_cuda_38ccc47.pyd
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bb058f48819d82150825b6a300fa2c5a37269641ff6de55d082472921a36b3f7
|
| 3 |
+
size 423424
|
build/torch210-cu128-x86_64-windows/metadata.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 1,
|
| 3 |
+
"license": "Apache-2.0",
|
| 4 |
+
"python-depends": [],
|
| 5 |
+
"backend": {
|
| 6 |
+
"type": "cuda",
|
| 7 |
+
"archs": [
|
| 8 |
+
"10.0",
|
| 9 |
+
"12.0",
|
| 10 |
+
"8.0",
|
| 11 |
+
"8.9",
|
| 12 |
+
"9.0"
|
| 13 |
+
]
|
| 14 |
+
}
|
| 15 |
+
}
|
build/torch210-cu128-x86_64-windows/rwkv/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
import importlib
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from types import ModuleType
|
| 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")))
|