Skip to main content

Compact-support piecewise-polynomial activation functions with tunable sparsity

Project description

Steklov Activations

Compact-support piecewise-polynomial activation functions with tunable sparsity.

Paper: Steklov Activations: Piecewise-Polynomial Gates with Compact Support and Tunable Sparsity

What is this?

SteklovSiLU is a drop-in replacement for GELU/SiLU/ReLU that produces exact zeros outside a finite support region. One parameter α controls the support width:

  • α = 2.0 → approximates GELU (sup error < 0.0091)
  • α = 0.8 → 28–64% of activations are exactly zero per token
  • α = 0.1 → 87% zeros, 98.4% natural NVIDIA 2:4 compliance
  • α = 0.005 → 90% zeros, 99.2% compliance, quality matches SiLU

The exact zeros enable structural pruning (permanently remove dead neurons) and hardware-accelerated N:M sparse inference.

Install

pip install steklov-activations

# With Triton kernel support
pip install steklov-activations[triton]

Quick Start

Drop-in activation replacement

from steklov_activations import SteklovSiLU

# GELU-like (α=2.0, sup error < 0.0091)
act = SteklovSiLU(alpha=2.0)

# High sparsity
act = SteklovSiLU(alpha=0.1)

# Learnable α (network finds its own sparsity level)
act = SteklovSiLU(alpha=2.0, learnable=True)

Swap activations in an existing architecture

from transformers import AutoConfig, AutoModelForCausalLM
from steklov_activations import swap_activation

# Initialize model with random weights
config = AutoConfig.from_pretrained("gpt2")
model = AutoModelForCausalLM.from_config(config)

# Replace all GELU activations with SteklovSiLU
swap_activation(model, alpha=0.8)
# Replaced 12 activation(s) with SteklovSiLU(alpha=0.8, order=3)

# Train from scratch (post-hoc swap on pretrained models
# does NOT produce meaningful sparsity)

Profile inactivity

from steklov_activations import InactivityProfiler

profiler = InactivityProfiler(model)

# Run calibration data through the model
for batch in calibration_loader:
    with torch.no_grad():
        model(**batch)

# Get report
report = profiler.report(threshold=0.999)
print(report.summary())
# Inactivity Report (50,000 tokens, threshold=99.9%)
#   Dynamic sparsity (per-token zeros): 64.4%
#   Structural sparsity (permanently dead): 9.0%
#   ...

profiler.remove_hooks()

Prune dead neurons

from steklov_activations import prune_inactive_neurons

# Remove permanently dead neurons from weight matrices
pruned = prune_inactive_neurons(model, report)
# Total: pruned 2,800 neurons across 12 layers

# Model is now physically smaller and faster
# Save the pruned model
model.save_pretrained("my-model-pruned")

Key Results (from paper)

Setting Result
Vision (CIFAR-10/100, 5 seeds) Steklov α=0.8 wins all 4 benchmarks
GPT-2 Small (124M, 5 seeds) 22.39 PPL vs GELU 22.97 (p=0.30)
GPT-2 Medium (354M, 3-4 seeds) Matches GELU within seed variability
LLaMA 105M (3 seeds) All variants beat SiLU
LLaMA 105M α=0.005 (1 seed) 90% zeros, PPL better than dense SiLU
Pruning 7% of 354M neurons +0.05 PPL (magnitude pruning: model collapse)
N:M compliance at α≤0.1 98–99% natural 2:4; SiLU: 0%
Inference after pruning 3–5% faster than unpruned GELU

Important Notes

  • Train from scratch. Post-hoc activation swap on pretrained models does not produce meaningful sparsity. The network must train with compact support to develop the inactivity patterns.
  • Single α is sufficient. A single global α shared across all layers works as well as per-layer α.
  • Architecture matters. GPT-2-style models produce permanently dead neurons (good for pruning). LLaMA-style models produce per-token zeros with no permanent death (good for N:M hardware sparsity).

Citation

@article{masalskikh2026steklov,
  author  = {Masalskikh, A.},
  title   = {Steklov Activations: Piecewise-Polynomial Gates with Compact Support and Tunable Sparsity},
  journal = {Zenodo},
  year    = {2026},
  doi     = {10.5281/zenodo.19454642},
  url     = {https://doi.org/10.5281/zenodo.19454642}
}

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

steklov_activations-0.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

steklov_activations-0.1.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file steklov_activations-0.1.0.tar.gz.

File metadata

  • Download URL: steklov_activations-0.1.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for steklov_activations-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cb8b26069faeef40359adf9659472d62ccca51ed55f3773c542e465b71950ea4
MD5 144927551496b7a80b5ac8ff91952478
BLAKE2b-256 be5fd6b41c455059f2a71273bb82cd0134a42783b30e01d3ab2f17ae1cb76af3

See more details on using hashes here.

File details

Details for the file steklov_activations-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for steklov_activations-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b90f0240dd7326eba96c9378aabde51760935808213f38e3fa5df8e9804eb22
MD5 4ea3c763b537028d3ae7d9ca43810c25
BLAKE2b-256 a7d3948d6ccd53e239b22a164774d8147ddaf86b7448724d66c5a1ff9417367a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page