kaf_act ๐Ÿš€

February 2, 2025 ยท View on GitHub

PyTorch implementation of a learnable activation function combining base activation and Random Fourier Features (RFF). This package provides a flexible and powerful activation function that can be easily integrated into your neural networks.

Features โœจ

  • Learnable Activation: Combines base activation with RFF for enhanced expressiveness
  • CUDA Support: Fully compatible with GPU acceleration
  • Flexible Configuration: Customizable number of Fourier feature grids, dropout, and base activation
  • Auto Dimension Inference: Automatically detects input dimension during first forward pass

Installation ๐Ÿ“ฆ

cd kaf_act
pip install .

Usage ๐Ÿš€

from kaf_act import RFFActivation
import torch.nn as nn
import torch.nn.functional as F

model = nn.Sequential(
    nn.Linear(128, 256),
    #RFFActivation(num_grids=16, dropout=0.1, activation_expectation=1.64, use_layernorm=False, base_activation=F.gelu),
    RFFActivation(base_activation=F.silu),
    nn.Linear(256, 10)
)

RFFActivation Parameters

ParameterDefaultDescription
num_grids9Number of RFF grid points
dropout0.0Dropout probability for RFF features
activation_expectation1.64Rff initial variance factor
use_layernormFalseEnable LayerNorm before RFF
base_activationF.geluBase activation function

Requirements ๐Ÿ“‹

  • Python >= 3.7
  • PyTorch >= 1.10.0

License ๐Ÿ“„

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing ๐Ÿค

Contributions are welcome! Please open an issue or submit a pull request.

Support ๐Ÿ’ฌ

For any questions or issues, please open an issue on GitHub.