Instructions to use kernels-community/activation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Kernels
How to use kernels-community/activation with Kernels:
# !pip install kernels from kernels import get_kernel # a version (or an explicit revision) is required; see the "Files and versions" tab for the available ones kernel = get_kernel("kernels-community/activation", version=1) - Notebooks
- Google Colab
- Kaggle
Download torch-ext/torch_binding.cpp from kernels-community/activation: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/kernels-community/activation/resolve/refs%2Fpr%2F2/torch-ext/torch_binding.cpp
- Command line
-
hf download hf://kernels-community/activation@refs/pr/2/torch-ext/torch_binding.cpp
-
curl -L -o torch_binding.cpp https://huggingface.co/kernels-community/activation/resolve/refs%2Fpr%2F2/torch-ext/torch_binding.cpp
1.35 kB
| TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) { | |
| // Activation ops | |
| // Activation function used in SwiGLU. | |
| ops.def("silu_and_mul(Tensor! out, Tensor input) -> ()"); | |
| ops.impl("silu_and_mul", torch::kCUDA, &silu_and_mul); | |
| // Activation function used in GeGLU with `none` approximation. | |
| ops.def("gelu_and_mul(Tensor! out, Tensor input) -> ()"); | |
| ops.impl("gelu_and_mul", torch::kCUDA, &gelu_and_mul); | |
| // Activation function used in GeGLU with `tanh` approximation. | |
| ops.def("gelu_tanh_and_mul(Tensor! out, Tensor input) -> ()"); | |
| ops.impl("gelu_tanh_and_mul", torch::kCUDA, &gelu_tanh_and_mul); | |
| // FATReLU implementation. | |
| ops.def("fatrelu_and_mul(Tensor! out, Tensor input, float threshold) -> ()"); | |
| ops.impl("fatrelu_and_mul", torch::kCUDA, &fatrelu_and_mul); | |
| // GELU implementation used in GPT-2. | |
| ops.def("gelu_new(Tensor! out, Tensor input) -> ()"); | |
| ops.impl("gelu_new", torch::kCUDA, &gelu_new); | |
| // Approximate GELU implementation. | |
| ops.def("gelu_fast(Tensor! out, Tensor input) -> ()"); | |
| ops.impl("gelu_fast", torch::kCUDA, &gelu_fast); | |
| // Quick GELU implementation. | |
| ops.def("gelu_quick(Tensor! out, Tensor input) -> ()"); | |
| ops.impl("gelu_quick", torch::kCUDA, &gelu_quick); | |
| } | |
| REGISTER_EXTENSION(TORCH_EXTENSION_NAME) | |