Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 4.3.0 instead.
Reason given by maintainers: Critical bugs fixed in v4.0.4: chunked LIF scan produces incorrect spikes and NaN

NeuraTensor

Fast neuromorphic inference for Python. Spiking neurons meet selective state space models — runs on CPU, CUDA, or Apple Silicon without any compilation hassles.

pip install neuratensor

Requires Python 3.9+ and PyTorch 2.0+.


What this is

Most neuromorphic packages are either academic toys or hardware-locked C++ binaries. NeuraTensor is pure PyTorch — leaky integrate-and-fire neurons with surrogate gradients, a Mamba-style selective SSM with HiPPO initialization, and real spike sparsity (75-90% activations are zero, depending on task complexity and training). It works wherever PyTorch works, compiles with torch.compile, and lets you fine-tune with standard optimizers.

I built this because existing options were either impractical for production or didn't deliver on the efficiency promises. This does both.

Sparsity note: Random-weight models show ~90% sparsity. Trained models typically converge to 70-80% sparsity — the network learns to use more neurons for better accuracy. Use spike_regularization during training to trade accuracy for efficiency.


Quickstart

from neuratensor import InferenceEngine
import torch

engine = InferenceEngine.from_preset("small")   # 80M params, auto device
input_ids = torch.randint(0, 32000, (1, 64))
result = engine.run(input_ids)

print(f"Latency:  {result.latency_ms:.1f} ms")
print(f"Sparsity: {result.metrics['estimated_sparsity_pct']:.1f}%")

No config files, no CUDA extensions to compile, no surprises.


Presets

Preset Params d_model Layers d_state Attention Max seq
pico 3.5M 96 4 8 None 512
nano 14.7M 288 6 16 Every 6th 1024
small 74.4M 640 12 32 Every 6th 2048
medium 333M 1152 20 64 Every 5th 4096
large 1.35B 2048 28 128 Every 7th 8192
from neuratensor import list_presets
list_presets()

Architecture (v4)

Each layer is a FusedSpikeBlock:

input → RMSNorm → expand(2×) → [LIF] → [Selective SSM] → sparse gate → project → + residual
                                                     ↓
                              Optional sliding-window attention every N layers

LIF (Leaky Integrate-and-Fire): Membrane potential accumulates input current, fires a binary spike when crossing threshold, then soft-resets. Differentiable via fast-sigmoid surrogate gradient. Decay constant β is learned per neuron. Chunked parallel scan reduces Python overhead from O(T) to O(T/chunk_size).

Selective SSM: Input-dependent B, C, Δ parameters (Mamba-style selection mechanism). HiPPO-inspired A matrix initialization for multi-scale temporal memory. Zero-order-hold discretization. State carries across calls for streaming inference.

Hybrid attention: Optional sliding-window attention with RoPE every N layers for long-range retrieval. Most layers are pure SNN-SSM (faster, sparser); attention is added only where needed.

Sparse inference: Output projection skips computation for positions with no spike activity during inference (~90% speedup when sparsity > 50%).

All pure PyTorch — no compiled extensions. Works with torch.compile out of the box.


Custom model

from neuratensor import NeuraTensorModel, ModelConfig

config = ModelConfig(
    vocab_size=50000,
    d_model=768,
    n_layers=16,
    d_state=32,
    expand=2,
    attn_every=4,        # attention every 4th layer
    attn_heads=8,
    attn_window=512,
    dropout=0.1,
)

model = NeuraTensorModel(config)
print(f"{model.count_parameters():,} parameters")

input_ids = torch.randint(0, 50000, (4, 128))
logits, states, metrics = model(input_ids)
# metrics: spike_rate, estimated_sparsity_pct, per_layer_spike_rate

Streaming inference

Carry state between calls — useful for real-time or autoregressive generation:

engine = InferenceEngine.from_preset("small")

# Process chunk by chunk, state flows through
for chunk in token_stream:
    result = engine.run(chunk, reset_state=False)
    yield result.logits

# Or use built-in generate
output, metrics = engine.generate(
    prompt_ids, 
    max_new_tokens=128, 
    temperature=0.8,
    top_k=50,
    repetition_penalty=1.1,
)

Training and fine-tuning

from neuratensor import NeuraTensorModel
from neuratensor.training import Trainer, TrainConfig, LoRAConfig, apply_lora

model = NeuraTensorModel.from_preset("small")

# Apply LoRA for efficient fine-tuning
apply_lora(model, LoRAConfig(r=16, alpha=32, target_modules=["in_proj", "out_proj"]))

config = TrainConfig(
    max_steps=10000,
    batch_size=8,
    learning_rate=3e-4,
    warmup_steps=500,
    gradient_accumulation_steps=4,
    spike_regularization=0.05,  # Penalize high spike rates (0.01-0.1 typical)
)

trainer = Trainer(model, config, train_data="data.jsonl")
trainer.train()

# Training will report spike rate — aim for 70-85% sparsity for good accuracy/efficiency balance

# Merge LoRA weights back into base model
from neuratensor.training import merge_lora
merge_lora(model)

Benchmark

neuratensor benchmark small --seq-length 64 --iters 100

Example output (NVIDIA A100):

================================================================
  NeuraTensor SMALL | Benchmark Results
================================================================
  Device:         cuda
  Dtype:          torch.bfloat16
  Parameters:     80,224,256
  Batch size:     1
  Seq length:     64
----------------------------------------------------------------
  Latency mean:   7.2 ms ± 0.4 ms
  Latency p99:    8.1 ms
  Throughput:     138.9 seq/s
----------------------------------------------------------------
  Spike rate:     0.082
  Sparsity:       91.8%
================================================================

Inference server

pip install 'neuratensor[server]'
neuratensor serve --preset small --port 8080

Endpoints: GET /health, GET /info, POST /infer, POST /generate, GET /metrics (Prometheus format).

Docker:

docker build -t neuratensor:4.0.0 .
docker run -p 8080:8080 -e NEURATENSOR_PRESET=small neuratensor:4.0.0

For ECS/EKS, see deploy/ecs_task_definition.json.


Save and load

engine.save("checkpoint.pt")

from neuratensor import InferenceEngine
engine = InferenceEngine.from_checkpoint("checkpoint.pt")

CLI

neuratensor info              # device + backend info
neuratensor presets           # list all presets with param counts
neuratensor benchmark small   # run benchmark
neuratensor serve --preset medium --port 8080

Telemetry

NeuraTensor collects anonymous usage data (SDK version, Python version, OS, preset name, latency) to help prioritize development. No personally identifiable information is collected. Opt out anytime:

export NEURATENSOR_TELEMETRY=0

Or in code:

import os
os.environ["NEURATENSOR_TELEMETRY"] = "0"
import neuratensor

Support

Questions or issues? Reach us at support@neuramorphic.ai

Built by Peter Fullé (Lead Architect) and the team at Neuramorphic, Inc.


License

Apache 2.0. See LICENSE.

Metadata

Release files for neuratensor 4.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neuratensor 4.0.2
File Size Uploaded Provenance Actions
neuratensor-4.0.2.tar.gz 41.0 kB Without provenance Details for neuratensor-4.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for neuratensor 4.0.2
File Interpreter ABI Platform Actions
neuratensor-4.0.2-py3-none-any.whl Python 3 none any Details for neuratensor-4.0.2-py3-none-any.whl

Total release size: 83.9 kB

Release files / neuratensor-4.0.2.tar.gz

Download URL neuratensor-4.0.2.tar.gz
Size 41.0 kB
Tags Source
SHA-256 checksum
How to use checksums
77e94eb87ca16ea5359210f97e075b3db1b7c493e82d27d65987dcbcd0c40e1f
BLAKE2b-256 checksum
How to use checksums
9dfaf72d05ffef93d15556f9e00ab91ed3accd88cb01b286e78db93e5ff5c4af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / neuratensor-4.0.2-py3-none-any.whl

Download URL neuratensor-4.0.2-py3-none-any.whl
Size 42.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3bce17c0836002286ff7a73aff8b3f83ae5c1a755dee025ed4e59c7ab21b827e
BLAKE2b-256 checksum
How to use checksums
a545952a69a346d8a075042b162535d708b75855e7faec89b3d8333f5c1ac04c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for neuratensor 4.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

4.0.2 This release

2 release files No provenance

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