Skip to main content

Astrocyte-Hebbian Spiking Transformer Plugin

A standalone PyTorch plugin containing Astrocyte-Hebbian spiking linear-attention components. This project is intentionally independent from Exact-SNN; no Exact-SNN code, imports, or dependencies are included.

Scope

This is a focused model plugin, not a general SNN framework. It provides:

  • AstrocyteHebbianAttention: multi-head linear attention using binary Q/K/V activations.
  • AstrocyteHebbianBlock: pre-norm Transformer-style block with a spiking FFN.
  • AstrocyteHebbianClassifier: ready-to-train sequence classifier.
  • spike_fn: binary Heaviside forward pass with surrogate gradients.

The implementation avoids an N x N attention matrix by computing the K^T V trace. It still uses ordinary dense PyTorch tensors for projections, normalization, residual paths, and training.

What this is (and is not)

  • Binary activation spikes: the inter-layer signals (Q, K, V, and the FFN hidden activation) are binary Heaviside spikes (0/1).
  • Surrogate gradients: training uses a fast-sigmoid surrogate gradient through the spike threshold; it is not an exact spike-time gradient library.
  • Dense PyTorch execution: forward/backward run on ordinary dense GPU tensors. This is a CPU/GPU software package, not an event-driven neuromorphic-hardware implementation, and reported times/memory are wall-clock/FLOP measurements, not hardware energy.
  • Full-sequence psMNIST mode: the core AstrocyteHebbianClassifier (and the frozen baseline below) is full-sequence attention over N=784 pixels.
  • Separate causal LM experimental mode: a distinct, experimental causal path (CausalAstrocyteLanguageModel) is provided for small language-model proof-of-concept work only.

This is a focused model plugin, not a complete SNN framework.

Install

pip install -e .

For development and tests:

pip install -e .[test]
pytest -q

For the optional psMNIST benchmark:

pip install -e .[benchmark]
python astrohebbian/benchmark.py

For a controlled three-seed summary:

python benchmarks/multi_seed.py --seeds 1 2 3 --output results/multi_seed.json

For the small causal language-model proof of concept:

python benchmarks/lm_prototype.py \
    --data /path/to/pretraining_code.jsonl \
    --max-bytes 10000000 --steps 50 --output results/lm_prototype.json

The causal LM is a separate experimental path. The full-sequence psMNIST model and its baseline remain unchanged.

Example

import torch
from astrohebbian import AstrocyteHebbianClassifier

model = AstrocyteHebbianClassifier(
    input_dim=1,
    d_model=128,
    seq_len=784,
    num_heads=4,
    v_levels=1,
)

pixels = torch.randn(8, 784, 1)
logits = model(pixels)
print(logits.shape)  # torch.Size([8, 10])

Results

Frozen three-seed psMNIST baseline (N=784, 60k train / 10k test, 6 epochs, RTX 3050, batch 64):

Model 3-seed mean test acc Peak VRAM
AstroHebbian Pure SNN 86.82% ± 2.48% ~1004 MB
Transformer (dense O(N²)) 77.80% ± 3.06% ~1565 MB

The SNN beats the dense baseline by +9.03 pts accuracy at ~36% lower peak VRAM. Mean runtime is not a headline figure: seed 2 was a large hardware/runtime outlier, so only accuracy and memory are claimed as reliable. Full per-seed data: results/multi_seed.json; the N-scaling memory crossover is in results/n_scaling.png.

Project status

This is the clean standalone starting point for production hardening. The current attention is full-sequence rather than causal or streaming. Results are tracked in docs/benchmark_baseline.md.

Download files

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

Source Distribution

astrohebbian-0.2.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

astrohebbian-0.2.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file astrohebbian-0.2.0.tar.gz.

File metadata

  • Download URL: astrohebbian-0.2.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.11

File hashes

Hashes for astrohebbian-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2b6b18f4461d6afeb77f34427dd363a46fe56d4341b8a4424803389a773311da
MD5 6ae501c635d2b453cb658058fa220839
BLAKE2b-256 2db9b920bf6d077ec740b8f14c609c9e57a613e69f88df5625d62d9e17ed2ec1

See more details on using hashes here.

File details

Details for the file astrohebbian-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: astrohebbian-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.11

File hashes

Hashes for astrohebbian-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2fb777863e3434b0ce274f115051d1bdc7ec61bf9599266d97240a68897f1cd8
MD5 4f947d0b65d1b125b156808decf7e5cb
BLAKE2b-256 0f771156cf52cef61715f6efc63cb828dd483f4f380202de7710c4527bda1686

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page