Instructions to use Motif-Technologies/activation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Kernels
How to use Motif-Technologies/activation with Kernels:
# !pip install kernels from kernels import get_kernel kernel = get_kernel("Motif-Technologies/activation") - Notebooks
- Google Colab
- Kaggle
feat: add setup.py for local CUDA development builds
Browse filesLocal build alternative to kernel-builder (nix) for development and
training yaml workflows. Builds _activation extension with nvcc for
sm_80/89/90/100 (B200 support with CUDA 12.8+).
Usage: pip install --no-build-isolation -e .
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- registration.h +14 -0
- setup.py +81 -0
registration.h
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// Local build compatibility shim for kernel-builder's registration.h
|
| 4 |
+
|
| 5 |
+
#include <torch/library.h>
|
| 6 |
+
#include <torch/extension.h>
|
| 7 |
+
|
| 8 |
+
// TORCH_LIBRARY_EXPAND may not be defined in all PyTorch versions
|
| 9 |
+
#ifndef TORCH_LIBRARY_EXPAND
|
| 10 |
+
#define TORCH_LIBRARY_EXPAND(ns, m) TORCH_LIBRARY(ns, m)
|
| 11 |
+
#endif
|
| 12 |
+
|
| 13 |
+
// Generate the PyInit_<name> entry point for the shared library
|
| 14 |
+
#define REGISTER_EXTENSION(name) PYBIND11_MODULE(name, m) {}
|
setup.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Local CUDA build for activation kernels.
|
| 2 |
+
|
| 3 |
+
Usage:
|
| 4 |
+
pip install -e . # editable install
|
| 5 |
+
python setup.py build_ext --inplace # build only
|
| 6 |
+
|
| 7 |
+
The built extension is named '_activation' and can be loaded via:
|
| 8 |
+
import _activation
|
| 9 |
+
torch.ops._activation.rms_norm(...)
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import os
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
import torch
|
| 16 |
+
from setuptools import setup
|
| 17 |
+
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
|
| 18 |
+
|
| 19 |
+
ROOT = Path(__file__).parent
|
| 20 |
+
|
| 21 |
+
CUDA_SOURCES = [
|
| 22 |
+
"activation/poly_norm.cu",
|
| 23 |
+
"activation/fused_mul_poly_norm.cu",
|
| 24 |
+
"activation/rms_norm.cu",
|
| 25 |
+
"activation/fused_add_rms_norm.cu",
|
| 26 |
+
"activation/grouped_poly_norm.cu",
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
CPP_SOURCES = [
|
| 30 |
+
"torch-ext/torch_binding.cpp",
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
# Include dirs: project root (for registration.h, activation/*.h)
|
| 34 |
+
# and torch-ext/ (for torch_binding.h)
|
| 35 |
+
INCLUDE_DIRS = [
|
| 36 |
+
str(ROOT),
|
| 37 |
+
str(ROOT / "activation"),
|
| 38 |
+
str(ROOT / "torch-ext"),
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
# CUDA flags matching the existing kernel style
|
| 42 |
+
NVCC_FLAGS = [
|
| 43 |
+
"-O3",
|
| 44 |
+
"--use_fast_math",
|
| 45 |
+
"-std=c++17",
|
| 46 |
+
# Generate code for common architectures
|
| 47 |
+
"-gencode=arch=compute_80,code=sm_80", # A100
|
| 48 |
+
"-gencode=arch=compute_89,code=sm_89", # L40/4090
|
| 49 |
+
"-gencode=arch=compute_90,code=sm_90", # H100
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
# Check for B200 support (sm_100, requires CUDA 12.8+)
|
| 53 |
+
cuda_version = tuple(int(x) for x in torch.version.cuda.split(".")[:2])
|
| 54 |
+
if cuda_version >= (12, 8):
|
| 55 |
+
NVCC_FLAGS.append("-gencode=arch=compute_100,code=sm_100")
|
| 56 |
+
|
| 57 |
+
CXX_FLAGS = ["-O3", "-std=c++17"]
|
| 58 |
+
|
| 59 |
+
ext_modules = [
|
| 60 |
+
CUDAExtension(
|
| 61 |
+
name="_activation",
|
| 62 |
+
sources=[str(ROOT / s) for s in CPP_SOURCES + CUDA_SOURCES],
|
| 63 |
+
include_dirs=INCLUDE_DIRS,
|
| 64 |
+
extra_compile_args={
|
| 65 |
+
"cxx": CXX_FLAGS,
|
| 66 |
+
"nvcc": NVCC_FLAGS,
|
| 67 |
+
},
|
| 68 |
+
),
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
setup(
|
| 72 |
+
name="activation",
|
| 73 |
+
version="0.1.0",
|
| 74 |
+
description="Custom CUDA normalization kernels for LLM training",
|
| 75 |
+
ext_modules=ext_modules,
|
| 76 |
+
cmdclass={"build_ext": BuildExtension},
|
| 77 |
+
packages=["activation"],
|
| 78 |
+
package_dir={"activation": "torch-ext/activation"},
|
| 79 |
+
python_requires=">=3.10",
|
| 80 |
+
install_requires=["torch>=2.7"],
|
| 81 |
+
)
|