Instructions to use replicate/activation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Kernels
How to use replicate/activation with Kernels:
# !pip install kernels from kernels import get_kernel # a version (or an explicit revision) is required; see the "Files and versions" tab for the available ones kernel = get_kernel("replicate/activation", version=1) - Notebooks
- Google Colab
- Kaggle
Build uploaded using `kernels`.
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- build/torch210-cxx11-cu126-x86_64-linux/__init__.py +0 -75
- build/torch210-cxx11-cu126-x86_64-linux/_activation_d8d5fa1.abi3.so +0 -3
- build/torch210-cxx11-cu126-x86_64-linux/_ops.py +0 -9
- build/torch210-cxx11-cu126-x86_64-linux/activation/__init__.py +0 -26
- build/torch210-cxx11-cu126-x86_64-linux/layers.py +0 -179
- build/torch210-cxx11-cu126-x86_64-linux/metadata.json +0 -1
- build/torch210-cxx11-cu128-x86_64-linux/__init__.py +0 -75
- build/torch210-cxx11-cu128-x86_64-linux/_activation_d8d5fa1.abi3.so +0 -3
- build/torch210-cxx11-cu128-x86_64-linux/_ops.py +0 -9
- build/torch210-cxx11-cu128-x86_64-linux/activation/__init__.py +0 -26
- build/torch210-cxx11-cu128-x86_64-linux/layers.py +0 -179
- build/torch210-cxx11-cu128-x86_64-linux/metadata.json +0 -1
- build/torch210-cxx11-cu130-x86_64-linux/__init__.py +0 -75
- build/torch210-cxx11-cu130-x86_64-linux/_activation_d8d5fa1.abi3.so +0 -3
- build/torch210-cxx11-cu130-x86_64-linux/_ops.py +0 -9
- build/torch210-cxx11-cu130-x86_64-linux/activation/__init__.py +0 -26
- build/torch210-cxx11-cu130-x86_64-linux/layers.py +0 -179
- build/torch210-cxx11-cu130-x86_64-linux/metadata.json +0 -1
- build/torch28-cxx11-cu126-x86_64-linux/__init__.py +0 -75
- build/torch28-cxx11-cu126-x86_64-linux/_activation_d8d5fa1.abi3.so +0 -3
- build/torch28-cxx11-cu126-x86_64-linux/_ops.py +0 -9
- build/torch28-cxx11-cu126-x86_64-linux/activation/__init__.py +0 -26
- build/torch28-cxx11-cu126-x86_64-linux/layers.py +0 -179
- build/torch28-cxx11-cu126-x86_64-linux/metadata.json +0 -1
- build/torch28-cxx11-cu128-x86_64-linux/__init__.py +0 -75
- build/torch28-cxx11-cu128-x86_64-linux/_activation_d8d5fa1.abi3.so +0 -3
- build/torch28-cxx11-cu128-x86_64-linux/_ops.py +0 -9
- build/torch28-cxx11-cu128-x86_64-linux/activation/__init__.py +0 -26
- build/torch28-cxx11-cu128-x86_64-linux/layers.py +0 -179
- build/torch28-cxx11-cu128-x86_64-linux/metadata.json +0 -1
- build/torch28-cxx11-cu129-x86_64-linux/__init__.py +0 -75
- build/torch28-cxx11-cu129-x86_64-linux/_activation_d8d5fa1.abi3.so +0 -3
- build/torch28-cxx11-cu129-x86_64-linux/_ops.py +0 -9
- build/torch28-cxx11-cu129-x86_64-linux/activation/__init__.py +0 -26
- build/torch28-cxx11-cu129-x86_64-linux/layers.py +0 -179
- build/torch28-cxx11-cu129-x86_64-linux/metadata.json +0 -1
- build/torch29-cxx11-cu126-x86_64-linux/__init__.py +0 -75
- build/torch29-cxx11-cu126-x86_64-linux/_activation_d8d5fa1.abi3.so +0 -3
- build/torch29-cxx11-cu126-x86_64-linux/_ops.py +0 -9
- build/torch29-cxx11-cu126-x86_64-linux/activation/__init__.py +0 -26
- build/torch29-cxx11-cu126-x86_64-linux/layers.py +0 -179
- build/torch29-cxx11-cu126-x86_64-linux/metadata.json +0 -1
- build/torch29-cxx11-cu128-x86_64-linux/__init__.py +0 -75
- build/torch29-cxx11-cu128-x86_64-linux/_activation_d8d5fa1.abi3.so +0 -3
- build/torch29-cxx11-cu128-x86_64-linux/_ops.py +0 -9
- build/torch29-cxx11-cu128-x86_64-linux/activation/__init__.py +0 -26
- build/torch29-cxx11-cu128-x86_64-linux/layers.py +0 -179
- build/torch29-cxx11-cu128-x86_64-linux/metadata.json +0 -1
- build/torch29-cxx11-cu130-x86_64-linux/__init__.py +0 -75
- build/torch29-cxx11-cu130-x86_64-linux/_activation_d8d5fa1.abi3.so +0 -3
build/torch210-cxx11-cu126-x86_64-linux/__init__.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
|
| 3 |
-
from ._ops import ops
|
| 4 |
-
|
| 5 |
-
from . import layers
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def silu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 9 |
-
ops.silu_and_mul(out, x)
|
| 10 |
-
return out
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def mul_and_silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 14 |
-
ops.mul_and_silu(out, x)
|
| 15 |
-
return out
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def gelu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 19 |
-
ops.gelu_and_mul(out, x)
|
| 20 |
-
return out
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def gelu_tanh_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 24 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 25 |
-
return out
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def fatrelu_and_mul(out: torch.Tensor, x: torch.Tensor, threshold: float = 0.0) -> None:
|
| 29 |
-
ops.fatrelu_and_mul(out, x, threshold)
|
| 30 |
-
return out
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def gelu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 34 |
-
ops.gelu(out, x)
|
| 35 |
-
return out
|
| 36 |
-
|
| 37 |
-
def silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 38 |
-
ops.silu(out, x)
|
| 39 |
-
return out
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def gelu_tanh(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 43 |
-
ops.gelu_tanh(out, x)
|
| 44 |
-
return out
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def gelu_fast(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 48 |
-
ops.gelu_fast(out, x)
|
| 49 |
-
return out
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def gelu_new(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 53 |
-
ops.gelu_new(out, x)
|
| 54 |
-
return out
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def gelu_quick(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 58 |
-
ops.gelu_quick(out, x)
|
| 59 |
-
return out
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
__all__ = [
|
| 63 |
-
"silu_and_mul",
|
| 64 |
-
"mul_and_silu",
|
| 65 |
-
"gelu_and_mul",
|
| 66 |
-
"gelu_tanh_and_mul",
|
| 67 |
-
"fatrelu_and_mul",
|
| 68 |
-
"gelu_fast",
|
| 69 |
-
"gelu_new",
|
| 70 |
-
"gelu_quick",
|
| 71 |
-
"gelu_tanh",
|
| 72 |
-
"silu",
|
| 73 |
-
"gelu",
|
| 74 |
-
"layers",
|
| 75 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu126-x86_64-linux/_activation_d8d5fa1.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:e964b58e4e1d4008e7a2431a9f248d8402a9a65fa10b2a0257c746235e4e289e
|
| 3 |
-
size 3126824
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu126-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _activation_d8d5fa1
|
| 3 |
-
ops = torch.ops._activation_d8d5fa1
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_activation_d8d5fa1::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu126-x86_64-linux/activation/__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/torch210-cxx11-cu126-x86_64-linux/layers.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
|
| 4 |
-
from ._ops import ops
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
class SiluAndMul(nn.Module):
|
| 8 |
-
"""An activation function for SwiGLU.
|
| 9 |
-
|
| 10 |
-
The function computes x -> silu(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 11 |
-
|
| 12 |
-
Shapes:
|
| 13 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 14 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
can_torch_compile: bool = True
|
| 18 |
-
|
| 19 |
-
def forward(self, x: torch.Tensor):
|
| 20 |
-
d = x.shape[-1] // 2
|
| 21 |
-
output_shape = x.shape[:-1] + (d,)
|
| 22 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 23 |
-
ops.silu_and_mul(out, x)
|
| 24 |
-
return out
|
| 25 |
-
|
| 26 |
-
class Silu(nn.Module):
|
| 27 |
-
"""An activation function for SiLU.
|
| 28 |
-
|
| 29 |
-
The function computes x -> silu(x).
|
| 30 |
-
|
| 31 |
-
Shapes:
|
| 32 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 33 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
can_torch_compile: bool = True
|
| 37 |
-
|
| 38 |
-
def forward(self, x: torch.Tensor):
|
| 39 |
-
out = torch.empty_like(x)
|
| 40 |
-
ops.silu(out, x)
|
| 41 |
-
return out
|
| 42 |
-
|
| 43 |
-
class Gelu(nn.Module):
|
| 44 |
-
"""An activation function for GELU.
|
| 45 |
-
|
| 46 |
-
The function computes x -> gelu(x).
|
| 47 |
-
|
| 48 |
-
Shapes:
|
| 49 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 50 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
can_torch_compile: bool = True
|
| 54 |
-
|
| 55 |
-
def forward(self, x: torch.Tensor):
|
| 56 |
-
out = torch.empty_like(x)
|
| 57 |
-
ops.gelu(out, x)
|
| 58 |
-
return out
|
| 59 |
-
|
| 60 |
-
class GeluTanh(nn.Module):
|
| 61 |
-
"""An activation function for GELU with `tanh` approximation.
|
| 62 |
-
|
| 63 |
-
The function computes x -> gelu_tanh(x).
|
| 64 |
-
|
| 65 |
-
Shapes:
|
| 66 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 67 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
can_torch_compile: bool = True
|
| 71 |
-
|
| 72 |
-
def forward(self, x: torch.Tensor):
|
| 73 |
-
out = torch.empty_like(x)
|
| 74 |
-
ops.gelu_tanh(out, x)
|
| 75 |
-
return out
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
class MulAndSilu(nn.Module):
|
| 79 |
-
"""An activation function for SwiGLU.
|
| 80 |
-
|
| 81 |
-
The function computes x -> x[:d] * silu(x[d:]) where d = x.shape[-1] // 2.
|
| 82 |
-
|
| 83 |
-
Shapes:
|
| 84 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 85 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 86 |
-
"""
|
| 87 |
-
|
| 88 |
-
can_torch_compile: bool = True
|
| 89 |
-
|
| 90 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 91 |
-
d = x.shape[-1] // 2
|
| 92 |
-
output_shape = x.shape[:-1] + (d,)
|
| 93 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 94 |
-
ops.mul_and_silu(out, x)
|
| 95 |
-
return out
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
class GeluAndMul(nn.Module):
|
| 99 |
-
"""An activation function for GeGLU.
|
| 100 |
-
|
| 101 |
-
The function computes x -> GELU(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 102 |
-
|
| 103 |
-
Shapes:
|
| 104 |
-
x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d)
|
| 105 |
-
return: (batch_size, seq_len, d) or (num_tokens, d)
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
-
can_torch_compile: bool = True
|
| 109 |
-
|
| 110 |
-
def forward(self, x: torch.Tensor):
|
| 111 |
-
d = x.shape[-1] // 2
|
| 112 |
-
output_shape = x.shape[:-1] + (d,)
|
| 113 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 114 |
-
ops.gelu_and_mul(out, x)
|
| 115 |
-
return out
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
class GeluTanhAndMul(nn.Module):
|
| 119 |
-
can_torch_compile: bool = True
|
| 120 |
-
|
| 121 |
-
def forward(self, x: torch.Tensor):
|
| 122 |
-
d = x.shape[-1] // 2
|
| 123 |
-
output_shape = x.shape[:-1] + (d,)
|
| 124 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 125 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 126 |
-
return out
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
class FatreluAndMul(nn.Module):
|
| 130 |
-
"""An activation function for FATReLU.
|
| 131 |
-
|
| 132 |
-
The function computes x -> FATReLU(x[:d]) * x[d:] where
|
| 133 |
-
d = x.shape[-1] // 2.
|
| 134 |
-
This is used in openbmb/MiniCPM-S-1B-sft.
|
| 135 |
-
|
| 136 |
-
Shapes:
|
| 137 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 138 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 139 |
-
"""
|
| 140 |
-
|
| 141 |
-
can_torch_compile: bool = True
|
| 142 |
-
|
| 143 |
-
def __init__(self, threshold: float = 0.0):
|
| 144 |
-
super().__init__()
|
| 145 |
-
self.threshold = threshold
|
| 146 |
-
|
| 147 |
-
def forward(self, x: torch.Tensor):
|
| 148 |
-
d = x.shape[-1] // 2
|
| 149 |
-
output_shape = x.shape[:-1] + (d,)
|
| 150 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 151 |
-
ops.fatrelu_and_mul(out, x, self.threshold)
|
| 152 |
-
return out
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
class FastGELU(nn.Module):
|
| 156 |
-
can_torch_compile: bool = True
|
| 157 |
-
|
| 158 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 159 |
-
out = torch.empty_like(x)
|
| 160 |
-
ops.gelu_fast(out, x)
|
| 161 |
-
return out
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
class NewGELU(nn.Module):
|
| 165 |
-
can_torch_compile: bool = True
|
| 166 |
-
|
| 167 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 168 |
-
out = torch.empty_like(x)
|
| 169 |
-
ops.gelu_new(out, x)
|
| 170 |
-
return out
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
class QuickGELU(nn.Module):
|
| 174 |
-
can_torch_compile: bool = True
|
| 175 |
-
|
| 176 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 177 |
-
out = torch.empty_like(x)
|
| 178 |
-
ops.gelu_quick(out, x)
|
| 179 |
-
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu126-x86_64-linux/metadata.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"python-depends":[]}
|
|
|
|
|
|
build/torch210-cxx11-cu128-x86_64-linux/__init__.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
|
| 3 |
-
from ._ops import ops
|
| 4 |
-
|
| 5 |
-
from . import layers
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def silu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 9 |
-
ops.silu_and_mul(out, x)
|
| 10 |
-
return out
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def mul_and_silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 14 |
-
ops.mul_and_silu(out, x)
|
| 15 |
-
return out
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def gelu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 19 |
-
ops.gelu_and_mul(out, x)
|
| 20 |
-
return out
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def gelu_tanh_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 24 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 25 |
-
return out
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def fatrelu_and_mul(out: torch.Tensor, x: torch.Tensor, threshold: float = 0.0) -> None:
|
| 29 |
-
ops.fatrelu_and_mul(out, x, threshold)
|
| 30 |
-
return out
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def gelu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 34 |
-
ops.gelu(out, x)
|
| 35 |
-
return out
|
| 36 |
-
|
| 37 |
-
def silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 38 |
-
ops.silu(out, x)
|
| 39 |
-
return out
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def gelu_tanh(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 43 |
-
ops.gelu_tanh(out, x)
|
| 44 |
-
return out
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def gelu_fast(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 48 |
-
ops.gelu_fast(out, x)
|
| 49 |
-
return out
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def gelu_new(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 53 |
-
ops.gelu_new(out, x)
|
| 54 |
-
return out
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def gelu_quick(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 58 |
-
ops.gelu_quick(out, x)
|
| 59 |
-
return out
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
__all__ = [
|
| 63 |
-
"silu_and_mul",
|
| 64 |
-
"mul_and_silu",
|
| 65 |
-
"gelu_and_mul",
|
| 66 |
-
"gelu_tanh_and_mul",
|
| 67 |
-
"fatrelu_and_mul",
|
| 68 |
-
"gelu_fast",
|
| 69 |
-
"gelu_new",
|
| 70 |
-
"gelu_quick",
|
| 71 |
-
"gelu_tanh",
|
| 72 |
-
"silu",
|
| 73 |
-
"gelu",
|
| 74 |
-
"layers",
|
| 75 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu128-x86_64-linux/_activation_d8d5fa1.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:b4b96fdb577e1f109b2ae39eb9b546a6ff48b71a22bc3d008fef4c36e8c338aa
|
| 3 |
-
size 4406608
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu128-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _activation_d8d5fa1
|
| 3 |
-
ops = torch.ops._activation_d8d5fa1
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_activation_d8d5fa1::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu128-x86_64-linux/activation/__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/torch210-cxx11-cu128-x86_64-linux/layers.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
|
| 4 |
-
from ._ops import ops
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
class SiluAndMul(nn.Module):
|
| 8 |
-
"""An activation function for SwiGLU.
|
| 9 |
-
|
| 10 |
-
The function computes x -> silu(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 11 |
-
|
| 12 |
-
Shapes:
|
| 13 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 14 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
can_torch_compile: bool = True
|
| 18 |
-
|
| 19 |
-
def forward(self, x: torch.Tensor):
|
| 20 |
-
d = x.shape[-1] // 2
|
| 21 |
-
output_shape = x.shape[:-1] + (d,)
|
| 22 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 23 |
-
ops.silu_and_mul(out, x)
|
| 24 |
-
return out
|
| 25 |
-
|
| 26 |
-
class Silu(nn.Module):
|
| 27 |
-
"""An activation function for SiLU.
|
| 28 |
-
|
| 29 |
-
The function computes x -> silu(x).
|
| 30 |
-
|
| 31 |
-
Shapes:
|
| 32 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 33 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
can_torch_compile: bool = True
|
| 37 |
-
|
| 38 |
-
def forward(self, x: torch.Tensor):
|
| 39 |
-
out = torch.empty_like(x)
|
| 40 |
-
ops.silu(out, x)
|
| 41 |
-
return out
|
| 42 |
-
|
| 43 |
-
class Gelu(nn.Module):
|
| 44 |
-
"""An activation function for GELU.
|
| 45 |
-
|
| 46 |
-
The function computes x -> gelu(x).
|
| 47 |
-
|
| 48 |
-
Shapes:
|
| 49 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 50 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
can_torch_compile: bool = True
|
| 54 |
-
|
| 55 |
-
def forward(self, x: torch.Tensor):
|
| 56 |
-
out = torch.empty_like(x)
|
| 57 |
-
ops.gelu(out, x)
|
| 58 |
-
return out
|
| 59 |
-
|
| 60 |
-
class GeluTanh(nn.Module):
|
| 61 |
-
"""An activation function for GELU with `tanh` approximation.
|
| 62 |
-
|
| 63 |
-
The function computes x -> gelu_tanh(x).
|
| 64 |
-
|
| 65 |
-
Shapes:
|
| 66 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 67 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
can_torch_compile: bool = True
|
| 71 |
-
|
| 72 |
-
def forward(self, x: torch.Tensor):
|
| 73 |
-
out = torch.empty_like(x)
|
| 74 |
-
ops.gelu_tanh(out, x)
|
| 75 |
-
return out
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
class MulAndSilu(nn.Module):
|
| 79 |
-
"""An activation function for SwiGLU.
|
| 80 |
-
|
| 81 |
-
The function computes x -> x[:d] * silu(x[d:]) where d = x.shape[-1] // 2.
|
| 82 |
-
|
| 83 |
-
Shapes:
|
| 84 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 85 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 86 |
-
"""
|
| 87 |
-
|
| 88 |
-
can_torch_compile: bool = True
|
| 89 |
-
|
| 90 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 91 |
-
d = x.shape[-1] // 2
|
| 92 |
-
output_shape = x.shape[:-1] + (d,)
|
| 93 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 94 |
-
ops.mul_and_silu(out, x)
|
| 95 |
-
return out
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
class GeluAndMul(nn.Module):
|
| 99 |
-
"""An activation function for GeGLU.
|
| 100 |
-
|
| 101 |
-
The function computes x -> GELU(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 102 |
-
|
| 103 |
-
Shapes:
|
| 104 |
-
x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d)
|
| 105 |
-
return: (batch_size, seq_len, d) or (num_tokens, d)
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
-
can_torch_compile: bool = True
|
| 109 |
-
|
| 110 |
-
def forward(self, x: torch.Tensor):
|
| 111 |
-
d = x.shape[-1] // 2
|
| 112 |
-
output_shape = x.shape[:-1] + (d,)
|
| 113 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 114 |
-
ops.gelu_and_mul(out, x)
|
| 115 |
-
return out
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
class GeluTanhAndMul(nn.Module):
|
| 119 |
-
can_torch_compile: bool = True
|
| 120 |
-
|
| 121 |
-
def forward(self, x: torch.Tensor):
|
| 122 |
-
d = x.shape[-1] // 2
|
| 123 |
-
output_shape = x.shape[:-1] + (d,)
|
| 124 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 125 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 126 |
-
return out
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
class FatreluAndMul(nn.Module):
|
| 130 |
-
"""An activation function for FATReLU.
|
| 131 |
-
|
| 132 |
-
The function computes x -> FATReLU(x[:d]) * x[d:] where
|
| 133 |
-
d = x.shape[-1] // 2.
|
| 134 |
-
This is used in openbmb/MiniCPM-S-1B-sft.
|
| 135 |
-
|
| 136 |
-
Shapes:
|
| 137 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 138 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 139 |
-
"""
|
| 140 |
-
|
| 141 |
-
can_torch_compile: bool = True
|
| 142 |
-
|
| 143 |
-
def __init__(self, threshold: float = 0.0):
|
| 144 |
-
super().__init__()
|
| 145 |
-
self.threshold = threshold
|
| 146 |
-
|
| 147 |
-
def forward(self, x: torch.Tensor):
|
| 148 |
-
d = x.shape[-1] // 2
|
| 149 |
-
output_shape = x.shape[:-1] + (d,)
|
| 150 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 151 |
-
ops.fatrelu_and_mul(out, x, self.threshold)
|
| 152 |
-
return out
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
class FastGELU(nn.Module):
|
| 156 |
-
can_torch_compile: bool = True
|
| 157 |
-
|
| 158 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 159 |
-
out = torch.empty_like(x)
|
| 160 |
-
ops.gelu_fast(out, x)
|
| 161 |
-
return out
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
class NewGELU(nn.Module):
|
| 165 |
-
can_torch_compile: bool = True
|
| 166 |
-
|
| 167 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 168 |
-
out = torch.empty_like(x)
|
| 169 |
-
ops.gelu_new(out, x)
|
| 170 |
-
return out
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
class QuickGELU(nn.Module):
|
| 174 |
-
can_torch_compile: bool = True
|
| 175 |
-
|
| 176 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 177 |
-
out = torch.empty_like(x)
|
| 178 |
-
ops.gelu_quick(out, x)
|
| 179 |
-
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu128-x86_64-linux/metadata.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"python-depends":[]}
|
|
|
|
|
|
build/torch210-cxx11-cu130-x86_64-linux/__init__.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
|
| 3 |
-
from ._ops import ops
|
| 4 |
-
|
| 5 |
-
from . import layers
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def silu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 9 |
-
ops.silu_and_mul(out, x)
|
| 10 |
-
return out
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def mul_and_silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 14 |
-
ops.mul_and_silu(out, x)
|
| 15 |
-
return out
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def gelu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 19 |
-
ops.gelu_and_mul(out, x)
|
| 20 |
-
return out
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def gelu_tanh_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 24 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 25 |
-
return out
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def fatrelu_and_mul(out: torch.Tensor, x: torch.Tensor, threshold: float = 0.0) -> None:
|
| 29 |
-
ops.fatrelu_and_mul(out, x, threshold)
|
| 30 |
-
return out
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def gelu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 34 |
-
ops.gelu(out, x)
|
| 35 |
-
return out
|
| 36 |
-
|
| 37 |
-
def silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 38 |
-
ops.silu(out, x)
|
| 39 |
-
return out
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def gelu_tanh(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 43 |
-
ops.gelu_tanh(out, x)
|
| 44 |
-
return out
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def gelu_fast(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 48 |
-
ops.gelu_fast(out, x)
|
| 49 |
-
return out
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def gelu_new(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 53 |
-
ops.gelu_new(out, x)
|
| 54 |
-
return out
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def gelu_quick(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 58 |
-
ops.gelu_quick(out, x)
|
| 59 |
-
return out
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
__all__ = [
|
| 63 |
-
"silu_and_mul",
|
| 64 |
-
"mul_and_silu",
|
| 65 |
-
"gelu_and_mul",
|
| 66 |
-
"gelu_tanh_and_mul",
|
| 67 |
-
"fatrelu_and_mul",
|
| 68 |
-
"gelu_fast",
|
| 69 |
-
"gelu_new",
|
| 70 |
-
"gelu_quick",
|
| 71 |
-
"gelu_tanh",
|
| 72 |
-
"silu",
|
| 73 |
-
"gelu",
|
| 74 |
-
"layers",
|
| 75 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu130-x86_64-linux/_activation_d8d5fa1.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:c688c1e1ba5c179198199a538379a9692a19cab64d67102bf7faa1b15afa55fe
|
| 3 |
-
size 4190152
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu130-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _activation_d8d5fa1
|
| 3 |
-
ops = torch.ops._activation_d8d5fa1
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_activation_d8d5fa1::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu130-x86_64-linux/activation/__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/torch210-cxx11-cu130-x86_64-linux/layers.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
|
| 4 |
-
from ._ops import ops
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
class SiluAndMul(nn.Module):
|
| 8 |
-
"""An activation function for SwiGLU.
|
| 9 |
-
|
| 10 |
-
The function computes x -> silu(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 11 |
-
|
| 12 |
-
Shapes:
|
| 13 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 14 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
can_torch_compile: bool = True
|
| 18 |
-
|
| 19 |
-
def forward(self, x: torch.Tensor):
|
| 20 |
-
d = x.shape[-1] // 2
|
| 21 |
-
output_shape = x.shape[:-1] + (d,)
|
| 22 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 23 |
-
ops.silu_and_mul(out, x)
|
| 24 |
-
return out
|
| 25 |
-
|
| 26 |
-
class Silu(nn.Module):
|
| 27 |
-
"""An activation function for SiLU.
|
| 28 |
-
|
| 29 |
-
The function computes x -> silu(x).
|
| 30 |
-
|
| 31 |
-
Shapes:
|
| 32 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 33 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
can_torch_compile: bool = True
|
| 37 |
-
|
| 38 |
-
def forward(self, x: torch.Tensor):
|
| 39 |
-
out = torch.empty_like(x)
|
| 40 |
-
ops.silu(out, x)
|
| 41 |
-
return out
|
| 42 |
-
|
| 43 |
-
class Gelu(nn.Module):
|
| 44 |
-
"""An activation function for GELU.
|
| 45 |
-
|
| 46 |
-
The function computes x -> gelu(x).
|
| 47 |
-
|
| 48 |
-
Shapes:
|
| 49 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 50 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
can_torch_compile: bool = True
|
| 54 |
-
|
| 55 |
-
def forward(self, x: torch.Tensor):
|
| 56 |
-
out = torch.empty_like(x)
|
| 57 |
-
ops.gelu(out, x)
|
| 58 |
-
return out
|
| 59 |
-
|
| 60 |
-
class GeluTanh(nn.Module):
|
| 61 |
-
"""An activation function for GELU with `tanh` approximation.
|
| 62 |
-
|
| 63 |
-
The function computes x -> gelu_tanh(x).
|
| 64 |
-
|
| 65 |
-
Shapes:
|
| 66 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 67 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
can_torch_compile: bool = True
|
| 71 |
-
|
| 72 |
-
def forward(self, x: torch.Tensor):
|
| 73 |
-
out = torch.empty_like(x)
|
| 74 |
-
ops.gelu_tanh(out, x)
|
| 75 |
-
return out
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
class MulAndSilu(nn.Module):
|
| 79 |
-
"""An activation function for SwiGLU.
|
| 80 |
-
|
| 81 |
-
The function computes x -> x[:d] * silu(x[d:]) where d = x.shape[-1] // 2.
|
| 82 |
-
|
| 83 |
-
Shapes:
|
| 84 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 85 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 86 |
-
"""
|
| 87 |
-
|
| 88 |
-
can_torch_compile: bool = True
|
| 89 |
-
|
| 90 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 91 |
-
d = x.shape[-1] // 2
|
| 92 |
-
output_shape = x.shape[:-1] + (d,)
|
| 93 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 94 |
-
ops.mul_and_silu(out, x)
|
| 95 |
-
return out
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
class GeluAndMul(nn.Module):
|
| 99 |
-
"""An activation function for GeGLU.
|
| 100 |
-
|
| 101 |
-
The function computes x -> GELU(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 102 |
-
|
| 103 |
-
Shapes:
|
| 104 |
-
x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d)
|
| 105 |
-
return: (batch_size, seq_len, d) or (num_tokens, d)
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
-
can_torch_compile: bool = True
|
| 109 |
-
|
| 110 |
-
def forward(self, x: torch.Tensor):
|
| 111 |
-
d = x.shape[-1] // 2
|
| 112 |
-
output_shape = x.shape[:-1] + (d,)
|
| 113 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 114 |
-
ops.gelu_and_mul(out, x)
|
| 115 |
-
return out
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
class GeluTanhAndMul(nn.Module):
|
| 119 |
-
can_torch_compile: bool = True
|
| 120 |
-
|
| 121 |
-
def forward(self, x: torch.Tensor):
|
| 122 |
-
d = x.shape[-1] // 2
|
| 123 |
-
output_shape = x.shape[:-1] + (d,)
|
| 124 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 125 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 126 |
-
return out
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
class FatreluAndMul(nn.Module):
|
| 130 |
-
"""An activation function for FATReLU.
|
| 131 |
-
|
| 132 |
-
The function computes x -> FATReLU(x[:d]) * x[d:] where
|
| 133 |
-
d = x.shape[-1] // 2.
|
| 134 |
-
This is used in openbmb/MiniCPM-S-1B-sft.
|
| 135 |
-
|
| 136 |
-
Shapes:
|
| 137 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 138 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 139 |
-
"""
|
| 140 |
-
|
| 141 |
-
can_torch_compile: bool = True
|
| 142 |
-
|
| 143 |
-
def __init__(self, threshold: float = 0.0):
|
| 144 |
-
super().__init__()
|
| 145 |
-
self.threshold = threshold
|
| 146 |
-
|
| 147 |
-
def forward(self, x: torch.Tensor):
|
| 148 |
-
d = x.shape[-1] // 2
|
| 149 |
-
output_shape = x.shape[:-1] + (d,)
|
| 150 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 151 |
-
ops.fatrelu_and_mul(out, x, self.threshold)
|
| 152 |
-
return out
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
class FastGELU(nn.Module):
|
| 156 |
-
can_torch_compile: bool = True
|
| 157 |
-
|
| 158 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 159 |
-
out = torch.empty_like(x)
|
| 160 |
-
ops.gelu_fast(out, x)
|
| 161 |
-
return out
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
class NewGELU(nn.Module):
|
| 165 |
-
can_torch_compile: bool = True
|
| 166 |
-
|
| 167 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 168 |
-
out = torch.empty_like(x)
|
| 169 |
-
ops.gelu_new(out, x)
|
| 170 |
-
return out
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
class QuickGELU(nn.Module):
|
| 174 |
-
can_torch_compile: bool = True
|
| 175 |
-
|
| 176 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 177 |
-
out = torch.empty_like(x)
|
| 178 |
-
ops.gelu_quick(out, x)
|
| 179 |
-
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cxx11-cu130-x86_64-linux/metadata.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"python-depends":[]}
|
|
|
|
|
|
build/torch28-cxx11-cu126-x86_64-linux/__init__.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
|
| 3 |
-
from ._ops import ops
|
| 4 |
-
|
| 5 |
-
from . import layers
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def silu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 9 |
-
ops.silu_and_mul(out, x)
|
| 10 |
-
return out
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def mul_and_silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 14 |
-
ops.mul_and_silu(out, x)
|
| 15 |
-
return out
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def gelu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 19 |
-
ops.gelu_and_mul(out, x)
|
| 20 |
-
return out
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def gelu_tanh_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 24 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 25 |
-
return out
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def fatrelu_and_mul(out: torch.Tensor, x: torch.Tensor, threshold: float = 0.0) -> None:
|
| 29 |
-
ops.fatrelu_and_mul(out, x, threshold)
|
| 30 |
-
return out
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def gelu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 34 |
-
ops.gelu(out, x)
|
| 35 |
-
return out
|
| 36 |
-
|
| 37 |
-
def silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 38 |
-
ops.silu(out, x)
|
| 39 |
-
return out
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def gelu_tanh(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 43 |
-
ops.gelu_tanh(out, x)
|
| 44 |
-
return out
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def gelu_fast(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 48 |
-
ops.gelu_fast(out, x)
|
| 49 |
-
return out
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def gelu_new(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 53 |
-
ops.gelu_new(out, x)
|
| 54 |
-
return out
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def gelu_quick(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 58 |
-
ops.gelu_quick(out, x)
|
| 59 |
-
return out
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
__all__ = [
|
| 63 |
-
"silu_and_mul",
|
| 64 |
-
"mul_and_silu",
|
| 65 |
-
"gelu_and_mul",
|
| 66 |
-
"gelu_tanh_and_mul",
|
| 67 |
-
"fatrelu_and_mul",
|
| 68 |
-
"gelu_fast",
|
| 69 |
-
"gelu_new",
|
| 70 |
-
"gelu_quick",
|
| 71 |
-
"gelu_tanh",
|
| 72 |
-
"silu",
|
| 73 |
-
"gelu",
|
| 74 |
-
"layers",
|
| 75 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu126-x86_64-linux/_activation_d8d5fa1.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:911660bed858a039ef77a306d7d9860f42b8bdd88ba3c286e93ed6e4e29de10f
|
| 3 |
-
size 3121056
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu126-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _activation_d8d5fa1
|
| 3 |
-
ops = torch.ops._activation_d8d5fa1
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_activation_d8d5fa1::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu126-x86_64-linux/activation/__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-cu126-x86_64-linux/layers.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
|
| 4 |
-
from ._ops import ops
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
class SiluAndMul(nn.Module):
|
| 8 |
-
"""An activation function for SwiGLU.
|
| 9 |
-
|
| 10 |
-
The function computes x -> silu(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 11 |
-
|
| 12 |
-
Shapes:
|
| 13 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 14 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
can_torch_compile: bool = True
|
| 18 |
-
|
| 19 |
-
def forward(self, x: torch.Tensor):
|
| 20 |
-
d = x.shape[-1] // 2
|
| 21 |
-
output_shape = x.shape[:-1] + (d,)
|
| 22 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 23 |
-
ops.silu_and_mul(out, x)
|
| 24 |
-
return out
|
| 25 |
-
|
| 26 |
-
class Silu(nn.Module):
|
| 27 |
-
"""An activation function for SiLU.
|
| 28 |
-
|
| 29 |
-
The function computes x -> silu(x).
|
| 30 |
-
|
| 31 |
-
Shapes:
|
| 32 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 33 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
can_torch_compile: bool = True
|
| 37 |
-
|
| 38 |
-
def forward(self, x: torch.Tensor):
|
| 39 |
-
out = torch.empty_like(x)
|
| 40 |
-
ops.silu(out, x)
|
| 41 |
-
return out
|
| 42 |
-
|
| 43 |
-
class Gelu(nn.Module):
|
| 44 |
-
"""An activation function for GELU.
|
| 45 |
-
|
| 46 |
-
The function computes x -> gelu(x).
|
| 47 |
-
|
| 48 |
-
Shapes:
|
| 49 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 50 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
can_torch_compile: bool = True
|
| 54 |
-
|
| 55 |
-
def forward(self, x: torch.Tensor):
|
| 56 |
-
out = torch.empty_like(x)
|
| 57 |
-
ops.gelu(out, x)
|
| 58 |
-
return out
|
| 59 |
-
|
| 60 |
-
class GeluTanh(nn.Module):
|
| 61 |
-
"""An activation function for GELU with `tanh` approximation.
|
| 62 |
-
|
| 63 |
-
The function computes x -> gelu_tanh(x).
|
| 64 |
-
|
| 65 |
-
Shapes:
|
| 66 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 67 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
can_torch_compile: bool = True
|
| 71 |
-
|
| 72 |
-
def forward(self, x: torch.Tensor):
|
| 73 |
-
out = torch.empty_like(x)
|
| 74 |
-
ops.gelu_tanh(out, x)
|
| 75 |
-
return out
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
class MulAndSilu(nn.Module):
|
| 79 |
-
"""An activation function for SwiGLU.
|
| 80 |
-
|
| 81 |
-
The function computes x -> x[:d] * silu(x[d:]) where d = x.shape[-1] // 2.
|
| 82 |
-
|
| 83 |
-
Shapes:
|
| 84 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 85 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 86 |
-
"""
|
| 87 |
-
|
| 88 |
-
can_torch_compile: bool = True
|
| 89 |
-
|
| 90 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 91 |
-
d = x.shape[-1] // 2
|
| 92 |
-
output_shape = x.shape[:-1] + (d,)
|
| 93 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 94 |
-
ops.mul_and_silu(out, x)
|
| 95 |
-
return out
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
class GeluAndMul(nn.Module):
|
| 99 |
-
"""An activation function for GeGLU.
|
| 100 |
-
|
| 101 |
-
The function computes x -> GELU(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 102 |
-
|
| 103 |
-
Shapes:
|
| 104 |
-
x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d)
|
| 105 |
-
return: (batch_size, seq_len, d) or (num_tokens, d)
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
-
can_torch_compile: bool = True
|
| 109 |
-
|
| 110 |
-
def forward(self, x: torch.Tensor):
|
| 111 |
-
d = x.shape[-1] // 2
|
| 112 |
-
output_shape = x.shape[:-1] + (d,)
|
| 113 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 114 |
-
ops.gelu_and_mul(out, x)
|
| 115 |
-
return out
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
class GeluTanhAndMul(nn.Module):
|
| 119 |
-
can_torch_compile: bool = True
|
| 120 |
-
|
| 121 |
-
def forward(self, x: torch.Tensor):
|
| 122 |
-
d = x.shape[-1] // 2
|
| 123 |
-
output_shape = x.shape[:-1] + (d,)
|
| 124 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 125 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 126 |
-
return out
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
class FatreluAndMul(nn.Module):
|
| 130 |
-
"""An activation function for FATReLU.
|
| 131 |
-
|
| 132 |
-
The function computes x -> FATReLU(x[:d]) * x[d:] where
|
| 133 |
-
d = x.shape[-1] // 2.
|
| 134 |
-
This is used in openbmb/MiniCPM-S-1B-sft.
|
| 135 |
-
|
| 136 |
-
Shapes:
|
| 137 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 138 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 139 |
-
"""
|
| 140 |
-
|
| 141 |
-
can_torch_compile: bool = True
|
| 142 |
-
|
| 143 |
-
def __init__(self, threshold: float = 0.0):
|
| 144 |
-
super().__init__()
|
| 145 |
-
self.threshold = threshold
|
| 146 |
-
|
| 147 |
-
def forward(self, x: torch.Tensor):
|
| 148 |
-
d = x.shape[-1] // 2
|
| 149 |
-
output_shape = x.shape[:-1] + (d,)
|
| 150 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 151 |
-
ops.fatrelu_and_mul(out, x, self.threshold)
|
| 152 |
-
return out
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
class FastGELU(nn.Module):
|
| 156 |
-
can_torch_compile: bool = True
|
| 157 |
-
|
| 158 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 159 |
-
out = torch.empty_like(x)
|
| 160 |
-
ops.gelu_fast(out, x)
|
| 161 |
-
return out
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
class NewGELU(nn.Module):
|
| 165 |
-
can_torch_compile: bool = True
|
| 166 |
-
|
| 167 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 168 |
-
out = torch.empty_like(x)
|
| 169 |
-
ops.gelu_new(out, x)
|
| 170 |
-
return out
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
class QuickGELU(nn.Module):
|
| 174 |
-
can_torch_compile: bool = True
|
| 175 |
-
|
| 176 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 177 |
-
out = torch.empty_like(x)
|
| 178 |
-
ops.gelu_quick(out, x)
|
| 179 |
-
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu126-x86_64-linux/metadata.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"python-depends":[]}
|
|
|
|
|
|
build/torch28-cxx11-cu128-x86_64-linux/__init__.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
|
| 3 |
-
from ._ops import ops
|
| 4 |
-
|
| 5 |
-
from . import layers
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def silu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 9 |
-
ops.silu_and_mul(out, x)
|
| 10 |
-
return out
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def mul_and_silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 14 |
-
ops.mul_and_silu(out, x)
|
| 15 |
-
return out
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def gelu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 19 |
-
ops.gelu_and_mul(out, x)
|
| 20 |
-
return out
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def gelu_tanh_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 24 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 25 |
-
return out
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def fatrelu_and_mul(out: torch.Tensor, x: torch.Tensor, threshold: float = 0.0) -> None:
|
| 29 |
-
ops.fatrelu_and_mul(out, x, threshold)
|
| 30 |
-
return out
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def gelu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 34 |
-
ops.gelu(out, x)
|
| 35 |
-
return out
|
| 36 |
-
|
| 37 |
-
def silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 38 |
-
ops.silu(out, x)
|
| 39 |
-
return out
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def gelu_tanh(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 43 |
-
ops.gelu_tanh(out, x)
|
| 44 |
-
return out
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def gelu_fast(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 48 |
-
ops.gelu_fast(out, x)
|
| 49 |
-
return out
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def gelu_new(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 53 |
-
ops.gelu_new(out, x)
|
| 54 |
-
return out
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def gelu_quick(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 58 |
-
ops.gelu_quick(out, x)
|
| 59 |
-
return out
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
__all__ = [
|
| 63 |
-
"silu_and_mul",
|
| 64 |
-
"mul_and_silu",
|
| 65 |
-
"gelu_and_mul",
|
| 66 |
-
"gelu_tanh_and_mul",
|
| 67 |
-
"fatrelu_and_mul",
|
| 68 |
-
"gelu_fast",
|
| 69 |
-
"gelu_new",
|
| 70 |
-
"gelu_quick",
|
| 71 |
-
"gelu_tanh",
|
| 72 |
-
"silu",
|
| 73 |
-
"gelu",
|
| 74 |
-
"layers",
|
| 75 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu128-x86_64-linux/_activation_d8d5fa1.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:7624549b7daad396ef5c550d3aac9b511fce95ba560f4cff9560f255b6212895
|
| 3 |
-
size 4400792
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu128-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _activation_d8d5fa1
|
| 3 |
-
ops = torch.ops._activation_d8d5fa1
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_activation_d8d5fa1::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu128-x86_64-linux/activation/__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/layers.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
|
| 4 |
-
from ._ops import ops
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
class SiluAndMul(nn.Module):
|
| 8 |
-
"""An activation function for SwiGLU.
|
| 9 |
-
|
| 10 |
-
The function computes x -> silu(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 11 |
-
|
| 12 |
-
Shapes:
|
| 13 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 14 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
can_torch_compile: bool = True
|
| 18 |
-
|
| 19 |
-
def forward(self, x: torch.Tensor):
|
| 20 |
-
d = x.shape[-1] // 2
|
| 21 |
-
output_shape = x.shape[:-1] + (d,)
|
| 22 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 23 |
-
ops.silu_and_mul(out, x)
|
| 24 |
-
return out
|
| 25 |
-
|
| 26 |
-
class Silu(nn.Module):
|
| 27 |
-
"""An activation function for SiLU.
|
| 28 |
-
|
| 29 |
-
The function computes x -> silu(x).
|
| 30 |
-
|
| 31 |
-
Shapes:
|
| 32 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 33 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
can_torch_compile: bool = True
|
| 37 |
-
|
| 38 |
-
def forward(self, x: torch.Tensor):
|
| 39 |
-
out = torch.empty_like(x)
|
| 40 |
-
ops.silu(out, x)
|
| 41 |
-
return out
|
| 42 |
-
|
| 43 |
-
class Gelu(nn.Module):
|
| 44 |
-
"""An activation function for GELU.
|
| 45 |
-
|
| 46 |
-
The function computes x -> gelu(x).
|
| 47 |
-
|
| 48 |
-
Shapes:
|
| 49 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 50 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
can_torch_compile: bool = True
|
| 54 |
-
|
| 55 |
-
def forward(self, x: torch.Tensor):
|
| 56 |
-
out = torch.empty_like(x)
|
| 57 |
-
ops.gelu(out, x)
|
| 58 |
-
return out
|
| 59 |
-
|
| 60 |
-
class GeluTanh(nn.Module):
|
| 61 |
-
"""An activation function for GELU with `tanh` approximation.
|
| 62 |
-
|
| 63 |
-
The function computes x -> gelu_tanh(x).
|
| 64 |
-
|
| 65 |
-
Shapes:
|
| 66 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 67 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
can_torch_compile: bool = True
|
| 71 |
-
|
| 72 |
-
def forward(self, x: torch.Tensor):
|
| 73 |
-
out = torch.empty_like(x)
|
| 74 |
-
ops.gelu_tanh(out, x)
|
| 75 |
-
return out
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
class MulAndSilu(nn.Module):
|
| 79 |
-
"""An activation function for SwiGLU.
|
| 80 |
-
|
| 81 |
-
The function computes x -> x[:d] * silu(x[d:]) where d = x.shape[-1] // 2.
|
| 82 |
-
|
| 83 |
-
Shapes:
|
| 84 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 85 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 86 |
-
"""
|
| 87 |
-
|
| 88 |
-
can_torch_compile: bool = True
|
| 89 |
-
|
| 90 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 91 |
-
d = x.shape[-1] // 2
|
| 92 |
-
output_shape = x.shape[:-1] + (d,)
|
| 93 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 94 |
-
ops.mul_and_silu(out, x)
|
| 95 |
-
return out
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
class GeluAndMul(nn.Module):
|
| 99 |
-
"""An activation function for GeGLU.
|
| 100 |
-
|
| 101 |
-
The function computes x -> GELU(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 102 |
-
|
| 103 |
-
Shapes:
|
| 104 |
-
x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d)
|
| 105 |
-
return: (batch_size, seq_len, d) or (num_tokens, d)
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
-
can_torch_compile: bool = True
|
| 109 |
-
|
| 110 |
-
def forward(self, x: torch.Tensor):
|
| 111 |
-
d = x.shape[-1] // 2
|
| 112 |
-
output_shape = x.shape[:-1] + (d,)
|
| 113 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 114 |
-
ops.gelu_and_mul(out, x)
|
| 115 |
-
return out
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
class GeluTanhAndMul(nn.Module):
|
| 119 |
-
can_torch_compile: bool = True
|
| 120 |
-
|
| 121 |
-
def forward(self, x: torch.Tensor):
|
| 122 |
-
d = x.shape[-1] // 2
|
| 123 |
-
output_shape = x.shape[:-1] + (d,)
|
| 124 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 125 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 126 |
-
return out
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
class FatreluAndMul(nn.Module):
|
| 130 |
-
"""An activation function for FATReLU.
|
| 131 |
-
|
| 132 |
-
The function computes x -> FATReLU(x[:d]) * x[d:] where
|
| 133 |
-
d = x.shape[-1] // 2.
|
| 134 |
-
This is used in openbmb/MiniCPM-S-1B-sft.
|
| 135 |
-
|
| 136 |
-
Shapes:
|
| 137 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 138 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 139 |
-
"""
|
| 140 |
-
|
| 141 |
-
can_torch_compile: bool = True
|
| 142 |
-
|
| 143 |
-
def __init__(self, threshold: float = 0.0):
|
| 144 |
-
super().__init__()
|
| 145 |
-
self.threshold = threshold
|
| 146 |
-
|
| 147 |
-
def forward(self, x: torch.Tensor):
|
| 148 |
-
d = x.shape[-1] // 2
|
| 149 |
-
output_shape = x.shape[:-1] + (d,)
|
| 150 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 151 |
-
ops.fatrelu_and_mul(out, x, self.threshold)
|
| 152 |
-
return out
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
class FastGELU(nn.Module):
|
| 156 |
-
can_torch_compile: bool = True
|
| 157 |
-
|
| 158 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 159 |
-
out = torch.empty_like(x)
|
| 160 |
-
ops.gelu_fast(out, x)
|
| 161 |
-
return out
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
class NewGELU(nn.Module):
|
| 165 |
-
can_torch_compile: bool = True
|
| 166 |
-
|
| 167 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 168 |
-
out = torch.empty_like(x)
|
| 169 |
-
ops.gelu_new(out, x)
|
| 170 |
-
return out
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
class QuickGELU(nn.Module):
|
| 174 |
-
can_torch_compile: bool = True
|
| 175 |
-
|
| 176 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 177 |
-
out = torch.empty_like(x)
|
| 178 |
-
ops.gelu_quick(out, x)
|
| 179 |
-
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu128-x86_64-linux/metadata.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"python-depends":[]}
|
|
|
|
|
|
build/torch28-cxx11-cu129-x86_64-linux/__init__.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
|
| 3 |
-
from ._ops import ops
|
| 4 |
-
|
| 5 |
-
from . import layers
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def silu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 9 |
-
ops.silu_and_mul(out, x)
|
| 10 |
-
return out
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def mul_and_silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 14 |
-
ops.mul_and_silu(out, x)
|
| 15 |
-
return out
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def gelu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 19 |
-
ops.gelu_and_mul(out, x)
|
| 20 |
-
return out
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def gelu_tanh_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 24 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 25 |
-
return out
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def fatrelu_and_mul(out: torch.Tensor, x: torch.Tensor, threshold: float = 0.0) -> None:
|
| 29 |
-
ops.fatrelu_and_mul(out, x, threshold)
|
| 30 |
-
return out
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def gelu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 34 |
-
ops.gelu(out, x)
|
| 35 |
-
return out
|
| 36 |
-
|
| 37 |
-
def silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 38 |
-
ops.silu(out, x)
|
| 39 |
-
return out
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def gelu_tanh(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 43 |
-
ops.gelu_tanh(out, x)
|
| 44 |
-
return out
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def gelu_fast(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 48 |
-
ops.gelu_fast(out, x)
|
| 49 |
-
return out
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def gelu_new(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 53 |
-
ops.gelu_new(out, x)
|
| 54 |
-
return out
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def gelu_quick(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 58 |
-
ops.gelu_quick(out, x)
|
| 59 |
-
return out
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
__all__ = [
|
| 63 |
-
"silu_and_mul",
|
| 64 |
-
"mul_and_silu",
|
| 65 |
-
"gelu_and_mul",
|
| 66 |
-
"gelu_tanh_and_mul",
|
| 67 |
-
"fatrelu_and_mul",
|
| 68 |
-
"gelu_fast",
|
| 69 |
-
"gelu_new",
|
| 70 |
-
"gelu_quick",
|
| 71 |
-
"gelu_tanh",
|
| 72 |
-
"silu",
|
| 73 |
-
"gelu",
|
| 74 |
-
"layers",
|
| 75 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu129-x86_64-linux/_activation_d8d5fa1.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:59858d94c625ceae30130a9e481971d577e69acb5fe1389610d299519d55a5d3
|
| 3 |
-
size 4438672
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu129-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _activation_d8d5fa1
|
| 3 |
-
ops = torch.ops._activation_d8d5fa1
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_activation_d8d5fa1::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu129-x86_64-linux/activation/__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/layers.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
|
| 4 |
-
from ._ops import ops
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
class SiluAndMul(nn.Module):
|
| 8 |
-
"""An activation function for SwiGLU.
|
| 9 |
-
|
| 10 |
-
The function computes x -> silu(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 11 |
-
|
| 12 |
-
Shapes:
|
| 13 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 14 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
can_torch_compile: bool = True
|
| 18 |
-
|
| 19 |
-
def forward(self, x: torch.Tensor):
|
| 20 |
-
d = x.shape[-1] // 2
|
| 21 |
-
output_shape = x.shape[:-1] + (d,)
|
| 22 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 23 |
-
ops.silu_and_mul(out, x)
|
| 24 |
-
return out
|
| 25 |
-
|
| 26 |
-
class Silu(nn.Module):
|
| 27 |
-
"""An activation function for SiLU.
|
| 28 |
-
|
| 29 |
-
The function computes x -> silu(x).
|
| 30 |
-
|
| 31 |
-
Shapes:
|
| 32 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 33 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
can_torch_compile: bool = True
|
| 37 |
-
|
| 38 |
-
def forward(self, x: torch.Tensor):
|
| 39 |
-
out = torch.empty_like(x)
|
| 40 |
-
ops.silu(out, x)
|
| 41 |
-
return out
|
| 42 |
-
|
| 43 |
-
class Gelu(nn.Module):
|
| 44 |
-
"""An activation function for GELU.
|
| 45 |
-
|
| 46 |
-
The function computes x -> gelu(x).
|
| 47 |
-
|
| 48 |
-
Shapes:
|
| 49 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 50 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
can_torch_compile: bool = True
|
| 54 |
-
|
| 55 |
-
def forward(self, x: torch.Tensor):
|
| 56 |
-
out = torch.empty_like(x)
|
| 57 |
-
ops.gelu(out, x)
|
| 58 |
-
return out
|
| 59 |
-
|
| 60 |
-
class GeluTanh(nn.Module):
|
| 61 |
-
"""An activation function for GELU with `tanh` approximation.
|
| 62 |
-
|
| 63 |
-
The function computes x -> gelu_tanh(x).
|
| 64 |
-
|
| 65 |
-
Shapes:
|
| 66 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 67 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
can_torch_compile: bool = True
|
| 71 |
-
|
| 72 |
-
def forward(self, x: torch.Tensor):
|
| 73 |
-
out = torch.empty_like(x)
|
| 74 |
-
ops.gelu_tanh(out, x)
|
| 75 |
-
return out
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
class MulAndSilu(nn.Module):
|
| 79 |
-
"""An activation function for SwiGLU.
|
| 80 |
-
|
| 81 |
-
The function computes x -> x[:d] * silu(x[d:]) where d = x.shape[-1] // 2.
|
| 82 |
-
|
| 83 |
-
Shapes:
|
| 84 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 85 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 86 |
-
"""
|
| 87 |
-
|
| 88 |
-
can_torch_compile: bool = True
|
| 89 |
-
|
| 90 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 91 |
-
d = x.shape[-1] // 2
|
| 92 |
-
output_shape = x.shape[:-1] + (d,)
|
| 93 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 94 |
-
ops.mul_and_silu(out, x)
|
| 95 |
-
return out
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
class GeluAndMul(nn.Module):
|
| 99 |
-
"""An activation function for GeGLU.
|
| 100 |
-
|
| 101 |
-
The function computes x -> GELU(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 102 |
-
|
| 103 |
-
Shapes:
|
| 104 |
-
x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d)
|
| 105 |
-
return: (batch_size, seq_len, d) or (num_tokens, d)
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
-
can_torch_compile: bool = True
|
| 109 |
-
|
| 110 |
-
def forward(self, x: torch.Tensor):
|
| 111 |
-
d = x.shape[-1] // 2
|
| 112 |
-
output_shape = x.shape[:-1] + (d,)
|
| 113 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 114 |
-
ops.gelu_and_mul(out, x)
|
| 115 |
-
return out
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
class GeluTanhAndMul(nn.Module):
|
| 119 |
-
can_torch_compile: bool = True
|
| 120 |
-
|
| 121 |
-
def forward(self, x: torch.Tensor):
|
| 122 |
-
d = x.shape[-1] // 2
|
| 123 |
-
output_shape = x.shape[:-1] + (d,)
|
| 124 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 125 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 126 |
-
return out
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
class FatreluAndMul(nn.Module):
|
| 130 |
-
"""An activation function for FATReLU.
|
| 131 |
-
|
| 132 |
-
The function computes x -> FATReLU(x[:d]) * x[d:] where
|
| 133 |
-
d = x.shape[-1] // 2.
|
| 134 |
-
This is used in openbmb/MiniCPM-S-1B-sft.
|
| 135 |
-
|
| 136 |
-
Shapes:
|
| 137 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 138 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 139 |
-
"""
|
| 140 |
-
|
| 141 |
-
can_torch_compile: bool = True
|
| 142 |
-
|
| 143 |
-
def __init__(self, threshold: float = 0.0):
|
| 144 |
-
super().__init__()
|
| 145 |
-
self.threshold = threshold
|
| 146 |
-
|
| 147 |
-
def forward(self, x: torch.Tensor):
|
| 148 |
-
d = x.shape[-1] // 2
|
| 149 |
-
output_shape = x.shape[:-1] + (d,)
|
| 150 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 151 |
-
ops.fatrelu_and_mul(out, x, self.threshold)
|
| 152 |
-
return out
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
class FastGELU(nn.Module):
|
| 156 |
-
can_torch_compile: bool = True
|
| 157 |
-
|
| 158 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 159 |
-
out = torch.empty_like(x)
|
| 160 |
-
ops.gelu_fast(out, x)
|
| 161 |
-
return out
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
class NewGELU(nn.Module):
|
| 165 |
-
can_torch_compile: bool = True
|
| 166 |
-
|
| 167 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 168 |
-
out = torch.empty_like(x)
|
| 169 |
-
ops.gelu_new(out, x)
|
| 170 |
-
return out
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
class QuickGELU(nn.Module):
|
| 174 |
-
can_torch_compile: bool = True
|
| 175 |
-
|
| 176 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 177 |
-
out = torch.empty_like(x)
|
| 178 |
-
ops.gelu_quick(out, x)
|
| 179 |
-
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch28-cxx11-cu129-x86_64-linux/metadata.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"python-depends":[]}
|
|
|
|
|
|
build/torch29-cxx11-cu126-x86_64-linux/__init__.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
|
| 3 |
-
from ._ops import ops
|
| 4 |
-
|
| 5 |
-
from . import layers
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def silu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 9 |
-
ops.silu_and_mul(out, x)
|
| 10 |
-
return out
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def mul_and_silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 14 |
-
ops.mul_and_silu(out, x)
|
| 15 |
-
return out
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def gelu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 19 |
-
ops.gelu_and_mul(out, x)
|
| 20 |
-
return out
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def gelu_tanh_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 24 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 25 |
-
return out
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def fatrelu_and_mul(out: torch.Tensor, x: torch.Tensor, threshold: float = 0.0) -> None:
|
| 29 |
-
ops.fatrelu_and_mul(out, x, threshold)
|
| 30 |
-
return out
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def gelu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 34 |
-
ops.gelu(out, x)
|
| 35 |
-
return out
|
| 36 |
-
|
| 37 |
-
def silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 38 |
-
ops.silu(out, x)
|
| 39 |
-
return out
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def gelu_tanh(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 43 |
-
ops.gelu_tanh(out, x)
|
| 44 |
-
return out
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def gelu_fast(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 48 |
-
ops.gelu_fast(out, x)
|
| 49 |
-
return out
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def gelu_new(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 53 |
-
ops.gelu_new(out, x)
|
| 54 |
-
return out
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def gelu_quick(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 58 |
-
ops.gelu_quick(out, x)
|
| 59 |
-
return out
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
__all__ = [
|
| 63 |
-
"silu_and_mul",
|
| 64 |
-
"mul_and_silu",
|
| 65 |
-
"gelu_and_mul",
|
| 66 |
-
"gelu_tanh_and_mul",
|
| 67 |
-
"fatrelu_and_mul",
|
| 68 |
-
"gelu_fast",
|
| 69 |
-
"gelu_new",
|
| 70 |
-
"gelu_quick",
|
| 71 |
-
"gelu_tanh",
|
| 72 |
-
"silu",
|
| 73 |
-
"gelu",
|
| 74 |
-
"layers",
|
| 75 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-x86_64-linux/_activation_d8d5fa1.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:89c27579202d7bb91fe260ba72dc77634d48662859ce719632f756e5a5a3d8eb
|
| 3 |
-
size 3121128
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _activation_d8d5fa1
|
| 3 |
-
ops = torch.ops._activation_d8d5fa1
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_activation_d8d5fa1::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-x86_64-linux/activation/__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/layers.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
|
| 4 |
-
from ._ops import ops
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
class SiluAndMul(nn.Module):
|
| 8 |
-
"""An activation function for SwiGLU.
|
| 9 |
-
|
| 10 |
-
The function computes x -> silu(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 11 |
-
|
| 12 |
-
Shapes:
|
| 13 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 14 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
can_torch_compile: bool = True
|
| 18 |
-
|
| 19 |
-
def forward(self, x: torch.Tensor):
|
| 20 |
-
d = x.shape[-1] // 2
|
| 21 |
-
output_shape = x.shape[:-1] + (d,)
|
| 22 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 23 |
-
ops.silu_and_mul(out, x)
|
| 24 |
-
return out
|
| 25 |
-
|
| 26 |
-
class Silu(nn.Module):
|
| 27 |
-
"""An activation function for SiLU.
|
| 28 |
-
|
| 29 |
-
The function computes x -> silu(x).
|
| 30 |
-
|
| 31 |
-
Shapes:
|
| 32 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 33 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
can_torch_compile: bool = True
|
| 37 |
-
|
| 38 |
-
def forward(self, x: torch.Tensor):
|
| 39 |
-
out = torch.empty_like(x)
|
| 40 |
-
ops.silu(out, x)
|
| 41 |
-
return out
|
| 42 |
-
|
| 43 |
-
class Gelu(nn.Module):
|
| 44 |
-
"""An activation function for GELU.
|
| 45 |
-
|
| 46 |
-
The function computes x -> gelu(x).
|
| 47 |
-
|
| 48 |
-
Shapes:
|
| 49 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 50 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
can_torch_compile: bool = True
|
| 54 |
-
|
| 55 |
-
def forward(self, x: torch.Tensor):
|
| 56 |
-
out = torch.empty_like(x)
|
| 57 |
-
ops.gelu(out, x)
|
| 58 |
-
return out
|
| 59 |
-
|
| 60 |
-
class GeluTanh(nn.Module):
|
| 61 |
-
"""An activation function for GELU with `tanh` approximation.
|
| 62 |
-
|
| 63 |
-
The function computes x -> gelu_tanh(x).
|
| 64 |
-
|
| 65 |
-
Shapes:
|
| 66 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 67 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
can_torch_compile: bool = True
|
| 71 |
-
|
| 72 |
-
def forward(self, x: torch.Tensor):
|
| 73 |
-
out = torch.empty_like(x)
|
| 74 |
-
ops.gelu_tanh(out, x)
|
| 75 |
-
return out
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
class MulAndSilu(nn.Module):
|
| 79 |
-
"""An activation function for SwiGLU.
|
| 80 |
-
|
| 81 |
-
The function computes x -> x[:d] * silu(x[d:]) where d = x.shape[-1] // 2.
|
| 82 |
-
|
| 83 |
-
Shapes:
|
| 84 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 85 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 86 |
-
"""
|
| 87 |
-
|
| 88 |
-
can_torch_compile: bool = True
|
| 89 |
-
|
| 90 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 91 |
-
d = x.shape[-1] // 2
|
| 92 |
-
output_shape = x.shape[:-1] + (d,)
|
| 93 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 94 |
-
ops.mul_and_silu(out, x)
|
| 95 |
-
return out
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
class GeluAndMul(nn.Module):
|
| 99 |
-
"""An activation function for GeGLU.
|
| 100 |
-
|
| 101 |
-
The function computes x -> GELU(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 102 |
-
|
| 103 |
-
Shapes:
|
| 104 |
-
x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d)
|
| 105 |
-
return: (batch_size, seq_len, d) or (num_tokens, d)
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
-
can_torch_compile: bool = True
|
| 109 |
-
|
| 110 |
-
def forward(self, x: torch.Tensor):
|
| 111 |
-
d = x.shape[-1] // 2
|
| 112 |
-
output_shape = x.shape[:-1] + (d,)
|
| 113 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 114 |
-
ops.gelu_and_mul(out, x)
|
| 115 |
-
return out
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
class GeluTanhAndMul(nn.Module):
|
| 119 |
-
can_torch_compile: bool = True
|
| 120 |
-
|
| 121 |
-
def forward(self, x: torch.Tensor):
|
| 122 |
-
d = x.shape[-1] // 2
|
| 123 |
-
output_shape = x.shape[:-1] + (d,)
|
| 124 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 125 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 126 |
-
return out
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
class FatreluAndMul(nn.Module):
|
| 130 |
-
"""An activation function for FATReLU.
|
| 131 |
-
|
| 132 |
-
The function computes x -> FATReLU(x[:d]) * x[d:] where
|
| 133 |
-
d = x.shape[-1] // 2.
|
| 134 |
-
This is used in openbmb/MiniCPM-S-1B-sft.
|
| 135 |
-
|
| 136 |
-
Shapes:
|
| 137 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 138 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 139 |
-
"""
|
| 140 |
-
|
| 141 |
-
can_torch_compile: bool = True
|
| 142 |
-
|
| 143 |
-
def __init__(self, threshold: float = 0.0):
|
| 144 |
-
super().__init__()
|
| 145 |
-
self.threshold = threshold
|
| 146 |
-
|
| 147 |
-
def forward(self, x: torch.Tensor):
|
| 148 |
-
d = x.shape[-1] // 2
|
| 149 |
-
output_shape = x.shape[:-1] + (d,)
|
| 150 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 151 |
-
ops.fatrelu_and_mul(out, x, self.threshold)
|
| 152 |
-
return out
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
class FastGELU(nn.Module):
|
| 156 |
-
can_torch_compile: bool = True
|
| 157 |
-
|
| 158 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 159 |
-
out = torch.empty_like(x)
|
| 160 |
-
ops.gelu_fast(out, x)
|
| 161 |
-
return out
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
class NewGELU(nn.Module):
|
| 165 |
-
can_torch_compile: bool = True
|
| 166 |
-
|
| 167 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 168 |
-
out = torch.empty_like(x)
|
| 169 |
-
ops.gelu_new(out, x)
|
| 170 |
-
return out
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
class QuickGELU(nn.Module):
|
| 174 |
-
can_torch_compile: bool = True
|
| 175 |
-
|
| 176 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 177 |
-
out = torch.empty_like(x)
|
| 178 |
-
ops.gelu_quick(out, x)
|
| 179 |
-
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu126-x86_64-linux/metadata.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"python-depends":[]}
|
|
|
|
|
|
build/torch29-cxx11-cu128-x86_64-linux/__init__.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
|
| 3 |
-
from ._ops import ops
|
| 4 |
-
|
| 5 |
-
from . import layers
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def silu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 9 |
-
ops.silu_and_mul(out, x)
|
| 10 |
-
return out
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def mul_and_silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 14 |
-
ops.mul_and_silu(out, x)
|
| 15 |
-
return out
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def gelu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 19 |
-
ops.gelu_and_mul(out, x)
|
| 20 |
-
return out
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def gelu_tanh_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 24 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 25 |
-
return out
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def fatrelu_and_mul(out: torch.Tensor, x: torch.Tensor, threshold: float = 0.0) -> None:
|
| 29 |
-
ops.fatrelu_and_mul(out, x, threshold)
|
| 30 |
-
return out
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def gelu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 34 |
-
ops.gelu(out, x)
|
| 35 |
-
return out
|
| 36 |
-
|
| 37 |
-
def silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 38 |
-
ops.silu(out, x)
|
| 39 |
-
return out
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def gelu_tanh(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 43 |
-
ops.gelu_tanh(out, x)
|
| 44 |
-
return out
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def gelu_fast(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 48 |
-
ops.gelu_fast(out, x)
|
| 49 |
-
return out
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def gelu_new(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 53 |
-
ops.gelu_new(out, x)
|
| 54 |
-
return out
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def gelu_quick(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 58 |
-
ops.gelu_quick(out, x)
|
| 59 |
-
return out
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
__all__ = [
|
| 63 |
-
"silu_and_mul",
|
| 64 |
-
"mul_and_silu",
|
| 65 |
-
"gelu_and_mul",
|
| 66 |
-
"gelu_tanh_and_mul",
|
| 67 |
-
"fatrelu_and_mul",
|
| 68 |
-
"gelu_fast",
|
| 69 |
-
"gelu_new",
|
| 70 |
-
"gelu_quick",
|
| 71 |
-
"gelu_tanh",
|
| 72 |
-
"silu",
|
| 73 |
-
"gelu",
|
| 74 |
-
"layers",
|
| 75 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu128-x86_64-linux/_activation_d8d5fa1.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:bf82685c2a9d82d9fee85dc71b12c6ae0130134757bf9af801fcf624d92d25c4
|
| 3 |
-
size 4400864
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu128-x86_64-linux/_ops.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from . import _activation_d8d5fa1
|
| 3 |
-
ops = torch.ops._activation_d8d5fa1
|
| 4 |
-
|
| 5 |
-
def add_op_namespace_prefix(op_name: str):
|
| 6 |
-
"""
|
| 7 |
-
Prefix op by namespace.
|
| 8 |
-
"""
|
| 9 |
-
return f"_activation_d8d5fa1::{op_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu128-x86_64-linux/activation/__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-cu128-x86_64-linux/layers.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
|
| 4 |
-
from ._ops import ops
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
class SiluAndMul(nn.Module):
|
| 8 |
-
"""An activation function for SwiGLU.
|
| 9 |
-
|
| 10 |
-
The function computes x -> silu(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 11 |
-
|
| 12 |
-
Shapes:
|
| 13 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 14 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 15 |
-
"""
|
| 16 |
-
|
| 17 |
-
can_torch_compile: bool = True
|
| 18 |
-
|
| 19 |
-
def forward(self, x: torch.Tensor):
|
| 20 |
-
d = x.shape[-1] // 2
|
| 21 |
-
output_shape = x.shape[:-1] + (d,)
|
| 22 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 23 |
-
ops.silu_and_mul(out, x)
|
| 24 |
-
return out
|
| 25 |
-
|
| 26 |
-
class Silu(nn.Module):
|
| 27 |
-
"""An activation function for SiLU.
|
| 28 |
-
|
| 29 |
-
The function computes x -> silu(x).
|
| 30 |
-
|
| 31 |
-
Shapes:
|
| 32 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 33 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
can_torch_compile: bool = True
|
| 37 |
-
|
| 38 |
-
def forward(self, x: torch.Tensor):
|
| 39 |
-
out = torch.empty_like(x)
|
| 40 |
-
ops.silu(out, x)
|
| 41 |
-
return out
|
| 42 |
-
|
| 43 |
-
class Gelu(nn.Module):
|
| 44 |
-
"""An activation function for GELU.
|
| 45 |
-
|
| 46 |
-
The function computes x -> gelu(x).
|
| 47 |
-
|
| 48 |
-
Shapes:
|
| 49 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 50 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
can_torch_compile: bool = True
|
| 54 |
-
|
| 55 |
-
def forward(self, x: torch.Tensor):
|
| 56 |
-
out = torch.empty_like(x)
|
| 57 |
-
ops.gelu(out, x)
|
| 58 |
-
return out
|
| 59 |
-
|
| 60 |
-
class GeluTanh(nn.Module):
|
| 61 |
-
"""An activation function for GELU with `tanh` approximation.
|
| 62 |
-
|
| 63 |
-
The function computes x -> gelu_tanh(x).
|
| 64 |
-
|
| 65 |
-
Shapes:
|
| 66 |
-
x: (num_tokens, d) or (batch_size, seq_len, d)
|
| 67 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
can_torch_compile: bool = True
|
| 71 |
-
|
| 72 |
-
def forward(self, x: torch.Tensor):
|
| 73 |
-
out = torch.empty_like(x)
|
| 74 |
-
ops.gelu_tanh(out, x)
|
| 75 |
-
return out
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
class MulAndSilu(nn.Module):
|
| 79 |
-
"""An activation function for SwiGLU.
|
| 80 |
-
|
| 81 |
-
The function computes x -> x[:d] * silu(x[d:]) where d = x.shape[-1] // 2.
|
| 82 |
-
|
| 83 |
-
Shapes:
|
| 84 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 85 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 86 |
-
"""
|
| 87 |
-
|
| 88 |
-
can_torch_compile: bool = True
|
| 89 |
-
|
| 90 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 91 |
-
d = x.shape[-1] // 2
|
| 92 |
-
output_shape = x.shape[:-1] + (d,)
|
| 93 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 94 |
-
ops.mul_and_silu(out, x)
|
| 95 |
-
return out
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
class GeluAndMul(nn.Module):
|
| 99 |
-
"""An activation function for GeGLU.
|
| 100 |
-
|
| 101 |
-
The function computes x -> GELU(x[:d]) * x[d:] where d = x.shape[-1] // 2.
|
| 102 |
-
|
| 103 |
-
Shapes:
|
| 104 |
-
x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d)
|
| 105 |
-
return: (batch_size, seq_len, d) or (num_tokens, d)
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
-
can_torch_compile: bool = True
|
| 109 |
-
|
| 110 |
-
def forward(self, x: torch.Tensor):
|
| 111 |
-
d = x.shape[-1] // 2
|
| 112 |
-
output_shape = x.shape[:-1] + (d,)
|
| 113 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 114 |
-
ops.gelu_and_mul(out, x)
|
| 115 |
-
return out
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
class GeluTanhAndMul(nn.Module):
|
| 119 |
-
can_torch_compile: bool = True
|
| 120 |
-
|
| 121 |
-
def forward(self, x: torch.Tensor):
|
| 122 |
-
d = x.shape[-1] // 2
|
| 123 |
-
output_shape = x.shape[:-1] + (d,)
|
| 124 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 125 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 126 |
-
return out
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
class FatreluAndMul(nn.Module):
|
| 130 |
-
"""An activation function for FATReLU.
|
| 131 |
-
|
| 132 |
-
The function computes x -> FATReLU(x[:d]) * x[d:] where
|
| 133 |
-
d = x.shape[-1] // 2.
|
| 134 |
-
This is used in openbmb/MiniCPM-S-1B-sft.
|
| 135 |
-
|
| 136 |
-
Shapes:
|
| 137 |
-
x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d)
|
| 138 |
-
return: (num_tokens, d) or (batch_size, seq_len, d)
|
| 139 |
-
"""
|
| 140 |
-
|
| 141 |
-
can_torch_compile: bool = True
|
| 142 |
-
|
| 143 |
-
def __init__(self, threshold: float = 0.0):
|
| 144 |
-
super().__init__()
|
| 145 |
-
self.threshold = threshold
|
| 146 |
-
|
| 147 |
-
def forward(self, x: torch.Tensor):
|
| 148 |
-
d = x.shape[-1] // 2
|
| 149 |
-
output_shape = x.shape[:-1] + (d,)
|
| 150 |
-
out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
|
| 151 |
-
ops.fatrelu_and_mul(out, x, self.threshold)
|
| 152 |
-
return out
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
class FastGELU(nn.Module):
|
| 156 |
-
can_torch_compile: bool = True
|
| 157 |
-
|
| 158 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 159 |
-
out = torch.empty_like(x)
|
| 160 |
-
ops.gelu_fast(out, x)
|
| 161 |
-
return out
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
class NewGELU(nn.Module):
|
| 165 |
-
can_torch_compile: bool = True
|
| 166 |
-
|
| 167 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 168 |
-
out = torch.empty_like(x)
|
| 169 |
-
ops.gelu_new(out, x)
|
| 170 |
-
return out
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
class QuickGELU(nn.Module):
|
| 174 |
-
can_torch_compile: bool = True
|
| 175 |
-
|
| 176 |
-
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 177 |
-
out = torch.empty_like(x)
|
| 178 |
-
ops.gelu_quick(out, x)
|
| 179 |
-
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu128-x86_64-linux/metadata.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"python-depends":[]}
|
|
|
|
|
|
build/torch29-cxx11-cu130-x86_64-linux/__init__.py
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
|
| 3 |
-
from ._ops import ops
|
| 4 |
-
|
| 5 |
-
from . import layers
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def silu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 9 |
-
ops.silu_and_mul(out, x)
|
| 10 |
-
return out
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def mul_and_silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 14 |
-
ops.mul_and_silu(out, x)
|
| 15 |
-
return out
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def gelu_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 19 |
-
ops.gelu_and_mul(out, x)
|
| 20 |
-
return out
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def gelu_tanh_and_mul(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 24 |
-
ops.gelu_tanh_and_mul(out, x)
|
| 25 |
-
return out
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def fatrelu_and_mul(out: torch.Tensor, x: torch.Tensor, threshold: float = 0.0) -> None:
|
| 29 |
-
ops.fatrelu_and_mul(out, x, threshold)
|
| 30 |
-
return out
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def gelu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 34 |
-
ops.gelu(out, x)
|
| 35 |
-
return out
|
| 36 |
-
|
| 37 |
-
def silu(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 38 |
-
ops.silu(out, x)
|
| 39 |
-
return out
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def gelu_tanh(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 43 |
-
ops.gelu_tanh(out, x)
|
| 44 |
-
return out
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def gelu_fast(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 48 |
-
ops.gelu_fast(out, x)
|
| 49 |
-
return out
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def gelu_new(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 53 |
-
ops.gelu_new(out, x)
|
| 54 |
-
return out
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def gelu_quick(out: torch.Tensor, x: torch.Tensor) -> None:
|
| 58 |
-
ops.gelu_quick(out, x)
|
| 59 |
-
return out
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
__all__ = [
|
| 63 |
-
"silu_and_mul",
|
| 64 |
-
"mul_and_silu",
|
| 65 |
-
"gelu_and_mul",
|
| 66 |
-
"gelu_tanh_and_mul",
|
| 67 |
-
"fatrelu_and_mul",
|
| 68 |
-
"gelu_fast",
|
| 69 |
-
"gelu_new",
|
| 70 |
-
"gelu_quick",
|
| 71 |
-
"gelu_tanh",
|
| 72 |
-
"silu",
|
| 73 |
-
"gelu",
|
| 74 |
-
"layers",
|
| 75 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch29-cxx11-cu130-x86_64-linux/_activation_d8d5fa1.abi3.so
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:2859f0a3d4cacf1c12aa748fc12f1a3b92ad40654d00b15b259f1f13e9d349fd
|
| 3 |
-
size 4180240
|
|
|
|
|
|
|
|
|
|
|
|