Kernels:
Trusted publisher
Remove builds incompatible with kernels >= 0.14
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- build/torch210-cu128-x86_64-windows/__init__.py +0 -170
- build/torch210-cu128-x86_64-windows/_ops.py +0 -9
- build/torch210-cu128-x86_64-windows/_rwkv_cuda_38ccc47.pyd +0 -3
- build/torch210-cu128-x86_64-windows/metadata.json +0 -15
- build/torch210-cu128-x86_64-windows/rwkv/__init__.py +0 -26
- build/torch211-cu128-x86_64-windows/__init__.py +0 -170
- build/torch211-cu128-x86_64-windows/_ops.py +0 -9
- build/torch211-cu128-x86_64-windows/_rwkv_cuda_34ead3e.pyd +0 -3
- build/torch211-cu128-x86_64-windows/metadata.json +0 -15
- build/torch211-cu128-x86_64-windows/rwkv/__init__.py +0 -26
- build/torch27-cxx11-cu118-x86_64-linux/rwkv/__init__.py +0 -170
- build/torch27-cxx11-cu118-x86_64-linux/rwkv/__pycache__/__init__.cpython-313.pyc +0 -0
- build/torch27-cxx11-cu118-x86_64-linux/rwkv/__pycache__/_ops.cpython-313.pyc +0 -0
- build/torch27-cxx11-cu118-x86_64-linux/rwkv/_ops.py +0 -9
- build/torch27-cxx11-cu118-x86_64-linux/rwkv/_rwkv_0aa7cb0.abi3.so +0 -3
- build/torch27-cxx11-cu126-x86_64-linux/rwkv/__init__.py +0 -170
- build/torch27-cxx11-cu126-x86_64-linux/rwkv/__pycache__/__init__.cpython-313.pyc +0 -0
- build/torch27-cxx11-cu126-x86_64-linux/rwkv/__pycache__/_ops.cpython-313.pyc +0 -0
- build/torch27-cxx11-cu126-x86_64-linux/rwkv/_ops.py +0 -9
- build/torch27-cxx11-cu126-x86_64-linux/rwkv/_rwkv_0aa7cb0.abi3.so +0 -3
- build/torch27-cxx11-cu128-x86_64-linux/rwkv/__init__.py +0 -170
- build/torch27-cxx11-cu128-x86_64-linux/rwkv/__pycache__/__init__.cpython-313.pyc +0 -0
- build/torch27-cxx11-cu128-x86_64-linux/rwkv/__pycache__/_ops.cpython-313.pyc +0 -0
- build/torch27-cxx11-cu128-x86_64-linux/rwkv/_ops.py +0 -9
- build/torch27-cxx11-cu128-x86_64-linux/rwkv/_rwkv_0aa7cb0.abi3.so +0 -3
- build/torch28-cxx11-cu126-x86_64-linux/__init__.py +0 -170
- build/torch28-cxx11-cu126-x86_64-linux/_ops.py +0 -9
- build/torch28-cxx11-cu126-x86_64-linux/_rwkv_44f2fa4.abi3.so +0 -3
- build/torch28-cxx11-cu126-x86_64-linux/metadata.json +0 -4
- build/torch28-cxx11-cu126-x86_64-linux/rwkv/__init__.py +0 -26
- build/torch28-cxx11-cu128-x86_64-linux/__init__.py +0 -170
- build/torch28-cxx11-cu128-x86_64-linux/_ops.py +0 -9
- build/torch28-cxx11-cu128-x86_64-linux/_rwkv_44f2fa4.abi3.so +0 -3
- build/torch28-cxx11-cu128-x86_64-linux/metadata.json +0 -4
- build/torch28-cxx11-cu128-x86_64-linux/rwkv/__init__.py +0 -26
- build/torch28-cxx11-cu129-x86_64-linux/__init__.py +0 -170
- build/torch28-cxx11-cu129-x86_64-linux/_ops.py +0 -9
- build/torch28-cxx11-cu129-x86_64-linux/_rwkv_44f2fa4.abi3.so +0 -3
- build/torch28-cxx11-cu129-x86_64-linux/metadata.json +0 -4
- build/torch28-cxx11-cu129-x86_64-linux/rwkv/__init__.py +0 -26
- build/torch29-cxx11-cu126-aarch64-linux/__init__.py +0 -170
- build/torch29-cxx11-cu126-aarch64-linux/_ops.py +0 -9
- build/torch29-cxx11-cu126-aarch64-linux/_rwkv_cuda_efd954c.abi3.so +0 -3
- build/torch29-cxx11-cu126-aarch64-linux/metadata.json +0 -13
- build/torch29-cxx11-cu126-aarch64-linux/rwkv/__init__.py +0 -26
- build/torch29-cxx11-cu126-x86_64-linux/__init__.py +0 -170
- build/torch29-cxx11-cu126-x86_64-linux/_ops.py +0 -9
- build/torch29-cxx11-cu126-x86_64-linux/_rwkv_44f2fa4.abi3.so +0 -3
- build/torch29-cxx11-cu126-x86_64-linux/metadata.json +0 -4
- build/torch29-cxx11-cu126-x86_64-linux/rwkv/__init__.py +0 -26
build/torch210-cu128-x86_64-windows/__init__.py
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 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
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 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
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:e29ecb0b1d346a26decac4671633cf56fbc0b12df10027b1cca06a41f48976a7
|
| 3 |
-
size 423424
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cu128-x86_64-windows/metadata.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
| 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
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 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")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch211-cu128-x86_64-windows/__init__.py
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 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/torch211-cu128-x86_64-windows/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _rwkv_cuda_34ead3e
|
| 3 |
-
ops = torch.ops._rwkv_cuda_34ead3e
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_rwkv_cuda_34ead3e::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch211-cu128-x86_64-windows/_rwkv_cuda_34ead3e.pyd
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:019c3000841ae541f82a5e49725fd28aafe20068e5b67685dd284da84d762148
|
| 3 |
-
size 423424
|
|
|
|
|
|
|
|
|
|
|
|
build/torch211-cu128-x86_64-windows/metadata.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
| 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/torch211-cu128-x86_64-windows/rwkv/__init__.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 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/torch27-cxx11-cu118-x86_64-linux/rwkv/__init__.py
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 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/torch27-cxx11-cu118-x86_64-linux/rwkv/__pycache__/__init__.cpython-313.pyc
DELETED
|
Binary file (7.21 kB)
|
|
|
build/torch27-cxx11-cu118-x86_64-linux/rwkv/__pycache__/_ops.cpython-313.pyc
DELETED
|
Binary file (508 Bytes)
|
|
|
build/torch27-cxx11-cu118-x86_64-linux/rwkv/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _rwkv_0aa7cb0
|
| 3 |
-
ops = torch.ops._rwkv_0aa7cb0
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_rwkv_0aa7cb0::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch27-cxx11-cu118-x86_64-linux/rwkv/_rwkv_0aa7cb0.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:a561edd91db3da01aad4f484eca06f44e98843f859317aeaa9a3df85339ce850
|
| 3 |
-
size 2065400
|
|
|
|
|
|
|
|
|
|
|
|
build/torch27-cxx11-cu126-x86_64-linux/rwkv/__init__.py
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 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/torch27-cxx11-cu126-x86_64-linux/rwkv/__pycache__/__init__.cpython-313.pyc
DELETED
|
Binary file (7.21 kB)
|
|
|
build/torch27-cxx11-cu126-x86_64-linux/rwkv/__pycache__/_ops.cpython-313.pyc
DELETED
|
Binary file (508 Bytes)
|
|
|
build/torch27-cxx11-cu126-x86_64-linux/rwkv/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _rwkv_0aa7cb0
|
| 3 |
-
ops = torch.ops._rwkv_0aa7cb0
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_rwkv_0aa7cb0::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch27-cxx11-cu126-x86_64-linux/rwkv/_rwkv_0aa7cb0.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:b115095e24c64d21eecefdc0ed4d9c13ea9485930f8f56cc99874762c501f278
|
| 3 |
-
size 2106408
|
|
|
|
|
|
|
|
|
|
|
|
build/torch27-cxx11-cu128-x86_64-linux/rwkv/__init__.py
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 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/torch27-cxx11-cu128-x86_64-linux/rwkv/__pycache__/__init__.cpython-313.pyc
DELETED
|
Binary file (7.21 kB)
|
|
|
build/torch27-cxx11-cu128-x86_64-linux/rwkv/__pycache__/_ops.cpython-313.pyc
DELETED
|
Binary file (508 Bytes)
|
|
|
build/torch27-cxx11-cu128-x86_64-linux/rwkv/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _rwkv_0aa7cb0
|
| 3 |
-
ops = torch.ops._rwkv_0aa7cb0
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_rwkv_0aa7cb0::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch27-cxx11-cu128-x86_64-linux/rwkv/_rwkv_0aa7cb0.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:19029bb516a8cf3428f4e47a2b5f26f091d169206e51df7c4e89880553a15df7
|
| 3 |
-
size 2308848
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu126-x86_64-linux/__init__.py
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 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/torch28-cxx11-cu126-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _rwkv_44f2fa4
|
| 3 |
-
ops = torch.ops._rwkv_44f2fa4
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_rwkv_44f2fa4::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu126-x86_64-linux/_rwkv_44f2fa4.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:0d383c1186dde17bb427291205ae83bdb2e49abf15b4eb482151aa0940e51d4d
|
| 3 |
-
size 2111504
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu126-x86_64-linux/metadata.json
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"version": 1,
|
| 3 |
-
"python-depends": []
|
| 4 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu126-x86_64-linux/rwkv/__init__.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 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")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu128-x86_64-linux/__init__.py
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 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/torch28-cxx11-cu128-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _rwkv_44f2fa4
|
| 3 |
-
ops = torch.ops._rwkv_44f2fa4
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_rwkv_44f2fa4::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu128-x86_64-linux/_rwkv_44f2fa4.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:5fb0335b36148895aac63e1822e14c4be054dd842dbdddcfab668b65b2335ff2
|
| 3 |
-
size 2318032
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu128-x86_64-linux/metadata.json
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"version": 1,
|
| 3 |
-
"python-depends": []
|
| 4 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu128-x86_64-linux/rwkv/__init__.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 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")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu129-x86_64-linux/__init__.py
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 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/torch28-cxx11-cu129-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _rwkv_44f2fa4
|
| 3 |
-
ops = torch.ops._rwkv_44f2fa4
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_rwkv_44f2fa4::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu129-x86_64-linux/_rwkv_44f2fa4.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:2178eb41ec85f3861d61391de45ec47c3127490fbd902f1e2167683514cf867b
|
| 3 |
-
size 2335432
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu129-x86_64-linux/metadata.json
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"version": 1,
|
| 3 |
-
"python-depends": []
|
| 4 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu129-x86_64-linux/rwkv/__init__.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 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")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-aarch64-linux/__init__.py
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 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/torch29-cxx11-cu126-aarch64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _rwkv_cuda_efd954c
|
| 3 |
-
ops = torch.ops._rwkv_cuda_efd954c
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_rwkv_cuda_efd954c::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-aarch64-linux/_rwkv_cuda_efd954c.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:f6d39263049bd9e5823007907a9b2f366226c9dacc5a6157f68f8e317bd1108c
|
| 3 |
-
size 2230968
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-aarch64-linux/metadata.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"version": 1,
|
| 3 |
-
"license": "Apache-2.0",
|
| 4 |
-
"python-depends": [],
|
| 5 |
-
"backend": {
|
| 6 |
-
"type": "cuda",
|
| 7 |
-
"archs": [
|
| 8 |
-
"8.0",
|
| 9 |
-
"8.9",
|
| 10 |
-
"9.0"
|
| 11 |
-
]
|
| 12 |
-
}
|
| 13 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-aarch64-linux/rwkv/__init__.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 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")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-x86_64-linux/__init__.py
DELETED
|
@@ -1,170 +0,0 @@
|
|
| 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/torch29-cxx11-cu126-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _rwkv_44f2fa4
|
| 3 |
-
ops = torch.ops._rwkv_44f2fa4
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_rwkv_44f2fa4::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-x86_64-linux/_rwkv_44f2fa4.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:64e542cd9e7f9a7ea5bf22a91a27fb34f6352b7fbbc39463f2f5d183f6386d05
|
| 3 |
-
size 2111480
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-x86_64-linux/metadata.json
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"version": 1,
|
| 3 |
-
"python-depends": []
|
| 4 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-x86_64-linux/rwkv/__init__.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 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")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|