Native Spiking Neural Network (SNN) implementation of the Baby Dragon Hatchling (BDH) architecture โ built for Neuromorphic & Edge AI with Continual Learning.
BDH-Spike bridges the theoretical bio-physical properties of the Baby Dragon Hatchling (BDH) architecture with discrete event-driven Spiking Neural Networks. No floating-point activations inside the core layers. No global backpropagation during inference. Just spikes.
| Invariant | Rule |
|---|---|
| Binary Spike Domain | All activations in core layers are discrete spikes |
| Dual-Weight Plasticity |
|
| Temporal Canonical Shape | All temporal tensors maintain |
| Energy Sparsity First | Target temporal sparsity of 85โ95% silent states. AC and bitwise ops instead of MACs wherever possible. |
BDH-PLIF Membrane Decay
Spike Trigger
Fast Sigmoid Surrogate Gradient (default slope
STDP Trace Decay (3-factor Hebbian learning, fully local)
Spiking networks replace dense Multiply-Accumulate (MAC) streams with sparse Accumulate (AC) events. Synaptic Operations scale with the number of active spikes, not with tensor density:
| Metric | Dense ANN | BDH-Spike |
|---|---|---|
| Core operation | MAC (32-bit float) | AC / POPCNT (bitwise) |
| Activation cost | Every neuron, every step | Only emitting neurons (~5โ15%) |
| Memory traffic | Full weight matrix per step | Active rows only |
| Inference learning | โ Frozen weights | โ
Online STDP ( |
| Target hardware | GPU / TPU | Neuromorphic (Loihi 2) / Edge MCU |
Measured multi-seed ablation study (python -m benchmarks.ablation_study --seeds 0 1 2,
| Ablation Variant | Configuration | Sparsity (%) | SOPs / sample | FLOPs/SOP Ratio | CL Forgetting |
|---|---|---|---|---|---|
| A: Full BDH-Spike | |||||
| B: No BDH Coupling | |||||
| C: No |
|||||
| D: No Homeostasis | |||||
| E: Bitwise vs Surrogate | Float-free vs surrogate graph | โ | โ | โ |
Requirements: Python 3.13+ ยท managed with uv ยท PyTorch 2.x
# clone & create the environment from the lockfile
git clone https://github.com/takzen/bdh-spike.git && cd bdh-spike
uv sync --devOptional โ compile custom CUDA kernels (fused PLIF dynamics, bitwise POPCNT matmul):
uv pip install -e . --no-build-isolation --config-settings "--build-option=--cuda"git clone https://github.com/takzen/bdh-spike.git && cd bdh-spike && uv sync --dev
uv run pytest tests/ -q # 123 tests, 100% green
uv run python -m benchmarks.n_mnist_eval --dataset synthetic # energy reportimport torch
from bdh_spike.core import BDHSpikeCell
cell = BDHSpikeCell(num_channels=64)
spikes, state = cell(torch.randn(16, 4, 64)) # [T, B, C] -> binary spikes [T, B, C]Every emitted activation is a discrete spike
Spike-driven attention โ no Softmax, just associative masking on binary spikes:
import torch
from bdh_spike.core import SpikeDrivenAttention
attn = SpikeDrivenAttention(embed_dim=64, num_heads=4)
y = attn(torch.randn(16, 4, 32, 64)) # [T, B, N, C] -> binary spikes [T, B, N, C]
# Deployment: strictly boolean-integer graph โ zero float tensors after encoding.
hw = SpikeDrivenAttention(embed_dim=64, num_heads=4, mode="bitwise")Dual-weight plasticity โ structural weights by BPTT, episodic weights online by local STDP (never touching autograd):
from bdh_spike.plasticity import DualWeightLinear
syn = DualWeightLinear(fan_in=64, fan_out=32)
current = syn(spikes_in) # differentiable via W_slow
state = syn.plastic_step(spikes_in, spikes_out) # grad-free W_fast updateHomeostatic threshold adaptation keeps firing in the healthy band:
from bdh_spike.plasticity import AdaptiveThreshold
homeo = AdaptiveThreshold(target_rate=0.10)
homeo.observe_sequence(output_spikes) # seizure โ V_th โ ; silence โ V_th โ
homeo.apply_to(cell) # inject into BDHSpikeCell.v_thTerminal telemetry & figures:
from bdh_spike.utils import TelemetryRecorder, ascii_raster
print(ascii_raster(spikes)) # text raster: โ = spike, ยท = silence
rec = TelemetryRecorder(fan_out=32)
rec.update(spikes)
rec.render() # terminal HUD
rec.dump("telemetry.json") # web-dashboard export- Stage 1 โ Repository & environment initialization (uv, Python 3.13, pyproject)
- Stage 2 โ Neuromorphic core:
BDHSpikeCell(PLIF decay, hard reset, fast-sigmoid surrogate, BDH recurrent coupling) - Stage 3 โ Spike-driven attention: softmax-free associative masking on binary spikes
- Stage 4 โ Dual plasticity engine: online STDP + homeostatic threshold adaptation (continual learning stability)
- Stage 5 โ Model assembly: Vision-BDH-Spike backbone + streaming sequence model + spike encoders
- Stage 6 โ Energy metrics & benchmarks: SOPs vs FLOPs tracker, N-MNIST eval, continual-learning split-task test
- Stage 7 โ Diagnostics: spike raster plots, membrane potential traces, telemetry HUD
- Stage 8 โ Documentation, full test pass, public release
Split-task benchmark (python -m benchmarks.ablation_study --seeds 0 1 2, 5 sequential tasks on a shared hidden layer). Structural weights are optimized per task; episodic W_fast adapts online via local STDP while each task stream flows through without global autograd.
Ablation results demonstrate that homeostatic threshold adaptation (
uv run pytest tests/ -v --durations=10 # unit tests must pass 100%
uv run ruff check . --fix && uv run ruff format . # lint & formatEvery completed stage additionally verifies a > 70% spike sparsity assertion via bdh_spike.neuromorphic.metrics.calculate_sparsity.
Released under the MIT License.
Krzysztof Pika