Fused FP8 CUDA kernel for FLUX.1 SingleStreamBlock with spike attention and step caching. Replaces ComfyUI's entire SingleStreamBlock forward pass with a single torch.ops call — modulation, dual GEMMs, QKV, RoPE, attention, gating and residual all fused. 30%+ faster than stock ComfyUI on RTX 4090. Spike attention: block-sparse Triton kernel that scores attention blocks by dot-product similarity and keeps only the top 45% after image structure forms. Step caching replays cached attention output on alternating spike steps for zero attention compute every other step. Works with all 38 ComfyUI samplers at any step count. FP16 ports included for 10-series, 20-series, and 30-series GPUs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""
|
|
Build script for flux_ext FP16 PyTorch C++/CUDA extension — 10-series (SM 61, Pascal).
|
|
|
|
Usage:
|
|
py -3.10 setup_ext.py install
|
|
|
|
Compiles the FP16-only FLUXNATION kernel (no FP8, no CUTLASS).
|
|
Compatible with GTX 1060, 1070, 1080, 1080 Ti.
|
|
"""
|
|
|
|
import os
|
|
|
|
os.environ["CUDA_HOME"] = r"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8"
|
|
os.environ["CUDA_PATH"] = os.environ["CUDA_HOME"]
|
|
|
|
from setuptools import setup
|
|
from torch.utils.cpp_extension import CUDAExtension, BuildExtension
|
|
|
|
ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
setup(
|
|
name="flux_ext",
|
|
ext_modules=[
|
|
CUDAExtension(
|
|
name="flux_ext",
|
|
sources=[
|
|
os.path.join(ROOT, "csrc", "FLUXPATCH_FP16.cpp"),
|
|
os.path.join(ROOT, "csrc", "FLUXNATION_FP16.cu"),
|
|
os.path.join(ROOT, "flux_opt_fp16.cu"),
|
|
],
|
|
include_dirs=[
|
|
ROOT, # SINGLE_STREAM_BLOCK_FP16.H
|
|
],
|
|
extra_compile_args={
|
|
"cxx": ["/O2", "/std:c++17", "/EHsc", "/MD"],
|
|
"nvcc": [
|
|
"-O3",
|
|
"-std=c++17",
|
|
"-arch=sm_61",
|
|
"-DFLUX_TORCH_EXT=1",
|
|
"--allow-unsupported-compiler",
|
|
"-diag-suppress=20013",
|
|
"-diag-suppress=20015",
|
|
"-Xcompiler", "/MD",
|
|
"-Xcompiler", "/EHsc",
|
|
"-Xcompiler", "/Zc:preprocessor",
|
|
],
|
|
},
|
|
libraries=["cublas"],
|
|
)
|
|
],
|
|
cmdclass={"build_ext": BuildExtension},
|
|
)
|