ALReLU activation package for PyTorch with fixed and trainable alpha variants.
Project description
alrelu-torch
PyPI-installable PyTorch package for the ALReLU activation with 2 variants:
ALReLU(default): fixedalpha=0.01TrainableALReLU: trainablealphaparameter
Formula:
ALReLU(x, alpha) = max(abs(alpha * x), x)
Reference
ALReLU paper:
ALReLU: A different approach on Leaky ReLU activation function to improve Neural Networks Performance
https://arxiv.org/abs/2012.07564
Installation
pip install alrelu-torch
From source:
pip install .
Training Examples (MNIST)
Scripts:
- Keras + TensorFlow:
scripts/train_mnist_keras_tf.py - PyTorch:
scripts/train_mnist_torch.py
Direct links:
- https://github.com/MStamatis/ALReLU/blob/main/scripts/train_mnist_keras_tf.py
- https://github.com/MStamatis/ALReLU/blob/main/scripts/train_mnist_torch.py
Run commands (from repo root):
# Keras + TensorFlow
python scripts/train_mnist_keras_tf.py --epochs 5 --variant fixed --alpha 0.01
python scripts/train_mnist_keras_tf.py --epochs 5 --variant learnable --alpha 0.01
# PyTorch
python scripts/train_mnist_torch.py --epochs 5 --variant fixed --alpha 0.01
python scripts/train_mnist_torch.py --epochs 5 --variant learnable --alpha 0.01
Usage
1) Functional API
import torch
from alrelu_torch import alrelu
x = torch.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
y = alrelu(x) # alpha=0.01 by default
2) Fixed module
import torch.nn as nn
from alrelu_torch import ALReLU
model = nn.Sequential(
nn.Linear(32, 64),
ALReLU(alpha=0.01),
nn.Linear(64, 10),
)
3) Trainable alpha module
import torch.nn as nn
from alrelu_torch import TrainableALReLU
model = nn.Sequential(
nn.Linear(32, 64),
TrainableALReLU(alpha_init=0.01, non_negative=True),
nn.Linear(64, 10),
)
Development
Install dev tools:
pip install -e .[dev]
Run tests:
pytest
Build package:
python -m build
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file alrelu_torch-0.1.2.tar.gz.
File metadata
- Download URL: alrelu_torch-0.1.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
401c3f04356144f81d3e309eb2bfd47c27bd1ca16e22c9aff30d75b348cd8987
|
|
| MD5 |
9a6e5960cddf97b1d9666da221ca54f6
|
|
| BLAKE2b-256 |
8aa04ce2d43490e9ae09b9cfb07fc756d5ae8b59a29262b1a093c0429e7a84f2
|
Provenance
The following attestation bundles were made for alrelu_torch-0.1.2.tar.gz:
Publisher:
publish-torch.yml on MStamatis/ALReLU
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alrelu_torch-0.1.2.tar.gz -
Subject digest:
401c3f04356144f81d3e309eb2bfd47c27bd1ca16e22c9aff30d75b348cd8987 - Sigstore transparency entry: 976167128
- Sigstore integration time:
-
Permalink:
MStamatis/ALReLU@b587ada4742ad7de948504259fb8e27248320d16 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MStamatis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-torch.yml@b587ada4742ad7de948504259fb8e27248320d16 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file alrelu_torch-0.1.2-py3-none-any.whl.
File metadata
- Download URL: alrelu_torch-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
701213769077113047566b90fc5c49f965b547e538035c03045aa1b7c043244a
|
|
| MD5 |
62d25a45f80e0ef94b72e6788a4e6230
|
|
| BLAKE2b-256 |
7a384a9bde5b3d44d60192d5a8d0f8dcaafc2cc4b19c962ac39dc145c41cc0f6
|
Provenance
The following attestation bundles were made for alrelu_torch-0.1.2-py3-none-any.whl:
Publisher:
publish-torch.yml on MStamatis/ALReLU
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alrelu_torch-0.1.2-py3-none-any.whl -
Subject digest:
701213769077113047566b90fc5c49f965b547e538035c03045aa1b7c043244a - Sigstore transparency entry: 976167129
- Sigstore integration time:
-
Permalink:
MStamatis/ALReLU@b587ada4742ad7de948504259fb8e27248320d16 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MStamatis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-torch.yml@b587ada4742ad7de948504259fb8e27248320d16 -
Trigger Event:
workflow_dispatch
-
Statement type: