Skip to main content

Triton-powered framework for training and deploying Spiking Transformers.

Project description

Tether

Gemini_Generated_Image_xofloxxofloxxofl

Tether is a Triton-powered framework for training and deploying Spiking Transformers and deep Spiking Neural Networks (SNNs).

We’ve solved the non-differentiability of discrete spikes by implementing high-performance Triton kernels with modular Surrogate Gradients.

Key Features

  • High-Performance Neurons:
    • LIF (Leaky Integrate-and-Fire): Standard spiking neuron with fused Triton kernels.
    • ALIF (Adaptive LIF): Neurons with adaptive thresholds for better temporal dynamics.
    • PLIF (Parametric LIF): Neurons with learnable, per-channel decay and threshold parameters.
  • Modular Surrogate Gradients: Choose from Arctan, Sigmoid, or FastSigmoid to train your SNNs effectively.
  • Linear Spike-Driven Attention: Eliminates the $O(N^2)$ Softmax bottleneck, allowing for massive context windows with significantly lower energy per inference.
  • Data Utilities: SpikingDatasetWrapper and encoding functions (rate_encoding, latency_encoding) to convert static datasets to spike trains.
  • Triton-Powered: Leverages OpenAI's Triton language for custom CUDA kernels, enabling massive speedups (60x+) over vanilla PyTorch.

Installation

This project is managed with uv.

uv sync

Or install dependencies manually:

pip install torch triton numpy

Usage

Using PLIF with Sigmoid Surrogate

import torch
from tether import PLIF, Sigmoid

# Create a Parametric LIF layer with Sigmoid surrogate
# Decay and threshold are learnable vectors per neuron
layer = PLIF(
    n_neurons=128, 
    init_decay=0.9, 
    surrogate=Sigmoid(alpha=4.0)
).cuda()

# Input sequence: (Time, Batch, Neurons)
x = torch.randn(32, 16, 128).cuda()
spikes = layer(x)

Training a Spiking Language Model

The train_stories.py script demonstrates training a Spiking-LLM on the TinyShakespeare dataset.

python train_stories.py

Data Encoding

from tether.data import SpikingDatasetWrapper, rate_encoding
from torchvision.datasets import MNIST

# Wrap MNIST to output spike trains
spiking_mnist = SpikingDatasetWrapper(
    MNIST(root="./data", download=True, train=True),
    encode_fn=lambda x: rate_encoding(x, n_steps=10)
)

Architecture

  • tether.kernels: Custom Triton kernels for LIF, ALIF, and PLIF.
  • tether.functional: PyTorch autograd functions wrapping the Triton kernels.
  • tether.nn: Neural network modules including LIF, ALIF, PLIF, SpikingSelfAttention.
  • tether.data: Utilities for spike encoding and dataset wrapping.

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

tetherpy-0.1.0.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

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

tetherpy-0.1.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tetherpy-0.1.0.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tetherpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ce63dfc57edba35355d1e851dde6fe09eb0b1f3a0a87d945ae008246ea0d09fa
MD5 aa0bad2d6b94efc01b1ddcb21440b174
BLAKE2b-256 b8a7c4b18dbbf6610d5337355eedf6864373f6428e422cc0ab63358ee098527b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetherpy-0.1.0.tar.gz:

Publisher: release.yml on Khushiyant/tether

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: tetherpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tetherpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d4b573a8bef19cf841f6b531c826cedc5997b8a5d0e40dbef866bb11ebef507
MD5 411a5561581cf807ece5a35749245900
BLAKE2b-256 22a0bfaa311e5f5ce3f5255d92db35046e102735d9eb10a2cb01b824a818692e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetherpy-0.1.0-py3-none-any.whl:

Publisher: release.yml on Khushiyant/tether

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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