Promote latest kernel artifacts to main
Browse files- .gitattributes +3 -35
- README.md +0 -9
- benchmarks/benchmark.py +262 -0
- build/torch210-cxx11-cu128-x86_64-linux/__init__.py +115 -0
- build/torch210-cxx11-cu128-x86_64-linux/_flashrt_adaptive_norms_cuda_cf903dd.abi3.so +3 -0
- build/torch210-cxx11-cu128-x86_64-linux/_ops.py +9 -0
- build/torch210-cxx11-cu128-x86_64-linux/flashrt_adaptive_norms/__init__.py +26 -0
- build/torch210-cxx11-cu128-x86_64-linux/metadata.json +23 -0
- build/torch210-cxx11-cu130-x86_64-linux/__init__.py +115 -0
- build/torch210-cxx11-cu130-x86_64-linux/_flashrt_adaptive_norms_cuda_cf903dd.abi3.so +3 -0
- build/torch210-cxx11-cu130-x86_64-linux/_ops.py +9 -0
- build/torch210-cxx11-cu130-x86_64-linux/flashrt_adaptive_norms/__init__.py +26 -0
- build/torch210-cxx11-cu130-x86_64-linux/metadata.json +21 -0
- build/torch211-cxx11-cu128-x86_64-linux/__init__.py +115 -0
- build/torch211-cxx11-cu128-x86_64-linux/_flashrt_adaptive_norms_cuda_5de4768.abi3.so +3 -0
- build/torch211-cxx11-cu128-x86_64-linux/_ops.py +9 -0
- build/torch211-cxx11-cu128-x86_64-linux/flashrt_adaptive_norms/__init__.py +26 -0
- build/torch211-cxx11-cu128-x86_64-linux/metadata.json +23 -0
- build/torch211-cxx11-cu130-x86_64-linux/__init__.py +115 -0
- build/torch211-cxx11-cu130-x86_64-linux/_flashrt_adaptive_norms_cuda_5de4768.abi3.so +3 -0
- build/torch211-cxx11-cu130-x86_64-linux/_ops.py +9 -0
- build/torch211-cxx11-cu130-x86_64-linux/flashrt_adaptive_norms/__init__.py +26 -0
- build/torch211-cxx11-cu130-x86_64-linux/metadata.json +22 -0
- build/torch212-cxx11-cu130-x86_64-linux/__init__.py +115 -0
- build/torch212-cxx11-cu130-x86_64-linux/_flashrt_adaptive_norms_cuda_5de4768.abi3.so +3 -0
- build/torch212-cxx11-cu130-x86_64-linux/_ops.py +9 -0
- build/torch212-cxx11-cu130-x86_64-linux/flashrt_adaptive_norms/__init__.py +26 -0
- build/torch212-cxx11-cu130-x86_64-linux/metadata.json +22 -0
- build/torch212-cxx11-cu132-x86_64-linux/__init__.py +115 -0
- build/torch212-cxx11-cu132-x86_64-linux/_flashrt_adaptive_norms_cuda_5de4768.abi3.so +3 -0
- build/torch212-cxx11-cu132-x86_64-linux/_ops.py +9 -0
- build/torch212-cxx11-cu132-x86_64-linux/flashrt_adaptive_norms/__init__.py +26 -0
- build/torch212-cxx11-cu132-x86_64-linux/metadata.json +22 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,3 @@
|
|
| 1 |
-
*.
|
| 2 |
-
*.
|
| 3 |
-
*.
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.so filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.pyd filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.dylib filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
# flashrt/flashrt-adaptive-norms
|
| 2 |
-
|
| 3 |
-
This repository is a compatibility mirror for older `kernels` clients
|
| 4 |
-
that resolve repositories through the default Hugging Face model repo API.
|
| 5 |
-
|
| 6 |
-
Canonical Kernel Hub repo: https://huggingface.co/kernels/flashrt/flashrt-adaptive-norms
|
| 7 |
-
|
| 8 |
-
Do not edit this mirror by hand. It is generated from the Kernel Hub
|
| 9 |
-
`vN` branches and contains the same `build/**` artifacts.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
benchmarks/benchmark.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Benchmark flashrt-adaptive-norms against PyTorch eager references."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import ctypes
|
| 8 |
+
import ctypes.util
|
| 9 |
+
import json
|
| 10 |
+
import math
|
| 11 |
+
import os
|
| 12 |
+
import sys
|
| 13 |
+
from dataclasses import asdict, dataclass
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
import torch
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
ROOT = Path(__file__).resolve().parents[2]
|
| 20 |
+
PACKAGE = ROOT / "flashrt-adaptive-norms"
|
| 21 |
+
REGISTRATION_INCLUDE = (
|
| 22 |
+
ROOT.parent
|
| 23 |
+
/ "kernels"
|
| 24 |
+
/ "kernel-builder"
|
| 25 |
+
/ "src"
|
| 26 |
+
/ "pyproject"
|
| 27 |
+
/ "templates"
|
| 28 |
+
/ "torch"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
SHAPES = {
|
| 32 |
+
"small": (64, 1024),
|
| 33 |
+
"vla_2k": (2520, 3072),
|
| 34 |
+
"vla_4k": (4096, 3072),
|
| 35 |
+
}
|
| 36 |
+
SHAPE_GROUPS = {
|
| 37 |
+
"smoke": ["small"],
|
| 38 |
+
"headline": ["vla_2k"],
|
| 39 |
+
"all": list(SHAPES.keys()),
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@dataclass
|
| 44 |
+
class Result:
|
| 45 |
+
shape: str
|
| 46 |
+
rows: int
|
| 47 |
+
dim: int
|
| 48 |
+
kernel: str
|
| 49 |
+
flashrt_us: float
|
| 50 |
+
torch_eager_us: float
|
| 51 |
+
speedup_vs_eager: float
|
| 52 |
+
p99_abs: float
|
| 53 |
+
cosine: float
|
| 54 |
+
status: str
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class SourceOps:
|
| 58 |
+
def __init__(self, namespace: str) -> None:
|
| 59 |
+
self._ops = getattr(torch.ops, namespace)
|
| 60 |
+
|
| 61 |
+
def ada_rms_norm_style_bf16(self, x, weight, style, eps, out, gate_out):
|
| 62 |
+
self._ops.ada_rms_norm_style_bf16(x, weight, style, float(eps), out, gate_out)
|
| 63 |
+
return out, gate_out
|
| 64 |
+
|
| 65 |
+
def gate_residual_ada_norm_fp8_static_bf16(self, residual, x, gate, weight, style, scale, eps, out, gate_out):
|
| 66 |
+
self._ops.gate_residual_ada_norm_fp8_static_bf16(
|
| 67 |
+
residual, x, gate, weight, style, scale, float(eps), out, gate_out
|
| 68 |
+
)
|
| 69 |
+
return residual, out, gate_out
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def _preload_cublaslt() -> None:
|
| 73 |
+
for parent in Path(torch.__file__).resolve().parents:
|
| 74 |
+
candidate = parent / "nvidia" / "cublas" / "lib" / "libcublasLt.so.12"
|
| 75 |
+
if candidate.exists():
|
| 76 |
+
ctypes.CDLL(str(candidate), mode=ctypes.RTLD_GLOBAL)
|
| 77 |
+
return
|
| 78 |
+
library = ctypes.util.find_library("cublasLt")
|
| 79 |
+
if library:
|
| 80 |
+
ctypes.CDLL(library, mode=ctypes.RTLD_GLOBAL)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _current_arch_list() -> str:
|
| 84 |
+
major, minor = torch.cuda.get_device_capability(0)
|
| 85 |
+
return f"{major}.{minor}"
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def load_source_ops() -> SourceOps:
|
| 89 |
+
from torch.utils.cpp_extension import load
|
| 90 |
+
|
| 91 |
+
if not REGISTRATION_INCLUDE.is_dir():
|
| 92 |
+
raise RuntimeError(f"missing kernel-builder registration include: {REGISTRATION_INCLUDE}")
|
| 93 |
+
_preload_cublaslt()
|
| 94 |
+
os.environ.setdefault("TORCH_CUDA_ARCH_LIST", _current_arch_list())
|
| 95 |
+
namespace = "flashrt_adaptive_norms_benchmark"
|
| 96 |
+
load(
|
| 97 |
+
name=namespace,
|
| 98 |
+
sources=[
|
| 99 |
+
str(PACKAGE / "torch-ext" / "torch_binding.cpp"),
|
| 100 |
+
str(PACKAGE / "csrc" / "adaptive_norms.cu"),
|
| 101 |
+
],
|
| 102 |
+
extra_include_paths=[str(PACKAGE / "csrc"), str(REGISTRATION_INCLUDE)],
|
| 103 |
+
extra_cflags=["-O3", "-DCUDA_KERNEL"],
|
| 104 |
+
extra_cuda_cflags=["-O3", "--expt-relaxed-constexpr", "-DCUDA_KERNEL"],
|
| 105 |
+
verbose=False,
|
| 106 |
+
)
|
| 107 |
+
return SourceOps(namespace)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def load_installed_ops(artifact: str | None):
|
| 111 |
+
if artifact:
|
| 112 |
+
sys.path.insert(0, artifact)
|
| 113 |
+
try:
|
| 114 |
+
return importlib.import_module("flashrt_adaptive_norms")
|
| 115 |
+
finally:
|
| 116 |
+
if artifact:
|
| 117 |
+
sys.path.remove(artifact)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def make_case(rows: int, dim: int):
|
| 121 |
+
x = torch.randn((rows, dim), device="cuda", dtype=torch.bfloat16)
|
| 122 |
+
residual = torch.randn_like(x)
|
| 123 |
+
gate = torch.randn_like(x)
|
| 124 |
+
weight = (1.0 + 0.1 * torch.randn((dim,), device="cuda", dtype=torch.bfloat16)).contiguous()
|
| 125 |
+
style = (0.05 * torch.randn((rows, 3 * dim), device="cuda", dtype=torch.bfloat16)).contiguous()
|
| 126 |
+
scale = torch.tensor([0.04], device="cuda", dtype=torch.float32)
|
| 127 |
+
return x, residual, gate, weight, style, scale
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def rms_norm(x, weight, eps):
|
| 131 |
+
rms = torch.rsqrt(torch.mean(x.float() * x.float(), dim=-1, keepdim=True) + eps)
|
| 132 |
+
return x.float() * rms * weight.float()
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def ref_ada(x, weight, style, eps):
|
| 136 |
+
dim = x.shape[1]
|
| 137 |
+
normed = rms_norm(x, weight, eps)
|
| 138 |
+
y = normed * (1.0 + style[:, :dim].float()) + style[:, dim : 2 * dim].float()
|
| 139 |
+
return y.to(torch.bfloat16), style[:, 2 * dim :].contiguous().to(torch.bfloat16)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def ref_fused(residual, x, gate, weight, style, scale, eps):
|
| 143 |
+
updated = (residual.float() + x.float() * gate.float()).to(torch.bfloat16)
|
| 144 |
+
dim = updated.shape[1]
|
| 145 |
+
normed = rms_norm(updated, weight, eps)
|
| 146 |
+
y = (normed * (1.0 + style[:, :dim].float()) + style[:, dim : 2 * dim].float()) / scale.float().reshape(())
|
| 147 |
+
return updated, y.to(torch.float8_e4m3fn), style[:, 2 * dim :].contiguous().to(torch.bfloat16)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def time_us(fn, warmup, iters):
|
| 151 |
+
for _ in range(warmup):
|
| 152 |
+
fn()
|
| 153 |
+
torch.cuda.synchronize()
|
| 154 |
+
start = torch.cuda.Event(enable_timing=True)
|
| 155 |
+
end = torch.cuda.Event(enable_timing=True)
|
| 156 |
+
start.record()
|
| 157 |
+
for _ in range(iters):
|
| 158 |
+
fn()
|
| 159 |
+
end.record()
|
| 160 |
+
torch.cuda.synchronize()
|
| 161 |
+
return start.elapsed_time(end) * 1000.0 / iters
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def percentile(x, q):
|
| 165 |
+
flat = x.flatten()
|
| 166 |
+
k = max(1, min(flat.numel(), math.ceil(q * flat.numel())))
|
| 167 |
+
return flat.kthvalue(k).values
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def metrics(got, expected):
|
| 171 |
+
diff = (got.float() - expected.float()).abs().flatten()
|
| 172 |
+
return float(percentile(diff, 0.99).item()), float(
|
| 173 |
+
torch.nn.functional.cosine_similarity(got.float().flatten(), expected.float().flatten(), dim=0).item()
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def run_one(ops, name, shape, args):
|
| 178 |
+
rows, dim = shape
|
| 179 |
+
x, residual, gate, weight, style, scale = make_case(rows, dim)
|
| 180 |
+
out = torch.empty_like(x)
|
| 181 |
+
gate_out = torch.empty_like(x)
|
| 182 |
+
fp8_out = torch.empty_like(x, dtype=torch.float8_e4m3fn)
|
| 183 |
+
fused_gate_out = torch.empty_like(x)
|
| 184 |
+
ada_got, _ = ops.ada_rms_norm_style_bf16(x, weight, style, args.eps, out, gate_out)
|
| 185 |
+
ada_exp, _ = ref_ada(x, weight, style, args.eps)
|
| 186 |
+
ada_p99, ada_cos = metrics(ada_got, ada_exp)
|
| 187 |
+
ada_flashrt_us = time_us(lambda: ops.ada_rms_norm_style_bf16(x, weight, style, args.eps, out, gate_out), args.warmup, args.iters)
|
| 188 |
+
ada_eager_us = time_us(lambda: ref_ada(x, weight, style, args.eps), args.warmup, args.iters)
|
| 189 |
+
|
| 190 |
+
residual_work = residual.clone()
|
| 191 |
+
fused_got = ops.gate_residual_ada_norm_fp8_static_bf16(
|
| 192 |
+
residual_work, x, gate, weight, style, scale, args.eps, fp8_out, fused_gate_out
|
| 193 |
+
)[1]
|
| 194 |
+
_, fused_exp, _ = ref_fused(residual, x, gate, weight, style, scale, args.eps)
|
| 195 |
+
fused_p99, fused_cos = metrics(fused_got.float(), fused_exp.float())
|
| 196 |
+
fused_flashrt_us = time_us(
|
| 197 |
+
lambda: ops.gate_residual_ada_norm_fp8_static_bf16(
|
| 198 |
+
residual_work, x, gate, weight, style, scale, args.eps, fp8_out, fused_gate_out
|
| 199 |
+
),
|
| 200 |
+
args.warmup,
|
| 201 |
+
args.iters,
|
| 202 |
+
)
|
| 203 |
+
fused_eager_us = time_us(lambda: ref_fused(residual, x, gate, weight, style, scale, args.eps), args.warmup, args.iters)
|
| 204 |
+
|
| 205 |
+
return [
|
| 206 |
+
Result(name, rows, dim, "ada_rms_norm_style_bf16", ada_flashrt_us, ada_eager_us, ada_eager_us / ada_flashrt_us, ada_p99, ada_cos, "PASS"),
|
| 207 |
+
Result(name, rows, dim, "gate_residual_ada_norm_fp8_static_bf16", fused_flashrt_us, fused_eager_us, fused_eager_us / fused_flashrt_us, fused_p99, fused_cos, "PASS"),
|
| 208 |
+
]
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def write_markdown(path: Path, results: list[Result]) -> None:
|
| 212 |
+
lines = [
|
| 213 |
+
"# Source Benchmark Results",
|
| 214 |
+
"",
|
| 215 |
+
"Environment: NVIDIA GeForce RTX 5090 local source-extension build.",
|
| 216 |
+
"Baseline: PyTorch eager tensor reference with matching BF16/FP8 math contract.",
|
| 217 |
+
"",
|
| 218 |
+
"| Shape | Rows,Dim | Kernel | FlashRT us | Eager us | vs eager | p99 abs | Cosine | Status |",
|
| 219 |
+
"|---|---:|---|---:|---:|---:|---:|---:|---|",
|
| 220 |
+
]
|
| 221 |
+
for r in results:
|
| 222 |
+
lines.append(
|
| 223 |
+
f"| {r.shape} | {r.rows},{r.dim} | {r.kernel} | {r.flashrt_us:.3f} | "
|
| 224 |
+
f"{r.torch_eager_us:.3f} | {r.speedup_vs_eager:.2f}x | {r.p99_abs:.6f} | "
|
| 225 |
+
f"{r.cosine:.8f} | {r.status} |"
|
| 226 |
+
)
|
| 227 |
+
path.write_text("\n".join(lines) + "\n")
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def main():
|
| 231 |
+
parser = argparse.ArgumentParser()
|
| 232 |
+
parser.add_argument("--backend", choices=["source", "installed"], default="source")
|
| 233 |
+
parser.add_argument("--artifact", default=None)
|
| 234 |
+
parser.add_argument("--shapes", choices=sorted(SHAPE_GROUPS), default="smoke")
|
| 235 |
+
parser.add_argument("--warmup", type=int, default=5)
|
| 236 |
+
parser.add_argument("--iters", type=int, default=20)
|
| 237 |
+
parser.add_argument("--eps", type=float, default=1e-6)
|
| 238 |
+
parser.add_argument("--output", default=None)
|
| 239 |
+
parser.add_argument("--markdown", default=None)
|
| 240 |
+
args = parser.parse_args()
|
| 241 |
+
if not torch.cuda.is_available():
|
| 242 |
+
raise SystemExit("CUDA is required")
|
| 243 |
+
torch.manual_seed(53)
|
| 244 |
+
ops = load_source_ops() if args.backend == "source" else load_installed_ops(args.artifact)
|
| 245 |
+
results = []
|
| 246 |
+
for name in SHAPE_GROUPS[args.shapes]:
|
| 247 |
+
results.extend(run_one(ops, name, SHAPES[name], args))
|
| 248 |
+
for r in results:
|
| 249 |
+
print(
|
| 250 |
+
f"{r.status} {r.shape}/{r.kernel}: flashrt={r.flashrt_us:.3f}us "
|
| 251 |
+
f"eager={r.torch_eager_us:.3f}us speedup={r.speedup_vs_eager:.2f}x p99={r.p99_abs:.6f}"
|
| 252 |
+
)
|
| 253 |
+
if args.output:
|
| 254 |
+
Path(args.output).parent.mkdir(parents=True, exist_ok=True)
|
| 255 |
+
Path(args.output).write_text(json.dumps([asdict(r) for r in results], indent=2) + "\n")
|
| 256 |
+
if args.markdown:
|
| 257 |
+
Path(args.markdown).parent.mkdir(parents=True, exist_ok=True)
|
| 258 |
+
write_markdown(Path(args.markdown), results)
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
if __name__ == "__main__":
|
| 262 |
+
main()
|
build/torch210-cxx11-cu128-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT adaptive norm kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _check_adaptive_shapes(
|
| 11 |
+
x: torch.Tensor,
|
| 12 |
+
weight: torch.Tensor,
|
| 13 |
+
style: torch.Tensor,
|
| 14 |
+
out: torch.Tensor,
|
| 15 |
+
gate_out: torch.Tensor,
|
| 16 |
+
) -> None:
|
| 17 |
+
if x.dim() != 2:
|
| 18 |
+
raise RuntimeError("x must have shape (rows, dim)")
|
| 19 |
+
rows, dim = x.shape
|
| 20 |
+
if dim % 2 != 0:
|
| 21 |
+
raise RuntimeError("x.shape[1] must be even")
|
| 22 |
+
if weight.shape != (dim,):
|
| 23 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 24 |
+
if style.shape != (rows, 3 * dim):
|
| 25 |
+
raise RuntimeError("style must have shape (rows, 3 * dim)")
|
| 26 |
+
if out.shape != x.shape or gate_out.shape != x.shape:
|
| 27 |
+
raise RuntimeError("out and gate_out must have the same shape as x")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@torch.library.register_fake(add_op_namespace_prefix("ada_rms_norm_style_bf16"))
|
| 31 |
+
def _ada_rms_norm_style_bf16_fake(
|
| 32 |
+
x: torch.Tensor,
|
| 33 |
+
weight: torch.Tensor,
|
| 34 |
+
style: torch.Tensor,
|
| 35 |
+
eps: float,
|
| 36 |
+
out: torch.Tensor,
|
| 37 |
+
gate_out: torch.Tensor,
|
| 38 |
+
) -> None:
|
| 39 |
+
_check_adaptive_shapes(x, weight, style, out, gate_out)
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@torch.library.register_fake(add_op_namespace_prefix("gate_residual_ada_norm_fp8_static_bf16"))
|
| 44 |
+
def _gate_residual_ada_norm_fp8_static_bf16_fake(
|
| 45 |
+
residual: torch.Tensor,
|
| 46 |
+
x: torch.Tensor,
|
| 47 |
+
gate: torch.Tensor,
|
| 48 |
+
weight: torch.Tensor,
|
| 49 |
+
style: torch.Tensor,
|
| 50 |
+
scale: torch.Tensor,
|
| 51 |
+
eps: float,
|
| 52 |
+
out: torch.Tensor,
|
| 53 |
+
gate_out: torch.Tensor,
|
| 54 |
+
) -> None:
|
| 55 |
+
_check_adaptive_shapes(residual, weight, style, out, gate_out)
|
| 56 |
+
if x.shape != residual.shape or gate.shape != residual.shape:
|
| 57 |
+
raise RuntimeError("x and gate must have the same shape as residual")
|
| 58 |
+
if scale.numel() != 1:
|
| 59 |
+
raise RuntimeError("scale must be a scalar tensor")
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def ada_rms_norm_style_bf16(
|
| 64 |
+
x: torch.Tensor,
|
| 65 |
+
weight: torch.Tensor,
|
| 66 |
+
style: torch.Tensor,
|
| 67 |
+
eps: float = 1e-6,
|
| 68 |
+
out: torch.Tensor | None = None,
|
| 69 |
+
gate_out: torch.Tensor | None = None,
|
| 70 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 71 |
+
"""Apply RMSNorm, style scale/shift, and return the style gate."""
|
| 72 |
+
|
| 73 |
+
if out is None:
|
| 74 |
+
out = torch.empty_like(x)
|
| 75 |
+
if gate_out is None:
|
| 76 |
+
gate_out = torch.empty_like(x)
|
| 77 |
+
ops.ada_rms_norm_style_bf16(x, weight, style, float(eps), out, gate_out)
|
| 78 |
+
return out, gate_out
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def gate_residual_ada_norm_fp8_static_bf16(
|
| 82 |
+
residual: torch.Tensor,
|
| 83 |
+
x: torch.Tensor,
|
| 84 |
+
gate: torch.Tensor,
|
| 85 |
+
weight: torch.Tensor,
|
| 86 |
+
style: torch.Tensor,
|
| 87 |
+
scale: torch.Tensor,
|
| 88 |
+
eps: float = 1e-6,
|
| 89 |
+
out: torch.Tensor | None = None,
|
| 90 |
+
gate_out: torch.Tensor | None = None,
|
| 91 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 92 |
+
"""Update residual in place, apply AdaRMSNorm, and emit static-scale FP8."""
|
| 93 |
+
|
| 94 |
+
if out is None:
|
| 95 |
+
out = torch.empty_like(residual, dtype=torch.float8_e4m3fn)
|
| 96 |
+
if gate_out is None:
|
| 97 |
+
gate_out = torch.empty_like(residual)
|
| 98 |
+
ops.gate_residual_ada_norm_fp8_static_bf16(
|
| 99 |
+
residual,
|
| 100 |
+
x,
|
| 101 |
+
gate,
|
| 102 |
+
weight,
|
| 103 |
+
style,
|
| 104 |
+
scale,
|
| 105 |
+
float(eps),
|
| 106 |
+
out,
|
| 107 |
+
gate_out,
|
| 108 |
+
)
|
| 109 |
+
return residual, out, gate_out
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
__all__ = [
|
| 113 |
+
"ada_rms_norm_style_bf16",
|
| 114 |
+
"gate_residual_ada_norm_fp8_static_bf16",
|
| 115 |
+
]
|
build/torch210-cxx11-cu128-x86_64-linux/_flashrt_adaptive_norms_cuda_cf903dd.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dd4d1f1d39139b7bcc835ea152870ca32ede8f17f6591eac7eba14194bcb0098
|
| 3 |
+
size 2358176
|
build/torch210-cxx11-cu128-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flashrt_adaptive_norms_cuda_cf903dd
|
| 3 |
+
ops = torch.ops._flashrt_adaptive_norms_cuda_cf903dd
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flashrt_adaptive_norms_cuda_cf903dd::{op_name}"
|
build/torch210-cxx11-cu128-x86_64-linux/flashrt_adaptive_norms/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch210-cxx11-cu128-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flashrt-adaptive-norms",
|
| 3 |
+
"id": "_flashrt_adaptive_norms_cuda_cf903dd",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"10.0",
|
| 11 |
+
"10.1",
|
| 12 |
+
"12.0+PTX",
|
| 13 |
+
"7.0",
|
| 14 |
+
"7.2",
|
| 15 |
+
"7.5",
|
| 16 |
+
"8.0",
|
| 17 |
+
"8.6",
|
| 18 |
+
"8.7",
|
| 19 |
+
"8.9",
|
| 20 |
+
"9.0"
|
| 21 |
+
]
|
| 22 |
+
}
|
| 23 |
+
}
|
build/torch210-cxx11-cu130-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT adaptive norm kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _check_adaptive_shapes(
|
| 11 |
+
x: torch.Tensor,
|
| 12 |
+
weight: torch.Tensor,
|
| 13 |
+
style: torch.Tensor,
|
| 14 |
+
out: torch.Tensor,
|
| 15 |
+
gate_out: torch.Tensor,
|
| 16 |
+
) -> None:
|
| 17 |
+
if x.dim() != 2:
|
| 18 |
+
raise RuntimeError("x must have shape (rows, dim)")
|
| 19 |
+
rows, dim = x.shape
|
| 20 |
+
if dim % 2 != 0:
|
| 21 |
+
raise RuntimeError("x.shape[1] must be even")
|
| 22 |
+
if weight.shape != (dim,):
|
| 23 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 24 |
+
if style.shape != (rows, 3 * dim):
|
| 25 |
+
raise RuntimeError("style must have shape (rows, 3 * dim)")
|
| 26 |
+
if out.shape != x.shape or gate_out.shape != x.shape:
|
| 27 |
+
raise RuntimeError("out and gate_out must have the same shape as x")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@torch.library.register_fake(add_op_namespace_prefix("ada_rms_norm_style_bf16"))
|
| 31 |
+
def _ada_rms_norm_style_bf16_fake(
|
| 32 |
+
x: torch.Tensor,
|
| 33 |
+
weight: torch.Tensor,
|
| 34 |
+
style: torch.Tensor,
|
| 35 |
+
eps: float,
|
| 36 |
+
out: torch.Tensor,
|
| 37 |
+
gate_out: torch.Tensor,
|
| 38 |
+
) -> None:
|
| 39 |
+
_check_adaptive_shapes(x, weight, style, out, gate_out)
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@torch.library.register_fake(add_op_namespace_prefix("gate_residual_ada_norm_fp8_static_bf16"))
|
| 44 |
+
def _gate_residual_ada_norm_fp8_static_bf16_fake(
|
| 45 |
+
residual: torch.Tensor,
|
| 46 |
+
x: torch.Tensor,
|
| 47 |
+
gate: torch.Tensor,
|
| 48 |
+
weight: torch.Tensor,
|
| 49 |
+
style: torch.Tensor,
|
| 50 |
+
scale: torch.Tensor,
|
| 51 |
+
eps: float,
|
| 52 |
+
out: torch.Tensor,
|
| 53 |
+
gate_out: torch.Tensor,
|
| 54 |
+
) -> None:
|
| 55 |
+
_check_adaptive_shapes(residual, weight, style, out, gate_out)
|
| 56 |
+
if x.shape != residual.shape or gate.shape != residual.shape:
|
| 57 |
+
raise RuntimeError("x and gate must have the same shape as residual")
|
| 58 |
+
if scale.numel() != 1:
|
| 59 |
+
raise RuntimeError("scale must be a scalar tensor")
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def ada_rms_norm_style_bf16(
|
| 64 |
+
x: torch.Tensor,
|
| 65 |
+
weight: torch.Tensor,
|
| 66 |
+
style: torch.Tensor,
|
| 67 |
+
eps: float = 1e-6,
|
| 68 |
+
out: torch.Tensor | None = None,
|
| 69 |
+
gate_out: torch.Tensor | None = None,
|
| 70 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 71 |
+
"""Apply RMSNorm, style scale/shift, and return the style gate."""
|
| 72 |
+
|
| 73 |
+
if out is None:
|
| 74 |
+
out = torch.empty_like(x)
|
| 75 |
+
if gate_out is None:
|
| 76 |
+
gate_out = torch.empty_like(x)
|
| 77 |
+
ops.ada_rms_norm_style_bf16(x, weight, style, float(eps), out, gate_out)
|
| 78 |
+
return out, gate_out
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def gate_residual_ada_norm_fp8_static_bf16(
|
| 82 |
+
residual: torch.Tensor,
|
| 83 |
+
x: torch.Tensor,
|
| 84 |
+
gate: torch.Tensor,
|
| 85 |
+
weight: torch.Tensor,
|
| 86 |
+
style: torch.Tensor,
|
| 87 |
+
scale: torch.Tensor,
|
| 88 |
+
eps: float = 1e-6,
|
| 89 |
+
out: torch.Tensor | None = None,
|
| 90 |
+
gate_out: torch.Tensor | None = None,
|
| 91 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 92 |
+
"""Update residual in place, apply AdaRMSNorm, and emit static-scale FP8."""
|
| 93 |
+
|
| 94 |
+
if out is None:
|
| 95 |
+
out = torch.empty_like(residual, dtype=torch.float8_e4m3fn)
|
| 96 |
+
if gate_out is None:
|
| 97 |
+
gate_out = torch.empty_like(residual)
|
| 98 |
+
ops.gate_residual_ada_norm_fp8_static_bf16(
|
| 99 |
+
residual,
|
| 100 |
+
x,
|
| 101 |
+
gate,
|
| 102 |
+
weight,
|
| 103 |
+
style,
|
| 104 |
+
scale,
|
| 105 |
+
float(eps),
|
| 106 |
+
out,
|
| 107 |
+
gate_out,
|
| 108 |
+
)
|
| 109 |
+
return residual, out, gate_out
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
__all__ = [
|
| 113 |
+
"ada_rms_norm_style_bf16",
|
| 114 |
+
"gate_residual_ada_norm_fp8_static_bf16",
|
| 115 |
+
]
|
build/torch210-cxx11-cu130-x86_64-linux/_flashrt_adaptive_norms_cuda_cf903dd.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c26b7df8029b54f99a1e76ce940e0aa389e282b0b21ea5cfd7162c9d94a10884
|
| 3 |
+
size 2312048
|
build/torch210-cxx11-cu130-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flashrt_adaptive_norms_cuda_cf903dd
|
| 3 |
+
ops = torch.ops._flashrt_adaptive_norms_cuda_cf903dd
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flashrt_adaptive_norms_cuda_cf903dd::{op_name}"
|
build/torch210-cxx11-cu130-x86_64-linux/flashrt_adaptive_norms/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch210-cxx11-cu130-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flashrt-adaptive-norms",
|
| 3 |
+
"id": "_flashrt_adaptive_norms_cuda_cf903dd",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"10.0",
|
| 11 |
+
"11.0",
|
| 12 |
+
"12.0+PTX",
|
| 13 |
+
"7.5",
|
| 14 |
+
"8.0",
|
| 15 |
+
"8.6",
|
| 16 |
+
"8.7",
|
| 17 |
+
"8.9",
|
| 18 |
+
"9.0"
|
| 19 |
+
]
|
| 20 |
+
}
|
| 21 |
+
}
|
build/torch211-cxx11-cu128-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT adaptive norm kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _check_adaptive_shapes(
|
| 11 |
+
x: torch.Tensor,
|
| 12 |
+
weight: torch.Tensor,
|
| 13 |
+
style: torch.Tensor,
|
| 14 |
+
out: torch.Tensor,
|
| 15 |
+
gate_out: torch.Tensor,
|
| 16 |
+
) -> None:
|
| 17 |
+
if x.dim() != 2:
|
| 18 |
+
raise RuntimeError("x must have shape (rows, dim)")
|
| 19 |
+
rows, dim = x.shape
|
| 20 |
+
if dim % 2 != 0:
|
| 21 |
+
raise RuntimeError("x.shape[1] must be even")
|
| 22 |
+
if weight.shape != (dim,):
|
| 23 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 24 |
+
if style.shape != (rows, 3 * dim):
|
| 25 |
+
raise RuntimeError("style must have shape (rows, 3 * dim)")
|
| 26 |
+
if out.shape != x.shape or gate_out.shape != x.shape:
|
| 27 |
+
raise RuntimeError("out and gate_out must have the same shape as x")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@torch.library.register_fake(add_op_namespace_prefix("ada_rms_norm_style_bf16"))
|
| 31 |
+
def _ada_rms_norm_style_bf16_fake(
|
| 32 |
+
x: torch.Tensor,
|
| 33 |
+
weight: torch.Tensor,
|
| 34 |
+
style: torch.Tensor,
|
| 35 |
+
eps: float,
|
| 36 |
+
out: torch.Tensor,
|
| 37 |
+
gate_out: torch.Tensor,
|
| 38 |
+
) -> None:
|
| 39 |
+
_check_adaptive_shapes(x, weight, style, out, gate_out)
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@torch.library.register_fake(add_op_namespace_prefix("gate_residual_ada_norm_fp8_static_bf16"))
|
| 44 |
+
def _gate_residual_ada_norm_fp8_static_bf16_fake(
|
| 45 |
+
residual: torch.Tensor,
|
| 46 |
+
x: torch.Tensor,
|
| 47 |
+
gate: torch.Tensor,
|
| 48 |
+
weight: torch.Tensor,
|
| 49 |
+
style: torch.Tensor,
|
| 50 |
+
scale: torch.Tensor,
|
| 51 |
+
eps: float,
|
| 52 |
+
out: torch.Tensor,
|
| 53 |
+
gate_out: torch.Tensor,
|
| 54 |
+
) -> None:
|
| 55 |
+
_check_adaptive_shapes(residual, weight, style, out, gate_out)
|
| 56 |
+
if x.shape != residual.shape or gate.shape != residual.shape:
|
| 57 |
+
raise RuntimeError("x and gate must have the same shape as residual")
|
| 58 |
+
if scale.numel() != 1:
|
| 59 |
+
raise RuntimeError("scale must be a scalar tensor")
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def ada_rms_norm_style_bf16(
|
| 64 |
+
x: torch.Tensor,
|
| 65 |
+
weight: torch.Tensor,
|
| 66 |
+
style: torch.Tensor,
|
| 67 |
+
eps: float = 1e-6,
|
| 68 |
+
out: torch.Tensor | None = None,
|
| 69 |
+
gate_out: torch.Tensor | None = None,
|
| 70 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 71 |
+
"""Apply RMSNorm, style scale/shift, and return the style gate."""
|
| 72 |
+
|
| 73 |
+
if out is None:
|
| 74 |
+
out = torch.empty_like(x)
|
| 75 |
+
if gate_out is None:
|
| 76 |
+
gate_out = torch.empty_like(x)
|
| 77 |
+
ops.ada_rms_norm_style_bf16(x, weight, style, float(eps), out, gate_out)
|
| 78 |
+
return out, gate_out
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def gate_residual_ada_norm_fp8_static_bf16(
|
| 82 |
+
residual: torch.Tensor,
|
| 83 |
+
x: torch.Tensor,
|
| 84 |
+
gate: torch.Tensor,
|
| 85 |
+
weight: torch.Tensor,
|
| 86 |
+
style: torch.Tensor,
|
| 87 |
+
scale: torch.Tensor,
|
| 88 |
+
eps: float = 1e-6,
|
| 89 |
+
out: torch.Tensor | None = None,
|
| 90 |
+
gate_out: torch.Tensor | None = None,
|
| 91 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 92 |
+
"""Update residual in place, apply AdaRMSNorm, and emit static-scale FP8."""
|
| 93 |
+
|
| 94 |
+
if out is None:
|
| 95 |
+
out = torch.empty_like(residual, dtype=torch.float8_e4m3fn)
|
| 96 |
+
if gate_out is None:
|
| 97 |
+
gate_out = torch.empty_like(residual)
|
| 98 |
+
ops.gate_residual_ada_norm_fp8_static_bf16(
|
| 99 |
+
residual,
|
| 100 |
+
x,
|
| 101 |
+
gate,
|
| 102 |
+
weight,
|
| 103 |
+
style,
|
| 104 |
+
scale,
|
| 105 |
+
float(eps),
|
| 106 |
+
out,
|
| 107 |
+
gate_out,
|
| 108 |
+
)
|
| 109 |
+
return residual, out, gate_out
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
__all__ = [
|
| 113 |
+
"ada_rms_norm_style_bf16",
|
| 114 |
+
"gate_residual_ada_norm_fp8_static_bf16",
|
| 115 |
+
]
|
build/torch211-cxx11-cu128-x86_64-linux/_flashrt_adaptive_norms_cuda_5de4768.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f1fd72149bb7c8814bfb36e67b97ea9db5f1c4303a01b7c62c7bbf94395f73ff
|
| 3 |
+
size 418528
|
build/torch211-cxx11-cu128-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flashrt_adaptive_norms_cuda_5de4768
|
| 3 |
+
ops = torch.ops._flashrt_adaptive_norms_cuda_5de4768
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flashrt_adaptive_norms_cuda_5de4768::{op_name}"
|
build/torch211-cxx11-cu128-x86_64-linux/flashrt_adaptive_norms/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch211-cxx11-cu128-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flashrt-adaptive-norms",
|
| 3 |
+
"id": "_flashrt_adaptive_norms_cuda_5de4768",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"10.0",
|
| 11 |
+
"10.1",
|
| 12 |
+
"12.0+PTX",
|
| 13 |
+
"7.0",
|
| 14 |
+
"7.2",
|
| 15 |
+
"7.5",
|
| 16 |
+
"8.0",
|
| 17 |
+
"8.6",
|
| 18 |
+
"8.7",
|
| 19 |
+
"8.9",
|
| 20 |
+
"9.0"
|
| 21 |
+
]
|
| 22 |
+
}
|
| 23 |
+
}
|
build/torch211-cxx11-cu130-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT adaptive norm kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _check_adaptive_shapes(
|
| 11 |
+
x: torch.Tensor,
|
| 12 |
+
weight: torch.Tensor,
|
| 13 |
+
style: torch.Tensor,
|
| 14 |
+
out: torch.Tensor,
|
| 15 |
+
gate_out: torch.Tensor,
|
| 16 |
+
) -> None:
|
| 17 |
+
if x.dim() != 2:
|
| 18 |
+
raise RuntimeError("x must have shape (rows, dim)")
|
| 19 |
+
rows, dim = x.shape
|
| 20 |
+
if dim % 2 != 0:
|
| 21 |
+
raise RuntimeError("x.shape[1] must be even")
|
| 22 |
+
if weight.shape != (dim,):
|
| 23 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 24 |
+
if style.shape != (rows, 3 * dim):
|
| 25 |
+
raise RuntimeError("style must have shape (rows, 3 * dim)")
|
| 26 |
+
if out.shape != x.shape or gate_out.shape != x.shape:
|
| 27 |
+
raise RuntimeError("out and gate_out must have the same shape as x")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@torch.library.register_fake(add_op_namespace_prefix("ada_rms_norm_style_bf16"))
|
| 31 |
+
def _ada_rms_norm_style_bf16_fake(
|
| 32 |
+
x: torch.Tensor,
|
| 33 |
+
weight: torch.Tensor,
|
| 34 |
+
style: torch.Tensor,
|
| 35 |
+
eps: float,
|
| 36 |
+
out: torch.Tensor,
|
| 37 |
+
gate_out: torch.Tensor,
|
| 38 |
+
) -> None:
|
| 39 |
+
_check_adaptive_shapes(x, weight, style, out, gate_out)
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@torch.library.register_fake(add_op_namespace_prefix("gate_residual_ada_norm_fp8_static_bf16"))
|
| 44 |
+
def _gate_residual_ada_norm_fp8_static_bf16_fake(
|
| 45 |
+
residual: torch.Tensor,
|
| 46 |
+
x: torch.Tensor,
|
| 47 |
+
gate: torch.Tensor,
|
| 48 |
+
weight: torch.Tensor,
|
| 49 |
+
style: torch.Tensor,
|
| 50 |
+
scale: torch.Tensor,
|
| 51 |
+
eps: float,
|
| 52 |
+
out: torch.Tensor,
|
| 53 |
+
gate_out: torch.Tensor,
|
| 54 |
+
) -> None:
|
| 55 |
+
_check_adaptive_shapes(residual, weight, style, out, gate_out)
|
| 56 |
+
if x.shape != residual.shape or gate.shape != residual.shape:
|
| 57 |
+
raise RuntimeError("x and gate must have the same shape as residual")
|
| 58 |
+
if scale.numel() != 1:
|
| 59 |
+
raise RuntimeError("scale must be a scalar tensor")
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def ada_rms_norm_style_bf16(
|
| 64 |
+
x: torch.Tensor,
|
| 65 |
+
weight: torch.Tensor,
|
| 66 |
+
style: torch.Tensor,
|
| 67 |
+
eps: float = 1e-6,
|
| 68 |
+
out: torch.Tensor | None = None,
|
| 69 |
+
gate_out: torch.Tensor | None = None,
|
| 70 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 71 |
+
"""Apply RMSNorm, style scale/shift, and return the style gate."""
|
| 72 |
+
|
| 73 |
+
if out is None:
|
| 74 |
+
out = torch.empty_like(x)
|
| 75 |
+
if gate_out is None:
|
| 76 |
+
gate_out = torch.empty_like(x)
|
| 77 |
+
ops.ada_rms_norm_style_bf16(x, weight, style, float(eps), out, gate_out)
|
| 78 |
+
return out, gate_out
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def gate_residual_ada_norm_fp8_static_bf16(
|
| 82 |
+
residual: torch.Tensor,
|
| 83 |
+
x: torch.Tensor,
|
| 84 |
+
gate: torch.Tensor,
|
| 85 |
+
weight: torch.Tensor,
|
| 86 |
+
style: torch.Tensor,
|
| 87 |
+
scale: torch.Tensor,
|
| 88 |
+
eps: float = 1e-6,
|
| 89 |
+
out: torch.Tensor | None = None,
|
| 90 |
+
gate_out: torch.Tensor | None = None,
|
| 91 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 92 |
+
"""Update residual in place, apply AdaRMSNorm, and emit static-scale FP8."""
|
| 93 |
+
|
| 94 |
+
if out is None:
|
| 95 |
+
out = torch.empty_like(residual, dtype=torch.float8_e4m3fn)
|
| 96 |
+
if gate_out is None:
|
| 97 |
+
gate_out = torch.empty_like(residual)
|
| 98 |
+
ops.gate_residual_ada_norm_fp8_static_bf16(
|
| 99 |
+
residual,
|
| 100 |
+
x,
|
| 101 |
+
gate,
|
| 102 |
+
weight,
|
| 103 |
+
style,
|
| 104 |
+
scale,
|
| 105 |
+
float(eps),
|
| 106 |
+
out,
|
| 107 |
+
gate_out,
|
| 108 |
+
)
|
| 109 |
+
return residual, out, gate_out
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
__all__ = [
|
| 113 |
+
"ada_rms_norm_style_bf16",
|
| 114 |
+
"gate_residual_ada_norm_fp8_static_bf16",
|
| 115 |
+
]
|
build/torch211-cxx11-cu130-x86_64-linux/_flashrt_adaptive_norms_cuda_5de4768.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ff1395fab2542b4b21ef298bd6c815c66187d6e8f5ff90190d13c863b0ddba43
|
| 3 |
+
size 417056
|
build/torch211-cxx11-cu130-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flashrt_adaptive_norms_cuda_5de4768
|
| 3 |
+
ops = torch.ops._flashrt_adaptive_norms_cuda_5de4768
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flashrt_adaptive_norms_cuda_5de4768::{op_name}"
|
build/torch211-cxx11-cu130-x86_64-linux/flashrt_adaptive_norms/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch211-cxx11-cu130-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flashrt-adaptive-norms",
|
| 3 |
+
"id": "_flashrt_adaptive_norms_cuda_5de4768",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"10.0",
|
| 11 |
+
"11.0",
|
| 12 |
+
"12.0",
|
| 13 |
+
"12.1+PTX",
|
| 14 |
+
"7.5",
|
| 15 |
+
"8.0",
|
| 16 |
+
"8.6",
|
| 17 |
+
"8.7",
|
| 18 |
+
"8.9",
|
| 19 |
+
"9.0"
|
| 20 |
+
]
|
| 21 |
+
}
|
| 22 |
+
}
|
build/torch212-cxx11-cu130-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT adaptive norm kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _check_adaptive_shapes(
|
| 11 |
+
x: torch.Tensor,
|
| 12 |
+
weight: torch.Tensor,
|
| 13 |
+
style: torch.Tensor,
|
| 14 |
+
out: torch.Tensor,
|
| 15 |
+
gate_out: torch.Tensor,
|
| 16 |
+
) -> None:
|
| 17 |
+
if x.dim() != 2:
|
| 18 |
+
raise RuntimeError("x must have shape (rows, dim)")
|
| 19 |
+
rows, dim = x.shape
|
| 20 |
+
if dim % 2 != 0:
|
| 21 |
+
raise RuntimeError("x.shape[1] must be even")
|
| 22 |
+
if weight.shape != (dim,):
|
| 23 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 24 |
+
if style.shape != (rows, 3 * dim):
|
| 25 |
+
raise RuntimeError("style must have shape (rows, 3 * dim)")
|
| 26 |
+
if out.shape != x.shape or gate_out.shape != x.shape:
|
| 27 |
+
raise RuntimeError("out and gate_out must have the same shape as x")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@torch.library.register_fake(add_op_namespace_prefix("ada_rms_norm_style_bf16"))
|
| 31 |
+
def _ada_rms_norm_style_bf16_fake(
|
| 32 |
+
x: torch.Tensor,
|
| 33 |
+
weight: torch.Tensor,
|
| 34 |
+
style: torch.Tensor,
|
| 35 |
+
eps: float,
|
| 36 |
+
out: torch.Tensor,
|
| 37 |
+
gate_out: torch.Tensor,
|
| 38 |
+
) -> None:
|
| 39 |
+
_check_adaptive_shapes(x, weight, style, out, gate_out)
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@torch.library.register_fake(add_op_namespace_prefix("gate_residual_ada_norm_fp8_static_bf16"))
|
| 44 |
+
def _gate_residual_ada_norm_fp8_static_bf16_fake(
|
| 45 |
+
residual: torch.Tensor,
|
| 46 |
+
x: torch.Tensor,
|
| 47 |
+
gate: torch.Tensor,
|
| 48 |
+
weight: torch.Tensor,
|
| 49 |
+
style: torch.Tensor,
|
| 50 |
+
scale: torch.Tensor,
|
| 51 |
+
eps: float,
|
| 52 |
+
out: torch.Tensor,
|
| 53 |
+
gate_out: torch.Tensor,
|
| 54 |
+
) -> None:
|
| 55 |
+
_check_adaptive_shapes(residual, weight, style, out, gate_out)
|
| 56 |
+
if x.shape != residual.shape or gate.shape != residual.shape:
|
| 57 |
+
raise RuntimeError("x and gate must have the same shape as residual")
|
| 58 |
+
if scale.numel() != 1:
|
| 59 |
+
raise RuntimeError("scale must be a scalar tensor")
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def ada_rms_norm_style_bf16(
|
| 64 |
+
x: torch.Tensor,
|
| 65 |
+
weight: torch.Tensor,
|
| 66 |
+
style: torch.Tensor,
|
| 67 |
+
eps: float = 1e-6,
|
| 68 |
+
out: torch.Tensor | None = None,
|
| 69 |
+
gate_out: torch.Tensor | None = None,
|
| 70 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 71 |
+
"""Apply RMSNorm, style scale/shift, and return the style gate."""
|
| 72 |
+
|
| 73 |
+
if out is None:
|
| 74 |
+
out = torch.empty_like(x)
|
| 75 |
+
if gate_out is None:
|
| 76 |
+
gate_out = torch.empty_like(x)
|
| 77 |
+
ops.ada_rms_norm_style_bf16(x, weight, style, float(eps), out, gate_out)
|
| 78 |
+
return out, gate_out
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def gate_residual_ada_norm_fp8_static_bf16(
|
| 82 |
+
residual: torch.Tensor,
|
| 83 |
+
x: torch.Tensor,
|
| 84 |
+
gate: torch.Tensor,
|
| 85 |
+
weight: torch.Tensor,
|
| 86 |
+
style: torch.Tensor,
|
| 87 |
+
scale: torch.Tensor,
|
| 88 |
+
eps: float = 1e-6,
|
| 89 |
+
out: torch.Tensor | None = None,
|
| 90 |
+
gate_out: torch.Tensor | None = None,
|
| 91 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 92 |
+
"""Update residual in place, apply AdaRMSNorm, and emit static-scale FP8."""
|
| 93 |
+
|
| 94 |
+
if out is None:
|
| 95 |
+
out = torch.empty_like(residual, dtype=torch.float8_e4m3fn)
|
| 96 |
+
if gate_out is None:
|
| 97 |
+
gate_out = torch.empty_like(residual)
|
| 98 |
+
ops.gate_residual_ada_norm_fp8_static_bf16(
|
| 99 |
+
residual,
|
| 100 |
+
x,
|
| 101 |
+
gate,
|
| 102 |
+
weight,
|
| 103 |
+
style,
|
| 104 |
+
scale,
|
| 105 |
+
float(eps),
|
| 106 |
+
out,
|
| 107 |
+
gate_out,
|
| 108 |
+
)
|
| 109 |
+
return residual, out, gate_out
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
__all__ = [
|
| 113 |
+
"ada_rms_norm_style_bf16",
|
| 114 |
+
"gate_residual_ada_norm_fp8_static_bf16",
|
| 115 |
+
]
|
build/torch212-cxx11-cu130-x86_64-linux/_flashrt_adaptive_norms_cuda_5de4768.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a1711b20458b40c1fc8f2c41ed9bc961ccf2ced600b8f29146b6c4edad2e188f
|
| 3 |
+
size 427392
|
build/torch212-cxx11-cu130-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flashrt_adaptive_norms_cuda_5de4768
|
| 3 |
+
ops = torch.ops._flashrt_adaptive_norms_cuda_5de4768
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flashrt_adaptive_norms_cuda_5de4768::{op_name}"
|
build/torch212-cxx11-cu130-x86_64-linux/flashrt_adaptive_norms/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch212-cxx11-cu130-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flashrt-adaptive-norms",
|
| 3 |
+
"id": "_flashrt_adaptive_norms_cuda_5de4768",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"10.0",
|
| 11 |
+
"11.0",
|
| 12 |
+
"12.0",
|
| 13 |
+
"12.1+PTX",
|
| 14 |
+
"7.5",
|
| 15 |
+
"8.0",
|
| 16 |
+
"8.6",
|
| 17 |
+
"8.7",
|
| 18 |
+
"8.9",
|
| 19 |
+
"9.0"
|
| 20 |
+
]
|
| 21 |
+
}
|
| 22 |
+
}
|
build/torch212-cxx11-cu132-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT adaptive norm kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _check_adaptive_shapes(
|
| 11 |
+
x: torch.Tensor,
|
| 12 |
+
weight: torch.Tensor,
|
| 13 |
+
style: torch.Tensor,
|
| 14 |
+
out: torch.Tensor,
|
| 15 |
+
gate_out: torch.Tensor,
|
| 16 |
+
) -> None:
|
| 17 |
+
if x.dim() != 2:
|
| 18 |
+
raise RuntimeError("x must have shape (rows, dim)")
|
| 19 |
+
rows, dim = x.shape
|
| 20 |
+
if dim % 2 != 0:
|
| 21 |
+
raise RuntimeError("x.shape[1] must be even")
|
| 22 |
+
if weight.shape != (dim,):
|
| 23 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 24 |
+
if style.shape != (rows, 3 * dim):
|
| 25 |
+
raise RuntimeError("style must have shape (rows, 3 * dim)")
|
| 26 |
+
if out.shape != x.shape or gate_out.shape != x.shape:
|
| 27 |
+
raise RuntimeError("out and gate_out must have the same shape as x")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@torch.library.register_fake(add_op_namespace_prefix("ada_rms_norm_style_bf16"))
|
| 31 |
+
def _ada_rms_norm_style_bf16_fake(
|
| 32 |
+
x: torch.Tensor,
|
| 33 |
+
weight: torch.Tensor,
|
| 34 |
+
style: torch.Tensor,
|
| 35 |
+
eps: float,
|
| 36 |
+
out: torch.Tensor,
|
| 37 |
+
gate_out: torch.Tensor,
|
| 38 |
+
) -> None:
|
| 39 |
+
_check_adaptive_shapes(x, weight, style, out, gate_out)
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@torch.library.register_fake(add_op_namespace_prefix("gate_residual_ada_norm_fp8_static_bf16"))
|
| 44 |
+
def _gate_residual_ada_norm_fp8_static_bf16_fake(
|
| 45 |
+
residual: torch.Tensor,
|
| 46 |
+
x: torch.Tensor,
|
| 47 |
+
gate: torch.Tensor,
|
| 48 |
+
weight: torch.Tensor,
|
| 49 |
+
style: torch.Tensor,
|
| 50 |
+
scale: torch.Tensor,
|
| 51 |
+
eps: float,
|
| 52 |
+
out: torch.Tensor,
|
| 53 |
+
gate_out: torch.Tensor,
|
| 54 |
+
) -> None:
|
| 55 |
+
_check_adaptive_shapes(residual, weight, style, out, gate_out)
|
| 56 |
+
if x.shape != residual.shape or gate.shape != residual.shape:
|
| 57 |
+
raise RuntimeError("x and gate must have the same shape as residual")
|
| 58 |
+
if scale.numel() != 1:
|
| 59 |
+
raise RuntimeError("scale must be a scalar tensor")
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def ada_rms_norm_style_bf16(
|
| 64 |
+
x: torch.Tensor,
|
| 65 |
+
weight: torch.Tensor,
|
| 66 |
+
style: torch.Tensor,
|
| 67 |
+
eps: float = 1e-6,
|
| 68 |
+
out: torch.Tensor | None = None,
|
| 69 |
+
gate_out: torch.Tensor | None = None,
|
| 70 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 71 |
+
"""Apply RMSNorm, style scale/shift, and return the style gate."""
|
| 72 |
+
|
| 73 |
+
if out is None:
|
| 74 |
+
out = torch.empty_like(x)
|
| 75 |
+
if gate_out is None:
|
| 76 |
+
gate_out = torch.empty_like(x)
|
| 77 |
+
ops.ada_rms_norm_style_bf16(x, weight, style, float(eps), out, gate_out)
|
| 78 |
+
return out, gate_out
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def gate_residual_ada_norm_fp8_static_bf16(
|
| 82 |
+
residual: torch.Tensor,
|
| 83 |
+
x: torch.Tensor,
|
| 84 |
+
gate: torch.Tensor,
|
| 85 |
+
weight: torch.Tensor,
|
| 86 |
+
style: torch.Tensor,
|
| 87 |
+
scale: torch.Tensor,
|
| 88 |
+
eps: float = 1e-6,
|
| 89 |
+
out: torch.Tensor | None = None,
|
| 90 |
+
gate_out: torch.Tensor | None = None,
|
| 91 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 92 |
+
"""Update residual in place, apply AdaRMSNorm, and emit static-scale FP8."""
|
| 93 |
+
|
| 94 |
+
if out is None:
|
| 95 |
+
out = torch.empty_like(residual, dtype=torch.float8_e4m3fn)
|
| 96 |
+
if gate_out is None:
|
| 97 |
+
gate_out = torch.empty_like(residual)
|
| 98 |
+
ops.gate_residual_ada_norm_fp8_static_bf16(
|
| 99 |
+
residual,
|
| 100 |
+
x,
|
| 101 |
+
gate,
|
| 102 |
+
weight,
|
| 103 |
+
style,
|
| 104 |
+
scale,
|
| 105 |
+
float(eps),
|
| 106 |
+
out,
|
| 107 |
+
gate_out,
|
| 108 |
+
)
|
| 109 |
+
return residual, out, gate_out
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
__all__ = [
|
| 113 |
+
"ada_rms_norm_style_bf16",
|
| 114 |
+
"gate_residual_ada_norm_fp8_static_bf16",
|
| 115 |
+
]
|
build/torch212-cxx11-cu132-x86_64-linux/_flashrt_adaptive_norms_cuda_5de4768.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:583119084a84654d0e5532e39e181882ae239009457adaf6a9e6f6e94513eff0
|
| 3 |
+
size 427392
|
build/torch212-cxx11-cu132-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flashrt_adaptive_norms_cuda_5de4768
|
| 3 |
+
ops = torch.ops._flashrt_adaptive_norms_cuda_5de4768
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flashrt_adaptive_norms_cuda_5de4768::{op_name}"
|
build/torch212-cxx11-cu132-x86_64-linux/flashrt_adaptive_norms/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch212-cxx11-cu132-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flashrt-adaptive-norms",
|
| 3 |
+
"id": "_flashrt_adaptive_norms_cuda_5de4768",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"10.0",
|
| 11 |
+
"11.0",
|
| 12 |
+
"12.0",
|
| 13 |
+
"12.1+PTX",
|
| 14 |
+
"7.5",
|
| 15 |
+
"8.0",
|
| 16 |
+
"8.6",
|
| 17 |
+
"8.7",
|
| 18 |
+
"8.9",
|
| 19 |
+
"9.0"
|
| 20 |
+
]
|
| 21 |
+
}
|
| 22 |
+
}
|