Promote latest kernel artifacts to main
Browse files- README.md +0 -9
- benchmarks/benchmark_native_parity.py +433 -0
- build/torch211-cxx11-cu128-x86_64-linux/__init__.py +304 -0
- build/{torch211-cxx11-cu130-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_5de4768.abi3.so → torch211-cxx11-cu128-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so} +2 -2
- build/torch211-cxx11-cu128-x86_64-linux/_ops.py +3 -3
- build/torch211-cxx11-cu128-x86_64-linux/metadata.json +1 -1
- build/torch211-cxx11-cu130-aarch64-linux/__init__.py +414 -0
- build/{torch212-cxx11-cu132-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_5de4768.abi3.so → torch211-cxx11-cu130-aarch64-linux/_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so} +2 -2
- build/torch211-cxx11-cu130-aarch64-linux/_ops.py +6 -0
- build/torch211-cxx11-cu130-aarch64-linux/flashrt_spatiotemporal_layout/__init__.py +14 -0
- build/torch211-cxx11-cu130-aarch64-linux/metadata.json +22 -0
- build/torch211-cxx11-cu130-x86_64-linux/__init__.py +304 -0
- build/{torch212-cxx11-cu130-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_5de4768.abi3.so → torch211-cxx11-cu130-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so} +2 -2
- build/torch211-cxx11-cu130-x86_64-linux/_ops.py +3 -3
- build/torch211-cxx11-cu130-x86_64-linux/metadata.json +1 -1
- build/torch212-cxx11-cu130-x86_64-linux/__init__.py +304 -0
- build/torch212-cxx11-cu130-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so +3 -0
- build/torch212-cxx11-cu130-x86_64-linux/_ops.py +3 -3
- build/torch212-cxx11-cu130-x86_64-linux/metadata.json +1 -1
- build/torch212-cxx11-cu132-x86_64-linux/__init__.py +304 -0
- build/torch212-cxx11-cu132-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so +3 -0
- build/torch212-cxx11-cu132-x86_64-linux/_ops.py +3 -3
- build/torch212-cxx11-cu132-x86_64-linux/metadata.json +1 -1
- build/torch213-cxx11-cu130-aarch64-linux/__init__.py +414 -0
- build/torch213-cxx11-cu130-aarch64-linux/_ops.py +6 -0
- build/torch213-cxx11-cu130-aarch64-linux/flashrt_spatiotemporal_layout/__init__.py +14 -0
- build/{torch211-cxx11-cu128-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_5de4768.abi3.so → torch213-cxx11-cu130-aarch64-linux/flashrt_spatiotemporal_layout_test.abi3.so} +2 -2
- build/torch213-cxx11-cu130-aarch64-linux/metadata.json +32 -0
README.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
# flashrt/flashrt-spatiotemporal-layout
|
| 2 |
-
|
| 3 |
-
This repository is a compatibility mirror for older `kernels` clients
|
| 4 |
-
that resolve repositories through the default Hugging Face model repo API.
|
| 5 |
-
|
| 6 |
-
Canonical Kernel Hub repo: https://huggingface.co/kernels/flashrt/flashrt-spatiotemporal-layout
|
| 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_native_parity.py
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Benchmark Tensor wrappers against native FlashRT and torch baselines."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import importlib
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
from dataclasses import asdict, dataclass
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
import torch
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
ROOT = Path(__file__).resolve().parents[2]
|
| 18 |
+
PACKAGE = ROOT / "flashrt-spatiotemporal-layout"
|
| 19 |
+
REGISTRATION = (
|
| 20 |
+
ROOT.parent / "kernels/kernel-builder/src/pyproject/templates/torch"
|
| 21 |
+
)
|
| 22 |
+
SHAPES = {
|
| 23 |
+
"latent-small": (1, 64, 4, 32, 32),
|
| 24 |
+
"vae-channel320": (1, 320, 17, 32, 32),
|
| 25 |
+
"vae-channel512": (1, 512, 4, 64, 64),
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@dataclass
|
| 30 |
+
class Result:
|
| 31 |
+
workload: str
|
| 32 |
+
shape: str
|
| 33 |
+
dtype: str
|
| 34 |
+
native_us: float
|
| 35 |
+
wrapper_us: float
|
| 36 |
+
native_parity: float
|
| 37 |
+
graph_native_us: float
|
| 38 |
+
graph_wrapper_us: float
|
| 39 |
+
graph_native_parity: float
|
| 40 |
+
eager_us: float
|
| 41 |
+
compile_us: float
|
| 42 |
+
strong_library_us: str
|
| 43 |
+
max_abs: float
|
| 44 |
+
mean_abs: float
|
| 45 |
+
p99_abs: float
|
| 46 |
+
cosine: float
|
| 47 |
+
accepted: bool
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def time_us(fn, warmup: int, iters: int) -> float:
|
| 51 |
+
for _ in range(warmup):
|
| 52 |
+
fn()
|
| 53 |
+
torch.cuda.synchronize()
|
| 54 |
+
begin = torch.cuda.Event(enable_timing=True)
|
| 55 |
+
end = torch.cuda.Event(enable_timing=True)
|
| 56 |
+
begin.record()
|
| 57 |
+
for _ in range(iters):
|
| 58 |
+
fn()
|
| 59 |
+
end.record()
|
| 60 |
+
torch.cuda.synchronize()
|
| 61 |
+
return begin.elapsed_time(end) * 1000.0 / iters
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def graph_time_us(fn, warmup: int, iters: int) -> float:
|
| 65 |
+
side = torch.cuda.Stream()
|
| 66 |
+
side.wait_stream(torch.cuda.current_stream())
|
| 67 |
+
with torch.cuda.stream(side):
|
| 68 |
+
fn()
|
| 69 |
+
torch.cuda.current_stream().wait_stream(side)
|
| 70 |
+
torch.cuda.synchronize()
|
| 71 |
+
graph = torch.cuda.CUDAGraph()
|
| 72 |
+
with torch.cuda.graph(graph):
|
| 73 |
+
fn()
|
| 74 |
+
return time_us(graph.replay, warmup, iters)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def build_source():
|
| 78 |
+
from torch.utils.cpp_extension import load
|
| 79 |
+
|
| 80 |
+
major, minor = torch.cuda.get_device_capability()
|
| 81 |
+
os.environ.setdefault("TORCH_CUDA_ARCH_LIST", f"{major}.{minor}")
|
| 82 |
+
namespace = "flashrt_spatiotemporal_layout_native_parity"
|
| 83 |
+
load(
|
| 84 |
+
name=namespace,
|
| 85 |
+
sources=[
|
| 86 |
+
str(PACKAGE / "torch-ext/torch_binding.cpp"),
|
| 87 |
+
str(PACKAGE / "csrc/spatiotemporal_layout.cu"),
|
| 88 |
+
str(PACKAGE / "csrc/bf16_ndhwc_to_ncdhw_transpose.cu"),
|
| 89 |
+
str(PACKAGE / "csrc/bf16_quant_fp8_ncdhw_to_ndhwc.cu"),
|
| 90 |
+
],
|
| 91 |
+
extra_include_paths=[str(PACKAGE / "csrc"), str(REGISTRATION)],
|
| 92 |
+
extra_cflags=["-O3", "-DCUDA_KERNEL"],
|
| 93 |
+
extra_cuda_cflags=["-O3", "-DCUDA_KERNEL"],
|
| 94 |
+
is_python_module=False,
|
| 95 |
+
verbose=False,
|
| 96 |
+
)
|
| 97 |
+
return getattr(torch.ops, namespace)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def load_wrapper(backend: str, artifact: str | None):
|
| 101 |
+
if backend == "source":
|
| 102 |
+
return build_source()
|
| 103 |
+
if artifact:
|
| 104 |
+
sys.path.insert(0, artifact)
|
| 105 |
+
try:
|
| 106 |
+
return importlib.import_module("flashrt_spatiotemporal_layout")
|
| 107 |
+
finally:
|
| 108 |
+
if artifact:
|
| 109 |
+
sys.path.remove(artifact)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def build_native():
|
| 113 |
+
from torch.utils.cpp_extension import load
|
| 114 |
+
|
| 115 |
+
return load(
|
| 116 |
+
name="flashrt_spatiotemporal_layout_raw_native",
|
| 117 |
+
sources=[
|
| 118 |
+
str(PACKAGE / "benchmarks/native_binding.cpp"),
|
| 119 |
+
str(PACKAGE / "csrc/spatiotemporal_layout.cu"),
|
| 120 |
+
str(PACKAGE / "csrc/bf16_ndhwc_to_ncdhw_transpose.cu"),
|
| 121 |
+
str(PACKAGE / "csrc/bf16_quant_fp8_ncdhw_to_ndhwc.cu"),
|
| 122 |
+
],
|
| 123 |
+
extra_include_paths=[str(PACKAGE / "csrc")],
|
| 124 |
+
extra_cflags=["-O3"],
|
| 125 |
+
extra_cuda_cflags=["-O3"],
|
| 126 |
+
verbose=False,
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def metrics(got: torch.Tensor, ref: torch.Tensor):
|
| 131 |
+
if got.dtype == torch.float8_e4m3fn:
|
| 132 |
+
exact = torch.equal(got.view(torch.uint8), ref.view(torch.uint8))
|
| 133 |
+
return (0.0, 0.0, 0.0, 1.0) if exact else (float("inf"),) * 4
|
| 134 |
+
diff = (got.float() - ref.float()).abs().flatten()
|
| 135 |
+
cosine = torch.nn.functional.cosine_similarity(
|
| 136 |
+
got.float().flatten(), ref.float().flatten(), dim=0
|
| 137 |
+
).item()
|
| 138 |
+
return (
|
| 139 |
+
diff.max().item(),
|
| 140 |
+
diff.mean().item(),
|
| 141 |
+
torch.quantile(diff, 0.99).item(),
|
| 142 |
+
cosine,
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def add_result(
|
| 147 |
+
rows,
|
| 148 |
+
workload,
|
| 149 |
+
shape,
|
| 150 |
+
wrapper_fn,
|
| 151 |
+
native_fn,
|
| 152 |
+
eager_fn,
|
| 153 |
+
compiled_fn,
|
| 154 |
+
got,
|
| 155 |
+
ref,
|
| 156 |
+
args,
|
| 157 |
+
):
|
| 158 |
+
native_us = time_us(native_fn, args.warmup, args.iters)
|
| 159 |
+
wrapper_us = time_us(wrapper_fn, args.warmup, args.iters)
|
| 160 |
+
graph_native_us = graph_time_us(native_fn, args.warmup, args.iters)
|
| 161 |
+
graph_wrapper_us = graph_time_us(wrapper_fn, args.warmup, args.iters)
|
| 162 |
+
eager_us = time_us(eager_fn, args.warmup, args.iters)
|
| 163 |
+
compile_us = time_us(compiled_fn, args.warmup, args.iters)
|
| 164 |
+
max_abs, mean_abs, p99_abs, cosine = metrics(got, ref)
|
| 165 |
+
parity = wrapper_us / native_us
|
| 166 |
+
rows.append(
|
| 167 |
+
Result(
|
| 168 |
+
workload,
|
| 169 |
+
str(shape),
|
| 170 |
+
str(got.dtype),
|
| 171 |
+
native_us,
|
| 172 |
+
wrapper_us,
|
| 173 |
+
parity,
|
| 174 |
+
graph_native_us,
|
| 175 |
+
graph_wrapper_us,
|
| 176 |
+
graph_wrapper_us / graph_native_us,
|
| 177 |
+
eager_us,
|
| 178 |
+
compile_us,
|
| 179 |
+
"N/A (no equivalent single library op)",
|
| 180 |
+
max_abs,
|
| 181 |
+
mean_abs,
|
| 182 |
+
p99_abs,
|
| 183 |
+
cosine,
|
| 184 |
+
(
|
| 185 |
+
wrapper_us - native_us <= max(0.75, native_us * 0.05)
|
| 186 |
+
or graph_wrapper_us - graph_native_us
|
| 187 |
+
<= max(0.5, graph_native_us * 0.05)
|
| 188 |
+
)
|
| 189 |
+
and min(wrapper_us, graph_wrapper_us)
|
| 190 |
+
<= min(eager_us, compile_us) * 0.98
|
| 191 |
+
and max_abs == 0.0,
|
| 192 |
+
)
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def run_shape(wrapper, native, name, shape, args):
|
| 197 |
+
b, c, t, h, w = shape
|
| 198 |
+
x = torch.randn(shape, device="cuda", dtype=torch.bfloat16)
|
| 199 |
+
ndhwc = x.permute(0, 2, 3, 4, 1).contiguous()
|
| 200 |
+
bias = torch.randn(c, device="cuda", dtype=torch.bfloat16)
|
| 201 |
+
residual = torch.randn_like(x)
|
| 202 |
+
scale = 0.03125
|
| 203 |
+
rows = []
|
| 204 |
+
|
| 205 |
+
def wrapper_layout():
|
| 206 |
+
wrapper.ndhwc_to_ncdhw_bf16(ndhwc, out_layout)
|
| 207 |
+
|
| 208 |
+
def eager_layout():
|
| 209 |
+
out_layout.copy_(ndhwc.permute(0, 4, 1, 2, 3))
|
| 210 |
+
|
| 211 |
+
compiled_layout = torch.compile(eager_layout, fullgraph=True)
|
| 212 |
+
out_layout = torch.empty_like(x)
|
| 213 |
+
native_layout = lambda: native.ndhwc_to_ncdhw(ndhwc, out_layout)
|
| 214 |
+
wrapper_layout()
|
| 215 |
+
ref = ndhwc.permute(0, 4, 1, 2, 3).contiguous()
|
| 216 |
+
add_result(
|
| 217 |
+
rows, f"{name}/ndhwc_to_ncdhw", shape, wrapper_layout, native_layout,
|
| 218 |
+
eager_layout, compiled_layout, out_layout, ref, args
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
out_bias = torch.empty_like(x)
|
| 222 |
+
wrapper_bias = lambda: wrapper.ndhwc_to_ncdhw_bias_bf16(
|
| 223 |
+
ndhwc, bias, out_bias
|
| 224 |
+
)
|
| 225 |
+
native_bias = lambda: native.ndhwc_to_ncdhw_bias(ndhwc, bias, out_bias)
|
| 226 |
+
|
| 227 |
+
def eager_bias():
|
| 228 |
+
out_bias.copy_(
|
| 229 |
+
(ndhwc.permute(0, 4, 1, 2, 3).float()
|
| 230 |
+
+ bias.float().view(1, c, 1, 1, 1)).to(torch.bfloat16)
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
compiled_bias = torch.compile(eager_bias, fullgraph=True)
|
| 234 |
+
wrapper_bias()
|
| 235 |
+
ref_bias = (
|
| 236 |
+
x.float() + bias.float().view(1, c, 1, 1, 1)
|
| 237 |
+
).to(torch.bfloat16)
|
| 238 |
+
add_result(
|
| 239 |
+
rows, f"{name}/ndhwc_to_ncdhw_bias", shape, wrapper_bias, native_bias,
|
| 240 |
+
eager_bias, compiled_bias, out_bias, ref_bias, args
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
out_add = torch.empty_like(x)
|
| 244 |
+
wrapper_add = lambda: wrapper.ndhwc_to_ncdhw_add_bf16(
|
| 245 |
+
ndhwc, residual, out_add
|
| 246 |
+
)
|
| 247 |
+
native_add = lambda: native.ndhwc_to_ncdhw_add(
|
| 248 |
+
ndhwc, residual, out_add
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
def eager_add():
|
| 252 |
+
out_add.copy_(
|
| 253 |
+
(ndhwc.permute(0, 4, 1, 2, 3).float()
|
| 254 |
+
+ residual.float()).to(torch.bfloat16)
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
compiled_add = torch.compile(eager_add, fullgraph=True)
|
| 258 |
+
wrapper_add()
|
| 259 |
+
ref_add = (x.float() + residual.float()).to(torch.bfloat16)
|
| 260 |
+
add_result(
|
| 261 |
+
rows, f"{name}/ndhwc_to_ncdhw_add", shape, wrapper_add, native_add,
|
| 262 |
+
eager_add, compiled_add, out_add, ref_add, args
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
out_fp8 = torch.empty(
|
| 266 |
+
(b, t, h, w, c), device="cuda", dtype=torch.float8_e4m3fn
|
| 267 |
+
)
|
| 268 |
+
wrapper_quant = lambda: wrapper.ncdhw_quantize_fp8_static_ndhwc_bf16(
|
| 269 |
+
x, scale, out_fp8
|
| 270 |
+
)
|
| 271 |
+
native_quant = lambda: native.ncdhw_quantize(x, scale, out_fp8)
|
| 272 |
+
|
| 273 |
+
def eager_quant():
|
| 274 |
+
out_fp8.copy_(
|
| 275 |
+
(x.float() / scale).clamp(-448.0, 448.0)
|
| 276 |
+
.to(torch.float8_e4m3fn).permute(0, 2, 3, 4, 1)
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
compiled_quant = torch.compile(eager_quant, fullgraph=True)
|
| 280 |
+
wrapper_quant()
|
| 281 |
+
ref_fp8 = (
|
| 282 |
+
(x.float() / scale).clamp(-448.0, 448.0)
|
| 283 |
+
.to(torch.float8_e4m3fn).permute(0, 2, 3, 4, 1).contiguous()
|
| 284 |
+
)
|
| 285 |
+
add_result(
|
| 286 |
+
rows, f"{name}/ncdhw_quantize_fp8_ndhwc", shape, wrapper_quant,
|
| 287 |
+
native_quant, eager_quant, compiled_quant, out_fp8, ref_fp8, args
|
| 288 |
+
)
|
| 289 |
+
return rows
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def run_cache_and_upsample(wrapper, native, args):
|
| 293 |
+
rows = []
|
| 294 |
+
previous = torch.randn(
|
| 295 |
+
(1, 64, 2, 32, 32), device="cuda", dtype=torch.bfloat16
|
| 296 |
+
)
|
| 297 |
+
current = torch.randn(
|
| 298 |
+
(1, 64, 1, 32, 32), device="cuda", dtype=torch.bfloat16
|
| 299 |
+
)
|
| 300 |
+
packed = torch.empty(
|
| 301 |
+
(1, 32, 32, 192), device="cuda", dtype=torch.bfloat16
|
| 302 |
+
)
|
| 303 |
+
wrapper_pack = lambda: wrapper.pack_causal_cache3_nhwc_bf16(
|
| 304 |
+
previous, current, packed
|
| 305 |
+
)
|
| 306 |
+
native_pack = lambda: native.pack_causal_cache3_nhwc(
|
| 307 |
+
previous, current, packed
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
def eager_pack():
|
| 311 |
+
packed.copy_(
|
| 312 |
+
torch.cat(
|
| 313 |
+
(previous[:, :, 0], previous[:, :, 1], current[:, :, 0]),
|
| 314 |
+
dim=1,
|
| 315 |
+
).permute(0, 2, 3, 1)
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
compiled_pack = torch.compile(eager_pack, fullgraph=True)
|
| 319 |
+
wrapper_pack()
|
| 320 |
+
got_pack = packed.clone()
|
| 321 |
+
ref_pack = torch.cat(
|
| 322 |
+
(previous[:, :, 0], previous[:, :, 1], current[:, :, 0]), dim=1
|
| 323 |
+
).permute(0, 2, 3, 1).contiguous()
|
| 324 |
+
add_result(
|
| 325 |
+
rows,
|
| 326 |
+
"vae-t1/pack_causal_cache3_nhwc",
|
| 327 |
+
tuple(current.shape),
|
| 328 |
+
wrapper_pack,
|
| 329 |
+
native_pack,
|
| 330 |
+
eager_pack,
|
| 331 |
+
compiled_pack,
|
| 332 |
+
got_pack,
|
| 333 |
+
ref_pack,
|
| 334 |
+
args,
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
+
for temporal_factor, first_chunk in ((1, False), (2, True)):
|
| 338 |
+
spatial_factor = 2
|
| 339 |
+
out_channels = 16 if temporal_factor == 1 else 8
|
| 340 |
+
input = current if temporal_factor == 1 else torch.randn(
|
| 341 |
+
(1, 64, 4, 16, 16), device="cuda", dtype=torch.bfloat16
|
| 342 |
+
)
|
| 343 |
+
out_t = input.shape[2] * temporal_factor - (
|
| 344 |
+
temporal_factor - 1 if first_chunk else 0
|
| 345 |
+
)
|
| 346 |
+
out = torch.empty(
|
| 347 |
+
(
|
| 348 |
+
input.shape[0], out_channels, out_t,
|
| 349 |
+
input.shape[3] * spatial_factor,
|
| 350 |
+
input.shape[4] * spatial_factor,
|
| 351 |
+
),
|
| 352 |
+
device="cuda",
|
| 353 |
+
dtype=torch.bfloat16,
|
| 354 |
+
)
|
| 355 |
+
wrapper_up = lambda: wrapper.channel_to_space3d_bf16(
|
| 356 |
+
input, out_channels, temporal_factor, spatial_factor, 1,
|
| 357 |
+
first_chunk, out
|
| 358 |
+
)
|
| 359 |
+
native_up = lambda: native.channel_to_space3d(
|
| 360 |
+
input, out_channels, temporal_factor, spatial_factor, 1,
|
| 361 |
+
first_chunk, out
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
def eager_up():
|
| 365 |
+
expanded = input[:, : out_channels * temporal_factor * 4]
|
| 366 |
+
expanded = expanded.view(
|
| 367 |
+
input.shape[0], out_channels, temporal_factor, 2, 2,
|
| 368 |
+
input.shape[2], input.shape[3], input.shape[4],
|
| 369 |
+
).permute(0, 1, 5, 2, 6, 3, 7, 4)
|
| 370 |
+
value = expanded.reshape(
|
| 371 |
+
input.shape[0], out_channels,
|
| 372 |
+
input.shape[2] * temporal_factor,
|
| 373 |
+
input.shape[3] * 2, input.shape[4] * 2,
|
| 374 |
+
)
|
| 375 |
+
if first_chunk:
|
| 376 |
+
value = value[:, :, temporal_factor - 1 :]
|
| 377 |
+
out.copy_(value)
|
| 378 |
+
|
| 379 |
+
compiled_up = torch.compile(eager_up, fullgraph=True)
|
| 380 |
+
wrapper_up()
|
| 381 |
+
got = out.clone()
|
| 382 |
+
eager_up()
|
| 383 |
+
ref = out.clone()
|
| 384 |
+
out.copy_(got)
|
| 385 |
+
add_result(
|
| 386 |
+
rows,
|
| 387 |
+
f"vae/channel_to_space3d-ft{temporal_factor}"
|
| 388 |
+
f"-first{int(first_chunk)}",
|
| 389 |
+
tuple(input.shape),
|
| 390 |
+
wrapper_up,
|
| 391 |
+
native_up,
|
| 392 |
+
eager_up,
|
| 393 |
+
compiled_up,
|
| 394 |
+
got,
|
| 395 |
+
ref,
|
| 396 |
+
args,
|
| 397 |
+
)
|
| 398 |
+
return rows
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
def main():
|
| 402 |
+
parser = argparse.ArgumentParser()
|
| 403 |
+
parser.add_argument("--backend", choices=["source", "installed"], default="source")
|
| 404 |
+
parser.add_argument("--artifact")
|
| 405 |
+
parser.add_argument("--warmup", type=int, default=20)
|
| 406 |
+
parser.add_argument("--iters", type=int, default=100)
|
| 407 |
+
parser.add_argument("--output")
|
| 408 |
+
args = parser.parse_args()
|
| 409 |
+
wrapper = load_wrapper(args.backend, args.artifact)
|
| 410 |
+
native = build_native()
|
| 411 |
+
rows = []
|
| 412 |
+
for name, shape in SHAPES.items():
|
| 413 |
+
rows.extend(run_shape(wrapper, native, name, shape, args))
|
| 414 |
+
rows.extend(run_cache_and_upsample(wrapper, native, args))
|
| 415 |
+
for row in rows:
|
| 416 |
+
print(
|
| 417 |
+
f"{row.workload}: native={row.native_us:.3f}us "
|
| 418 |
+
f"wrapper={row.wrapper_us:.3f}us parity={row.native_parity:.3f} "
|
| 419 |
+
f"graph={row.graph_wrapper_us:.3f}/"
|
| 420 |
+
f"{row.graph_native_us:.3f}us "
|
| 421 |
+
f"eager={row.eager_us:.3f}us compile={row.compile_us:.3f}us "
|
| 422 |
+
f"accepted={row.accepted}"
|
| 423 |
+
)
|
| 424 |
+
if args.output:
|
| 425 |
+
path = Path(args.output)
|
| 426 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 427 |
+
path.write_text(json.dumps([asdict(row) for row in rows], indent=2) + "\n")
|
| 428 |
+
if not all(row.accepted for row in rows):
|
| 429 |
+
raise SystemExit("performance/correctness acceptance failed")
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
if __name__ == "__main__":
|
| 433 |
+
main()
|
build/torch211-cxx11-cu128-x86_64-linux/__init__.py
CHANGED
|
@@ -58,6 +58,137 @@ def _update_cache2_ncdhw_bf16_fake(cur: torch.Tensor, prev: torch.Tensor, out: t
|
|
| 58 |
return None
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def ncdhw_to_blc_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 62 |
"""Convert BF16 NCDHW tensor to BLC where L = T * H * W."""
|
| 63 |
|
|
@@ -101,10 +232,183 @@ def update_cache2_ncdhw_bf16(cur: torch.Tensor, prev: torch.Tensor, out: torch.T
|
|
| 101 |
return out
|
| 102 |
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
__all__ = [
|
| 105 |
"ncdhw_to_blc_bf16",
|
| 106 |
"patch_im2col_bf16",
|
| 107 |
"time_unshuffle2_bf16",
|
| 108 |
"add_bias_ncdhw_bf16",
|
| 109 |
"update_cache2_ncdhw_bf16",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
]
|
|
|
|
| 58 |
return None
|
| 59 |
|
| 60 |
|
| 61 |
+
@torch.library.register_fake(add_op_namespace_prefix("channel_to_space3d_bf16"))
|
| 62 |
+
def _channel_to_space3d_bf16_fake(
|
| 63 |
+
x: torch.Tensor,
|
| 64 |
+
out_channels: int,
|
| 65 |
+
temporal_factor: int,
|
| 66 |
+
spatial_factor: int,
|
| 67 |
+
repeats: int,
|
| 68 |
+
first_chunk: bool,
|
| 69 |
+
out: torch.Tensor,
|
| 70 |
+
) -> None:
|
| 71 |
+
_check_ncdhw(x, "x")
|
| 72 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 73 |
+
temporal_factor - 1 if first_chunk else 0
|
| 74 |
+
)
|
| 75 |
+
expected = (
|
| 76 |
+
x.shape[0],
|
| 77 |
+
out_channels,
|
| 78 |
+
out_t,
|
| 79 |
+
x.shape[3] * spatial_factor,
|
| 80 |
+
x.shape[4] * spatial_factor,
|
| 81 |
+
)
|
| 82 |
+
if (
|
| 83 |
+
out_channels <= 0
|
| 84 |
+
or temporal_factor <= 0
|
| 85 |
+
or spatial_factor <= 0
|
| 86 |
+
or repeats <= 0
|
| 87 |
+
or x.shape[1] * repeats
|
| 88 |
+
< out_channels * temporal_factor * spatial_factor * spatial_factor
|
| 89 |
+
or out.shape != expected
|
| 90 |
+
):
|
| 91 |
+
raise RuntimeError("channel_to_space3d_bf16 shape contract failed")
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
@torch.library.register_fake(
|
| 96 |
+
add_op_namespace_prefix("pack_causal_cache3_nhwc_bf16")
|
| 97 |
+
)
|
| 98 |
+
def _pack_causal_cache3_nhwc_bf16_fake(
|
| 99 |
+
previous: torch.Tensor, current: torch.Tensor, out: torch.Tensor
|
| 100 |
+
) -> None:
|
| 101 |
+
_check_ncdhw(previous, "previous")
|
| 102 |
+
_check_ncdhw(current, "current")
|
| 103 |
+
b, c, t, h, w = current.shape
|
| 104 |
+
if (
|
| 105 |
+
t != 1
|
| 106 |
+
or previous.shape != (b, c, 2, h, w)
|
| 107 |
+
or out.shape != (b, h, w, 3 * c)
|
| 108 |
+
):
|
| 109 |
+
raise RuntimeError("causal cache pack shape contract failed")
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@torch.library.register_fake(add_op_namespace_prefix("avg_pool3d_channels_bf16"))
|
| 114 |
+
def _avg_pool3d_channels_bf16_fake(
|
| 115 |
+
x: torch.Tensor,
|
| 116 |
+
out_channels: int,
|
| 117 |
+
factor_t: int,
|
| 118 |
+
factor_s: int,
|
| 119 |
+
group_size: int,
|
| 120 |
+
out: torch.Tensor,
|
| 121 |
+
) -> None:
|
| 122 |
+
_check_ncdhw(x, "x")
|
| 123 |
+
expected = (
|
| 124 |
+
x.shape[0],
|
| 125 |
+
out_channels,
|
| 126 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 127 |
+
x.shape[3] // factor_s,
|
| 128 |
+
x.shape[4] // factor_s,
|
| 129 |
+
)
|
| 130 |
+
if out.shape != expected:
|
| 131 |
+
raise RuntimeError("out has the wrong pooled NCDHW shape")
|
| 132 |
+
return None
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bf16"))
|
| 136 |
+
def _ndhwc_to_ncdhw_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 137 |
+
if x.dim() != 5:
|
| 138 |
+
raise RuntimeError("x must have shape (B, T, H, W, C)")
|
| 139 |
+
expected = (x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3])
|
| 140 |
+
if out.shape != expected:
|
| 141 |
+
raise RuntimeError("out must have shape (B, C, T, H, W)")
|
| 142 |
+
return None
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bias_bf16"))
|
| 146 |
+
def _ndhwc_to_ncdhw_bias_bf16_fake(
|
| 147 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor
|
| 148 |
+
) -> None:
|
| 149 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 150 |
+
if bias.shape != (x.shape[4],):
|
| 151 |
+
raise RuntimeError("bias must have shape (C,)")
|
| 152 |
+
return None
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_add_bf16"))
|
| 156 |
+
def _ndhwc_to_ncdhw_add_bf16_fake(
|
| 157 |
+
x: torch.Tensor, residual: torch.Tensor, out: torch.Tensor
|
| 158 |
+
) -> None:
|
| 159 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 160 |
+
if residual.shape != out.shape:
|
| 161 |
+
raise RuntimeError("residual must match the NCDHW output shape")
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
@torch.library.register_fake(
|
| 166 |
+
add_op_namespace_prefix("ncdhw_quantize_fp8_static_ndhwc_bf16")
|
| 167 |
+
)
|
| 168 |
+
def _ncdhw_quantize_fp8_static_ndhwc_bf16_fake(
|
| 169 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 170 |
+
) -> None:
|
| 171 |
+
_check_ncdhw(x, "x")
|
| 172 |
+
expected = (x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1])
|
| 173 |
+
if out.shape != expected:
|
| 174 |
+
raise RuntimeError("out must have shape (B, T, H, W, C)")
|
| 175 |
+
return None
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
@torch.library.register_fake(
|
| 179 |
+
add_op_namespace_prefix("upsample2x_quantize_fp8_static_nhwc_bf16")
|
| 180 |
+
)
|
| 181 |
+
def _upsample2x_quantize_fp8_static_nhwc_bf16_fake(
|
| 182 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 183 |
+
) -> None:
|
| 184 |
+
if x.dim() != 4:
|
| 185 |
+
raise RuntimeError("x must have shape (N, C, H, W)")
|
| 186 |
+
expected = (x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1])
|
| 187 |
+
if out.shape != expected:
|
| 188 |
+
raise RuntimeError("out must have shape (N, 2H, 2W, C)")
|
| 189 |
+
return None
|
| 190 |
+
|
| 191 |
+
|
| 192 |
def ncdhw_to_blc_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 193 |
"""Convert BF16 NCDHW tensor to BLC where L = T * H * W."""
|
| 194 |
|
|
|
|
| 232 |
return out
|
| 233 |
|
| 234 |
|
| 235 |
+
def channel_to_space3d_bf16(
|
| 236 |
+
x: torch.Tensor,
|
| 237 |
+
out_channels: int,
|
| 238 |
+
temporal_factor: int,
|
| 239 |
+
spatial_factor: int,
|
| 240 |
+
repeats: int = 1,
|
| 241 |
+
first_chunk: bool = False,
|
| 242 |
+
out: torch.Tensor | None = None,
|
| 243 |
+
) -> torch.Tensor:
|
| 244 |
+
"""Move expanded channels into temporal/spatial dimensions."""
|
| 245 |
+
|
| 246 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 247 |
+
temporal_factor - 1 if first_chunk else 0
|
| 248 |
+
)
|
| 249 |
+
if out is None:
|
| 250 |
+
out = torch.empty(
|
| 251 |
+
(
|
| 252 |
+
x.shape[0],
|
| 253 |
+
out_channels,
|
| 254 |
+
out_t,
|
| 255 |
+
x.shape[3] * spatial_factor,
|
| 256 |
+
x.shape[4] * spatial_factor,
|
| 257 |
+
),
|
| 258 |
+
device=x.device,
|
| 259 |
+
dtype=x.dtype,
|
| 260 |
+
)
|
| 261 |
+
ops.channel_to_space3d_bf16(
|
| 262 |
+
x,
|
| 263 |
+
int(out_channels),
|
| 264 |
+
int(temporal_factor),
|
| 265 |
+
int(spatial_factor),
|
| 266 |
+
int(repeats),
|
| 267 |
+
bool(first_chunk),
|
| 268 |
+
out,
|
| 269 |
+
)
|
| 270 |
+
return out
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def pack_causal_cache3_nhwc_bf16(
|
| 274 |
+
previous: torch.Tensor,
|
| 275 |
+
current: torch.Tensor,
|
| 276 |
+
out: torch.Tensor | None = None,
|
| 277 |
+
) -> torch.Tensor:
|
| 278 |
+
"""Pack two cached and one current NCDHW frame into NHWC with 3C."""
|
| 279 |
+
|
| 280 |
+
if out is None:
|
| 281 |
+
out = torch.empty(
|
| 282 |
+
(
|
| 283 |
+
current.shape[0],
|
| 284 |
+
current.shape[3],
|
| 285 |
+
current.shape[4],
|
| 286 |
+
3 * current.shape[1],
|
| 287 |
+
),
|
| 288 |
+
device=current.device,
|
| 289 |
+
dtype=current.dtype,
|
| 290 |
+
)
|
| 291 |
+
ops.pack_causal_cache3_nhwc_bf16(previous, current, out)
|
| 292 |
+
return out
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def avg_pool3d_channels_bf16(
|
| 296 |
+
x: torch.Tensor,
|
| 297 |
+
out_channels: int,
|
| 298 |
+
factor_t: int,
|
| 299 |
+
factor_s: int,
|
| 300 |
+
group_size: int,
|
| 301 |
+
out: torch.Tensor | None = None,
|
| 302 |
+
) -> torch.Tensor:
|
| 303 |
+
"""Pool NCDHW blocks while folding spatiotemporal factors into channels."""
|
| 304 |
+
|
| 305 |
+
if out is None:
|
| 306 |
+
out = torch.empty(
|
| 307 |
+
(
|
| 308 |
+
x.shape[0],
|
| 309 |
+
out_channels,
|
| 310 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 311 |
+
x.shape[3] // factor_s,
|
| 312 |
+
x.shape[4] // factor_s,
|
| 313 |
+
),
|
| 314 |
+
device=x.device,
|
| 315 |
+
dtype=x.dtype,
|
| 316 |
+
)
|
| 317 |
+
ops.avg_pool3d_channels_bf16(
|
| 318 |
+
x, out_channels, factor_t, factor_s, group_size, out
|
| 319 |
+
)
|
| 320 |
+
return out
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def ndhwc_to_ncdhw_bf16(
|
| 324 |
+
x: torch.Tensor, out: torch.Tensor | None = None
|
| 325 |
+
) -> torch.Tensor:
|
| 326 |
+
"""Convert contiguous BF16 NDHWC to contiguous BF16 NCDHW."""
|
| 327 |
+
|
| 328 |
+
if out is None:
|
| 329 |
+
out = torch.empty(
|
| 330 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 331 |
+
device=x.device,
|
| 332 |
+
dtype=x.dtype,
|
| 333 |
+
)
|
| 334 |
+
ops.ndhwc_to_ncdhw_bf16(x, out)
|
| 335 |
+
return out
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def ndhwc_to_ncdhw_bias_bf16(
|
| 339 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor | None = None
|
| 340 |
+
) -> torch.Tensor:
|
| 341 |
+
"""Convert NDHWC to NCDHW and add a BF16 channel bias."""
|
| 342 |
+
|
| 343 |
+
if out is None:
|
| 344 |
+
out = torch.empty(
|
| 345 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 346 |
+
device=x.device,
|
| 347 |
+
dtype=x.dtype,
|
| 348 |
+
)
|
| 349 |
+
ops.ndhwc_to_ncdhw_bias_bf16(x, bias, out)
|
| 350 |
+
return out
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def ndhwc_to_ncdhw_add_bf16(
|
| 354 |
+
x: torch.Tensor,
|
| 355 |
+
residual: torch.Tensor,
|
| 356 |
+
out: torch.Tensor | None = None,
|
| 357 |
+
) -> torch.Tensor:
|
| 358 |
+
"""Convert NDHWC to NCDHW and add a BF16 NCDHW residual."""
|
| 359 |
+
|
| 360 |
+
if out is None:
|
| 361 |
+
out = torch.empty_like(residual)
|
| 362 |
+
ops.ndhwc_to_ncdhw_add_bf16(x, residual, out)
|
| 363 |
+
return out
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def ncdhw_quantize_fp8_static_ndhwc_bf16(
|
| 367 |
+
x: torch.Tensor,
|
| 368 |
+
scale: float,
|
| 369 |
+
out: torch.Tensor | None = None,
|
| 370 |
+
) -> torch.Tensor:
|
| 371 |
+
"""Quantize BF16 NCDHW to FP8 E4M3 NDHWC using a static scale."""
|
| 372 |
+
|
| 373 |
+
if out is None:
|
| 374 |
+
out = torch.empty(
|
| 375 |
+
(x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1]),
|
| 376 |
+
device=x.device,
|
| 377 |
+
dtype=torch.float8_e4m3fn,
|
| 378 |
+
)
|
| 379 |
+
ops.ncdhw_quantize_fp8_static_ndhwc_bf16(x, scale, out)
|
| 380 |
+
return out
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
def upsample2x_quantize_fp8_static_nhwc_bf16(
|
| 384 |
+
x: torch.Tensor,
|
| 385 |
+
scale: float,
|
| 386 |
+
out: torch.Tensor | None = None,
|
| 387 |
+
) -> torch.Tensor:
|
| 388 |
+
"""Nearest-neighbor 2x upsample NCHW and emit static-scaled FP8 NHWC."""
|
| 389 |
+
|
| 390 |
+
if out is None:
|
| 391 |
+
out = torch.empty(
|
| 392 |
+
(x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1]),
|
| 393 |
+
device=x.device,
|
| 394 |
+
dtype=torch.float8_e4m3fn,
|
| 395 |
+
)
|
| 396 |
+
ops.upsample2x_quantize_fp8_static_nhwc_bf16(x, scale, out)
|
| 397 |
+
return out
|
| 398 |
+
|
| 399 |
+
|
| 400 |
__all__ = [
|
| 401 |
"ncdhw_to_blc_bf16",
|
| 402 |
"patch_im2col_bf16",
|
| 403 |
"time_unshuffle2_bf16",
|
| 404 |
"add_bias_ncdhw_bf16",
|
| 405 |
"update_cache2_ncdhw_bf16",
|
| 406 |
+
"channel_to_space3d_bf16",
|
| 407 |
+
"pack_causal_cache3_nhwc_bf16",
|
| 408 |
+
"avg_pool3d_channels_bf16",
|
| 409 |
+
"ndhwc_to_ncdhw_bf16",
|
| 410 |
+
"ndhwc_to_ncdhw_bias_bf16",
|
| 411 |
+
"ndhwc_to_ncdhw_add_bf16",
|
| 412 |
+
"ncdhw_quantize_fp8_static_ndhwc_bf16",
|
| 413 |
+
"upsample2x_quantize_fp8_static_nhwc_bf16",
|
| 414 |
]
|
build/{torch211-cxx11-cu130-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_5de4768.abi3.so → torch211-cxx11-cu128-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:54170a1e1ac254a6ba0e14432e3fe9b5ec1f09f3ff218a9e4fbf0463134653ab
|
| 3 |
+
size 1887872
|
build/torch211-cxx11-cu128-x86_64-linux/_ops.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import torch
|
| 2 |
-
from . import
|
| 3 |
-
ops = torch.ops.
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
-
return f"
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from . import _flashrt_spatiotemporal_layout_cuda_7781728
|
| 3 |
+
ops = torch.ops._flashrt_spatiotemporal_layout_cuda_7781728
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
+
return f"_flashrt_spatiotemporal_layout_cuda_7781728::{op_name}"
|
build/torch211-cxx11-cu128-x86_64-linux/metadata.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "flashrt-spatiotemporal-layout",
|
| 3 |
-
"id": "
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
|
|
| 1 |
{
|
| 2 |
"name": "flashrt-spatiotemporal-layout",
|
| 3 |
+
"id": "_flashrt_spatiotemporal_layout_cuda_7781728",
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
build/torch211-cxx11-cu130-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT spatiotemporal layout kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _check_ncdhw(x: torch.Tensor, name: str) -> None:
|
| 11 |
+
if x.dim() != 5:
|
| 12 |
+
raise RuntimeError(f"{name} must have shape (B, C, T, H, W)")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@torch.library.register_fake(add_op_namespace_prefix("ncdhw_to_blc_bf16"))
|
| 16 |
+
def _ncdhw_to_blc_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 17 |
+
_check_ncdhw(x, "x")
|
| 18 |
+
b, c, t, h, w = x.shape
|
| 19 |
+
if out.shape != (b, t * h * w, c):
|
| 20 |
+
raise RuntimeError("out must have shape (B, T * H * W, C)")
|
| 21 |
+
return None
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@torch.library.register_fake(add_op_namespace_prefix("patch_im2col_bf16"))
|
| 25 |
+
def _patch_im2col_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 26 |
+
if x.dim() != 4 or x.shape[1:] != (224, 224, 3):
|
| 27 |
+
raise RuntimeError("x must have shape (num_views, 224, 224, 3)")
|
| 28 |
+
if out.shape != (x.shape[0] * 256, 588):
|
| 29 |
+
raise RuntimeError("out must have shape (num_views * 256, 588)")
|
| 30 |
+
return None
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@torch.library.register_fake(add_op_namespace_prefix("time_unshuffle2_bf16"))
|
| 34 |
+
def _time_unshuffle2_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 35 |
+
_check_ncdhw(x, "x")
|
| 36 |
+
b, c2, t, h, w = x.shape
|
| 37 |
+
if c2 % 2 != 0:
|
| 38 |
+
raise RuntimeError("x.shape[1] must be even")
|
| 39 |
+
if out.shape != (b, c2 // 2, 2 * t, h, w):
|
| 40 |
+
raise RuntimeError("out must have shape (B, C / 2, 2 * T, H, W)")
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@torch.library.register_fake(add_op_namespace_prefix("add_bias_ncdhw_bf16"))
|
| 45 |
+
def _add_bias_ncdhw_bf16_fake(x: torch.Tensor, bias: torch.Tensor) -> None:
|
| 46 |
+
_check_ncdhw(x, "x")
|
| 47 |
+
if bias.shape != (x.shape[1],):
|
| 48 |
+
raise RuntimeError("bias must have shape (C,)")
|
| 49 |
+
return None
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@torch.library.register_fake(add_op_namespace_prefix("update_cache2_ncdhw_bf16"))
|
| 53 |
+
def _update_cache2_ncdhw_bf16_fake(cur: torch.Tensor, prev: torch.Tensor, out: torch.Tensor) -> None:
|
| 54 |
+
_check_ncdhw(cur, "cur")
|
| 55 |
+
b, c, _, h, w = cur.shape
|
| 56 |
+
if prev.shape != (b, c, 2, h, w) or out.shape != (b, c, 2, h, w):
|
| 57 |
+
raise RuntimeError("prev and out must have shape (B, C, 2, H, W)")
|
| 58 |
+
return None
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@torch.library.register_fake(add_op_namespace_prefix("channel_to_space3d_bf16"))
|
| 62 |
+
def _channel_to_space3d_bf16_fake(
|
| 63 |
+
x: torch.Tensor,
|
| 64 |
+
out_channels: int,
|
| 65 |
+
temporal_factor: int,
|
| 66 |
+
spatial_factor: int,
|
| 67 |
+
repeats: int,
|
| 68 |
+
first_chunk: bool,
|
| 69 |
+
out: torch.Tensor,
|
| 70 |
+
) -> None:
|
| 71 |
+
_check_ncdhw(x, "x")
|
| 72 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 73 |
+
temporal_factor - 1 if first_chunk else 0
|
| 74 |
+
)
|
| 75 |
+
expected = (
|
| 76 |
+
x.shape[0],
|
| 77 |
+
out_channels,
|
| 78 |
+
out_t,
|
| 79 |
+
x.shape[3] * spatial_factor,
|
| 80 |
+
x.shape[4] * spatial_factor,
|
| 81 |
+
)
|
| 82 |
+
if (
|
| 83 |
+
out_channels <= 0
|
| 84 |
+
or temporal_factor <= 0
|
| 85 |
+
or spatial_factor <= 0
|
| 86 |
+
or repeats <= 0
|
| 87 |
+
or x.shape[1] * repeats
|
| 88 |
+
< out_channels * temporal_factor * spatial_factor * spatial_factor
|
| 89 |
+
or out.shape != expected
|
| 90 |
+
):
|
| 91 |
+
raise RuntimeError("channel_to_space3d_bf16 shape contract failed")
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
@torch.library.register_fake(
|
| 96 |
+
add_op_namespace_prefix("pack_causal_cache3_nhwc_bf16")
|
| 97 |
+
)
|
| 98 |
+
def _pack_causal_cache3_nhwc_bf16_fake(
|
| 99 |
+
previous: torch.Tensor, current: torch.Tensor, out: torch.Tensor
|
| 100 |
+
) -> None:
|
| 101 |
+
_check_ncdhw(previous, "previous")
|
| 102 |
+
_check_ncdhw(current, "current")
|
| 103 |
+
b, c, t, h, w = current.shape
|
| 104 |
+
if (
|
| 105 |
+
t != 1
|
| 106 |
+
or previous.shape != (b, c, 2, h, w)
|
| 107 |
+
or out.shape != (b, h, w, 3 * c)
|
| 108 |
+
):
|
| 109 |
+
raise RuntimeError("causal cache pack shape contract failed")
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@torch.library.register_fake(add_op_namespace_prefix("avg_pool3d_channels_bf16"))
|
| 114 |
+
def _avg_pool3d_channels_bf16_fake(
|
| 115 |
+
x: torch.Tensor,
|
| 116 |
+
out_channels: int,
|
| 117 |
+
factor_t: int,
|
| 118 |
+
factor_s: int,
|
| 119 |
+
group_size: int,
|
| 120 |
+
out: torch.Tensor,
|
| 121 |
+
) -> None:
|
| 122 |
+
_check_ncdhw(x, "x")
|
| 123 |
+
expected = (
|
| 124 |
+
x.shape[0],
|
| 125 |
+
out_channels,
|
| 126 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 127 |
+
x.shape[3] // factor_s,
|
| 128 |
+
x.shape[4] // factor_s,
|
| 129 |
+
)
|
| 130 |
+
if out.shape != expected:
|
| 131 |
+
raise RuntimeError("out has the wrong pooled NCDHW shape")
|
| 132 |
+
return None
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bf16"))
|
| 136 |
+
def _ndhwc_to_ncdhw_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 137 |
+
if x.dim() != 5:
|
| 138 |
+
raise RuntimeError("x must have shape (B, T, H, W, C)")
|
| 139 |
+
expected = (x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3])
|
| 140 |
+
if out.shape != expected:
|
| 141 |
+
raise RuntimeError("out must have shape (B, C, T, H, W)")
|
| 142 |
+
return None
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bias_bf16"))
|
| 146 |
+
def _ndhwc_to_ncdhw_bias_bf16_fake(
|
| 147 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor
|
| 148 |
+
) -> None:
|
| 149 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 150 |
+
if bias.shape != (x.shape[4],):
|
| 151 |
+
raise RuntimeError("bias must have shape (C,)")
|
| 152 |
+
return None
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_add_bf16"))
|
| 156 |
+
def _ndhwc_to_ncdhw_add_bf16_fake(
|
| 157 |
+
x: torch.Tensor, residual: torch.Tensor, out: torch.Tensor
|
| 158 |
+
) -> None:
|
| 159 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 160 |
+
if residual.shape != out.shape:
|
| 161 |
+
raise RuntimeError("residual must match the NCDHW output shape")
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
@torch.library.register_fake(
|
| 166 |
+
add_op_namespace_prefix("ncdhw_quantize_fp8_static_ndhwc_bf16")
|
| 167 |
+
)
|
| 168 |
+
def _ncdhw_quantize_fp8_static_ndhwc_bf16_fake(
|
| 169 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 170 |
+
) -> None:
|
| 171 |
+
_check_ncdhw(x, "x")
|
| 172 |
+
expected = (x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1])
|
| 173 |
+
if out.shape != expected:
|
| 174 |
+
raise RuntimeError("out must have shape (B, T, H, W, C)")
|
| 175 |
+
return None
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
@torch.library.register_fake(
|
| 179 |
+
add_op_namespace_prefix("upsample2x_quantize_fp8_static_nhwc_bf16")
|
| 180 |
+
)
|
| 181 |
+
def _upsample2x_quantize_fp8_static_nhwc_bf16_fake(
|
| 182 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 183 |
+
) -> None:
|
| 184 |
+
if x.dim() != 4:
|
| 185 |
+
raise RuntimeError("x must have shape (N, C, H, W)")
|
| 186 |
+
expected = (x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1])
|
| 187 |
+
if out.shape != expected:
|
| 188 |
+
raise RuntimeError("out must have shape (N, 2H, 2W, C)")
|
| 189 |
+
return None
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def ncdhw_to_blc_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 193 |
+
"""Convert BF16 NCDHW tensor to BLC where L = T * H * W."""
|
| 194 |
+
|
| 195 |
+
if out is None:
|
| 196 |
+
out = torch.empty((x.shape[0], x.shape[2] * x.shape[3] * x.shape[4], x.shape[1]), device=x.device, dtype=x.dtype)
|
| 197 |
+
ops.ncdhw_to_blc_bf16(x, out)
|
| 198 |
+
return out
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def patch_im2col_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 202 |
+
"""Convert BF16 NHWC images into flattened 14x14 patch rows."""
|
| 203 |
+
|
| 204 |
+
if out is None:
|
| 205 |
+
out = torch.empty((x.shape[0] * 256, 588), device=x.device, dtype=x.dtype)
|
| 206 |
+
ops.patch_im2col_bf16(x, out)
|
| 207 |
+
return out
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def time_unshuffle2_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 211 |
+
"""Convert BF16 (B, 2C, T, H, W) into (B, C, 2T, H, W)."""
|
| 212 |
+
|
| 213 |
+
if out is None:
|
| 214 |
+
out = torch.empty((x.shape[0], x.shape[1] // 2, 2 * x.shape[2], x.shape[3], x.shape[4]), device=x.device, dtype=x.dtype)
|
| 215 |
+
ops.time_unshuffle2_bf16(x, out)
|
| 216 |
+
return out
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def add_bias_ncdhw_bf16(x: torch.Tensor, bias: torch.Tensor) -> torch.Tensor:
|
| 220 |
+
"""Add channel bias to an NCDHW tensor in place."""
|
| 221 |
+
|
| 222 |
+
ops.add_bias_ncdhw_bf16(x, bias)
|
| 223 |
+
return x
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def update_cache2_ncdhw_bf16(cur: torch.Tensor, prev: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 227 |
+
"""Update two-frame latent cache from current and previous NCDHW tensors."""
|
| 228 |
+
|
| 229 |
+
if out is None:
|
| 230 |
+
out = torch.empty((cur.shape[0], cur.shape[1], 2, cur.shape[3], cur.shape[4]), device=cur.device, dtype=cur.dtype)
|
| 231 |
+
ops.update_cache2_ncdhw_bf16(cur, prev, out)
|
| 232 |
+
return out
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def channel_to_space3d_bf16(
|
| 236 |
+
x: torch.Tensor,
|
| 237 |
+
out_channels: int,
|
| 238 |
+
temporal_factor: int,
|
| 239 |
+
spatial_factor: int,
|
| 240 |
+
repeats: int = 1,
|
| 241 |
+
first_chunk: bool = False,
|
| 242 |
+
out: torch.Tensor | None = None,
|
| 243 |
+
) -> torch.Tensor:
|
| 244 |
+
"""Move expanded channels into temporal/spatial dimensions."""
|
| 245 |
+
|
| 246 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 247 |
+
temporal_factor - 1 if first_chunk else 0
|
| 248 |
+
)
|
| 249 |
+
if out is None:
|
| 250 |
+
out = torch.empty(
|
| 251 |
+
(
|
| 252 |
+
x.shape[0],
|
| 253 |
+
out_channels,
|
| 254 |
+
out_t,
|
| 255 |
+
x.shape[3] * spatial_factor,
|
| 256 |
+
x.shape[4] * spatial_factor,
|
| 257 |
+
),
|
| 258 |
+
device=x.device,
|
| 259 |
+
dtype=x.dtype,
|
| 260 |
+
)
|
| 261 |
+
ops.channel_to_space3d_bf16(
|
| 262 |
+
x,
|
| 263 |
+
int(out_channels),
|
| 264 |
+
int(temporal_factor),
|
| 265 |
+
int(spatial_factor),
|
| 266 |
+
int(repeats),
|
| 267 |
+
bool(first_chunk),
|
| 268 |
+
out,
|
| 269 |
+
)
|
| 270 |
+
return out
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def pack_causal_cache3_nhwc_bf16(
|
| 274 |
+
previous: torch.Tensor,
|
| 275 |
+
current: torch.Tensor,
|
| 276 |
+
out: torch.Tensor | None = None,
|
| 277 |
+
) -> torch.Tensor:
|
| 278 |
+
"""Pack two cached and one current NCDHW frame into NHWC with 3C."""
|
| 279 |
+
|
| 280 |
+
if out is None:
|
| 281 |
+
out = torch.empty(
|
| 282 |
+
(
|
| 283 |
+
current.shape[0],
|
| 284 |
+
current.shape[3],
|
| 285 |
+
current.shape[4],
|
| 286 |
+
3 * current.shape[1],
|
| 287 |
+
),
|
| 288 |
+
device=current.device,
|
| 289 |
+
dtype=current.dtype,
|
| 290 |
+
)
|
| 291 |
+
ops.pack_causal_cache3_nhwc_bf16(previous, current, out)
|
| 292 |
+
return out
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def avg_pool3d_channels_bf16(
|
| 296 |
+
x: torch.Tensor,
|
| 297 |
+
out_channels: int,
|
| 298 |
+
factor_t: int,
|
| 299 |
+
factor_s: int,
|
| 300 |
+
group_size: int,
|
| 301 |
+
out: torch.Tensor | None = None,
|
| 302 |
+
) -> torch.Tensor:
|
| 303 |
+
"""Pool NCDHW blocks while folding spatiotemporal factors into channels."""
|
| 304 |
+
|
| 305 |
+
if out is None:
|
| 306 |
+
out = torch.empty(
|
| 307 |
+
(
|
| 308 |
+
x.shape[0],
|
| 309 |
+
out_channels,
|
| 310 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 311 |
+
x.shape[3] // factor_s,
|
| 312 |
+
x.shape[4] // factor_s,
|
| 313 |
+
),
|
| 314 |
+
device=x.device,
|
| 315 |
+
dtype=x.dtype,
|
| 316 |
+
)
|
| 317 |
+
ops.avg_pool3d_channels_bf16(
|
| 318 |
+
x, out_channels, factor_t, factor_s, group_size, out
|
| 319 |
+
)
|
| 320 |
+
return out
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def ndhwc_to_ncdhw_bf16(
|
| 324 |
+
x: torch.Tensor, out: torch.Tensor | None = None
|
| 325 |
+
) -> torch.Tensor:
|
| 326 |
+
"""Convert contiguous BF16 NDHWC to contiguous BF16 NCDHW."""
|
| 327 |
+
|
| 328 |
+
if out is None:
|
| 329 |
+
out = torch.empty(
|
| 330 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 331 |
+
device=x.device,
|
| 332 |
+
dtype=x.dtype,
|
| 333 |
+
)
|
| 334 |
+
ops.ndhwc_to_ncdhw_bf16(x, out)
|
| 335 |
+
return out
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def ndhwc_to_ncdhw_bias_bf16(
|
| 339 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor | None = None
|
| 340 |
+
) -> torch.Tensor:
|
| 341 |
+
"""Convert NDHWC to NCDHW and add a BF16 channel bias."""
|
| 342 |
+
|
| 343 |
+
if out is None:
|
| 344 |
+
out = torch.empty(
|
| 345 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 346 |
+
device=x.device,
|
| 347 |
+
dtype=x.dtype,
|
| 348 |
+
)
|
| 349 |
+
ops.ndhwc_to_ncdhw_bias_bf16(x, bias, out)
|
| 350 |
+
return out
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def ndhwc_to_ncdhw_add_bf16(
|
| 354 |
+
x: torch.Tensor,
|
| 355 |
+
residual: torch.Tensor,
|
| 356 |
+
out: torch.Tensor | None = None,
|
| 357 |
+
) -> torch.Tensor:
|
| 358 |
+
"""Convert NDHWC to NCDHW and add a BF16 NCDHW residual."""
|
| 359 |
+
|
| 360 |
+
if out is None:
|
| 361 |
+
out = torch.empty_like(residual)
|
| 362 |
+
ops.ndhwc_to_ncdhw_add_bf16(x, residual, out)
|
| 363 |
+
return out
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def ncdhw_quantize_fp8_static_ndhwc_bf16(
|
| 367 |
+
x: torch.Tensor,
|
| 368 |
+
scale: float,
|
| 369 |
+
out: torch.Tensor | None = None,
|
| 370 |
+
) -> torch.Tensor:
|
| 371 |
+
"""Quantize BF16 NCDHW to FP8 E4M3 NDHWC using a static scale."""
|
| 372 |
+
|
| 373 |
+
if out is None:
|
| 374 |
+
out = torch.empty(
|
| 375 |
+
(x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1]),
|
| 376 |
+
device=x.device,
|
| 377 |
+
dtype=torch.float8_e4m3fn,
|
| 378 |
+
)
|
| 379 |
+
ops.ncdhw_quantize_fp8_static_ndhwc_bf16(x, scale, out)
|
| 380 |
+
return out
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
def upsample2x_quantize_fp8_static_nhwc_bf16(
|
| 384 |
+
x: torch.Tensor,
|
| 385 |
+
scale: float,
|
| 386 |
+
out: torch.Tensor | None = None,
|
| 387 |
+
) -> torch.Tensor:
|
| 388 |
+
"""Nearest-neighbor 2x upsample NCHW and emit static-scaled FP8 NHWC."""
|
| 389 |
+
|
| 390 |
+
if out is None:
|
| 391 |
+
out = torch.empty(
|
| 392 |
+
(x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1]),
|
| 393 |
+
device=x.device,
|
| 394 |
+
dtype=torch.float8_e4m3fn,
|
| 395 |
+
)
|
| 396 |
+
ops.upsample2x_quantize_fp8_static_nhwc_bf16(x, scale, out)
|
| 397 |
+
return out
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
__all__ = [
|
| 401 |
+
"ncdhw_to_blc_bf16",
|
| 402 |
+
"patch_im2col_bf16",
|
| 403 |
+
"time_unshuffle2_bf16",
|
| 404 |
+
"add_bias_ncdhw_bf16",
|
| 405 |
+
"update_cache2_ncdhw_bf16",
|
| 406 |
+
"channel_to_space3d_bf16",
|
| 407 |
+
"pack_causal_cache3_nhwc_bf16",
|
| 408 |
+
"avg_pool3d_channels_bf16",
|
| 409 |
+
"ndhwc_to_ncdhw_bf16",
|
| 410 |
+
"ndhwc_to_ncdhw_bias_bf16",
|
| 411 |
+
"ndhwc_to_ncdhw_add_bf16",
|
| 412 |
+
"ncdhw_quantize_fp8_static_ndhwc_bf16",
|
| 413 |
+
"upsample2x_quantize_fp8_static_nhwc_bf16",
|
| 414 |
+
]
|
build/{torch212-cxx11-cu132-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_5de4768.abi3.so → torch211-cxx11-cu130-aarch64-linux/_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ec2a08c6333c68c9b6d126414c005a8fd83a6499a8141b90c8c96a842c107df4
|
| 3 |
+
size 458904
|
build/torch211-cxx11-cu130-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flashrt_spatiotemporal_layout_cuda_7781728
|
| 3 |
+
ops = torch.ops._flashrt_spatiotemporal_layout_cuda_7781728
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
return f"_flashrt_spatiotemporal_layout_cuda_7781728::{op_name}"
|
build/torch211-cxx11-cu130-aarch64-linux/flashrt_spatiotemporal_layout/__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": "flashrt-spatiotemporal-layout",
|
| 3 |
+
"id": "_flashrt_spatiotemporal_layout_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": "4WRzvPydgNf2NK7ZljUlhO8NWc3qbONgjAzNb7YayKE=",
|
| 17 |
+
"_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so": "7CoIxjM8aMm20SZBTABaj9g6ZJmoFBuQyMlqhCwQffQ=",
|
| 18 |
+
"_ops.py": "jbNHl3Z/6eFjOcwAfHyy7aALNepozLB2kHUYItLSAaE=",
|
| 19 |
+
"flashrt_spatiotemporal_layout/__init__.py": "v6p5XMfQzddhi1fLSAw4HX9CyS0rQsidvu9VsT01xi4="
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
}
|
build/torch211-cxx11-cu130-x86_64-linux/__init__.py
CHANGED
|
@@ -58,6 +58,137 @@ def _update_cache2_ncdhw_bf16_fake(cur: torch.Tensor, prev: torch.Tensor, out: t
|
|
| 58 |
return None
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def ncdhw_to_blc_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 62 |
"""Convert BF16 NCDHW tensor to BLC where L = T * H * W."""
|
| 63 |
|
|
@@ -101,10 +232,183 @@ def update_cache2_ncdhw_bf16(cur: torch.Tensor, prev: torch.Tensor, out: torch.T
|
|
| 101 |
return out
|
| 102 |
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
__all__ = [
|
| 105 |
"ncdhw_to_blc_bf16",
|
| 106 |
"patch_im2col_bf16",
|
| 107 |
"time_unshuffle2_bf16",
|
| 108 |
"add_bias_ncdhw_bf16",
|
| 109 |
"update_cache2_ncdhw_bf16",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
]
|
|
|
|
| 58 |
return None
|
| 59 |
|
| 60 |
|
| 61 |
+
@torch.library.register_fake(add_op_namespace_prefix("channel_to_space3d_bf16"))
|
| 62 |
+
def _channel_to_space3d_bf16_fake(
|
| 63 |
+
x: torch.Tensor,
|
| 64 |
+
out_channels: int,
|
| 65 |
+
temporal_factor: int,
|
| 66 |
+
spatial_factor: int,
|
| 67 |
+
repeats: int,
|
| 68 |
+
first_chunk: bool,
|
| 69 |
+
out: torch.Tensor,
|
| 70 |
+
) -> None:
|
| 71 |
+
_check_ncdhw(x, "x")
|
| 72 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 73 |
+
temporal_factor - 1 if first_chunk else 0
|
| 74 |
+
)
|
| 75 |
+
expected = (
|
| 76 |
+
x.shape[0],
|
| 77 |
+
out_channels,
|
| 78 |
+
out_t,
|
| 79 |
+
x.shape[3] * spatial_factor,
|
| 80 |
+
x.shape[4] * spatial_factor,
|
| 81 |
+
)
|
| 82 |
+
if (
|
| 83 |
+
out_channels <= 0
|
| 84 |
+
or temporal_factor <= 0
|
| 85 |
+
or spatial_factor <= 0
|
| 86 |
+
or repeats <= 0
|
| 87 |
+
or x.shape[1] * repeats
|
| 88 |
+
< out_channels * temporal_factor * spatial_factor * spatial_factor
|
| 89 |
+
or out.shape != expected
|
| 90 |
+
):
|
| 91 |
+
raise RuntimeError("channel_to_space3d_bf16 shape contract failed")
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
@torch.library.register_fake(
|
| 96 |
+
add_op_namespace_prefix("pack_causal_cache3_nhwc_bf16")
|
| 97 |
+
)
|
| 98 |
+
def _pack_causal_cache3_nhwc_bf16_fake(
|
| 99 |
+
previous: torch.Tensor, current: torch.Tensor, out: torch.Tensor
|
| 100 |
+
) -> None:
|
| 101 |
+
_check_ncdhw(previous, "previous")
|
| 102 |
+
_check_ncdhw(current, "current")
|
| 103 |
+
b, c, t, h, w = current.shape
|
| 104 |
+
if (
|
| 105 |
+
t != 1
|
| 106 |
+
or previous.shape != (b, c, 2, h, w)
|
| 107 |
+
or out.shape != (b, h, w, 3 * c)
|
| 108 |
+
):
|
| 109 |
+
raise RuntimeError("causal cache pack shape contract failed")
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@torch.library.register_fake(add_op_namespace_prefix("avg_pool3d_channels_bf16"))
|
| 114 |
+
def _avg_pool3d_channels_bf16_fake(
|
| 115 |
+
x: torch.Tensor,
|
| 116 |
+
out_channels: int,
|
| 117 |
+
factor_t: int,
|
| 118 |
+
factor_s: int,
|
| 119 |
+
group_size: int,
|
| 120 |
+
out: torch.Tensor,
|
| 121 |
+
) -> None:
|
| 122 |
+
_check_ncdhw(x, "x")
|
| 123 |
+
expected = (
|
| 124 |
+
x.shape[0],
|
| 125 |
+
out_channels,
|
| 126 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 127 |
+
x.shape[3] // factor_s,
|
| 128 |
+
x.shape[4] // factor_s,
|
| 129 |
+
)
|
| 130 |
+
if out.shape != expected:
|
| 131 |
+
raise RuntimeError("out has the wrong pooled NCDHW shape")
|
| 132 |
+
return None
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bf16"))
|
| 136 |
+
def _ndhwc_to_ncdhw_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 137 |
+
if x.dim() != 5:
|
| 138 |
+
raise RuntimeError("x must have shape (B, T, H, W, C)")
|
| 139 |
+
expected = (x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3])
|
| 140 |
+
if out.shape != expected:
|
| 141 |
+
raise RuntimeError("out must have shape (B, C, T, H, W)")
|
| 142 |
+
return None
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bias_bf16"))
|
| 146 |
+
def _ndhwc_to_ncdhw_bias_bf16_fake(
|
| 147 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor
|
| 148 |
+
) -> None:
|
| 149 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 150 |
+
if bias.shape != (x.shape[4],):
|
| 151 |
+
raise RuntimeError("bias must have shape (C,)")
|
| 152 |
+
return None
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_add_bf16"))
|
| 156 |
+
def _ndhwc_to_ncdhw_add_bf16_fake(
|
| 157 |
+
x: torch.Tensor, residual: torch.Tensor, out: torch.Tensor
|
| 158 |
+
) -> None:
|
| 159 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 160 |
+
if residual.shape != out.shape:
|
| 161 |
+
raise RuntimeError("residual must match the NCDHW output shape")
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
@torch.library.register_fake(
|
| 166 |
+
add_op_namespace_prefix("ncdhw_quantize_fp8_static_ndhwc_bf16")
|
| 167 |
+
)
|
| 168 |
+
def _ncdhw_quantize_fp8_static_ndhwc_bf16_fake(
|
| 169 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 170 |
+
) -> None:
|
| 171 |
+
_check_ncdhw(x, "x")
|
| 172 |
+
expected = (x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1])
|
| 173 |
+
if out.shape != expected:
|
| 174 |
+
raise RuntimeError("out must have shape (B, T, H, W, C)")
|
| 175 |
+
return None
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
@torch.library.register_fake(
|
| 179 |
+
add_op_namespace_prefix("upsample2x_quantize_fp8_static_nhwc_bf16")
|
| 180 |
+
)
|
| 181 |
+
def _upsample2x_quantize_fp8_static_nhwc_bf16_fake(
|
| 182 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 183 |
+
) -> None:
|
| 184 |
+
if x.dim() != 4:
|
| 185 |
+
raise RuntimeError("x must have shape (N, C, H, W)")
|
| 186 |
+
expected = (x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1])
|
| 187 |
+
if out.shape != expected:
|
| 188 |
+
raise RuntimeError("out must have shape (N, 2H, 2W, C)")
|
| 189 |
+
return None
|
| 190 |
+
|
| 191 |
+
|
| 192 |
def ncdhw_to_blc_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 193 |
"""Convert BF16 NCDHW tensor to BLC where L = T * H * W."""
|
| 194 |
|
|
|
|
| 232 |
return out
|
| 233 |
|
| 234 |
|
| 235 |
+
def channel_to_space3d_bf16(
|
| 236 |
+
x: torch.Tensor,
|
| 237 |
+
out_channels: int,
|
| 238 |
+
temporal_factor: int,
|
| 239 |
+
spatial_factor: int,
|
| 240 |
+
repeats: int = 1,
|
| 241 |
+
first_chunk: bool = False,
|
| 242 |
+
out: torch.Tensor | None = None,
|
| 243 |
+
) -> torch.Tensor:
|
| 244 |
+
"""Move expanded channels into temporal/spatial dimensions."""
|
| 245 |
+
|
| 246 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 247 |
+
temporal_factor - 1 if first_chunk else 0
|
| 248 |
+
)
|
| 249 |
+
if out is None:
|
| 250 |
+
out = torch.empty(
|
| 251 |
+
(
|
| 252 |
+
x.shape[0],
|
| 253 |
+
out_channels,
|
| 254 |
+
out_t,
|
| 255 |
+
x.shape[3] * spatial_factor,
|
| 256 |
+
x.shape[4] * spatial_factor,
|
| 257 |
+
),
|
| 258 |
+
device=x.device,
|
| 259 |
+
dtype=x.dtype,
|
| 260 |
+
)
|
| 261 |
+
ops.channel_to_space3d_bf16(
|
| 262 |
+
x,
|
| 263 |
+
int(out_channels),
|
| 264 |
+
int(temporal_factor),
|
| 265 |
+
int(spatial_factor),
|
| 266 |
+
int(repeats),
|
| 267 |
+
bool(first_chunk),
|
| 268 |
+
out,
|
| 269 |
+
)
|
| 270 |
+
return out
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def pack_causal_cache3_nhwc_bf16(
|
| 274 |
+
previous: torch.Tensor,
|
| 275 |
+
current: torch.Tensor,
|
| 276 |
+
out: torch.Tensor | None = None,
|
| 277 |
+
) -> torch.Tensor:
|
| 278 |
+
"""Pack two cached and one current NCDHW frame into NHWC with 3C."""
|
| 279 |
+
|
| 280 |
+
if out is None:
|
| 281 |
+
out = torch.empty(
|
| 282 |
+
(
|
| 283 |
+
current.shape[0],
|
| 284 |
+
current.shape[3],
|
| 285 |
+
current.shape[4],
|
| 286 |
+
3 * current.shape[1],
|
| 287 |
+
),
|
| 288 |
+
device=current.device,
|
| 289 |
+
dtype=current.dtype,
|
| 290 |
+
)
|
| 291 |
+
ops.pack_causal_cache3_nhwc_bf16(previous, current, out)
|
| 292 |
+
return out
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def avg_pool3d_channels_bf16(
|
| 296 |
+
x: torch.Tensor,
|
| 297 |
+
out_channels: int,
|
| 298 |
+
factor_t: int,
|
| 299 |
+
factor_s: int,
|
| 300 |
+
group_size: int,
|
| 301 |
+
out: torch.Tensor | None = None,
|
| 302 |
+
) -> torch.Tensor:
|
| 303 |
+
"""Pool NCDHW blocks while folding spatiotemporal factors into channels."""
|
| 304 |
+
|
| 305 |
+
if out is None:
|
| 306 |
+
out = torch.empty(
|
| 307 |
+
(
|
| 308 |
+
x.shape[0],
|
| 309 |
+
out_channels,
|
| 310 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 311 |
+
x.shape[3] // factor_s,
|
| 312 |
+
x.shape[4] // factor_s,
|
| 313 |
+
),
|
| 314 |
+
device=x.device,
|
| 315 |
+
dtype=x.dtype,
|
| 316 |
+
)
|
| 317 |
+
ops.avg_pool3d_channels_bf16(
|
| 318 |
+
x, out_channels, factor_t, factor_s, group_size, out
|
| 319 |
+
)
|
| 320 |
+
return out
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def ndhwc_to_ncdhw_bf16(
|
| 324 |
+
x: torch.Tensor, out: torch.Tensor | None = None
|
| 325 |
+
) -> torch.Tensor:
|
| 326 |
+
"""Convert contiguous BF16 NDHWC to contiguous BF16 NCDHW."""
|
| 327 |
+
|
| 328 |
+
if out is None:
|
| 329 |
+
out = torch.empty(
|
| 330 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 331 |
+
device=x.device,
|
| 332 |
+
dtype=x.dtype,
|
| 333 |
+
)
|
| 334 |
+
ops.ndhwc_to_ncdhw_bf16(x, out)
|
| 335 |
+
return out
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def ndhwc_to_ncdhw_bias_bf16(
|
| 339 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor | None = None
|
| 340 |
+
) -> torch.Tensor:
|
| 341 |
+
"""Convert NDHWC to NCDHW and add a BF16 channel bias."""
|
| 342 |
+
|
| 343 |
+
if out is None:
|
| 344 |
+
out = torch.empty(
|
| 345 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 346 |
+
device=x.device,
|
| 347 |
+
dtype=x.dtype,
|
| 348 |
+
)
|
| 349 |
+
ops.ndhwc_to_ncdhw_bias_bf16(x, bias, out)
|
| 350 |
+
return out
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def ndhwc_to_ncdhw_add_bf16(
|
| 354 |
+
x: torch.Tensor,
|
| 355 |
+
residual: torch.Tensor,
|
| 356 |
+
out: torch.Tensor | None = None,
|
| 357 |
+
) -> torch.Tensor:
|
| 358 |
+
"""Convert NDHWC to NCDHW and add a BF16 NCDHW residual."""
|
| 359 |
+
|
| 360 |
+
if out is None:
|
| 361 |
+
out = torch.empty_like(residual)
|
| 362 |
+
ops.ndhwc_to_ncdhw_add_bf16(x, residual, out)
|
| 363 |
+
return out
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def ncdhw_quantize_fp8_static_ndhwc_bf16(
|
| 367 |
+
x: torch.Tensor,
|
| 368 |
+
scale: float,
|
| 369 |
+
out: torch.Tensor | None = None,
|
| 370 |
+
) -> torch.Tensor:
|
| 371 |
+
"""Quantize BF16 NCDHW to FP8 E4M3 NDHWC using a static scale."""
|
| 372 |
+
|
| 373 |
+
if out is None:
|
| 374 |
+
out = torch.empty(
|
| 375 |
+
(x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1]),
|
| 376 |
+
device=x.device,
|
| 377 |
+
dtype=torch.float8_e4m3fn,
|
| 378 |
+
)
|
| 379 |
+
ops.ncdhw_quantize_fp8_static_ndhwc_bf16(x, scale, out)
|
| 380 |
+
return out
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
def upsample2x_quantize_fp8_static_nhwc_bf16(
|
| 384 |
+
x: torch.Tensor,
|
| 385 |
+
scale: float,
|
| 386 |
+
out: torch.Tensor | None = None,
|
| 387 |
+
) -> torch.Tensor:
|
| 388 |
+
"""Nearest-neighbor 2x upsample NCHW and emit static-scaled FP8 NHWC."""
|
| 389 |
+
|
| 390 |
+
if out is None:
|
| 391 |
+
out = torch.empty(
|
| 392 |
+
(x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1]),
|
| 393 |
+
device=x.device,
|
| 394 |
+
dtype=torch.float8_e4m3fn,
|
| 395 |
+
)
|
| 396 |
+
ops.upsample2x_quantize_fp8_static_nhwc_bf16(x, scale, out)
|
| 397 |
+
return out
|
| 398 |
+
|
| 399 |
+
|
| 400 |
__all__ = [
|
| 401 |
"ncdhw_to_blc_bf16",
|
| 402 |
"patch_im2col_bf16",
|
| 403 |
"time_unshuffle2_bf16",
|
| 404 |
"add_bias_ncdhw_bf16",
|
| 405 |
"update_cache2_ncdhw_bf16",
|
| 406 |
+
"channel_to_space3d_bf16",
|
| 407 |
+
"pack_causal_cache3_nhwc_bf16",
|
| 408 |
+
"avg_pool3d_channels_bf16",
|
| 409 |
+
"ndhwc_to_ncdhw_bf16",
|
| 410 |
+
"ndhwc_to_ncdhw_bias_bf16",
|
| 411 |
+
"ndhwc_to_ncdhw_add_bf16",
|
| 412 |
+
"ncdhw_quantize_fp8_static_ndhwc_bf16",
|
| 413 |
+
"upsample2x_quantize_fp8_static_nhwc_bf16",
|
| 414 |
]
|
build/{torch212-cxx11-cu130-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_5de4768.abi3.so → torch211-cxx11-cu130-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4849a4c21396b8d1ca4173e837ea16491d7962e7720820d191008890de99ccf1
|
| 3 |
+
size 1804176
|
build/torch211-cxx11-cu130-x86_64-linux/_ops.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import torch
|
| 2 |
-
from . import
|
| 3 |
-
ops = torch.ops.
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
-
return f"
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from . import _flashrt_spatiotemporal_layout_cuda_7781728
|
| 3 |
+
ops = torch.ops._flashrt_spatiotemporal_layout_cuda_7781728
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
+
return f"_flashrt_spatiotemporal_layout_cuda_7781728::{op_name}"
|
build/torch211-cxx11-cu130-x86_64-linux/metadata.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "flashrt-spatiotemporal-layout",
|
| 3 |
-
"id": "
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
|
|
| 1 |
{
|
| 2 |
"name": "flashrt-spatiotemporal-layout",
|
| 3 |
+
"id": "_flashrt_spatiotemporal_layout_cuda_7781728",
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
build/torch212-cxx11-cu130-x86_64-linux/__init__.py
CHANGED
|
@@ -58,6 +58,137 @@ def _update_cache2_ncdhw_bf16_fake(cur: torch.Tensor, prev: torch.Tensor, out: t
|
|
| 58 |
return None
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def ncdhw_to_blc_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 62 |
"""Convert BF16 NCDHW tensor to BLC where L = T * H * W."""
|
| 63 |
|
|
@@ -101,10 +232,183 @@ def update_cache2_ncdhw_bf16(cur: torch.Tensor, prev: torch.Tensor, out: torch.T
|
|
| 101 |
return out
|
| 102 |
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
__all__ = [
|
| 105 |
"ncdhw_to_blc_bf16",
|
| 106 |
"patch_im2col_bf16",
|
| 107 |
"time_unshuffle2_bf16",
|
| 108 |
"add_bias_ncdhw_bf16",
|
| 109 |
"update_cache2_ncdhw_bf16",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
]
|
|
|
|
| 58 |
return None
|
| 59 |
|
| 60 |
|
| 61 |
+
@torch.library.register_fake(add_op_namespace_prefix("channel_to_space3d_bf16"))
|
| 62 |
+
def _channel_to_space3d_bf16_fake(
|
| 63 |
+
x: torch.Tensor,
|
| 64 |
+
out_channels: int,
|
| 65 |
+
temporal_factor: int,
|
| 66 |
+
spatial_factor: int,
|
| 67 |
+
repeats: int,
|
| 68 |
+
first_chunk: bool,
|
| 69 |
+
out: torch.Tensor,
|
| 70 |
+
) -> None:
|
| 71 |
+
_check_ncdhw(x, "x")
|
| 72 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 73 |
+
temporal_factor - 1 if first_chunk else 0
|
| 74 |
+
)
|
| 75 |
+
expected = (
|
| 76 |
+
x.shape[0],
|
| 77 |
+
out_channels,
|
| 78 |
+
out_t,
|
| 79 |
+
x.shape[3] * spatial_factor,
|
| 80 |
+
x.shape[4] * spatial_factor,
|
| 81 |
+
)
|
| 82 |
+
if (
|
| 83 |
+
out_channels <= 0
|
| 84 |
+
or temporal_factor <= 0
|
| 85 |
+
or spatial_factor <= 0
|
| 86 |
+
or repeats <= 0
|
| 87 |
+
or x.shape[1] * repeats
|
| 88 |
+
< out_channels * temporal_factor * spatial_factor * spatial_factor
|
| 89 |
+
or out.shape != expected
|
| 90 |
+
):
|
| 91 |
+
raise RuntimeError("channel_to_space3d_bf16 shape contract failed")
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
@torch.library.register_fake(
|
| 96 |
+
add_op_namespace_prefix("pack_causal_cache3_nhwc_bf16")
|
| 97 |
+
)
|
| 98 |
+
def _pack_causal_cache3_nhwc_bf16_fake(
|
| 99 |
+
previous: torch.Tensor, current: torch.Tensor, out: torch.Tensor
|
| 100 |
+
) -> None:
|
| 101 |
+
_check_ncdhw(previous, "previous")
|
| 102 |
+
_check_ncdhw(current, "current")
|
| 103 |
+
b, c, t, h, w = current.shape
|
| 104 |
+
if (
|
| 105 |
+
t != 1
|
| 106 |
+
or previous.shape != (b, c, 2, h, w)
|
| 107 |
+
or out.shape != (b, h, w, 3 * c)
|
| 108 |
+
):
|
| 109 |
+
raise RuntimeError("causal cache pack shape contract failed")
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@torch.library.register_fake(add_op_namespace_prefix("avg_pool3d_channels_bf16"))
|
| 114 |
+
def _avg_pool3d_channels_bf16_fake(
|
| 115 |
+
x: torch.Tensor,
|
| 116 |
+
out_channels: int,
|
| 117 |
+
factor_t: int,
|
| 118 |
+
factor_s: int,
|
| 119 |
+
group_size: int,
|
| 120 |
+
out: torch.Tensor,
|
| 121 |
+
) -> None:
|
| 122 |
+
_check_ncdhw(x, "x")
|
| 123 |
+
expected = (
|
| 124 |
+
x.shape[0],
|
| 125 |
+
out_channels,
|
| 126 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 127 |
+
x.shape[3] // factor_s,
|
| 128 |
+
x.shape[4] // factor_s,
|
| 129 |
+
)
|
| 130 |
+
if out.shape != expected:
|
| 131 |
+
raise RuntimeError("out has the wrong pooled NCDHW shape")
|
| 132 |
+
return None
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bf16"))
|
| 136 |
+
def _ndhwc_to_ncdhw_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 137 |
+
if x.dim() != 5:
|
| 138 |
+
raise RuntimeError("x must have shape (B, T, H, W, C)")
|
| 139 |
+
expected = (x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3])
|
| 140 |
+
if out.shape != expected:
|
| 141 |
+
raise RuntimeError("out must have shape (B, C, T, H, W)")
|
| 142 |
+
return None
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bias_bf16"))
|
| 146 |
+
def _ndhwc_to_ncdhw_bias_bf16_fake(
|
| 147 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor
|
| 148 |
+
) -> None:
|
| 149 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 150 |
+
if bias.shape != (x.shape[4],):
|
| 151 |
+
raise RuntimeError("bias must have shape (C,)")
|
| 152 |
+
return None
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_add_bf16"))
|
| 156 |
+
def _ndhwc_to_ncdhw_add_bf16_fake(
|
| 157 |
+
x: torch.Tensor, residual: torch.Tensor, out: torch.Tensor
|
| 158 |
+
) -> None:
|
| 159 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 160 |
+
if residual.shape != out.shape:
|
| 161 |
+
raise RuntimeError("residual must match the NCDHW output shape")
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
@torch.library.register_fake(
|
| 166 |
+
add_op_namespace_prefix("ncdhw_quantize_fp8_static_ndhwc_bf16")
|
| 167 |
+
)
|
| 168 |
+
def _ncdhw_quantize_fp8_static_ndhwc_bf16_fake(
|
| 169 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 170 |
+
) -> None:
|
| 171 |
+
_check_ncdhw(x, "x")
|
| 172 |
+
expected = (x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1])
|
| 173 |
+
if out.shape != expected:
|
| 174 |
+
raise RuntimeError("out must have shape (B, T, H, W, C)")
|
| 175 |
+
return None
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
@torch.library.register_fake(
|
| 179 |
+
add_op_namespace_prefix("upsample2x_quantize_fp8_static_nhwc_bf16")
|
| 180 |
+
)
|
| 181 |
+
def _upsample2x_quantize_fp8_static_nhwc_bf16_fake(
|
| 182 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 183 |
+
) -> None:
|
| 184 |
+
if x.dim() != 4:
|
| 185 |
+
raise RuntimeError("x must have shape (N, C, H, W)")
|
| 186 |
+
expected = (x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1])
|
| 187 |
+
if out.shape != expected:
|
| 188 |
+
raise RuntimeError("out must have shape (N, 2H, 2W, C)")
|
| 189 |
+
return None
|
| 190 |
+
|
| 191 |
+
|
| 192 |
def ncdhw_to_blc_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 193 |
"""Convert BF16 NCDHW tensor to BLC where L = T * H * W."""
|
| 194 |
|
|
|
|
| 232 |
return out
|
| 233 |
|
| 234 |
|
| 235 |
+
def channel_to_space3d_bf16(
|
| 236 |
+
x: torch.Tensor,
|
| 237 |
+
out_channels: int,
|
| 238 |
+
temporal_factor: int,
|
| 239 |
+
spatial_factor: int,
|
| 240 |
+
repeats: int = 1,
|
| 241 |
+
first_chunk: bool = False,
|
| 242 |
+
out: torch.Tensor | None = None,
|
| 243 |
+
) -> torch.Tensor:
|
| 244 |
+
"""Move expanded channels into temporal/spatial dimensions."""
|
| 245 |
+
|
| 246 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 247 |
+
temporal_factor - 1 if first_chunk else 0
|
| 248 |
+
)
|
| 249 |
+
if out is None:
|
| 250 |
+
out = torch.empty(
|
| 251 |
+
(
|
| 252 |
+
x.shape[0],
|
| 253 |
+
out_channels,
|
| 254 |
+
out_t,
|
| 255 |
+
x.shape[3] * spatial_factor,
|
| 256 |
+
x.shape[4] * spatial_factor,
|
| 257 |
+
),
|
| 258 |
+
device=x.device,
|
| 259 |
+
dtype=x.dtype,
|
| 260 |
+
)
|
| 261 |
+
ops.channel_to_space3d_bf16(
|
| 262 |
+
x,
|
| 263 |
+
int(out_channels),
|
| 264 |
+
int(temporal_factor),
|
| 265 |
+
int(spatial_factor),
|
| 266 |
+
int(repeats),
|
| 267 |
+
bool(first_chunk),
|
| 268 |
+
out,
|
| 269 |
+
)
|
| 270 |
+
return out
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def pack_causal_cache3_nhwc_bf16(
|
| 274 |
+
previous: torch.Tensor,
|
| 275 |
+
current: torch.Tensor,
|
| 276 |
+
out: torch.Tensor | None = None,
|
| 277 |
+
) -> torch.Tensor:
|
| 278 |
+
"""Pack two cached and one current NCDHW frame into NHWC with 3C."""
|
| 279 |
+
|
| 280 |
+
if out is None:
|
| 281 |
+
out = torch.empty(
|
| 282 |
+
(
|
| 283 |
+
current.shape[0],
|
| 284 |
+
current.shape[3],
|
| 285 |
+
current.shape[4],
|
| 286 |
+
3 * current.shape[1],
|
| 287 |
+
),
|
| 288 |
+
device=current.device,
|
| 289 |
+
dtype=current.dtype,
|
| 290 |
+
)
|
| 291 |
+
ops.pack_causal_cache3_nhwc_bf16(previous, current, out)
|
| 292 |
+
return out
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def avg_pool3d_channels_bf16(
|
| 296 |
+
x: torch.Tensor,
|
| 297 |
+
out_channels: int,
|
| 298 |
+
factor_t: int,
|
| 299 |
+
factor_s: int,
|
| 300 |
+
group_size: int,
|
| 301 |
+
out: torch.Tensor | None = None,
|
| 302 |
+
) -> torch.Tensor:
|
| 303 |
+
"""Pool NCDHW blocks while folding spatiotemporal factors into channels."""
|
| 304 |
+
|
| 305 |
+
if out is None:
|
| 306 |
+
out = torch.empty(
|
| 307 |
+
(
|
| 308 |
+
x.shape[0],
|
| 309 |
+
out_channels,
|
| 310 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 311 |
+
x.shape[3] // factor_s,
|
| 312 |
+
x.shape[4] // factor_s,
|
| 313 |
+
),
|
| 314 |
+
device=x.device,
|
| 315 |
+
dtype=x.dtype,
|
| 316 |
+
)
|
| 317 |
+
ops.avg_pool3d_channels_bf16(
|
| 318 |
+
x, out_channels, factor_t, factor_s, group_size, out
|
| 319 |
+
)
|
| 320 |
+
return out
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def ndhwc_to_ncdhw_bf16(
|
| 324 |
+
x: torch.Tensor, out: torch.Tensor | None = None
|
| 325 |
+
) -> torch.Tensor:
|
| 326 |
+
"""Convert contiguous BF16 NDHWC to contiguous BF16 NCDHW."""
|
| 327 |
+
|
| 328 |
+
if out is None:
|
| 329 |
+
out = torch.empty(
|
| 330 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 331 |
+
device=x.device,
|
| 332 |
+
dtype=x.dtype,
|
| 333 |
+
)
|
| 334 |
+
ops.ndhwc_to_ncdhw_bf16(x, out)
|
| 335 |
+
return out
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def ndhwc_to_ncdhw_bias_bf16(
|
| 339 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor | None = None
|
| 340 |
+
) -> torch.Tensor:
|
| 341 |
+
"""Convert NDHWC to NCDHW and add a BF16 channel bias."""
|
| 342 |
+
|
| 343 |
+
if out is None:
|
| 344 |
+
out = torch.empty(
|
| 345 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 346 |
+
device=x.device,
|
| 347 |
+
dtype=x.dtype,
|
| 348 |
+
)
|
| 349 |
+
ops.ndhwc_to_ncdhw_bias_bf16(x, bias, out)
|
| 350 |
+
return out
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def ndhwc_to_ncdhw_add_bf16(
|
| 354 |
+
x: torch.Tensor,
|
| 355 |
+
residual: torch.Tensor,
|
| 356 |
+
out: torch.Tensor | None = None,
|
| 357 |
+
) -> torch.Tensor:
|
| 358 |
+
"""Convert NDHWC to NCDHW and add a BF16 NCDHW residual."""
|
| 359 |
+
|
| 360 |
+
if out is None:
|
| 361 |
+
out = torch.empty_like(residual)
|
| 362 |
+
ops.ndhwc_to_ncdhw_add_bf16(x, residual, out)
|
| 363 |
+
return out
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def ncdhw_quantize_fp8_static_ndhwc_bf16(
|
| 367 |
+
x: torch.Tensor,
|
| 368 |
+
scale: float,
|
| 369 |
+
out: torch.Tensor | None = None,
|
| 370 |
+
) -> torch.Tensor:
|
| 371 |
+
"""Quantize BF16 NCDHW to FP8 E4M3 NDHWC using a static scale."""
|
| 372 |
+
|
| 373 |
+
if out is None:
|
| 374 |
+
out = torch.empty(
|
| 375 |
+
(x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1]),
|
| 376 |
+
device=x.device,
|
| 377 |
+
dtype=torch.float8_e4m3fn,
|
| 378 |
+
)
|
| 379 |
+
ops.ncdhw_quantize_fp8_static_ndhwc_bf16(x, scale, out)
|
| 380 |
+
return out
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
def upsample2x_quantize_fp8_static_nhwc_bf16(
|
| 384 |
+
x: torch.Tensor,
|
| 385 |
+
scale: float,
|
| 386 |
+
out: torch.Tensor | None = None,
|
| 387 |
+
) -> torch.Tensor:
|
| 388 |
+
"""Nearest-neighbor 2x upsample NCHW and emit static-scaled FP8 NHWC."""
|
| 389 |
+
|
| 390 |
+
if out is None:
|
| 391 |
+
out = torch.empty(
|
| 392 |
+
(x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1]),
|
| 393 |
+
device=x.device,
|
| 394 |
+
dtype=torch.float8_e4m3fn,
|
| 395 |
+
)
|
| 396 |
+
ops.upsample2x_quantize_fp8_static_nhwc_bf16(x, scale, out)
|
| 397 |
+
return out
|
| 398 |
+
|
| 399 |
+
|
| 400 |
__all__ = [
|
| 401 |
"ncdhw_to_blc_bf16",
|
| 402 |
"patch_im2col_bf16",
|
| 403 |
"time_unshuffle2_bf16",
|
| 404 |
"add_bias_ncdhw_bf16",
|
| 405 |
"update_cache2_ncdhw_bf16",
|
| 406 |
+
"channel_to_space3d_bf16",
|
| 407 |
+
"pack_causal_cache3_nhwc_bf16",
|
| 408 |
+
"avg_pool3d_channels_bf16",
|
| 409 |
+
"ndhwc_to_ncdhw_bf16",
|
| 410 |
+
"ndhwc_to_ncdhw_bias_bf16",
|
| 411 |
+
"ndhwc_to_ncdhw_add_bf16",
|
| 412 |
+
"ncdhw_quantize_fp8_static_ndhwc_bf16",
|
| 413 |
+
"upsample2x_quantize_fp8_static_nhwc_bf16",
|
| 414 |
]
|
build/torch212-cxx11-cu130-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:917fb550fc3481af63a6c63aa6ad864c76f76c61ce59e9236769c3f08b2e54b6
|
| 3 |
+
size 1810440
|
build/torch212-cxx11-cu130-x86_64-linux/_ops.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import torch
|
| 2 |
-
from . import
|
| 3 |
-
ops = torch.ops.
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
-
return f"
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from . import _flashrt_spatiotemporal_layout_cuda_7781728
|
| 3 |
+
ops = torch.ops._flashrt_spatiotemporal_layout_cuda_7781728
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
+
return f"_flashrt_spatiotemporal_layout_cuda_7781728::{op_name}"
|
build/torch212-cxx11-cu130-x86_64-linux/metadata.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "flashrt-spatiotemporal-layout",
|
| 3 |
-
"id": "
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
|
|
| 1 |
{
|
| 2 |
"name": "flashrt-spatiotemporal-layout",
|
| 3 |
+
"id": "_flashrt_spatiotemporal_layout_cuda_7781728",
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
build/torch212-cxx11-cu132-x86_64-linux/__init__.py
CHANGED
|
@@ -58,6 +58,137 @@ def _update_cache2_ncdhw_bf16_fake(cur: torch.Tensor, prev: torch.Tensor, out: t
|
|
| 58 |
return None
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def ncdhw_to_blc_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 62 |
"""Convert BF16 NCDHW tensor to BLC where L = T * H * W."""
|
| 63 |
|
|
@@ -101,10 +232,183 @@ def update_cache2_ncdhw_bf16(cur: torch.Tensor, prev: torch.Tensor, out: torch.T
|
|
| 101 |
return out
|
| 102 |
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
__all__ = [
|
| 105 |
"ncdhw_to_blc_bf16",
|
| 106 |
"patch_im2col_bf16",
|
| 107 |
"time_unshuffle2_bf16",
|
| 108 |
"add_bias_ncdhw_bf16",
|
| 109 |
"update_cache2_ncdhw_bf16",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
]
|
|
|
|
| 58 |
return None
|
| 59 |
|
| 60 |
|
| 61 |
+
@torch.library.register_fake(add_op_namespace_prefix("channel_to_space3d_bf16"))
|
| 62 |
+
def _channel_to_space3d_bf16_fake(
|
| 63 |
+
x: torch.Tensor,
|
| 64 |
+
out_channels: int,
|
| 65 |
+
temporal_factor: int,
|
| 66 |
+
spatial_factor: int,
|
| 67 |
+
repeats: int,
|
| 68 |
+
first_chunk: bool,
|
| 69 |
+
out: torch.Tensor,
|
| 70 |
+
) -> None:
|
| 71 |
+
_check_ncdhw(x, "x")
|
| 72 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 73 |
+
temporal_factor - 1 if first_chunk else 0
|
| 74 |
+
)
|
| 75 |
+
expected = (
|
| 76 |
+
x.shape[0],
|
| 77 |
+
out_channels,
|
| 78 |
+
out_t,
|
| 79 |
+
x.shape[3] * spatial_factor,
|
| 80 |
+
x.shape[4] * spatial_factor,
|
| 81 |
+
)
|
| 82 |
+
if (
|
| 83 |
+
out_channels <= 0
|
| 84 |
+
or temporal_factor <= 0
|
| 85 |
+
or spatial_factor <= 0
|
| 86 |
+
or repeats <= 0
|
| 87 |
+
or x.shape[1] * repeats
|
| 88 |
+
< out_channels * temporal_factor * spatial_factor * spatial_factor
|
| 89 |
+
or out.shape != expected
|
| 90 |
+
):
|
| 91 |
+
raise RuntimeError("channel_to_space3d_bf16 shape contract failed")
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
@torch.library.register_fake(
|
| 96 |
+
add_op_namespace_prefix("pack_causal_cache3_nhwc_bf16")
|
| 97 |
+
)
|
| 98 |
+
def _pack_causal_cache3_nhwc_bf16_fake(
|
| 99 |
+
previous: torch.Tensor, current: torch.Tensor, out: torch.Tensor
|
| 100 |
+
) -> None:
|
| 101 |
+
_check_ncdhw(previous, "previous")
|
| 102 |
+
_check_ncdhw(current, "current")
|
| 103 |
+
b, c, t, h, w = current.shape
|
| 104 |
+
if (
|
| 105 |
+
t != 1
|
| 106 |
+
or previous.shape != (b, c, 2, h, w)
|
| 107 |
+
or out.shape != (b, h, w, 3 * c)
|
| 108 |
+
):
|
| 109 |
+
raise RuntimeError("causal cache pack shape contract failed")
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@torch.library.register_fake(add_op_namespace_prefix("avg_pool3d_channels_bf16"))
|
| 114 |
+
def _avg_pool3d_channels_bf16_fake(
|
| 115 |
+
x: torch.Tensor,
|
| 116 |
+
out_channels: int,
|
| 117 |
+
factor_t: int,
|
| 118 |
+
factor_s: int,
|
| 119 |
+
group_size: int,
|
| 120 |
+
out: torch.Tensor,
|
| 121 |
+
) -> None:
|
| 122 |
+
_check_ncdhw(x, "x")
|
| 123 |
+
expected = (
|
| 124 |
+
x.shape[0],
|
| 125 |
+
out_channels,
|
| 126 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 127 |
+
x.shape[3] // factor_s,
|
| 128 |
+
x.shape[4] // factor_s,
|
| 129 |
+
)
|
| 130 |
+
if out.shape != expected:
|
| 131 |
+
raise RuntimeError("out has the wrong pooled NCDHW shape")
|
| 132 |
+
return None
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bf16"))
|
| 136 |
+
def _ndhwc_to_ncdhw_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 137 |
+
if x.dim() != 5:
|
| 138 |
+
raise RuntimeError("x must have shape (B, T, H, W, C)")
|
| 139 |
+
expected = (x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3])
|
| 140 |
+
if out.shape != expected:
|
| 141 |
+
raise RuntimeError("out must have shape (B, C, T, H, W)")
|
| 142 |
+
return None
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bias_bf16"))
|
| 146 |
+
def _ndhwc_to_ncdhw_bias_bf16_fake(
|
| 147 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor
|
| 148 |
+
) -> None:
|
| 149 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 150 |
+
if bias.shape != (x.shape[4],):
|
| 151 |
+
raise RuntimeError("bias must have shape (C,)")
|
| 152 |
+
return None
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_add_bf16"))
|
| 156 |
+
def _ndhwc_to_ncdhw_add_bf16_fake(
|
| 157 |
+
x: torch.Tensor, residual: torch.Tensor, out: torch.Tensor
|
| 158 |
+
) -> None:
|
| 159 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 160 |
+
if residual.shape != out.shape:
|
| 161 |
+
raise RuntimeError("residual must match the NCDHW output shape")
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
@torch.library.register_fake(
|
| 166 |
+
add_op_namespace_prefix("ncdhw_quantize_fp8_static_ndhwc_bf16")
|
| 167 |
+
)
|
| 168 |
+
def _ncdhw_quantize_fp8_static_ndhwc_bf16_fake(
|
| 169 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 170 |
+
) -> None:
|
| 171 |
+
_check_ncdhw(x, "x")
|
| 172 |
+
expected = (x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1])
|
| 173 |
+
if out.shape != expected:
|
| 174 |
+
raise RuntimeError("out must have shape (B, T, H, W, C)")
|
| 175 |
+
return None
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
@torch.library.register_fake(
|
| 179 |
+
add_op_namespace_prefix("upsample2x_quantize_fp8_static_nhwc_bf16")
|
| 180 |
+
)
|
| 181 |
+
def _upsample2x_quantize_fp8_static_nhwc_bf16_fake(
|
| 182 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 183 |
+
) -> None:
|
| 184 |
+
if x.dim() != 4:
|
| 185 |
+
raise RuntimeError("x must have shape (N, C, H, W)")
|
| 186 |
+
expected = (x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1])
|
| 187 |
+
if out.shape != expected:
|
| 188 |
+
raise RuntimeError("out must have shape (N, 2H, 2W, C)")
|
| 189 |
+
return None
|
| 190 |
+
|
| 191 |
+
|
| 192 |
def ncdhw_to_blc_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 193 |
"""Convert BF16 NCDHW tensor to BLC where L = T * H * W."""
|
| 194 |
|
|
|
|
| 232 |
return out
|
| 233 |
|
| 234 |
|
| 235 |
+
def channel_to_space3d_bf16(
|
| 236 |
+
x: torch.Tensor,
|
| 237 |
+
out_channels: int,
|
| 238 |
+
temporal_factor: int,
|
| 239 |
+
spatial_factor: int,
|
| 240 |
+
repeats: int = 1,
|
| 241 |
+
first_chunk: bool = False,
|
| 242 |
+
out: torch.Tensor | None = None,
|
| 243 |
+
) -> torch.Tensor:
|
| 244 |
+
"""Move expanded channels into temporal/spatial dimensions."""
|
| 245 |
+
|
| 246 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 247 |
+
temporal_factor - 1 if first_chunk else 0
|
| 248 |
+
)
|
| 249 |
+
if out is None:
|
| 250 |
+
out = torch.empty(
|
| 251 |
+
(
|
| 252 |
+
x.shape[0],
|
| 253 |
+
out_channels,
|
| 254 |
+
out_t,
|
| 255 |
+
x.shape[3] * spatial_factor,
|
| 256 |
+
x.shape[4] * spatial_factor,
|
| 257 |
+
),
|
| 258 |
+
device=x.device,
|
| 259 |
+
dtype=x.dtype,
|
| 260 |
+
)
|
| 261 |
+
ops.channel_to_space3d_bf16(
|
| 262 |
+
x,
|
| 263 |
+
int(out_channels),
|
| 264 |
+
int(temporal_factor),
|
| 265 |
+
int(spatial_factor),
|
| 266 |
+
int(repeats),
|
| 267 |
+
bool(first_chunk),
|
| 268 |
+
out,
|
| 269 |
+
)
|
| 270 |
+
return out
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def pack_causal_cache3_nhwc_bf16(
|
| 274 |
+
previous: torch.Tensor,
|
| 275 |
+
current: torch.Tensor,
|
| 276 |
+
out: torch.Tensor | None = None,
|
| 277 |
+
) -> torch.Tensor:
|
| 278 |
+
"""Pack two cached and one current NCDHW frame into NHWC with 3C."""
|
| 279 |
+
|
| 280 |
+
if out is None:
|
| 281 |
+
out = torch.empty(
|
| 282 |
+
(
|
| 283 |
+
current.shape[0],
|
| 284 |
+
current.shape[3],
|
| 285 |
+
current.shape[4],
|
| 286 |
+
3 * current.shape[1],
|
| 287 |
+
),
|
| 288 |
+
device=current.device,
|
| 289 |
+
dtype=current.dtype,
|
| 290 |
+
)
|
| 291 |
+
ops.pack_causal_cache3_nhwc_bf16(previous, current, out)
|
| 292 |
+
return out
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def avg_pool3d_channels_bf16(
|
| 296 |
+
x: torch.Tensor,
|
| 297 |
+
out_channels: int,
|
| 298 |
+
factor_t: int,
|
| 299 |
+
factor_s: int,
|
| 300 |
+
group_size: int,
|
| 301 |
+
out: torch.Tensor | None = None,
|
| 302 |
+
) -> torch.Tensor:
|
| 303 |
+
"""Pool NCDHW blocks while folding spatiotemporal factors into channels."""
|
| 304 |
+
|
| 305 |
+
if out is None:
|
| 306 |
+
out = torch.empty(
|
| 307 |
+
(
|
| 308 |
+
x.shape[0],
|
| 309 |
+
out_channels,
|
| 310 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 311 |
+
x.shape[3] // factor_s,
|
| 312 |
+
x.shape[4] // factor_s,
|
| 313 |
+
),
|
| 314 |
+
device=x.device,
|
| 315 |
+
dtype=x.dtype,
|
| 316 |
+
)
|
| 317 |
+
ops.avg_pool3d_channels_bf16(
|
| 318 |
+
x, out_channels, factor_t, factor_s, group_size, out
|
| 319 |
+
)
|
| 320 |
+
return out
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def ndhwc_to_ncdhw_bf16(
|
| 324 |
+
x: torch.Tensor, out: torch.Tensor | None = None
|
| 325 |
+
) -> torch.Tensor:
|
| 326 |
+
"""Convert contiguous BF16 NDHWC to contiguous BF16 NCDHW."""
|
| 327 |
+
|
| 328 |
+
if out is None:
|
| 329 |
+
out = torch.empty(
|
| 330 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 331 |
+
device=x.device,
|
| 332 |
+
dtype=x.dtype,
|
| 333 |
+
)
|
| 334 |
+
ops.ndhwc_to_ncdhw_bf16(x, out)
|
| 335 |
+
return out
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def ndhwc_to_ncdhw_bias_bf16(
|
| 339 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor | None = None
|
| 340 |
+
) -> torch.Tensor:
|
| 341 |
+
"""Convert NDHWC to NCDHW and add a BF16 channel bias."""
|
| 342 |
+
|
| 343 |
+
if out is None:
|
| 344 |
+
out = torch.empty(
|
| 345 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 346 |
+
device=x.device,
|
| 347 |
+
dtype=x.dtype,
|
| 348 |
+
)
|
| 349 |
+
ops.ndhwc_to_ncdhw_bias_bf16(x, bias, out)
|
| 350 |
+
return out
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def ndhwc_to_ncdhw_add_bf16(
|
| 354 |
+
x: torch.Tensor,
|
| 355 |
+
residual: torch.Tensor,
|
| 356 |
+
out: torch.Tensor | None = None,
|
| 357 |
+
) -> torch.Tensor:
|
| 358 |
+
"""Convert NDHWC to NCDHW and add a BF16 NCDHW residual."""
|
| 359 |
+
|
| 360 |
+
if out is None:
|
| 361 |
+
out = torch.empty_like(residual)
|
| 362 |
+
ops.ndhwc_to_ncdhw_add_bf16(x, residual, out)
|
| 363 |
+
return out
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def ncdhw_quantize_fp8_static_ndhwc_bf16(
|
| 367 |
+
x: torch.Tensor,
|
| 368 |
+
scale: float,
|
| 369 |
+
out: torch.Tensor | None = None,
|
| 370 |
+
) -> torch.Tensor:
|
| 371 |
+
"""Quantize BF16 NCDHW to FP8 E4M3 NDHWC using a static scale."""
|
| 372 |
+
|
| 373 |
+
if out is None:
|
| 374 |
+
out = torch.empty(
|
| 375 |
+
(x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1]),
|
| 376 |
+
device=x.device,
|
| 377 |
+
dtype=torch.float8_e4m3fn,
|
| 378 |
+
)
|
| 379 |
+
ops.ncdhw_quantize_fp8_static_ndhwc_bf16(x, scale, out)
|
| 380 |
+
return out
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
def upsample2x_quantize_fp8_static_nhwc_bf16(
|
| 384 |
+
x: torch.Tensor,
|
| 385 |
+
scale: float,
|
| 386 |
+
out: torch.Tensor | None = None,
|
| 387 |
+
) -> torch.Tensor:
|
| 388 |
+
"""Nearest-neighbor 2x upsample NCHW and emit static-scaled FP8 NHWC."""
|
| 389 |
+
|
| 390 |
+
if out is None:
|
| 391 |
+
out = torch.empty(
|
| 392 |
+
(x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1]),
|
| 393 |
+
device=x.device,
|
| 394 |
+
dtype=torch.float8_e4m3fn,
|
| 395 |
+
)
|
| 396 |
+
ops.upsample2x_quantize_fp8_static_nhwc_bf16(x, scale, out)
|
| 397 |
+
return out
|
| 398 |
+
|
| 399 |
+
|
| 400 |
__all__ = [
|
| 401 |
"ncdhw_to_blc_bf16",
|
| 402 |
"patch_im2col_bf16",
|
| 403 |
"time_unshuffle2_bf16",
|
| 404 |
"add_bias_ncdhw_bf16",
|
| 405 |
"update_cache2_ncdhw_bf16",
|
| 406 |
+
"channel_to_space3d_bf16",
|
| 407 |
+
"pack_causal_cache3_nhwc_bf16",
|
| 408 |
+
"avg_pool3d_channels_bf16",
|
| 409 |
+
"ndhwc_to_ncdhw_bf16",
|
| 410 |
+
"ndhwc_to_ncdhw_bias_bf16",
|
| 411 |
+
"ndhwc_to_ncdhw_add_bf16",
|
| 412 |
+
"ncdhw_quantize_fp8_static_ndhwc_bf16",
|
| 413 |
+
"upsample2x_quantize_fp8_static_nhwc_bf16",
|
| 414 |
]
|
build/torch212-cxx11-cu132-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_7781728.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0e671b827971af10d928dcfc1cfea4676931152975e33829a1e6cf3743cb746e
|
| 3 |
+
size 1818632
|
build/torch212-cxx11-cu132-x86_64-linux/_ops.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import torch
|
| 2 |
-
from . import
|
| 3 |
-
ops = torch.ops.
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
-
return f"
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from . import _flashrt_spatiotemporal_layout_cuda_7781728
|
| 3 |
+
ops = torch.ops._flashrt_spatiotemporal_layout_cuda_7781728
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
+
return f"_flashrt_spatiotemporal_layout_cuda_7781728::{op_name}"
|
build/torch212-cxx11-cu132-x86_64-linux/metadata.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "flashrt-spatiotemporal-layout",
|
| 3 |
-
"id": "
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
|
|
| 1 |
{
|
| 2 |
"name": "flashrt-spatiotemporal-layout",
|
| 3 |
+
"id": "_flashrt_spatiotemporal_layout_cuda_7781728",
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
build/torch213-cxx11-cu130-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT spatiotemporal layout kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _check_ncdhw(x: torch.Tensor, name: str) -> None:
|
| 11 |
+
if x.dim() != 5:
|
| 12 |
+
raise RuntimeError(f"{name} must have shape (B, C, T, H, W)")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@torch.library.register_fake(add_op_namespace_prefix("ncdhw_to_blc_bf16"))
|
| 16 |
+
def _ncdhw_to_blc_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 17 |
+
_check_ncdhw(x, "x")
|
| 18 |
+
b, c, t, h, w = x.shape
|
| 19 |
+
if out.shape != (b, t * h * w, c):
|
| 20 |
+
raise RuntimeError("out must have shape (B, T * H * W, C)")
|
| 21 |
+
return None
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@torch.library.register_fake(add_op_namespace_prefix("patch_im2col_bf16"))
|
| 25 |
+
def _patch_im2col_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 26 |
+
if x.dim() != 4 or x.shape[1:] != (224, 224, 3):
|
| 27 |
+
raise RuntimeError("x must have shape (num_views, 224, 224, 3)")
|
| 28 |
+
if out.shape != (x.shape[0] * 256, 588):
|
| 29 |
+
raise RuntimeError("out must have shape (num_views * 256, 588)")
|
| 30 |
+
return None
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@torch.library.register_fake(add_op_namespace_prefix("time_unshuffle2_bf16"))
|
| 34 |
+
def _time_unshuffle2_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 35 |
+
_check_ncdhw(x, "x")
|
| 36 |
+
b, c2, t, h, w = x.shape
|
| 37 |
+
if c2 % 2 != 0:
|
| 38 |
+
raise RuntimeError("x.shape[1] must be even")
|
| 39 |
+
if out.shape != (b, c2 // 2, 2 * t, h, w):
|
| 40 |
+
raise RuntimeError("out must have shape (B, C / 2, 2 * T, H, W)")
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@torch.library.register_fake(add_op_namespace_prefix("add_bias_ncdhw_bf16"))
|
| 45 |
+
def _add_bias_ncdhw_bf16_fake(x: torch.Tensor, bias: torch.Tensor) -> None:
|
| 46 |
+
_check_ncdhw(x, "x")
|
| 47 |
+
if bias.shape != (x.shape[1],):
|
| 48 |
+
raise RuntimeError("bias must have shape (C,)")
|
| 49 |
+
return None
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@torch.library.register_fake(add_op_namespace_prefix("update_cache2_ncdhw_bf16"))
|
| 53 |
+
def _update_cache2_ncdhw_bf16_fake(cur: torch.Tensor, prev: torch.Tensor, out: torch.Tensor) -> None:
|
| 54 |
+
_check_ncdhw(cur, "cur")
|
| 55 |
+
b, c, _, h, w = cur.shape
|
| 56 |
+
if prev.shape != (b, c, 2, h, w) or out.shape != (b, c, 2, h, w):
|
| 57 |
+
raise RuntimeError("prev and out must have shape (B, C, 2, H, W)")
|
| 58 |
+
return None
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@torch.library.register_fake(add_op_namespace_prefix("channel_to_space3d_bf16"))
|
| 62 |
+
def _channel_to_space3d_bf16_fake(
|
| 63 |
+
x: torch.Tensor,
|
| 64 |
+
out_channels: int,
|
| 65 |
+
temporal_factor: int,
|
| 66 |
+
spatial_factor: int,
|
| 67 |
+
repeats: int,
|
| 68 |
+
first_chunk: bool,
|
| 69 |
+
out: torch.Tensor,
|
| 70 |
+
) -> None:
|
| 71 |
+
_check_ncdhw(x, "x")
|
| 72 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 73 |
+
temporal_factor - 1 if first_chunk else 0
|
| 74 |
+
)
|
| 75 |
+
expected = (
|
| 76 |
+
x.shape[0],
|
| 77 |
+
out_channels,
|
| 78 |
+
out_t,
|
| 79 |
+
x.shape[3] * spatial_factor,
|
| 80 |
+
x.shape[4] * spatial_factor,
|
| 81 |
+
)
|
| 82 |
+
if (
|
| 83 |
+
out_channels <= 0
|
| 84 |
+
or temporal_factor <= 0
|
| 85 |
+
or spatial_factor <= 0
|
| 86 |
+
or repeats <= 0
|
| 87 |
+
or x.shape[1] * repeats
|
| 88 |
+
< out_channels * temporal_factor * spatial_factor * spatial_factor
|
| 89 |
+
or out.shape != expected
|
| 90 |
+
):
|
| 91 |
+
raise RuntimeError("channel_to_space3d_bf16 shape contract failed")
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
@torch.library.register_fake(
|
| 96 |
+
add_op_namespace_prefix("pack_causal_cache3_nhwc_bf16")
|
| 97 |
+
)
|
| 98 |
+
def _pack_causal_cache3_nhwc_bf16_fake(
|
| 99 |
+
previous: torch.Tensor, current: torch.Tensor, out: torch.Tensor
|
| 100 |
+
) -> None:
|
| 101 |
+
_check_ncdhw(previous, "previous")
|
| 102 |
+
_check_ncdhw(current, "current")
|
| 103 |
+
b, c, t, h, w = current.shape
|
| 104 |
+
if (
|
| 105 |
+
t != 1
|
| 106 |
+
or previous.shape != (b, c, 2, h, w)
|
| 107 |
+
or out.shape != (b, h, w, 3 * c)
|
| 108 |
+
):
|
| 109 |
+
raise RuntimeError("causal cache pack shape contract failed")
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@torch.library.register_fake(add_op_namespace_prefix("avg_pool3d_channels_bf16"))
|
| 114 |
+
def _avg_pool3d_channels_bf16_fake(
|
| 115 |
+
x: torch.Tensor,
|
| 116 |
+
out_channels: int,
|
| 117 |
+
factor_t: int,
|
| 118 |
+
factor_s: int,
|
| 119 |
+
group_size: int,
|
| 120 |
+
out: torch.Tensor,
|
| 121 |
+
) -> None:
|
| 122 |
+
_check_ncdhw(x, "x")
|
| 123 |
+
expected = (
|
| 124 |
+
x.shape[0],
|
| 125 |
+
out_channels,
|
| 126 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 127 |
+
x.shape[3] // factor_s,
|
| 128 |
+
x.shape[4] // factor_s,
|
| 129 |
+
)
|
| 130 |
+
if out.shape != expected:
|
| 131 |
+
raise RuntimeError("out has the wrong pooled NCDHW shape")
|
| 132 |
+
return None
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bf16"))
|
| 136 |
+
def _ndhwc_to_ncdhw_bf16_fake(x: torch.Tensor, out: torch.Tensor) -> None:
|
| 137 |
+
if x.dim() != 5:
|
| 138 |
+
raise RuntimeError("x must have shape (B, T, H, W, C)")
|
| 139 |
+
expected = (x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3])
|
| 140 |
+
if out.shape != expected:
|
| 141 |
+
raise RuntimeError("out must have shape (B, C, T, H, W)")
|
| 142 |
+
return None
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_bias_bf16"))
|
| 146 |
+
def _ndhwc_to_ncdhw_bias_bf16_fake(
|
| 147 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor
|
| 148 |
+
) -> None:
|
| 149 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 150 |
+
if bias.shape != (x.shape[4],):
|
| 151 |
+
raise RuntimeError("bias must have shape (C,)")
|
| 152 |
+
return None
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@torch.library.register_fake(add_op_namespace_prefix("ndhwc_to_ncdhw_add_bf16"))
|
| 156 |
+
def _ndhwc_to_ncdhw_add_bf16_fake(
|
| 157 |
+
x: torch.Tensor, residual: torch.Tensor, out: torch.Tensor
|
| 158 |
+
) -> None:
|
| 159 |
+
_ndhwc_to_ncdhw_bf16_fake(x, out)
|
| 160 |
+
if residual.shape != out.shape:
|
| 161 |
+
raise RuntimeError("residual must match the NCDHW output shape")
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
@torch.library.register_fake(
|
| 166 |
+
add_op_namespace_prefix("ncdhw_quantize_fp8_static_ndhwc_bf16")
|
| 167 |
+
)
|
| 168 |
+
def _ncdhw_quantize_fp8_static_ndhwc_bf16_fake(
|
| 169 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 170 |
+
) -> None:
|
| 171 |
+
_check_ncdhw(x, "x")
|
| 172 |
+
expected = (x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1])
|
| 173 |
+
if out.shape != expected:
|
| 174 |
+
raise RuntimeError("out must have shape (B, T, H, W, C)")
|
| 175 |
+
return None
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
@torch.library.register_fake(
|
| 179 |
+
add_op_namespace_prefix("upsample2x_quantize_fp8_static_nhwc_bf16")
|
| 180 |
+
)
|
| 181 |
+
def _upsample2x_quantize_fp8_static_nhwc_bf16_fake(
|
| 182 |
+
x: torch.Tensor, scale: float, out: torch.Tensor
|
| 183 |
+
) -> None:
|
| 184 |
+
if x.dim() != 4:
|
| 185 |
+
raise RuntimeError("x must have shape (N, C, H, W)")
|
| 186 |
+
expected = (x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1])
|
| 187 |
+
if out.shape != expected:
|
| 188 |
+
raise RuntimeError("out must have shape (N, 2H, 2W, C)")
|
| 189 |
+
return None
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def ncdhw_to_blc_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 193 |
+
"""Convert BF16 NCDHW tensor to BLC where L = T * H * W."""
|
| 194 |
+
|
| 195 |
+
if out is None:
|
| 196 |
+
out = torch.empty((x.shape[0], x.shape[2] * x.shape[3] * x.shape[4], x.shape[1]), device=x.device, dtype=x.dtype)
|
| 197 |
+
ops.ncdhw_to_blc_bf16(x, out)
|
| 198 |
+
return out
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def patch_im2col_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 202 |
+
"""Convert BF16 NHWC images into flattened 14x14 patch rows."""
|
| 203 |
+
|
| 204 |
+
if out is None:
|
| 205 |
+
out = torch.empty((x.shape[0] * 256, 588), device=x.device, dtype=x.dtype)
|
| 206 |
+
ops.patch_im2col_bf16(x, out)
|
| 207 |
+
return out
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def time_unshuffle2_bf16(x: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 211 |
+
"""Convert BF16 (B, 2C, T, H, W) into (B, C, 2T, H, W)."""
|
| 212 |
+
|
| 213 |
+
if out is None:
|
| 214 |
+
out = torch.empty((x.shape[0], x.shape[1] // 2, 2 * x.shape[2], x.shape[3], x.shape[4]), device=x.device, dtype=x.dtype)
|
| 215 |
+
ops.time_unshuffle2_bf16(x, out)
|
| 216 |
+
return out
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def add_bias_ncdhw_bf16(x: torch.Tensor, bias: torch.Tensor) -> torch.Tensor:
|
| 220 |
+
"""Add channel bias to an NCDHW tensor in place."""
|
| 221 |
+
|
| 222 |
+
ops.add_bias_ncdhw_bf16(x, bias)
|
| 223 |
+
return x
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def update_cache2_ncdhw_bf16(cur: torch.Tensor, prev: torch.Tensor, out: torch.Tensor | None = None) -> torch.Tensor:
|
| 227 |
+
"""Update two-frame latent cache from current and previous NCDHW tensors."""
|
| 228 |
+
|
| 229 |
+
if out is None:
|
| 230 |
+
out = torch.empty((cur.shape[0], cur.shape[1], 2, cur.shape[3], cur.shape[4]), device=cur.device, dtype=cur.dtype)
|
| 231 |
+
ops.update_cache2_ncdhw_bf16(cur, prev, out)
|
| 232 |
+
return out
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def channel_to_space3d_bf16(
|
| 236 |
+
x: torch.Tensor,
|
| 237 |
+
out_channels: int,
|
| 238 |
+
temporal_factor: int,
|
| 239 |
+
spatial_factor: int,
|
| 240 |
+
repeats: int = 1,
|
| 241 |
+
first_chunk: bool = False,
|
| 242 |
+
out: torch.Tensor | None = None,
|
| 243 |
+
) -> torch.Tensor:
|
| 244 |
+
"""Move expanded channels into temporal/spatial dimensions."""
|
| 245 |
+
|
| 246 |
+
out_t = x.shape[2] * temporal_factor - (
|
| 247 |
+
temporal_factor - 1 if first_chunk else 0
|
| 248 |
+
)
|
| 249 |
+
if out is None:
|
| 250 |
+
out = torch.empty(
|
| 251 |
+
(
|
| 252 |
+
x.shape[0],
|
| 253 |
+
out_channels,
|
| 254 |
+
out_t,
|
| 255 |
+
x.shape[3] * spatial_factor,
|
| 256 |
+
x.shape[4] * spatial_factor,
|
| 257 |
+
),
|
| 258 |
+
device=x.device,
|
| 259 |
+
dtype=x.dtype,
|
| 260 |
+
)
|
| 261 |
+
ops.channel_to_space3d_bf16(
|
| 262 |
+
x,
|
| 263 |
+
int(out_channels),
|
| 264 |
+
int(temporal_factor),
|
| 265 |
+
int(spatial_factor),
|
| 266 |
+
int(repeats),
|
| 267 |
+
bool(first_chunk),
|
| 268 |
+
out,
|
| 269 |
+
)
|
| 270 |
+
return out
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def pack_causal_cache3_nhwc_bf16(
|
| 274 |
+
previous: torch.Tensor,
|
| 275 |
+
current: torch.Tensor,
|
| 276 |
+
out: torch.Tensor | None = None,
|
| 277 |
+
) -> torch.Tensor:
|
| 278 |
+
"""Pack two cached and one current NCDHW frame into NHWC with 3C."""
|
| 279 |
+
|
| 280 |
+
if out is None:
|
| 281 |
+
out = torch.empty(
|
| 282 |
+
(
|
| 283 |
+
current.shape[0],
|
| 284 |
+
current.shape[3],
|
| 285 |
+
current.shape[4],
|
| 286 |
+
3 * current.shape[1],
|
| 287 |
+
),
|
| 288 |
+
device=current.device,
|
| 289 |
+
dtype=current.dtype,
|
| 290 |
+
)
|
| 291 |
+
ops.pack_causal_cache3_nhwc_bf16(previous, current, out)
|
| 292 |
+
return out
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def avg_pool3d_channels_bf16(
|
| 296 |
+
x: torch.Tensor,
|
| 297 |
+
out_channels: int,
|
| 298 |
+
factor_t: int,
|
| 299 |
+
factor_s: int,
|
| 300 |
+
group_size: int,
|
| 301 |
+
out: torch.Tensor | None = None,
|
| 302 |
+
) -> torch.Tensor:
|
| 303 |
+
"""Pool NCDHW blocks while folding spatiotemporal factors into channels."""
|
| 304 |
+
|
| 305 |
+
if out is None:
|
| 306 |
+
out = torch.empty(
|
| 307 |
+
(
|
| 308 |
+
x.shape[0],
|
| 309 |
+
out_channels,
|
| 310 |
+
(x.shape[2] + factor_t - 1) // factor_t,
|
| 311 |
+
x.shape[3] // factor_s,
|
| 312 |
+
x.shape[4] // factor_s,
|
| 313 |
+
),
|
| 314 |
+
device=x.device,
|
| 315 |
+
dtype=x.dtype,
|
| 316 |
+
)
|
| 317 |
+
ops.avg_pool3d_channels_bf16(
|
| 318 |
+
x, out_channels, factor_t, factor_s, group_size, out
|
| 319 |
+
)
|
| 320 |
+
return out
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def ndhwc_to_ncdhw_bf16(
|
| 324 |
+
x: torch.Tensor, out: torch.Tensor | None = None
|
| 325 |
+
) -> torch.Tensor:
|
| 326 |
+
"""Convert contiguous BF16 NDHWC to contiguous BF16 NCDHW."""
|
| 327 |
+
|
| 328 |
+
if out is None:
|
| 329 |
+
out = torch.empty(
|
| 330 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 331 |
+
device=x.device,
|
| 332 |
+
dtype=x.dtype,
|
| 333 |
+
)
|
| 334 |
+
ops.ndhwc_to_ncdhw_bf16(x, out)
|
| 335 |
+
return out
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def ndhwc_to_ncdhw_bias_bf16(
|
| 339 |
+
x: torch.Tensor, bias: torch.Tensor, out: torch.Tensor | None = None
|
| 340 |
+
) -> torch.Tensor:
|
| 341 |
+
"""Convert NDHWC to NCDHW and add a BF16 channel bias."""
|
| 342 |
+
|
| 343 |
+
if out is None:
|
| 344 |
+
out = torch.empty(
|
| 345 |
+
(x.shape[0], x.shape[4], x.shape[1], x.shape[2], x.shape[3]),
|
| 346 |
+
device=x.device,
|
| 347 |
+
dtype=x.dtype,
|
| 348 |
+
)
|
| 349 |
+
ops.ndhwc_to_ncdhw_bias_bf16(x, bias, out)
|
| 350 |
+
return out
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def ndhwc_to_ncdhw_add_bf16(
|
| 354 |
+
x: torch.Tensor,
|
| 355 |
+
residual: torch.Tensor,
|
| 356 |
+
out: torch.Tensor | None = None,
|
| 357 |
+
) -> torch.Tensor:
|
| 358 |
+
"""Convert NDHWC to NCDHW and add a BF16 NCDHW residual."""
|
| 359 |
+
|
| 360 |
+
if out is None:
|
| 361 |
+
out = torch.empty_like(residual)
|
| 362 |
+
ops.ndhwc_to_ncdhw_add_bf16(x, residual, out)
|
| 363 |
+
return out
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def ncdhw_quantize_fp8_static_ndhwc_bf16(
|
| 367 |
+
x: torch.Tensor,
|
| 368 |
+
scale: float,
|
| 369 |
+
out: torch.Tensor | None = None,
|
| 370 |
+
) -> torch.Tensor:
|
| 371 |
+
"""Quantize BF16 NCDHW to FP8 E4M3 NDHWC using a static scale."""
|
| 372 |
+
|
| 373 |
+
if out is None:
|
| 374 |
+
out = torch.empty(
|
| 375 |
+
(x.shape[0], x.shape[2], x.shape[3], x.shape[4], x.shape[1]),
|
| 376 |
+
device=x.device,
|
| 377 |
+
dtype=torch.float8_e4m3fn,
|
| 378 |
+
)
|
| 379 |
+
ops.ncdhw_quantize_fp8_static_ndhwc_bf16(x, scale, out)
|
| 380 |
+
return out
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
def upsample2x_quantize_fp8_static_nhwc_bf16(
|
| 384 |
+
x: torch.Tensor,
|
| 385 |
+
scale: float,
|
| 386 |
+
out: torch.Tensor | None = None,
|
| 387 |
+
) -> torch.Tensor:
|
| 388 |
+
"""Nearest-neighbor 2x upsample NCHW and emit static-scaled FP8 NHWC."""
|
| 389 |
+
|
| 390 |
+
if out is None:
|
| 391 |
+
out = torch.empty(
|
| 392 |
+
(x.shape[0], 2 * x.shape[2], 2 * x.shape[3], x.shape[1]),
|
| 393 |
+
device=x.device,
|
| 394 |
+
dtype=torch.float8_e4m3fn,
|
| 395 |
+
)
|
| 396 |
+
ops.upsample2x_quantize_fp8_static_nhwc_bf16(x, scale, out)
|
| 397 |
+
return out
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
__all__ = [
|
| 401 |
+
"ncdhw_to_blc_bf16",
|
| 402 |
+
"patch_im2col_bf16",
|
| 403 |
+
"time_unshuffle2_bf16",
|
| 404 |
+
"add_bias_ncdhw_bf16",
|
| 405 |
+
"update_cache2_ncdhw_bf16",
|
| 406 |
+
"channel_to_space3d_bf16",
|
| 407 |
+
"pack_causal_cache3_nhwc_bf16",
|
| 408 |
+
"avg_pool3d_channels_bf16",
|
| 409 |
+
"ndhwc_to_ncdhw_bf16",
|
| 410 |
+
"ndhwc_to_ncdhw_bias_bf16",
|
| 411 |
+
"ndhwc_to_ncdhw_add_bf16",
|
| 412 |
+
"ncdhw_quantize_fp8_static_ndhwc_bf16",
|
| 413 |
+
"upsample2x_quantize_fp8_static_nhwc_bf16",
|
| 414 |
+
]
|
build/torch213-cxx11-cu130-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import flashrt_spatiotemporal_layout_test
|
| 3 |
+
ops = torch.ops.flashrt_spatiotemporal_layout_test
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
return f"flashrt_spatiotemporal_layout_test::{op_name}"
|
build/torch213-cxx11-cu130-aarch64-linux/flashrt_spatiotemporal_layout/__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-cu128-x86_64-linux/_flashrt_spatiotemporal_layout_cuda_5de4768.abi3.so → torch213-cxx11-cu130-aarch64-linux/flashrt_spatiotemporal_layout_test.abi3.so}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:16f0b72634927e102b0ce7c17a8addd5eaed791906b19d034f2729cf909e895a
|
| 3 |
+
size 461408
|
build/torch213-cxx11-cu130-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flashrt-spatiotemporal-layout",
|
| 3 |
+
"id": "flashrt_spatiotemporal_layout_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": "4WRzvPydgNf2NK7ZljUlhO8NWc3qbONgjAzNb7YayKE=",
|
| 17 |
+
"flashrt_spatiotemporal_layout_test.abi3.so": "FvC3JjSSfhArDOfBeord1erteRkGsZ0DTycpz5CeiVo=",
|
| 18 |
+
"_ops.py": "P29ghFUoONBA3NS6cY+kzbwr/RczjL8AdMewXrgZDCA=",
|
| 19 |
+
"flashrt_spatiotemporal_layout/__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 |
+
}
|