Promote latest kernel artifacts to main
Browse files- .gitattributes +3 -35
- README.md +0 -9
- benchmarks/benchmark.py +123 -0
- build/torch211-cxx11-cu128-x86_64-linux/__init__.py +297 -0
- build/torch211-cxx11-cu128-x86_64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so +3 -0
- build/torch211-cxx11-cu128-x86_64-linux/_ops.py +9 -0
- build/torch211-cxx11-cu128-x86_64-linux/blockwise_fp8_producers/__init__.py +26 -0
- build/torch211-cxx11-cu128-x86_64-linux/metadata.json +23 -0
- build/torch211-cxx11-cu130-aarch64-linux/__init__.py +297 -0
- build/torch211-cxx11-cu130-aarch64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so +3 -0
- build/torch211-cxx11-cu130-aarch64-linux/_ops.py +6 -0
- build/torch211-cxx11-cu130-aarch64-linux/blockwise_fp8_producers/__init__.py +14 -0
- build/torch211-cxx11-cu130-aarch64-linux/metadata.json +22 -0
- build/torch211-cxx11-cu130-x86_64-linux/__init__.py +297 -0
- build/torch211-cxx11-cu130-x86_64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so +3 -0
- build/torch211-cxx11-cu130-x86_64-linux/_ops.py +9 -0
- build/torch211-cxx11-cu130-x86_64-linux/blockwise_fp8_producers/__init__.py +26 -0
- build/torch211-cxx11-cu130-x86_64-linux/metadata.json +22 -0
- build/torch212-cxx11-cu130-x86_64-linux/__init__.py +297 -0
- build/torch212-cxx11-cu130-x86_64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so +3 -0
- build/torch212-cxx11-cu130-x86_64-linux/_ops.py +9 -0
- build/torch212-cxx11-cu130-x86_64-linux/blockwise_fp8_producers/__init__.py +26 -0
- build/torch212-cxx11-cu130-x86_64-linux/metadata.json +22 -0
- build/torch212-cxx11-cu132-x86_64-linux/__init__.py +297 -0
- build/torch212-cxx11-cu132-x86_64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so +3 -0
- build/torch212-cxx11-cu132-x86_64-linux/_ops.py +9 -0
- build/torch212-cxx11-cu132-x86_64-linux/blockwise_fp8_producers/__init__.py +26 -0
- build/torch212-cxx11-cu132-x86_64-linux/metadata.json +22 -0
- build/torch213-cxx11-cu130-aarch64-linux/__init__.py +297 -0
- build/torch213-cxx11-cu130-aarch64-linux/_ops.py +6 -0
- build/torch213-cxx11-cu130-aarch64-linux/blockwise_fp8_producers/__init__.py +14 -0
- build/torch213-cxx11-cu130-aarch64-linux/blockwise_fp8_producers_source_test.abi3.so +3 -0
- build/torch213-cxx11-cu130-aarch64-linux/metadata.json +32 -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/blockwise-fp8-producers
|
| 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/blockwise-fp8-producers
|
| 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,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Benchmark blockwise FP8 producer APIs."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import importlib
|
| 8 |
+
import sys
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import torch
|
| 12 |
+
import torch.nn.functional as F
|
| 13 |
+
|
| 14 |
+
ROOT = Path(__file__).resolve().parents[2]
|
| 15 |
+
sys.path.insert(0, str(ROOT / "blockwise-fp8-producers" / "tests"))
|
| 16 |
+
from test_blockwise_fp8_producers import load_source_ops # noqa: E402
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def load_ops(backend: str, artifact: str | None):
|
| 20 |
+
if backend == "source":
|
| 21 |
+
return load_source_ops()
|
| 22 |
+
if artifact:
|
| 23 |
+
sys.path.insert(0, artifact)
|
| 24 |
+
try:
|
| 25 |
+
return importlib.import_module("blockwise_fp8_producers")
|
| 26 |
+
finally:
|
| 27 |
+
if artifact:
|
| 28 |
+
sys.path.remove(artifact)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def reference(kind, x, weight, bias):
|
| 32 |
+
if kind == "layer_norm":
|
| 33 |
+
produced = F.layer_norm(
|
| 34 |
+
x.float(), (x.shape[1],), weight.float(), bias.float(), 1e-6
|
| 35 |
+
)
|
| 36 |
+
elif kind == "rms_norm":
|
| 37 |
+
produced = (
|
| 38 |
+
x.float()
|
| 39 |
+
* torch.rsqrt(x.float().square().mean(-1, keepdim=True) + 1e-6)
|
| 40 |
+
* weight.float()
|
| 41 |
+
)
|
| 42 |
+
elif kind == "gelu_bias":
|
| 43 |
+
produced = F.gelu(x.float() + bias.float(), approximate="tanh")
|
| 44 |
+
else:
|
| 45 |
+
produced = x.float()
|
| 46 |
+
blocks = produced.reshape(produced.shape[0], produced.shape[1] // 128, 128)
|
| 47 |
+
scale = torch.clamp(blocks.abs().amax(-1) / 448.0, min=1.0e-12)
|
| 48 |
+
quantized = torch.clamp(
|
| 49 |
+
blocks / scale.unsqueeze(-1), -448.0, 448.0
|
| 50 |
+
).to(torch.float8_e4m3fn)
|
| 51 |
+
return quantized.reshape_as(x), scale
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def time_us(fn, warmup: int, iters: int) -> float:
|
| 55 |
+
for _ in range(warmup):
|
| 56 |
+
fn()
|
| 57 |
+
torch.cuda.synchronize()
|
| 58 |
+
start = torch.cuda.Event(enable_timing=True)
|
| 59 |
+
end = torch.cuda.Event(enable_timing=True)
|
| 60 |
+
start.record()
|
| 61 |
+
for _ in range(iters):
|
| 62 |
+
fn()
|
| 63 |
+
end.record()
|
| 64 |
+
torch.cuda.synchronize()
|
| 65 |
+
return start.elapsed_time(end) * 1000.0 / iters
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def main() -> int:
|
| 69 |
+
parser = argparse.ArgumentParser()
|
| 70 |
+
parser.add_argument("--backend", choices=["source", "installed"], default="source")
|
| 71 |
+
parser.add_argument("--artifact", default=None)
|
| 72 |
+
parser.add_argument("--mode", choices=["headline", "full"], default="headline")
|
| 73 |
+
parser.add_argument("--warmup", type=int, default=30)
|
| 74 |
+
parser.add_argument("--iters", type=int, default=200)
|
| 75 |
+
args = parser.parse_args()
|
| 76 |
+
ops = load_ops(args.backend, args.artifact)
|
| 77 |
+
shapes = [(51, 4096), (277, 9216), (1024, 1152)]
|
| 78 |
+
if args.mode == "full":
|
| 79 |
+
shapes = [(1, 4096), (17, 1152), (51, 4096), (65, 4352), (277, 9216), (1024, 1152)]
|
| 80 |
+
|
| 81 |
+
print("kind,shape,artifact_us,eager_us,compile_us,eager_speedup,compile_speedup")
|
| 82 |
+
for rows, dim in shapes:
|
| 83 |
+
x = torch.randn((rows, dim), device="cuda", dtype=torch.bfloat16)
|
| 84 |
+
weight = torch.randn((dim,), device="cuda", dtype=torch.bfloat16)
|
| 85 |
+
bias = torch.randn((dim,), device="cuda", dtype=torch.bfloat16)
|
| 86 |
+
output = torch.empty_like(x, dtype=torch.float8_e4m3fn)
|
| 87 |
+
scale = torch.empty((rows, dim // 128), device="cuda", dtype=torch.float32)
|
| 88 |
+
for kind in ("quantize", "layer_norm", "rms_norm", "gelu_bias"):
|
| 89 |
+
if kind == "quantize":
|
| 90 |
+
artifact_fn = lambda: ops.quantize_fp8_block128_bf16(
|
| 91 |
+
x, output=output, scale=scale
|
| 92 |
+
)
|
| 93 |
+
elif kind == "layer_norm":
|
| 94 |
+
artifact_fn = lambda: ops.layer_norm_fp8_block128_bf16(
|
| 95 |
+
x, weight, bias, output=output, scale=scale
|
| 96 |
+
)
|
| 97 |
+
elif kind == "rms_norm":
|
| 98 |
+
artifact_fn = lambda: ops.rms_norm_fp8_block128_bf16(
|
| 99 |
+
x, weight, output=output, scale=scale
|
| 100 |
+
)
|
| 101 |
+
else:
|
| 102 |
+
artifact_fn = lambda: ops.gelu_tanh_bias_fp8_block128_bf16(
|
| 103 |
+
x, bias, output=output, scale=scale
|
| 104 |
+
)
|
| 105 |
+
eager_fn = lambda: reference(kind, x, weight, bias)
|
| 106 |
+
torch._dynamo.reset()
|
| 107 |
+
compiled = torch.compile(
|
| 108 |
+
lambda a, w, b: reference(kind, a, w, b), fullgraph=True
|
| 109 |
+
)
|
| 110 |
+
compiled_fn = lambda: compiled(x, weight, bias)
|
| 111 |
+
artifact_us = time_us(artifact_fn, args.warmup, args.iters)
|
| 112 |
+
eager_us = time_us(eager_fn, max(10, args.warmup // 2), max(50, args.iters // 2))
|
| 113 |
+
compile_us = time_us(compiled_fn, max(10, args.warmup // 2), max(50, args.iters // 2))
|
| 114 |
+
print(
|
| 115 |
+
f"{kind},{rows}x{dim},{artifact_us:.3f},{eager_us:.3f},"
|
| 116 |
+
f"{compile_us:.3f},{eager_us/artifact_us:.2f}x,"
|
| 117 |
+
f"{compile_us/artifact_us:.2f}x"
|
| 118 |
+
)
|
| 119 |
+
return 0
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
if __name__ == "__main__":
|
| 123 |
+
raise SystemExit(main())
|
build/torch211-cxx11-cu128-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Blockwise FP8 producers for transformer and world-model regions."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def _check_matrix(input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor) -> None:
|
| 13 |
+
if (
|
| 14 |
+
input.dim() != 2
|
| 15 |
+
or input.shape[0] <= 0
|
| 16 |
+
or input.shape[1] <= 0
|
| 17 |
+
or input.shape[1] % 128 != 0
|
| 18 |
+
or output.shape != input.shape
|
| 19 |
+
or scale.shape != (input.shape[0], input.shape[1] // 128)
|
| 20 |
+
):
|
| 21 |
+
raise RuntimeError(
|
| 22 |
+
"expected input/output (rows, dim) with dim a positive multiple "
|
| 23 |
+
"of 128 and scale (rows, dim / 128)"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@torch.library.register_fake(add_op_namespace_prefix("quantize_fp8_block128_bf16"))
|
| 28 |
+
def _quantize_fake(
|
| 29 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 30 |
+
) -> None:
|
| 31 |
+
_check_matrix(input, output, scale)
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@torch.library.register_fake(add_op_namespace_prefix("layer_norm_fp8_block128_bf16"))
|
| 36 |
+
def _layer_norm_fake(
|
| 37 |
+
input: torch.Tensor,
|
| 38 |
+
weight: torch.Tensor,
|
| 39 |
+
bias: torch.Tensor,
|
| 40 |
+
eps: float,
|
| 41 |
+
output: torch.Tensor,
|
| 42 |
+
scale: torch.Tensor,
|
| 43 |
+
) -> None:
|
| 44 |
+
_check_matrix(input, output, scale)
|
| 45 |
+
if weight.shape != (input.shape[1],) or bias.shape != weight.shape:
|
| 46 |
+
raise RuntimeError("weight and bias must have shape (dim,)")
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@torch.library.register_fake(add_op_namespace_prefix("rms_norm_fp8_block128_bf16"))
|
| 51 |
+
def _rms_norm_fake(
|
| 52 |
+
input: torch.Tensor,
|
| 53 |
+
weight: torch.Tensor,
|
| 54 |
+
eps: float,
|
| 55 |
+
output: torch.Tensor,
|
| 56 |
+
scale: torch.Tensor,
|
| 57 |
+
) -> None:
|
| 58 |
+
_check_matrix(input, output, scale)
|
| 59 |
+
if weight.shape != (input.shape[1],):
|
| 60 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 61 |
+
return None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@torch.library.register_fake(
|
| 65 |
+
add_op_namespace_prefix("residual_add_rms_norm_fp8_block128_bf16")
|
| 66 |
+
)
|
| 67 |
+
def _residual_rms_norm_fake(
|
| 68 |
+
residual: torch.Tensor,
|
| 69 |
+
input: torch.Tensor,
|
| 70 |
+
weight: torch.Tensor,
|
| 71 |
+
eps: float,
|
| 72 |
+
residual_out: torch.Tensor,
|
| 73 |
+
output: torch.Tensor,
|
| 74 |
+
scale: torch.Tensor,
|
| 75 |
+
) -> None:
|
| 76 |
+
_check_matrix(input, output, scale)
|
| 77 |
+
if (
|
| 78 |
+
residual.shape != input.shape
|
| 79 |
+
or residual_out.shape != input.shape
|
| 80 |
+
or weight.shape != (input.shape[1],)
|
| 81 |
+
):
|
| 82 |
+
raise RuntimeError("residual/output must match input and weight must be (dim,)")
|
| 83 |
+
return None
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@torch.library.register_fake(add_op_namespace_prefix("gelu_tanh_fp8_block128_bf16"))
|
| 87 |
+
def _gelu_fake(
|
| 88 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 89 |
+
) -> None:
|
| 90 |
+
_check_matrix(input, output, scale)
|
| 91 |
+
return None
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@torch.library.register_fake(
|
| 95 |
+
add_op_namespace_prefix("gelu_tanh_bias_fp8_block128_bf16")
|
| 96 |
+
)
|
| 97 |
+
def _gelu_bias_fake(
|
| 98 |
+
input: torch.Tensor,
|
| 99 |
+
bias: torch.Tensor,
|
| 100 |
+
output: torch.Tensor,
|
| 101 |
+
scale: torch.Tensor,
|
| 102 |
+
) -> None:
|
| 103 |
+
_check_matrix(input, output, scale)
|
| 104 |
+
if bias.shape != (input.shape[1],):
|
| 105 |
+
raise RuntimeError("bias must have shape (dim,)")
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
@torch.library.register_fake(add_op_namespace_prefix("silu_mul_fp8_block128_bf16"))
|
| 110 |
+
def _silu_mul_fake(
|
| 111 |
+
gate: torch.Tensor,
|
| 112 |
+
up: torch.Tensor,
|
| 113 |
+
output: torch.Tensor,
|
| 114 |
+
scale: torch.Tensor,
|
| 115 |
+
) -> None:
|
| 116 |
+
_check_matrix(gate, output, scale)
|
| 117 |
+
if up.shape != gate.shape:
|
| 118 |
+
raise RuntimeError("up must match gate")
|
| 119 |
+
return None
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@torch.library.register_fake(
|
| 123 |
+
add_op_namespace_prefix("silu_mul_merged_fp8_block128_bf16")
|
| 124 |
+
)
|
| 125 |
+
def _silu_merged_fake(
|
| 126 |
+
gate_up: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 127 |
+
) -> None:
|
| 128 |
+
if (
|
| 129 |
+
gate_up.dim() != 2
|
| 130 |
+
or gate_up.shape[0] <= 0
|
| 131 |
+
or gate_up.shape[1] <= 0
|
| 132 |
+
or gate_up.shape[1] % 256 != 0
|
| 133 |
+
or output.shape != (gate_up.shape[0], gate_up.shape[1] // 2)
|
| 134 |
+
or scale.shape != (gate_up.shape[0], gate_up.shape[1] // 256)
|
| 135 |
+
):
|
| 136 |
+
raise RuntimeError(
|
| 137 |
+
"gate_up must be (rows, 2 * dim), dim multiple of 128"
|
| 138 |
+
)
|
| 139 |
+
return None
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _allocate(input: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
| 143 |
+
return (
|
| 144 |
+
torch.empty_like(input, dtype=torch.float8_e4m3fn),
|
| 145 |
+
torch.empty(
|
| 146 |
+
(input.shape[0], input.shape[1] // 128),
|
| 147 |
+
device=input.device,
|
| 148 |
+
dtype=torch.float32,
|
| 149 |
+
),
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def quantize_fp8_block128_bf16(
|
| 154 |
+
input: torch.Tensor,
|
| 155 |
+
*,
|
| 156 |
+
output: Optional[torch.Tensor] = None,
|
| 157 |
+
scale: Optional[torch.Tensor] = None,
|
| 158 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 159 |
+
if output is None or scale is None:
|
| 160 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 161 |
+
output = allocated_output if output is None else output
|
| 162 |
+
scale = allocated_scale if scale is None else scale
|
| 163 |
+
ops.quantize_fp8_block128_bf16(input, output, scale)
|
| 164 |
+
return output, scale
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def layer_norm_fp8_block128_bf16(
|
| 168 |
+
input: torch.Tensor,
|
| 169 |
+
weight: torch.Tensor,
|
| 170 |
+
bias: torch.Tensor,
|
| 171 |
+
eps: float = 1e-6,
|
| 172 |
+
*,
|
| 173 |
+
output: Optional[torch.Tensor] = None,
|
| 174 |
+
scale: Optional[torch.Tensor] = None,
|
| 175 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 176 |
+
if output is None or scale is None:
|
| 177 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 178 |
+
output = allocated_output if output is None else output
|
| 179 |
+
scale = allocated_scale if scale is None else scale
|
| 180 |
+
ops.layer_norm_fp8_block128_bf16(
|
| 181 |
+
input, weight, bias, float(eps), output, scale
|
| 182 |
+
)
|
| 183 |
+
return output, scale
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def rms_norm_fp8_block128_bf16(
|
| 187 |
+
input: torch.Tensor,
|
| 188 |
+
weight: torch.Tensor,
|
| 189 |
+
eps: float = 1e-6,
|
| 190 |
+
*,
|
| 191 |
+
output: Optional[torch.Tensor] = None,
|
| 192 |
+
scale: Optional[torch.Tensor] = None,
|
| 193 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 194 |
+
if output is None or scale is None:
|
| 195 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 196 |
+
output = allocated_output if output is None else output
|
| 197 |
+
scale = allocated_scale if scale is None else scale
|
| 198 |
+
ops.rms_norm_fp8_block128_bf16(input, weight, float(eps), output, scale)
|
| 199 |
+
return output, scale
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def residual_add_rms_norm_fp8_block128_bf16(
|
| 203 |
+
residual: torch.Tensor,
|
| 204 |
+
input: torch.Tensor,
|
| 205 |
+
weight: torch.Tensor,
|
| 206 |
+
eps: float = 1e-6,
|
| 207 |
+
*,
|
| 208 |
+
residual_out: Optional[torch.Tensor] = None,
|
| 209 |
+
output: Optional[torch.Tensor] = None,
|
| 210 |
+
scale: Optional[torch.Tensor] = None,
|
| 211 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 212 |
+
if residual_out is None:
|
| 213 |
+
residual_out = torch.empty_like(input)
|
| 214 |
+
if output is None or scale is None:
|
| 215 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 216 |
+
output = allocated_output if output is None else output
|
| 217 |
+
scale = allocated_scale if scale is None else scale
|
| 218 |
+
ops.residual_add_rms_norm_fp8_block128_bf16(
|
| 219 |
+
residual, input, weight, float(eps), residual_out, output, scale
|
| 220 |
+
)
|
| 221 |
+
return residual_out, output, scale
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def gelu_tanh_fp8_block128_bf16(
|
| 225 |
+
input: torch.Tensor,
|
| 226 |
+
*,
|
| 227 |
+
output: Optional[torch.Tensor] = None,
|
| 228 |
+
scale: Optional[torch.Tensor] = None,
|
| 229 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 230 |
+
if output is None or scale is None:
|
| 231 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 232 |
+
output = allocated_output if output is None else output
|
| 233 |
+
scale = allocated_scale if scale is None else scale
|
| 234 |
+
ops.gelu_tanh_fp8_block128_bf16(input, output, scale)
|
| 235 |
+
return output, scale
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def gelu_tanh_bias_fp8_block128_bf16(
|
| 239 |
+
input: torch.Tensor,
|
| 240 |
+
bias: torch.Tensor,
|
| 241 |
+
*,
|
| 242 |
+
output: Optional[torch.Tensor] = None,
|
| 243 |
+
scale: Optional[torch.Tensor] = None,
|
| 244 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 245 |
+
if output is None or scale is None:
|
| 246 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 247 |
+
output = allocated_output if output is None else output
|
| 248 |
+
scale = allocated_scale if scale is None else scale
|
| 249 |
+
ops.gelu_tanh_bias_fp8_block128_bf16(input, bias, output, scale)
|
| 250 |
+
return output, scale
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def silu_mul_fp8_block128_bf16(
|
| 254 |
+
gate: torch.Tensor,
|
| 255 |
+
up: torch.Tensor,
|
| 256 |
+
*,
|
| 257 |
+
output: Optional[torch.Tensor] = None,
|
| 258 |
+
scale: Optional[torch.Tensor] = None,
|
| 259 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 260 |
+
if output is None or scale is None:
|
| 261 |
+
allocated_output, allocated_scale = _allocate(gate)
|
| 262 |
+
output = allocated_output if output is None else output
|
| 263 |
+
scale = allocated_scale if scale is None else scale
|
| 264 |
+
ops.silu_mul_fp8_block128_bf16(gate, up, output, scale)
|
| 265 |
+
return output, scale
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def silu_mul_merged_fp8_block128_bf16(
|
| 269 |
+
gate_up: torch.Tensor,
|
| 270 |
+
*,
|
| 271 |
+
output: Optional[torch.Tensor] = None,
|
| 272 |
+
scale: Optional[torch.Tensor] = None,
|
| 273 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 274 |
+
rows, merged_dim = gate_up.shape
|
| 275 |
+
dim = merged_dim // 2
|
| 276 |
+
if output is None:
|
| 277 |
+
output = torch.empty(
|
| 278 |
+
(rows, dim), device=gate_up.device, dtype=torch.float8_e4m3fn
|
| 279 |
+
)
|
| 280 |
+
if scale is None:
|
| 281 |
+
scale = torch.empty(
|
| 282 |
+
(rows, dim // 128), device=gate_up.device, dtype=torch.float32
|
| 283 |
+
)
|
| 284 |
+
ops.silu_mul_merged_fp8_block128_bf16(gate_up, output, scale)
|
| 285 |
+
return output, scale
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
__all__ = [
|
| 289 |
+
"quantize_fp8_block128_bf16",
|
| 290 |
+
"layer_norm_fp8_block128_bf16",
|
| 291 |
+
"rms_norm_fp8_block128_bf16",
|
| 292 |
+
"residual_add_rms_norm_fp8_block128_bf16",
|
| 293 |
+
"gelu_tanh_fp8_block128_bf16",
|
| 294 |
+
"gelu_tanh_bias_fp8_block128_bf16",
|
| 295 |
+
"silu_mul_fp8_block128_bf16",
|
| 296 |
+
"silu_mul_merged_fp8_block128_bf16",
|
| 297 |
+
]
|
build/torch211-cxx11-cu128-x86_64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:03a00a579f79e06cf2047011f707091466083eaa57930fa6d2f5dbff919f4119
|
| 3 |
+
size 2044952
|
build/torch211-cxx11-cu128-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _blockwise_fp8_producers_cuda_7781728
|
| 3 |
+
ops = torch.ops._blockwise_fp8_producers_cuda_7781728
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_blockwise_fp8_producers_cuda_7781728::{op_name}"
|
build/torch211-cxx11-cu128-x86_64-linux/blockwise_fp8_producers/__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": "blockwise-fp8-producers",
|
| 3 |
+
"id": "_blockwise_fp8_producers_cuda_7781728",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends":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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Blockwise FP8 producers for transformer and world-model regions."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def _check_matrix(input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor) -> None:
|
| 13 |
+
if (
|
| 14 |
+
input.dim() != 2
|
| 15 |
+
or input.shape[0] <= 0
|
| 16 |
+
or input.shape[1] <= 0
|
| 17 |
+
or input.shape[1] % 128 != 0
|
| 18 |
+
or output.shape != input.shape
|
| 19 |
+
or scale.shape != (input.shape[0], input.shape[1] // 128)
|
| 20 |
+
):
|
| 21 |
+
raise RuntimeError(
|
| 22 |
+
"expected input/output (rows, dim) with dim a positive multiple "
|
| 23 |
+
"of 128 and scale (rows, dim / 128)"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@torch.library.register_fake(add_op_namespace_prefix("quantize_fp8_block128_bf16"))
|
| 28 |
+
def _quantize_fake(
|
| 29 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 30 |
+
) -> None:
|
| 31 |
+
_check_matrix(input, output, scale)
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@torch.library.register_fake(add_op_namespace_prefix("layer_norm_fp8_block128_bf16"))
|
| 36 |
+
def _layer_norm_fake(
|
| 37 |
+
input: torch.Tensor,
|
| 38 |
+
weight: torch.Tensor,
|
| 39 |
+
bias: torch.Tensor,
|
| 40 |
+
eps: float,
|
| 41 |
+
output: torch.Tensor,
|
| 42 |
+
scale: torch.Tensor,
|
| 43 |
+
) -> None:
|
| 44 |
+
_check_matrix(input, output, scale)
|
| 45 |
+
if weight.shape != (input.shape[1],) or bias.shape != weight.shape:
|
| 46 |
+
raise RuntimeError("weight and bias must have shape (dim,)")
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@torch.library.register_fake(add_op_namespace_prefix("rms_norm_fp8_block128_bf16"))
|
| 51 |
+
def _rms_norm_fake(
|
| 52 |
+
input: torch.Tensor,
|
| 53 |
+
weight: torch.Tensor,
|
| 54 |
+
eps: float,
|
| 55 |
+
output: torch.Tensor,
|
| 56 |
+
scale: torch.Tensor,
|
| 57 |
+
) -> None:
|
| 58 |
+
_check_matrix(input, output, scale)
|
| 59 |
+
if weight.shape != (input.shape[1],):
|
| 60 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 61 |
+
return None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@torch.library.register_fake(
|
| 65 |
+
add_op_namespace_prefix("residual_add_rms_norm_fp8_block128_bf16")
|
| 66 |
+
)
|
| 67 |
+
def _residual_rms_norm_fake(
|
| 68 |
+
residual: torch.Tensor,
|
| 69 |
+
input: torch.Tensor,
|
| 70 |
+
weight: torch.Tensor,
|
| 71 |
+
eps: float,
|
| 72 |
+
residual_out: torch.Tensor,
|
| 73 |
+
output: torch.Tensor,
|
| 74 |
+
scale: torch.Tensor,
|
| 75 |
+
) -> None:
|
| 76 |
+
_check_matrix(input, output, scale)
|
| 77 |
+
if (
|
| 78 |
+
residual.shape != input.shape
|
| 79 |
+
or residual_out.shape != input.shape
|
| 80 |
+
or weight.shape != (input.shape[1],)
|
| 81 |
+
):
|
| 82 |
+
raise RuntimeError("residual/output must match input and weight must be (dim,)")
|
| 83 |
+
return None
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@torch.library.register_fake(add_op_namespace_prefix("gelu_tanh_fp8_block128_bf16"))
|
| 87 |
+
def _gelu_fake(
|
| 88 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 89 |
+
) -> None:
|
| 90 |
+
_check_matrix(input, output, scale)
|
| 91 |
+
return None
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@torch.library.register_fake(
|
| 95 |
+
add_op_namespace_prefix("gelu_tanh_bias_fp8_block128_bf16")
|
| 96 |
+
)
|
| 97 |
+
def _gelu_bias_fake(
|
| 98 |
+
input: torch.Tensor,
|
| 99 |
+
bias: torch.Tensor,
|
| 100 |
+
output: torch.Tensor,
|
| 101 |
+
scale: torch.Tensor,
|
| 102 |
+
) -> None:
|
| 103 |
+
_check_matrix(input, output, scale)
|
| 104 |
+
if bias.shape != (input.shape[1],):
|
| 105 |
+
raise RuntimeError("bias must have shape (dim,)")
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
@torch.library.register_fake(add_op_namespace_prefix("silu_mul_fp8_block128_bf16"))
|
| 110 |
+
def _silu_mul_fake(
|
| 111 |
+
gate: torch.Tensor,
|
| 112 |
+
up: torch.Tensor,
|
| 113 |
+
output: torch.Tensor,
|
| 114 |
+
scale: torch.Tensor,
|
| 115 |
+
) -> None:
|
| 116 |
+
_check_matrix(gate, output, scale)
|
| 117 |
+
if up.shape != gate.shape:
|
| 118 |
+
raise RuntimeError("up must match gate")
|
| 119 |
+
return None
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@torch.library.register_fake(
|
| 123 |
+
add_op_namespace_prefix("silu_mul_merged_fp8_block128_bf16")
|
| 124 |
+
)
|
| 125 |
+
def _silu_merged_fake(
|
| 126 |
+
gate_up: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 127 |
+
) -> None:
|
| 128 |
+
if (
|
| 129 |
+
gate_up.dim() != 2
|
| 130 |
+
or gate_up.shape[0] <= 0
|
| 131 |
+
or gate_up.shape[1] <= 0
|
| 132 |
+
or gate_up.shape[1] % 256 != 0
|
| 133 |
+
or output.shape != (gate_up.shape[0], gate_up.shape[1] // 2)
|
| 134 |
+
or scale.shape != (gate_up.shape[0], gate_up.shape[1] // 256)
|
| 135 |
+
):
|
| 136 |
+
raise RuntimeError(
|
| 137 |
+
"gate_up must be (rows, 2 * dim), dim multiple of 128"
|
| 138 |
+
)
|
| 139 |
+
return None
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _allocate(input: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
| 143 |
+
return (
|
| 144 |
+
torch.empty_like(input, dtype=torch.float8_e4m3fn),
|
| 145 |
+
torch.empty(
|
| 146 |
+
(input.shape[0], input.shape[1] // 128),
|
| 147 |
+
device=input.device,
|
| 148 |
+
dtype=torch.float32,
|
| 149 |
+
),
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def quantize_fp8_block128_bf16(
|
| 154 |
+
input: torch.Tensor,
|
| 155 |
+
*,
|
| 156 |
+
output: Optional[torch.Tensor] = None,
|
| 157 |
+
scale: Optional[torch.Tensor] = None,
|
| 158 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 159 |
+
if output is None or scale is None:
|
| 160 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 161 |
+
output = allocated_output if output is None else output
|
| 162 |
+
scale = allocated_scale if scale is None else scale
|
| 163 |
+
ops.quantize_fp8_block128_bf16(input, output, scale)
|
| 164 |
+
return output, scale
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def layer_norm_fp8_block128_bf16(
|
| 168 |
+
input: torch.Tensor,
|
| 169 |
+
weight: torch.Tensor,
|
| 170 |
+
bias: torch.Tensor,
|
| 171 |
+
eps: float = 1e-6,
|
| 172 |
+
*,
|
| 173 |
+
output: Optional[torch.Tensor] = None,
|
| 174 |
+
scale: Optional[torch.Tensor] = None,
|
| 175 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 176 |
+
if output is None or scale is None:
|
| 177 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 178 |
+
output = allocated_output if output is None else output
|
| 179 |
+
scale = allocated_scale if scale is None else scale
|
| 180 |
+
ops.layer_norm_fp8_block128_bf16(
|
| 181 |
+
input, weight, bias, float(eps), output, scale
|
| 182 |
+
)
|
| 183 |
+
return output, scale
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def rms_norm_fp8_block128_bf16(
|
| 187 |
+
input: torch.Tensor,
|
| 188 |
+
weight: torch.Tensor,
|
| 189 |
+
eps: float = 1e-6,
|
| 190 |
+
*,
|
| 191 |
+
output: Optional[torch.Tensor] = None,
|
| 192 |
+
scale: Optional[torch.Tensor] = None,
|
| 193 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 194 |
+
if output is None or scale is None:
|
| 195 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 196 |
+
output = allocated_output if output is None else output
|
| 197 |
+
scale = allocated_scale if scale is None else scale
|
| 198 |
+
ops.rms_norm_fp8_block128_bf16(input, weight, float(eps), output, scale)
|
| 199 |
+
return output, scale
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def residual_add_rms_norm_fp8_block128_bf16(
|
| 203 |
+
residual: torch.Tensor,
|
| 204 |
+
input: torch.Tensor,
|
| 205 |
+
weight: torch.Tensor,
|
| 206 |
+
eps: float = 1e-6,
|
| 207 |
+
*,
|
| 208 |
+
residual_out: Optional[torch.Tensor] = None,
|
| 209 |
+
output: Optional[torch.Tensor] = None,
|
| 210 |
+
scale: Optional[torch.Tensor] = None,
|
| 211 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 212 |
+
if residual_out is None:
|
| 213 |
+
residual_out = torch.empty_like(input)
|
| 214 |
+
if output is None or scale is None:
|
| 215 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 216 |
+
output = allocated_output if output is None else output
|
| 217 |
+
scale = allocated_scale if scale is None else scale
|
| 218 |
+
ops.residual_add_rms_norm_fp8_block128_bf16(
|
| 219 |
+
residual, input, weight, float(eps), residual_out, output, scale
|
| 220 |
+
)
|
| 221 |
+
return residual_out, output, scale
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def gelu_tanh_fp8_block128_bf16(
|
| 225 |
+
input: torch.Tensor,
|
| 226 |
+
*,
|
| 227 |
+
output: Optional[torch.Tensor] = None,
|
| 228 |
+
scale: Optional[torch.Tensor] = None,
|
| 229 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 230 |
+
if output is None or scale is None:
|
| 231 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 232 |
+
output = allocated_output if output is None else output
|
| 233 |
+
scale = allocated_scale if scale is None else scale
|
| 234 |
+
ops.gelu_tanh_fp8_block128_bf16(input, output, scale)
|
| 235 |
+
return output, scale
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def gelu_tanh_bias_fp8_block128_bf16(
|
| 239 |
+
input: torch.Tensor,
|
| 240 |
+
bias: torch.Tensor,
|
| 241 |
+
*,
|
| 242 |
+
output: Optional[torch.Tensor] = None,
|
| 243 |
+
scale: Optional[torch.Tensor] = None,
|
| 244 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 245 |
+
if output is None or scale is None:
|
| 246 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 247 |
+
output = allocated_output if output is None else output
|
| 248 |
+
scale = allocated_scale if scale is None else scale
|
| 249 |
+
ops.gelu_tanh_bias_fp8_block128_bf16(input, bias, output, scale)
|
| 250 |
+
return output, scale
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def silu_mul_fp8_block128_bf16(
|
| 254 |
+
gate: torch.Tensor,
|
| 255 |
+
up: torch.Tensor,
|
| 256 |
+
*,
|
| 257 |
+
output: Optional[torch.Tensor] = None,
|
| 258 |
+
scale: Optional[torch.Tensor] = None,
|
| 259 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 260 |
+
if output is None or scale is None:
|
| 261 |
+
allocated_output, allocated_scale = _allocate(gate)
|
| 262 |
+
output = allocated_output if output is None else output
|
| 263 |
+
scale = allocated_scale if scale is None else scale
|
| 264 |
+
ops.silu_mul_fp8_block128_bf16(gate, up, output, scale)
|
| 265 |
+
return output, scale
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def silu_mul_merged_fp8_block128_bf16(
|
| 269 |
+
gate_up: torch.Tensor,
|
| 270 |
+
*,
|
| 271 |
+
output: Optional[torch.Tensor] = None,
|
| 272 |
+
scale: Optional[torch.Tensor] = None,
|
| 273 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 274 |
+
rows, merged_dim = gate_up.shape
|
| 275 |
+
dim = merged_dim // 2
|
| 276 |
+
if output is None:
|
| 277 |
+
output = torch.empty(
|
| 278 |
+
(rows, dim), device=gate_up.device, dtype=torch.float8_e4m3fn
|
| 279 |
+
)
|
| 280 |
+
if scale is None:
|
| 281 |
+
scale = torch.empty(
|
| 282 |
+
(rows, dim // 128), device=gate_up.device, dtype=torch.float32
|
| 283 |
+
)
|
| 284 |
+
ops.silu_mul_merged_fp8_block128_bf16(gate_up, output, scale)
|
| 285 |
+
return output, scale
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
__all__ = [
|
| 289 |
+
"quantize_fp8_block128_bf16",
|
| 290 |
+
"layer_norm_fp8_block128_bf16",
|
| 291 |
+
"rms_norm_fp8_block128_bf16",
|
| 292 |
+
"residual_add_rms_norm_fp8_block128_bf16",
|
| 293 |
+
"gelu_tanh_fp8_block128_bf16",
|
| 294 |
+
"gelu_tanh_bias_fp8_block128_bf16",
|
| 295 |
+
"silu_mul_fp8_block128_bf16",
|
| 296 |
+
"silu_mul_merged_fp8_block128_bf16",
|
| 297 |
+
]
|
build/torch211-cxx11-cu130-aarch64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:293d539efbdddbf49f647c269e2fd34d619e35ae6eb462dac4434780075d0bf6
|
| 3 |
+
size 455696
|
build/torch211-cxx11-cu130-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _blockwise_fp8_producers_cuda_7781728
|
| 3 |
+
ops = torch.ops._blockwise_fp8_producers_cuda_7781728
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
return f"_blockwise_fp8_producers_cuda_7781728::{op_name}"
|
build/torch211-cxx11-cu130-aarch64-linux/blockwise_fp8_producers/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
def _import_from_path(file_path: Path):
|
| 7 |
+
path_hash = '{:x}'.format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 8 |
+
spec = importlib.util.spec_from_file_location(path_hash, file_path)
|
| 9 |
+
module = importlib.util.module_from_spec(spec)
|
| 10 |
+
sys.modules[path_hash] = module
|
| 11 |
+
spec.loader.exec_module(module)
|
| 12 |
+
return module
|
| 13 |
+
|
| 14 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / '__init__.py')))
|
build/torch211-cxx11-cu130-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "blockwise-fp8-producers",
|
| 3 |
+
"id": "_blockwise_fp8_producers_cuda_7781728",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"11.0"
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
"digest": {
|
| 14 |
+
"algorithm": "sha256",
|
| 15 |
+
"files": {
|
| 16 |
+
"__init__.py": "jTa/yZ4lH7PUVKeENwdd7iZgdhrc9AOOJ8+L2usA23M=",
|
| 17 |
+
"_blockwise_fp8_producers_cuda_7781728.abi3.so": "KT1Tnvvd2/SfZHwmni/TTWGeNa5utGLaxENHgAddC/Y=",
|
| 18 |
+
"_ops.py": "pl0Svm/AyQFPOD+QjsTr7CaugfBN69uRVroTvi3cHrE=",
|
| 19 |
+
"blockwise_fp8_producers/__init__.py": "v6p5XMfQzddhi1fLSAw4HX9CyS0rQsidvu9VsT01xi4="
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
}
|
build/torch211-cxx11-cu130-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Blockwise FP8 producers for transformer and world-model regions."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def _check_matrix(input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor) -> None:
|
| 13 |
+
if (
|
| 14 |
+
input.dim() != 2
|
| 15 |
+
or input.shape[0] <= 0
|
| 16 |
+
or input.shape[1] <= 0
|
| 17 |
+
or input.shape[1] % 128 != 0
|
| 18 |
+
or output.shape != input.shape
|
| 19 |
+
or scale.shape != (input.shape[0], input.shape[1] // 128)
|
| 20 |
+
):
|
| 21 |
+
raise RuntimeError(
|
| 22 |
+
"expected input/output (rows, dim) with dim a positive multiple "
|
| 23 |
+
"of 128 and scale (rows, dim / 128)"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@torch.library.register_fake(add_op_namespace_prefix("quantize_fp8_block128_bf16"))
|
| 28 |
+
def _quantize_fake(
|
| 29 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 30 |
+
) -> None:
|
| 31 |
+
_check_matrix(input, output, scale)
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@torch.library.register_fake(add_op_namespace_prefix("layer_norm_fp8_block128_bf16"))
|
| 36 |
+
def _layer_norm_fake(
|
| 37 |
+
input: torch.Tensor,
|
| 38 |
+
weight: torch.Tensor,
|
| 39 |
+
bias: torch.Tensor,
|
| 40 |
+
eps: float,
|
| 41 |
+
output: torch.Tensor,
|
| 42 |
+
scale: torch.Tensor,
|
| 43 |
+
) -> None:
|
| 44 |
+
_check_matrix(input, output, scale)
|
| 45 |
+
if weight.shape != (input.shape[1],) or bias.shape != weight.shape:
|
| 46 |
+
raise RuntimeError("weight and bias must have shape (dim,)")
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@torch.library.register_fake(add_op_namespace_prefix("rms_norm_fp8_block128_bf16"))
|
| 51 |
+
def _rms_norm_fake(
|
| 52 |
+
input: torch.Tensor,
|
| 53 |
+
weight: torch.Tensor,
|
| 54 |
+
eps: float,
|
| 55 |
+
output: torch.Tensor,
|
| 56 |
+
scale: torch.Tensor,
|
| 57 |
+
) -> None:
|
| 58 |
+
_check_matrix(input, output, scale)
|
| 59 |
+
if weight.shape != (input.shape[1],):
|
| 60 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 61 |
+
return None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@torch.library.register_fake(
|
| 65 |
+
add_op_namespace_prefix("residual_add_rms_norm_fp8_block128_bf16")
|
| 66 |
+
)
|
| 67 |
+
def _residual_rms_norm_fake(
|
| 68 |
+
residual: torch.Tensor,
|
| 69 |
+
input: torch.Tensor,
|
| 70 |
+
weight: torch.Tensor,
|
| 71 |
+
eps: float,
|
| 72 |
+
residual_out: torch.Tensor,
|
| 73 |
+
output: torch.Tensor,
|
| 74 |
+
scale: torch.Tensor,
|
| 75 |
+
) -> None:
|
| 76 |
+
_check_matrix(input, output, scale)
|
| 77 |
+
if (
|
| 78 |
+
residual.shape != input.shape
|
| 79 |
+
or residual_out.shape != input.shape
|
| 80 |
+
or weight.shape != (input.shape[1],)
|
| 81 |
+
):
|
| 82 |
+
raise RuntimeError("residual/output must match input and weight must be (dim,)")
|
| 83 |
+
return None
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@torch.library.register_fake(add_op_namespace_prefix("gelu_tanh_fp8_block128_bf16"))
|
| 87 |
+
def _gelu_fake(
|
| 88 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 89 |
+
) -> None:
|
| 90 |
+
_check_matrix(input, output, scale)
|
| 91 |
+
return None
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@torch.library.register_fake(
|
| 95 |
+
add_op_namespace_prefix("gelu_tanh_bias_fp8_block128_bf16")
|
| 96 |
+
)
|
| 97 |
+
def _gelu_bias_fake(
|
| 98 |
+
input: torch.Tensor,
|
| 99 |
+
bias: torch.Tensor,
|
| 100 |
+
output: torch.Tensor,
|
| 101 |
+
scale: torch.Tensor,
|
| 102 |
+
) -> None:
|
| 103 |
+
_check_matrix(input, output, scale)
|
| 104 |
+
if bias.shape != (input.shape[1],):
|
| 105 |
+
raise RuntimeError("bias must have shape (dim,)")
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
@torch.library.register_fake(add_op_namespace_prefix("silu_mul_fp8_block128_bf16"))
|
| 110 |
+
def _silu_mul_fake(
|
| 111 |
+
gate: torch.Tensor,
|
| 112 |
+
up: torch.Tensor,
|
| 113 |
+
output: torch.Tensor,
|
| 114 |
+
scale: torch.Tensor,
|
| 115 |
+
) -> None:
|
| 116 |
+
_check_matrix(gate, output, scale)
|
| 117 |
+
if up.shape != gate.shape:
|
| 118 |
+
raise RuntimeError("up must match gate")
|
| 119 |
+
return None
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@torch.library.register_fake(
|
| 123 |
+
add_op_namespace_prefix("silu_mul_merged_fp8_block128_bf16")
|
| 124 |
+
)
|
| 125 |
+
def _silu_merged_fake(
|
| 126 |
+
gate_up: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 127 |
+
) -> None:
|
| 128 |
+
if (
|
| 129 |
+
gate_up.dim() != 2
|
| 130 |
+
or gate_up.shape[0] <= 0
|
| 131 |
+
or gate_up.shape[1] <= 0
|
| 132 |
+
or gate_up.shape[1] % 256 != 0
|
| 133 |
+
or output.shape != (gate_up.shape[0], gate_up.shape[1] // 2)
|
| 134 |
+
or scale.shape != (gate_up.shape[0], gate_up.shape[1] // 256)
|
| 135 |
+
):
|
| 136 |
+
raise RuntimeError(
|
| 137 |
+
"gate_up must be (rows, 2 * dim), dim multiple of 128"
|
| 138 |
+
)
|
| 139 |
+
return None
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _allocate(input: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
| 143 |
+
return (
|
| 144 |
+
torch.empty_like(input, dtype=torch.float8_e4m3fn),
|
| 145 |
+
torch.empty(
|
| 146 |
+
(input.shape[0], input.shape[1] // 128),
|
| 147 |
+
device=input.device,
|
| 148 |
+
dtype=torch.float32,
|
| 149 |
+
),
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def quantize_fp8_block128_bf16(
|
| 154 |
+
input: torch.Tensor,
|
| 155 |
+
*,
|
| 156 |
+
output: Optional[torch.Tensor] = None,
|
| 157 |
+
scale: Optional[torch.Tensor] = None,
|
| 158 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 159 |
+
if output is None or scale is None:
|
| 160 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 161 |
+
output = allocated_output if output is None else output
|
| 162 |
+
scale = allocated_scale if scale is None else scale
|
| 163 |
+
ops.quantize_fp8_block128_bf16(input, output, scale)
|
| 164 |
+
return output, scale
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def layer_norm_fp8_block128_bf16(
|
| 168 |
+
input: torch.Tensor,
|
| 169 |
+
weight: torch.Tensor,
|
| 170 |
+
bias: torch.Tensor,
|
| 171 |
+
eps: float = 1e-6,
|
| 172 |
+
*,
|
| 173 |
+
output: Optional[torch.Tensor] = None,
|
| 174 |
+
scale: Optional[torch.Tensor] = None,
|
| 175 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 176 |
+
if output is None or scale is None:
|
| 177 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 178 |
+
output = allocated_output if output is None else output
|
| 179 |
+
scale = allocated_scale if scale is None else scale
|
| 180 |
+
ops.layer_norm_fp8_block128_bf16(
|
| 181 |
+
input, weight, bias, float(eps), output, scale
|
| 182 |
+
)
|
| 183 |
+
return output, scale
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def rms_norm_fp8_block128_bf16(
|
| 187 |
+
input: torch.Tensor,
|
| 188 |
+
weight: torch.Tensor,
|
| 189 |
+
eps: float = 1e-6,
|
| 190 |
+
*,
|
| 191 |
+
output: Optional[torch.Tensor] = None,
|
| 192 |
+
scale: Optional[torch.Tensor] = None,
|
| 193 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 194 |
+
if output is None or scale is None:
|
| 195 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 196 |
+
output = allocated_output if output is None else output
|
| 197 |
+
scale = allocated_scale if scale is None else scale
|
| 198 |
+
ops.rms_norm_fp8_block128_bf16(input, weight, float(eps), output, scale)
|
| 199 |
+
return output, scale
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def residual_add_rms_norm_fp8_block128_bf16(
|
| 203 |
+
residual: torch.Tensor,
|
| 204 |
+
input: torch.Tensor,
|
| 205 |
+
weight: torch.Tensor,
|
| 206 |
+
eps: float = 1e-6,
|
| 207 |
+
*,
|
| 208 |
+
residual_out: Optional[torch.Tensor] = None,
|
| 209 |
+
output: Optional[torch.Tensor] = None,
|
| 210 |
+
scale: Optional[torch.Tensor] = None,
|
| 211 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 212 |
+
if residual_out is None:
|
| 213 |
+
residual_out = torch.empty_like(input)
|
| 214 |
+
if output is None or scale is None:
|
| 215 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 216 |
+
output = allocated_output if output is None else output
|
| 217 |
+
scale = allocated_scale if scale is None else scale
|
| 218 |
+
ops.residual_add_rms_norm_fp8_block128_bf16(
|
| 219 |
+
residual, input, weight, float(eps), residual_out, output, scale
|
| 220 |
+
)
|
| 221 |
+
return residual_out, output, scale
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def gelu_tanh_fp8_block128_bf16(
|
| 225 |
+
input: torch.Tensor,
|
| 226 |
+
*,
|
| 227 |
+
output: Optional[torch.Tensor] = None,
|
| 228 |
+
scale: Optional[torch.Tensor] = None,
|
| 229 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 230 |
+
if output is None or scale is None:
|
| 231 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 232 |
+
output = allocated_output if output is None else output
|
| 233 |
+
scale = allocated_scale if scale is None else scale
|
| 234 |
+
ops.gelu_tanh_fp8_block128_bf16(input, output, scale)
|
| 235 |
+
return output, scale
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def gelu_tanh_bias_fp8_block128_bf16(
|
| 239 |
+
input: torch.Tensor,
|
| 240 |
+
bias: torch.Tensor,
|
| 241 |
+
*,
|
| 242 |
+
output: Optional[torch.Tensor] = None,
|
| 243 |
+
scale: Optional[torch.Tensor] = None,
|
| 244 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 245 |
+
if output is None or scale is None:
|
| 246 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 247 |
+
output = allocated_output if output is None else output
|
| 248 |
+
scale = allocated_scale if scale is None else scale
|
| 249 |
+
ops.gelu_tanh_bias_fp8_block128_bf16(input, bias, output, scale)
|
| 250 |
+
return output, scale
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def silu_mul_fp8_block128_bf16(
|
| 254 |
+
gate: torch.Tensor,
|
| 255 |
+
up: torch.Tensor,
|
| 256 |
+
*,
|
| 257 |
+
output: Optional[torch.Tensor] = None,
|
| 258 |
+
scale: Optional[torch.Tensor] = None,
|
| 259 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 260 |
+
if output is None or scale is None:
|
| 261 |
+
allocated_output, allocated_scale = _allocate(gate)
|
| 262 |
+
output = allocated_output if output is None else output
|
| 263 |
+
scale = allocated_scale if scale is None else scale
|
| 264 |
+
ops.silu_mul_fp8_block128_bf16(gate, up, output, scale)
|
| 265 |
+
return output, scale
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def silu_mul_merged_fp8_block128_bf16(
|
| 269 |
+
gate_up: torch.Tensor,
|
| 270 |
+
*,
|
| 271 |
+
output: Optional[torch.Tensor] = None,
|
| 272 |
+
scale: Optional[torch.Tensor] = None,
|
| 273 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 274 |
+
rows, merged_dim = gate_up.shape
|
| 275 |
+
dim = merged_dim // 2
|
| 276 |
+
if output is None:
|
| 277 |
+
output = torch.empty(
|
| 278 |
+
(rows, dim), device=gate_up.device, dtype=torch.float8_e4m3fn
|
| 279 |
+
)
|
| 280 |
+
if scale is None:
|
| 281 |
+
scale = torch.empty(
|
| 282 |
+
(rows, dim // 128), device=gate_up.device, dtype=torch.float32
|
| 283 |
+
)
|
| 284 |
+
ops.silu_mul_merged_fp8_block128_bf16(gate_up, output, scale)
|
| 285 |
+
return output, scale
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
__all__ = [
|
| 289 |
+
"quantize_fp8_block128_bf16",
|
| 290 |
+
"layer_norm_fp8_block128_bf16",
|
| 291 |
+
"rms_norm_fp8_block128_bf16",
|
| 292 |
+
"residual_add_rms_norm_fp8_block128_bf16",
|
| 293 |
+
"gelu_tanh_fp8_block128_bf16",
|
| 294 |
+
"gelu_tanh_bias_fp8_block128_bf16",
|
| 295 |
+
"silu_mul_fp8_block128_bf16",
|
| 296 |
+
"silu_mul_merged_fp8_block128_bf16",
|
| 297 |
+
]
|
build/torch211-cxx11-cu130-x86_64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e93a29699c24fd814affd52be775e1fd46f77c9b0a7b080e0ff68f132b03add2
|
| 3 |
+
size 1965336
|
build/torch211-cxx11-cu130-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _blockwise_fp8_producers_cuda_7781728
|
| 3 |
+
ops = torch.ops._blockwise_fp8_producers_cuda_7781728
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_blockwise_fp8_producers_cuda_7781728::{op_name}"
|
build/torch211-cxx11-cu130-x86_64-linux/blockwise_fp8_producers/__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": "blockwise-fp8-producers",
|
| 3 |
+
"id": "_blockwise_fp8_producers_cuda_7781728",
|
| 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,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Blockwise FP8 producers for transformer and world-model regions."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def _check_matrix(input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor) -> None:
|
| 13 |
+
if (
|
| 14 |
+
input.dim() != 2
|
| 15 |
+
or input.shape[0] <= 0
|
| 16 |
+
or input.shape[1] <= 0
|
| 17 |
+
or input.shape[1] % 128 != 0
|
| 18 |
+
or output.shape != input.shape
|
| 19 |
+
or scale.shape != (input.shape[0], input.shape[1] // 128)
|
| 20 |
+
):
|
| 21 |
+
raise RuntimeError(
|
| 22 |
+
"expected input/output (rows, dim) with dim a positive multiple "
|
| 23 |
+
"of 128 and scale (rows, dim / 128)"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@torch.library.register_fake(add_op_namespace_prefix("quantize_fp8_block128_bf16"))
|
| 28 |
+
def _quantize_fake(
|
| 29 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 30 |
+
) -> None:
|
| 31 |
+
_check_matrix(input, output, scale)
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@torch.library.register_fake(add_op_namespace_prefix("layer_norm_fp8_block128_bf16"))
|
| 36 |
+
def _layer_norm_fake(
|
| 37 |
+
input: torch.Tensor,
|
| 38 |
+
weight: torch.Tensor,
|
| 39 |
+
bias: torch.Tensor,
|
| 40 |
+
eps: float,
|
| 41 |
+
output: torch.Tensor,
|
| 42 |
+
scale: torch.Tensor,
|
| 43 |
+
) -> None:
|
| 44 |
+
_check_matrix(input, output, scale)
|
| 45 |
+
if weight.shape != (input.shape[1],) or bias.shape != weight.shape:
|
| 46 |
+
raise RuntimeError("weight and bias must have shape (dim,)")
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@torch.library.register_fake(add_op_namespace_prefix("rms_norm_fp8_block128_bf16"))
|
| 51 |
+
def _rms_norm_fake(
|
| 52 |
+
input: torch.Tensor,
|
| 53 |
+
weight: torch.Tensor,
|
| 54 |
+
eps: float,
|
| 55 |
+
output: torch.Tensor,
|
| 56 |
+
scale: torch.Tensor,
|
| 57 |
+
) -> None:
|
| 58 |
+
_check_matrix(input, output, scale)
|
| 59 |
+
if weight.shape != (input.shape[1],):
|
| 60 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 61 |
+
return None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@torch.library.register_fake(
|
| 65 |
+
add_op_namespace_prefix("residual_add_rms_norm_fp8_block128_bf16")
|
| 66 |
+
)
|
| 67 |
+
def _residual_rms_norm_fake(
|
| 68 |
+
residual: torch.Tensor,
|
| 69 |
+
input: torch.Tensor,
|
| 70 |
+
weight: torch.Tensor,
|
| 71 |
+
eps: float,
|
| 72 |
+
residual_out: torch.Tensor,
|
| 73 |
+
output: torch.Tensor,
|
| 74 |
+
scale: torch.Tensor,
|
| 75 |
+
) -> None:
|
| 76 |
+
_check_matrix(input, output, scale)
|
| 77 |
+
if (
|
| 78 |
+
residual.shape != input.shape
|
| 79 |
+
or residual_out.shape != input.shape
|
| 80 |
+
or weight.shape != (input.shape[1],)
|
| 81 |
+
):
|
| 82 |
+
raise RuntimeError("residual/output must match input and weight must be (dim,)")
|
| 83 |
+
return None
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@torch.library.register_fake(add_op_namespace_prefix("gelu_tanh_fp8_block128_bf16"))
|
| 87 |
+
def _gelu_fake(
|
| 88 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 89 |
+
) -> None:
|
| 90 |
+
_check_matrix(input, output, scale)
|
| 91 |
+
return None
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@torch.library.register_fake(
|
| 95 |
+
add_op_namespace_prefix("gelu_tanh_bias_fp8_block128_bf16")
|
| 96 |
+
)
|
| 97 |
+
def _gelu_bias_fake(
|
| 98 |
+
input: torch.Tensor,
|
| 99 |
+
bias: torch.Tensor,
|
| 100 |
+
output: torch.Tensor,
|
| 101 |
+
scale: torch.Tensor,
|
| 102 |
+
) -> None:
|
| 103 |
+
_check_matrix(input, output, scale)
|
| 104 |
+
if bias.shape != (input.shape[1],):
|
| 105 |
+
raise RuntimeError("bias must have shape (dim,)")
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
@torch.library.register_fake(add_op_namespace_prefix("silu_mul_fp8_block128_bf16"))
|
| 110 |
+
def _silu_mul_fake(
|
| 111 |
+
gate: torch.Tensor,
|
| 112 |
+
up: torch.Tensor,
|
| 113 |
+
output: torch.Tensor,
|
| 114 |
+
scale: torch.Tensor,
|
| 115 |
+
) -> None:
|
| 116 |
+
_check_matrix(gate, output, scale)
|
| 117 |
+
if up.shape != gate.shape:
|
| 118 |
+
raise RuntimeError("up must match gate")
|
| 119 |
+
return None
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@torch.library.register_fake(
|
| 123 |
+
add_op_namespace_prefix("silu_mul_merged_fp8_block128_bf16")
|
| 124 |
+
)
|
| 125 |
+
def _silu_merged_fake(
|
| 126 |
+
gate_up: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 127 |
+
) -> None:
|
| 128 |
+
if (
|
| 129 |
+
gate_up.dim() != 2
|
| 130 |
+
or gate_up.shape[0] <= 0
|
| 131 |
+
or gate_up.shape[1] <= 0
|
| 132 |
+
or gate_up.shape[1] % 256 != 0
|
| 133 |
+
or output.shape != (gate_up.shape[0], gate_up.shape[1] // 2)
|
| 134 |
+
or scale.shape != (gate_up.shape[0], gate_up.shape[1] // 256)
|
| 135 |
+
):
|
| 136 |
+
raise RuntimeError(
|
| 137 |
+
"gate_up must be (rows, 2 * dim), dim multiple of 128"
|
| 138 |
+
)
|
| 139 |
+
return None
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _allocate(input: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
| 143 |
+
return (
|
| 144 |
+
torch.empty_like(input, dtype=torch.float8_e4m3fn),
|
| 145 |
+
torch.empty(
|
| 146 |
+
(input.shape[0], input.shape[1] // 128),
|
| 147 |
+
device=input.device,
|
| 148 |
+
dtype=torch.float32,
|
| 149 |
+
),
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def quantize_fp8_block128_bf16(
|
| 154 |
+
input: torch.Tensor,
|
| 155 |
+
*,
|
| 156 |
+
output: Optional[torch.Tensor] = None,
|
| 157 |
+
scale: Optional[torch.Tensor] = None,
|
| 158 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 159 |
+
if output is None or scale is None:
|
| 160 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 161 |
+
output = allocated_output if output is None else output
|
| 162 |
+
scale = allocated_scale if scale is None else scale
|
| 163 |
+
ops.quantize_fp8_block128_bf16(input, output, scale)
|
| 164 |
+
return output, scale
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def layer_norm_fp8_block128_bf16(
|
| 168 |
+
input: torch.Tensor,
|
| 169 |
+
weight: torch.Tensor,
|
| 170 |
+
bias: torch.Tensor,
|
| 171 |
+
eps: float = 1e-6,
|
| 172 |
+
*,
|
| 173 |
+
output: Optional[torch.Tensor] = None,
|
| 174 |
+
scale: Optional[torch.Tensor] = None,
|
| 175 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 176 |
+
if output is None or scale is None:
|
| 177 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 178 |
+
output = allocated_output if output is None else output
|
| 179 |
+
scale = allocated_scale if scale is None else scale
|
| 180 |
+
ops.layer_norm_fp8_block128_bf16(
|
| 181 |
+
input, weight, bias, float(eps), output, scale
|
| 182 |
+
)
|
| 183 |
+
return output, scale
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def rms_norm_fp8_block128_bf16(
|
| 187 |
+
input: torch.Tensor,
|
| 188 |
+
weight: torch.Tensor,
|
| 189 |
+
eps: float = 1e-6,
|
| 190 |
+
*,
|
| 191 |
+
output: Optional[torch.Tensor] = None,
|
| 192 |
+
scale: Optional[torch.Tensor] = None,
|
| 193 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 194 |
+
if output is None or scale is None:
|
| 195 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 196 |
+
output = allocated_output if output is None else output
|
| 197 |
+
scale = allocated_scale if scale is None else scale
|
| 198 |
+
ops.rms_norm_fp8_block128_bf16(input, weight, float(eps), output, scale)
|
| 199 |
+
return output, scale
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def residual_add_rms_norm_fp8_block128_bf16(
|
| 203 |
+
residual: torch.Tensor,
|
| 204 |
+
input: torch.Tensor,
|
| 205 |
+
weight: torch.Tensor,
|
| 206 |
+
eps: float = 1e-6,
|
| 207 |
+
*,
|
| 208 |
+
residual_out: Optional[torch.Tensor] = None,
|
| 209 |
+
output: Optional[torch.Tensor] = None,
|
| 210 |
+
scale: Optional[torch.Tensor] = None,
|
| 211 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 212 |
+
if residual_out is None:
|
| 213 |
+
residual_out = torch.empty_like(input)
|
| 214 |
+
if output is None or scale is None:
|
| 215 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 216 |
+
output = allocated_output if output is None else output
|
| 217 |
+
scale = allocated_scale if scale is None else scale
|
| 218 |
+
ops.residual_add_rms_norm_fp8_block128_bf16(
|
| 219 |
+
residual, input, weight, float(eps), residual_out, output, scale
|
| 220 |
+
)
|
| 221 |
+
return residual_out, output, scale
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def gelu_tanh_fp8_block128_bf16(
|
| 225 |
+
input: torch.Tensor,
|
| 226 |
+
*,
|
| 227 |
+
output: Optional[torch.Tensor] = None,
|
| 228 |
+
scale: Optional[torch.Tensor] = None,
|
| 229 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 230 |
+
if output is None or scale is None:
|
| 231 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 232 |
+
output = allocated_output if output is None else output
|
| 233 |
+
scale = allocated_scale if scale is None else scale
|
| 234 |
+
ops.gelu_tanh_fp8_block128_bf16(input, output, scale)
|
| 235 |
+
return output, scale
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def gelu_tanh_bias_fp8_block128_bf16(
|
| 239 |
+
input: torch.Tensor,
|
| 240 |
+
bias: torch.Tensor,
|
| 241 |
+
*,
|
| 242 |
+
output: Optional[torch.Tensor] = None,
|
| 243 |
+
scale: Optional[torch.Tensor] = None,
|
| 244 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 245 |
+
if output is None or scale is None:
|
| 246 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 247 |
+
output = allocated_output if output is None else output
|
| 248 |
+
scale = allocated_scale if scale is None else scale
|
| 249 |
+
ops.gelu_tanh_bias_fp8_block128_bf16(input, bias, output, scale)
|
| 250 |
+
return output, scale
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def silu_mul_fp8_block128_bf16(
|
| 254 |
+
gate: torch.Tensor,
|
| 255 |
+
up: torch.Tensor,
|
| 256 |
+
*,
|
| 257 |
+
output: Optional[torch.Tensor] = None,
|
| 258 |
+
scale: Optional[torch.Tensor] = None,
|
| 259 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 260 |
+
if output is None or scale is None:
|
| 261 |
+
allocated_output, allocated_scale = _allocate(gate)
|
| 262 |
+
output = allocated_output if output is None else output
|
| 263 |
+
scale = allocated_scale if scale is None else scale
|
| 264 |
+
ops.silu_mul_fp8_block128_bf16(gate, up, output, scale)
|
| 265 |
+
return output, scale
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def silu_mul_merged_fp8_block128_bf16(
|
| 269 |
+
gate_up: torch.Tensor,
|
| 270 |
+
*,
|
| 271 |
+
output: Optional[torch.Tensor] = None,
|
| 272 |
+
scale: Optional[torch.Tensor] = None,
|
| 273 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 274 |
+
rows, merged_dim = gate_up.shape
|
| 275 |
+
dim = merged_dim // 2
|
| 276 |
+
if output is None:
|
| 277 |
+
output = torch.empty(
|
| 278 |
+
(rows, dim), device=gate_up.device, dtype=torch.float8_e4m3fn
|
| 279 |
+
)
|
| 280 |
+
if scale is None:
|
| 281 |
+
scale = torch.empty(
|
| 282 |
+
(rows, dim // 128), device=gate_up.device, dtype=torch.float32
|
| 283 |
+
)
|
| 284 |
+
ops.silu_mul_merged_fp8_block128_bf16(gate_up, output, scale)
|
| 285 |
+
return output, scale
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
__all__ = [
|
| 289 |
+
"quantize_fp8_block128_bf16",
|
| 290 |
+
"layer_norm_fp8_block128_bf16",
|
| 291 |
+
"rms_norm_fp8_block128_bf16",
|
| 292 |
+
"residual_add_rms_norm_fp8_block128_bf16",
|
| 293 |
+
"gelu_tanh_fp8_block128_bf16",
|
| 294 |
+
"gelu_tanh_bias_fp8_block128_bf16",
|
| 295 |
+
"silu_mul_fp8_block128_bf16",
|
| 296 |
+
"silu_mul_merged_fp8_block128_bf16",
|
| 297 |
+
]
|
build/torch212-cxx11-cu130-x86_64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c7611d3c85039b78b8d4270343b02a026e8f069068fb38a0c7caac2a1a384ce
|
| 3 |
+
size 1975904
|
build/torch212-cxx11-cu130-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _blockwise_fp8_producers_cuda_7781728
|
| 3 |
+
ops = torch.ops._blockwise_fp8_producers_cuda_7781728
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_blockwise_fp8_producers_cuda_7781728::{op_name}"
|
build/torch212-cxx11-cu130-x86_64-linux/blockwise_fp8_producers/__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": "blockwise-fp8-producers",
|
| 3 |
+
"id": "_blockwise_fp8_producers_cuda_7781728",
|
| 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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
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def _check_matrix(input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor) -> None:
|
| 13 |
+
if (
|
| 14 |
+
input.dim() != 2
|
| 15 |
+
or input.shape[0] <= 0
|
| 16 |
+
or input.shape[1] <= 0
|
| 17 |
+
or input.shape[1] % 128 != 0
|
| 18 |
+
or output.shape != input.shape
|
| 19 |
+
or scale.shape != (input.shape[0], input.shape[1] // 128)
|
| 20 |
+
):
|
| 21 |
+
raise RuntimeError(
|
| 22 |
+
"expected input/output (rows, dim) with dim a positive multiple "
|
| 23 |
+
"of 128 and scale (rows, dim / 128)"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@torch.library.register_fake(add_op_namespace_prefix("quantize_fp8_block128_bf16"))
|
| 28 |
+
def _quantize_fake(
|
| 29 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 30 |
+
) -> None:
|
| 31 |
+
_check_matrix(input, output, scale)
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@torch.library.register_fake(add_op_namespace_prefix("layer_norm_fp8_block128_bf16"))
|
| 36 |
+
def _layer_norm_fake(
|
| 37 |
+
input: torch.Tensor,
|
| 38 |
+
weight: torch.Tensor,
|
| 39 |
+
bias: torch.Tensor,
|
| 40 |
+
eps: float,
|
| 41 |
+
output: torch.Tensor,
|
| 42 |
+
scale: torch.Tensor,
|
| 43 |
+
) -> None:
|
| 44 |
+
_check_matrix(input, output, scale)
|
| 45 |
+
if weight.shape != (input.shape[1],) or bias.shape != weight.shape:
|
| 46 |
+
raise RuntimeError("weight and bias must have shape (dim,)")
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@torch.library.register_fake(add_op_namespace_prefix("rms_norm_fp8_block128_bf16"))
|
| 51 |
+
def _rms_norm_fake(
|
| 52 |
+
input: torch.Tensor,
|
| 53 |
+
weight: torch.Tensor,
|
| 54 |
+
eps: float,
|
| 55 |
+
output: torch.Tensor,
|
| 56 |
+
scale: torch.Tensor,
|
| 57 |
+
) -> None:
|
| 58 |
+
_check_matrix(input, output, scale)
|
| 59 |
+
if weight.shape != (input.shape[1],):
|
| 60 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 61 |
+
return None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@torch.library.register_fake(
|
| 65 |
+
add_op_namespace_prefix("residual_add_rms_norm_fp8_block128_bf16")
|
| 66 |
+
)
|
| 67 |
+
def _residual_rms_norm_fake(
|
| 68 |
+
residual: torch.Tensor,
|
| 69 |
+
input: torch.Tensor,
|
| 70 |
+
weight: torch.Tensor,
|
| 71 |
+
eps: float,
|
| 72 |
+
residual_out: torch.Tensor,
|
| 73 |
+
output: torch.Tensor,
|
| 74 |
+
scale: torch.Tensor,
|
| 75 |
+
) -> None:
|
| 76 |
+
_check_matrix(input, output, scale)
|
| 77 |
+
if (
|
| 78 |
+
residual.shape != input.shape
|
| 79 |
+
or residual_out.shape != input.shape
|
| 80 |
+
or weight.shape != (input.shape[1],)
|
| 81 |
+
):
|
| 82 |
+
raise RuntimeError("residual/output must match input and weight must be (dim,)")
|
| 83 |
+
return None
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@torch.library.register_fake(add_op_namespace_prefix("gelu_tanh_fp8_block128_bf16"))
|
| 87 |
+
def _gelu_fake(
|
| 88 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 89 |
+
) -> None:
|
| 90 |
+
_check_matrix(input, output, scale)
|
| 91 |
+
return None
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@torch.library.register_fake(
|
| 95 |
+
add_op_namespace_prefix("gelu_tanh_bias_fp8_block128_bf16")
|
| 96 |
+
)
|
| 97 |
+
def _gelu_bias_fake(
|
| 98 |
+
input: torch.Tensor,
|
| 99 |
+
bias: torch.Tensor,
|
| 100 |
+
output: torch.Tensor,
|
| 101 |
+
scale: torch.Tensor,
|
| 102 |
+
) -> None:
|
| 103 |
+
_check_matrix(input, output, scale)
|
| 104 |
+
if bias.shape != (input.shape[1],):
|
| 105 |
+
raise RuntimeError("bias must have shape (dim,)")
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
@torch.library.register_fake(add_op_namespace_prefix("silu_mul_fp8_block128_bf16"))
|
| 110 |
+
def _silu_mul_fake(
|
| 111 |
+
gate: torch.Tensor,
|
| 112 |
+
up: torch.Tensor,
|
| 113 |
+
output: torch.Tensor,
|
| 114 |
+
scale: torch.Tensor,
|
| 115 |
+
) -> None:
|
| 116 |
+
_check_matrix(gate, output, scale)
|
| 117 |
+
if up.shape != gate.shape:
|
| 118 |
+
raise RuntimeError("up must match gate")
|
| 119 |
+
return None
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@torch.library.register_fake(
|
| 123 |
+
add_op_namespace_prefix("silu_mul_merged_fp8_block128_bf16")
|
| 124 |
+
)
|
| 125 |
+
def _silu_merged_fake(
|
| 126 |
+
gate_up: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 127 |
+
) -> None:
|
| 128 |
+
if (
|
| 129 |
+
gate_up.dim() != 2
|
| 130 |
+
or gate_up.shape[0] <= 0
|
| 131 |
+
or gate_up.shape[1] <= 0
|
| 132 |
+
or gate_up.shape[1] % 256 != 0
|
| 133 |
+
or output.shape != (gate_up.shape[0], gate_up.shape[1] // 2)
|
| 134 |
+
or scale.shape != (gate_up.shape[0], gate_up.shape[1] // 256)
|
| 135 |
+
):
|
| 136 |
+
raise RuntimeError(
|
| 137 |
+
"gate_up must be (rows, 2 * dim), dim multiple of 128"
|
| 138 |
+
)
|
| 139 |
+
return None
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _allocate(input: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
| 143 |
+
return (
|
| 144 |
+
torch.empty_like(input, dtype=torch.float8_e4m3fn),
|
| 145 |
+
torch.empty(
|
| 146 |
+
(input.shape[0], input.shape[1] // 128),
|
| 147 |
+
device=input.device,
|
| 148 |
+
dtype=torch.float32,
|
| 149 |
+
),
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def quantize_fp8_block128_bf16(
|
| 154 |
+
input: torch.Tensor,
|
| 155 |
+
*,
|
| 156 |
+
output: Optional[torch.Tensor] = None,
|
| 157 |
+
scale: Optional[torch.Tensor] = None,
|
| 158 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 159 |
+
if output is None or scale is None:
|
| 160 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 161 |
+
output = allocated_output if output is None else output
|
| 162 |
+
scale = allocated_scale if scale is None else scale
|
| 163 |
+
ops.quantize_fp8_block128_bf16(input, output, scale)
|
| 164 |
+
return output, scale
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def layer_norm_fp8_block128_bf16(
|
| 168 |
+
input: torch.Tensor,
|
| 169 |
+
weight: torch.Tensor,
|
| 170 |
+
bias: torch.Tensor,
|
| 171 |
+
eps: float = 1e-6,
|
| 172 |
+
*,
|
| 173 |
+
output: Optional[torch.Tensor] = None,
|
| 174 |
+
scale: Optional[torch.Tensor] = None,
|
| 175 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 176 |
+
if output is None or scale is None:
|
| 177 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 178 |
+
output = allocated_output if output is None else output
|
| 179 |
+
scale = allocated_scale if scale is None else scale
|
| 180 |
+
ops.layer_norm_fp8_block128_bf16(
|
| 181 |
+
input, weight, bias, float(eps), output, scale
|
| 182 |
+
)
|
| 183 |
+
return output, scale
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def rms_norm_fp8_block128_bf16(
|
| 187 |
+
input: torch.Tensor,
|
| 188 |
+
weight: torch.Tensor,
|
| 189 |
+
eps: float = 1e-6,
|
| 190 |
+
*,
|
| 191 |
+
output: Optional[torch.Tensor] = None,
|
| 192 |
+
scale: Optional[torch.Tensor] = None,
|
| 193 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 194 |
+
if output is None or scale is None:
|
| 195 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 196 |
+
output = allocated_output if output is None else output
|
| 197 |
+
scale = allocated_scale if scale is None else scale
|
| 198 |
+
ops.rms_norm_fp8_block128_bf16(input, weight, float(eps), output, scale)
|
| 199 |
+
return output, scale
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def residual_add_rms_norm_fp8_block128_bf16(
|
| 203 |
+
residual: torch.Tensor,
|
| 204 |
+
input: torch.Tensor,
|
| 205 |
+
weight: torch.Tensor,
|
| 206 |
+
eps: float = 1e-6,
|
| 207 |
+
*,
|
| 208 |
+
residual_out: Optional[torch.Tensor] = None,
|
| 209 |
+
output: Optional[torch.Tensor] = None,
|
| 210 |
+
scale: Optional[torch.Tensor] = None,
|
| 211 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 212 |
+
if residual_out is None:
|
| 213 |
+
residual_out = torch.empty_like(input)
|
| 214 |
+
if output is None or scale is None:
|
| 215 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 216 |
+
output = allocated_output if output is None else output
|
| 217 |
+
scale = allocated_scale if scale is None else scale
|
| 218 |
+
ops.residual_add_rms_norm_fp8_block128_bf16(
|
| 219 |
+
residual, input, weight, float(eps), residual_out, output, scale
|
| 220 |
+
)
|
| 221 |
+
return residual_out, output, scale
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def gelu_tanh_fp8_block128_bf16(
|
| 225 |
+
input: torch.Tensor,
|
| 226 |
+
*,
|
| 227 |
+
output: Optional[torch.Tensor] = None,
|
| 228 |
+
scale: Optional[torch.Tensor] = None,
|
| 229 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 230 |
+
if output is None or scale is None:
|
| 231 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 232 |
+
output = allocated_output if output is None else output
|
| 233 |
+
scale = allocated_scale if scale is None else scale
|
| 234 |
+
ops.gelu_tanh_fp8_block128_bf16(input, output, scale)
|
| 235 |
+
return output, scale
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def gelu_tanh_bias_fp8_block128_bf16(
|
| 239 |
+
input: torch.Tensor,
|
| 240 |
+
bias: torch.Tensor,
|
| 241 |
+
*,
|
| 242 |
+
output: Optional[torch.Tensor] = None,
|
| 243 |
+
scale: Optional[torch.Tensor] = None,
|
| 244 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 245 |
+
if output is None or scale is None:
|
| 246 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 247 |
+
output = allocated_output if output is None else output
|
| 248 |
+
scale = allocated_scale if scale is None else scale
|
| 249 |
+
ops.gelu_tanh_bias_fp8_block128_bf16(input, bias, output, scale)
|
| 250 |
+
return output, scale
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def silu_mul_fp8_block128_bf16(
|
| 254 |
+
gate: torch.Tensor,
|
| 255 |
+
up: torch.Tensor,
|
| 256 |
+
*,
|
| 257 |
+
output: Optional[torch.Tensor] = None,
|
| 258 |
+
scale: Optional[torch.Tensor] = None,
|
| 259 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 260 |
+
if output is None or scale is None:
|
| 261 |
+
allocated_output, allocated_scale = _allocate(gate)
|
| 262 |
+
output = allocated_output if output is None else output
|
| 263 |
+
scale = allocated_scale if scale is None else scale
|
| 264 |
+
ops.silu_mul_fp8_block128_bf16(gate, up, output, scale)
|
| 265 |
+
return output, scale
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def silu_mul_merged_fp8_block128_bf16(
|
| 269 |
+
gate_up: torch.Tensor,
|
| 270 |
+
*,
|
| 271 |
+
output: Optional[torch.Tensor] = None,
|
| 272 |
+
scale: Optional[torch.Tensor] = None,
|
| 273 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 274 |
+
rows, merged_dim = gate_up.shape
|
| 275 |
+
dim = merged_dim // 2
|
| 276 |
+
if output is None:
|
| 277 |
+
output = torch.empty(
|
| 278 |
+
(rows, dim), device=gate_up.device, dtype=torch.float8_e4m3fn
|
| 279 |
+
)
|
| 280 |
+
if scale is None:
|
| 281 |
+
scale = torch.empty(
|
| 282 |
+
(rows, dim // 128), device=gate_up.device, dtype=torch.float32
|
| 283 |
+
)
|
| 284 |
+
ops.silu_mul_merged_fp8_block128_bf16(gate_up, output, scale)
|
| 285 |
+
return output, scale
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
__all__ = [
|
| 289 |
+
"quantize_fp8_block128_bf16",
|
| 290 |
+
"layer_norm_fp8_block128_bf16",
|
| 291 |
+
"rms_norm_fp8_block128_bf16",
|
| 292 |
+
"residual_add_rms_norm_fp8_block128_bf16",
|
| 293 |
+
"gelu_tanh_fp8_block128_bf16",
|
| 294 |
+
"gelu_tanh_bias_fp8_block128_bf16",
|
| 295 |
+
"silu_mul_fp8_block128_bf16",
|
| 296 |
+
"silu_mul_merged_fp8_block128_bf16",
|
| 297 |
+
]
|
build/torch212-cxx11-cu132-x86_64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2c97dac88cca54b24510190aa866b5495d96ab666ebae5449d3c40dbf2c18584
|
| 3 |
+
size 1980000
|
build/torch212-cxx11-cu132-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _blockwise_fp8_producers_cuda_7781728
|
| 3 |
+
ops = torch.ops._blockwise_fp8_producers_cuda_7781728
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_blockwise_fp8_producers_cuda_7781728::{op_name}"
|
build/torch212-cxx11-cu132-x86_64-linux/blockwise_fp8_producers/__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": "blockwise-fp8-producers",
|
| 3 |
+
"id": "_blockwise_fp8_producers_cuda_7781728",
|
| 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/torch213-cxx11-cu130-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Blockwise FP8 producers for transformer and world-model regions."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def _check_matrix(input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor) -> None:
|
| 13 |
+
if (
|
| 14 |
+
input.dim() != 2
|
| 15 |
+
or input.shape[0] <= 0
|
| 16 |
+
or input.shape[1] <= 0
|
| 17 |
+
or input.shape[1] % 128 != 0
|
| 18 |
+
or output.shape != input.shape
|
| 19 |
+
or scale.shape != (input.shape[0], input.shape[1] // 128)
|
| 20 |
+
):
|
| 21 |
+
raise RuntimeError(
|
| 22 |
+
"expected input/output (rows, dim) with dim a positive multiple "
|
| 23 |
+
"of 128 and scale (rows, dim / 128)"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@torch.library.register_fake(add_op_namespace_prefix("quantize_fp8_block128_bf16"))
|
| 28 |
+
def _quantize_fake(
|
| 29 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 30 |
+
) -> None:
|
| 31 |
+
_check_matrix(input, output, scale)
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@torch.library.register_fake(add_op_namespace_prefix("layer_norm_fp8_block128_bf16"))
|
| 36 |
+
def _layer_norm_fake(
|
| 37 |
+
input: torch.Tensor,
|
| 38 |
+
weight: torch.Tensor,
|
| 39 |
+
bias: torch.Tensor,
|
| 40 |
+
eps: float,
|
| 41 |
+
output: torch.Tensor,
|
| 42 |
+
scale: torch.Tensor,
|
| 43 |
+
) -> None:
|
| 44 |
+
_check_matrix(input, output, scale)
|
| 45 |
+
if weight.shape != (input.shape[1],) or bias.shape != weight.shape:
|
| 46 |
+
raise RuntimeError("weight and bias must have shape (dim,)")
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@torch.library.register_fake(add_op_namespace_prefix("rms_norm_fp8_block128_bf16"))
|
| 51 |
+
def _rms_norm_fake(
|
| 52 |
+
input: torch.Tensor,
|
| 53 |
+
weight: torch.Tensor,
|
| 54 |
+
eps: float,
|
| 55 |
+
output: torch.Tensor,
|
| 56 |
+
scale: torch.Tensor,
|
| 57 |
+
) -> None:
|
| 58 |
+
_check_matrix(input, output, scale)
|
| 59 |
+
if weight.shape != (input.shape[1],):
|
| 60 |
+
raise RuntimeError("weight must have shape (dim,)")
|
| 61 |
+
return None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@torch.library.register_fake(
|
| 65 |
+
add_op_namespace_prefix("residual_add_rms_norm_fp8_block128_bf16")
|
| 66 |
+
)
|
| 67 |
+
def _residual_rms_norm_fake(
|
| 68 |
+
residual: torch.Tensor,
|
| 69 |
+
input: torch.Tensor,
|
| 70 |
+
weight: torch.Tensor,
|
| 71 |
+
eps: float,
|
| 72 |
+
residual_out: torch.Tensor,
|
| 73 |
+
output: torch.Tensor,
|
| 74 |
+
scale: torch.Tensor,
|
| 75 |
+
) -> None:
|
| 76 |
+
_check_matrix(input, output, scale)
|
| 77 |
+
if (
|
| 78 |
+
residual.shape != input.shape
|
| 79 |
+
or residual_out.shape != input.shape
|
| 80 |
+
or weight.shape != (input.shape[1],)
|
| 81 |
+
):
|
| 82 |
+
raise RuntimeError("residual/output must match input and weight must be (dim,)")
|
| 83 |
+
return None
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@torch.library.register_fake(add_op_namespace_prefix("gelu_tanh_fp8_block128_bf16"))
|
| 87 |
+
def _gelu_fake(
|
| 88 |
+
input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 89 |
+
) -> None:
|
| 90 |
+
_check_matrix(input, output, scale)
|
| 91 |
+
return None
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@torch.library.register_fake(
|
| 95 |
+
add_op_namespace_prefix("gelu_tanh_bias_fp8_block128_bf16")
|
| 96 |
+
)
|
| 97 |
+
def _gelu_bias_fake(
|
| 98 |
+
input: torch.Tensor,
|
| 99 |
+
bias: torch.Tensor,
|
| 100 |
+
output: torch.Tensor,
|
| 101 |
+
scale: torch.Tensor,
|
| 102 |
+
) -> None:
|
| 103 |
+
_check_matrix(input, output, scale)
|
| 104 |
+
if bias.shape != (input.shape[1],):
|
| 105 |
+
raise RuntimeError("bias must have shape (dim,)")
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
@torch.library.register_fake(add_op_namespace_prefix("silu_mul_fp8_block128_bf16"))
|
| 110 |
+
def _silu_mul_fake(
|
| 111 |
+
gate: torch.Tensor,
|
| 112 |
+
up: torch.Tensor,
|
| 113 |
+
output: torch.Tensor,
|
| 114 |
+
scale: torch.Tensor,
|
| 115 |
+
) -> None:
|
| 116 |
+
_check_matrix(gate, output, scale)
|
| 117 |
+
if up.shape != gate.shape:
|
| 118 |
+
raise RuntimeError("up must match gate")
|
| 119 |
+
return None
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@torch.library.register_fake(
|
| 123 |
+
add_op_namespace_prefix("silu_mul_merged_fp8_block128_bf16")
|
| 124 |
+
)
|
| 125 |
+
def _silu_merged_fake(
|
| 126 |
+
gate_up: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
|
| 127 |
+
) -> None:
|
| 128 |
+
if (
|
| 129 |
+
gate_up.dim() != 2
|
| 130 |
+
or gate_up.shape[0] <= 0
|
| 131 |
+
or gate_up.shape[1] <= 0
|
| 132 |
+
or gate_up.shape[1] % 256 != 0
|
| 133 |
+
or output.shape != (gate_up.shape[0], gate_up.shape[1] // 2)
|
| 134 |
+
or scale.shape != (gate_up.shape[0], gate_up.shape[1] // 256)
|
| 135 |
+
):
|
| 136 |
+
raise RuntimeError(
|
| 137 |
+
"gate_up must be (rows, 2 * dim), dim multiple of 128"
|
| 138 |
+
)
|
| 139 |
+
return None
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _allocate(input: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
| 143 |
+
return (
|
| 144 |
+
torch.empty_like(input, dtype=torch.float8_e4m3fn),
|
| 145 |
+
torch.empty(
|
| 146 |
+
(input.shape[0], input.shape[1] // 128),
|
| 147 |
+
device=input.device,
|
| 148 |
+
dtype=torch.float32,
|
| 149 |
+
),
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def quantize_fp8_block128_bf16(
|
| 154 |
+
input: torch.Tensor,
|
| 155 |
+
*,
|
| 156 |
+
output: Optional[torch.Tensor] = None,
|
| 157 |
+
scale: Optional[torch.Tensor] = None,
|
| 158 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 159 |
+
if output is None or scale is None:
|
| 160 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 161 |
+
output = allocated_output if output is None else output
|
| 162 |
+
scale = allocated_scale if scale is None else scale
|
| 163 |
+
ops.quantize_fp8_block128_bf16(input, output, scale)
|
| 164 |
+
return output, scale
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def layer_norm_fp8_block128_bf16(
|
| 168 |
+
input: torch.Tensor,
|
| 169 |
+
weight: torch.Tensor,
|
| 170 |
+
bias: torch.Tensor,
|
| 171 |
+
eps: float = 1e-6,
|
| 172 |
+
*,
|
| 173 |
+
output: Optional[torch.Tensor] = None,
|
| 174 |
+
scale: Optional[torch.Tensor] = None,
|
| 175 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 176 |
+
if output is None or scale is None:
|
| 177 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 178 |
+
output = allocated_output if output is None else output
|
| 179 |
+
scale = allocated_scale if scale is None else scale
|
| 180 |
+
ops.layer_norm_fp8_block128_bf16(
|
| 181 |
+
input, weight, bias, float(eps), output, scale
|
| 182 |
+
)
|
| 183 |
+
return output, scale
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def rms_norm_fp8_block128_bf16(
|
| 187 |
+
input: torch.Tensor,
|
| 188 |
+
weight: torch.Tensor,
|
| 189 |
+
eps: float = 1e-6,
|
| 190 |
+
*,
|
| 191 |
+
output: Optional[torch.Tensor] = None,
|
| 192 |
+
scale: Optional[torch.Tensor] = None,
|
| 193 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 194 |
+
if output is None or scale is None:
|
| 195 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 196 |
+
output = allocated_output if output is None else output
|
| 197 |
+
scale = allocated_scale if scale is None else scale
|
| 198 |
+
ops.rms_norm_fp8_block128_bf16(input, weight, float(eps), output, scale)
|
| 199 |
+
return output, scale
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def residual_add_rms_norm_fp8_block128_bf16(
|
| 203 |
+
residual: torch.Tensor,
|
| 204 |
+
input: torch.Tensor,
|
| 205 |
+
weight: torch.Tensor,
|
| 206 |
+
eps: float = 1e-6,
|
| 207 |
+
*,
|
| 208 |
+
residual_out: Optional[torch.Tensor] = None,
|
| 209 |
+
output: Optional[torch.Tensor] = None,
|
| 210 |
+
scale: Optional[torch.Tensor] = None,
|
| 211 |
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 212 |
+
if residual_out is None:
|
| 213 |
+
residual_out = torch.empty_like(input)
|
| 214 |
+
if output is None or scale is None:
|
| 215 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 216 |
+
output = allocated_output if output is None else output
|
| 217 |
+
scale = allocated_scale if scale is None else scale
|
| 218 |
+
ops.residual_add_rms_norm_fp8_block128_bf16(
|
| 219 |
+
residual, input, weight, float(eps), residual_out, output, scale
|
| 220 |
+
)
|
| 221 |
+
return residual_out, output, scale
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def gelu_tanh_fp8_block128_bf16(
|
| 225 |
+
input: torch.Tensor,
|
| 226 |
+
*,
|
| 227 |
+
output: Optional[torch.Tensor] = None,
|
| 228 |
+
scale: Optional[torch.Tensor] = None,
|
| 229 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 230 |
+
if output is None or scale is None:
|
| 231 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 232 |
+
output = allocated_output if output is None else output
|
| 233 |
+
scale = allocated_scale if scale is None else scale
|
| 234 |
+
ops.gelu_tanh_fp8_block128_bf16(input, output, scale)
|
| 235 |
+
return output, scale
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def gelu_tanh_bias_fp8_block128_bf16(
|
| 239 |
+
input: torch.Tensor,
|
| 240 |
+
bias: torch.Tensor,
|
| 241 |
+
*,
|
| 242 |
+
output: Optional[torch.Tensor] = None,
|
| 243 |
+
scale: Optional[torch.Tensor] = None,
|
| 244 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 245 |
+
if output is None or scale is None:
|
| 246 |
+
allocated_output, allocated_scale = _allocate(input)
|
| 247 |
+
output = allocated_output if output is None else output
|
| 248 |
+
scale = allocated_scale if scale is None else scale
|
| 249 |
+
ops.gelu_tanh_bias_fp8_block128_bf16(input, bias, output, scale)
|
| 250 |
+
return output, scale
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def silu_mul_fp8_block128_bf16(
|
| 254 |
+
gate: torch.Tensor,
|
| 255 |
+
up: torch.Tensor,
|
| 256 |
+
*,
|
| 257 |
+
output: Optional[torch.Tensor] = None,
|
| 258 |
+
scale: Optional[torch.Tensor] = None,
|
| 259 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 260 |
+
if output is None or scale is None:
|
| 261 |
+
allocated_output, allocated_scale = _allocate(gate)
|
| 262 |
+
output = allocated_output if output is None else output
|
| 263 |
+
scale = allocated_scale if scale is None else scale
|
| 264 |
+
ops.silu_mul_fp8_block128_bf16(gate, up, output, scale)
|
| 265 |
+
return output, scale
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def silu_mul_merged_fp8_block128_bf16(
|
| 269 |
+
gate_up: torch.Tensor,
|
| 270 |
+
*,
|
| 271 |
+
output: Optional[torch.Tensor] = None,
|
| 272 |
+
scale: Optional[torch.Tensor] = None,
|
| 273 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 274 |
+
rows, merged_dim = gate_up.shape
|
| 275 |
+
dim = merged_dim // 2
|
| 276 |
+
if output is None:
|
| 277 |
+
output = torch.empty(
|
| 278 |
+
(rows, dim), device=gate_up.device, dtype=torch.float8_e4m3fn
|
| 279 |
+
)
|
| 280 |
+
if scale is None:
|
| 281 |
+
scale = torch.empty(
|
| 282 |
+
(rows, dim // 128), device=gate_up.device, dtype=torch.float32
|
| 283 |
+
)
|
| 284 |
+
ops.silu_mul_merged_fp8_block128_bf16(gate_up, output, scale)
|
| 285 |
+
return output, scale
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
__all__ = [
|
| 289 |
+
"quantize_fp8_block128_bf16",
|
| 290 |
+
"layer_norm_fp8_block128_bf16",
|
| 291 |
+
"rms_norm_fp8_block128_bf16",
|
| 292 |
+
"residual_add_rms_norm_fp8_block128_bf16",
|
| 293 |
+
"gelu_tanh_fp8_block128_bf16",
|
| 294 |
+
"gelu_tanh_bias_fp8_block128_bf16",
|
| 295 |
+
"silu_mul_fp8_block128_bf16",
|
| 296 |
+
"silu_mul_merged_fp8_block128_bf16",
|
| 297 |
+
]
|
build/torch213-cxx11-cu130-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import blockwise_fp8_producers_source_test
|
| 3 |
+
ops = torch.ops.blockwise_fp8_producers_source_test
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
return f"blockwise_fp8_producers_source_test::{op_name}"
|
build/torch213-cxx11-cu130-aarch64-linux/blockwise_fp8_producers/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
def _import_from_path(file_path: Path):
|
| 7 |
+
path_hash = '{:x}'.format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 8 |
+
spec = importlib.util.spec_from_file_location(path_hash, file_path)
|
| 9 |
+
module = importlib.util.module_from_spec(spec)
|
| 10 |
+
sys.modules[path_hash] = module
|
| 11 |
+
spec.loader.exec_module(module)
|
| 12 |
+
return module
|
| 13 |
+
|
| 14 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / '__init__.py')))
|
build/torch213-cxx11-cu130-aarch64-linux/blockwise_fp8_producers_source_test.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:482bf87ff6a9a2a9d92b8608e41f8255e151853f0de46dc95594801236cfe335
|
| 3 |
+
size 458120
|
build/torch213-cxx11-cu130-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "blockwise-fp8-producers",
|
| 3 |
+
"id": "blockwise_fp8_producers_source_test",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"11.0"
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
"digest": {
|
| 14 |
+
"algorithm": "sha256",
|
| 15 |
+
"files": {
|
| 16 |
+
"__init__.py": "jTa/yZ4lH7PUVKeENwdd7iZgdhrc9AOOJ8+L2usA23M=",
|
| 17 |
+
"blockwise_fp8_producers_source_test.abi3.so": "SCv4f/apoqnZK4YI5B+CVeFRhT8N5G3JVZSAEjbP4zU=",
|
| 18 |
+
"_ops.py": "gWnlQMRiABwvEGwVmY0l2A/6y1/DB/ruVb0A4WOgziE=",
|
| 19 |
+
"blockwise_fp8_producers/__init__.py": "v6p5XMfQzddhi1fLSAw4HX9CyS0rQsidvu9VsT01xi4="
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
"provenance": {
|
| 23 |
+
"kernel": {
|
| 24 |
+
"sha": "456d297",
|
| 25 |
+
"dirty": false
|
| 26 |
+
},
|
| 27 |
+
"validation": {
|
| 28 |
+
"torch": "2.13.0+cu130",
|
| 29 |
+
"cuda": "13.0"
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
}
|