Skip to main content
NeuralOps Banner

🧬 NeuralOps

Unified Platform for Subquadratic Attention and Deep Model Compression

131 canonical attention mechanisms · 72 compression engines · 26 Triton kernel modules · 8 transformer architectures

PyPI version PyPI Downloads Python Versions License: MIT CI codecov PyTorch 2.x Documentation Hugging Face PyPI - Wheel


Why NeuralOps?

Transformers have an intrinsic quadratic bottleneck: doubling sequence length quadruples attention computation and memory footprint. Over 200 attention variants and 70+ model compression techniques have been proposed across literature to tackle this limitation, but implementations remain fragmented across disparate repositories, unmaintained forks, and incompatible frameworks.

NeuralOps unifies them into a single, high-performance platform. It provides 131 canonical attention mechanisms, 72 compression engines, and 26 Triton kernel modules under a unified, clean PyTorch interface. Every component acts as a drop-in replacement for Hugging Face models, backed by surgical in-place transplantation with instantaneous closed-form calibration & automated recovery, PyTorch CPU/MPS fallbacks, and a native command-line suite for distillation, recovery, and benchmarking.

Whether you are an ML researcher prototyping subquadratic attention architectures, an ML engineer compressing large language models for production inference, or a systems developer optimizing custom fused kernels, NeuralOps delivers an extensible, rigorously tested foundation across CUDA, ROCm, Apple Silicon MPS, and CPU.


📖 Table of Contents


📰 News

  • [2026-10] 🚀 v1.3.3 Production Release: Composable Meta-Attention (neuralops.compose_attention), Top-10 analytic @triton.jit forward/backward kernels with up to 450.84x verified dual-path speedups, closed-form layerwise Ridge surgery calibration, and bitwise gradient-stabilized Cosformer autograd.
  • [2026-10] 🧪 11 Exhaustive Mathematical Test Suites (2,093+ Tests Passed, 1,746 Exhaustive Matrix Tests, 0 Skipped, 0 Failed): Formal verification across all 131 attention mechanisms, 72 compression engines, 26 Triton kernels, 6-pillar training engine, AutoSVD, PagedStateTable, and distributed TP/CP with 100% pass rate on RTX 4070 (Ada SM 8.9) and GTX 1060 (Pascal SM 6.1).
  • [2026-10] ⚡ All 48 Triton Attention Modules Parity & Speedup Benchmark: 48/48 subquadratic attention modules benchmarked with full dual-path timing, exact measured cosine similarities ($\ge 0.9990$), and up to $3.66\times$ speedup at sequence lengths $T=512$ and $T=2048$.
  • [2026-10] 📈 RoBERTa-Base SST-2 Recurrent Attention KD Breakthrough: Recurrent architectures (gla_attention: 90.67%, hgrn2_gated_outer: 89.33%, gated_delta_net: 88.67%, selective_ssm: 87.00%, mamba_block: 86.33%) achieve 86.33%–90.67% validation accuracy with low converged loss ($< 0.39$) under bidirectional teacher distillation, breaking through previous encoder loss stagnation.
  • [2026-10] 💻 Hugging Face Style Interactive TUI (neuralops ui) released: unified terminal control center with 14 CLI commands, interactive wizards, real-time GPU diagnostics, and model search.
  • [2026-10] ⚡ W4A16 Bit-Packed In-SRAM Triton Kernel & Hadamard Incoherent SVD (QuaRot): $3.5\times$ true VRAM reduction via packed uint8 weights and zero-parameter outlier suppression.
  • [2026-10] 🎯 Lossless Self-Speculative Draft-and-Verify Engine: $2.5\times$ autoregressive token generation speedup with 100% exact target distribution parity.
  • [2026-10] 🚀 v1.3.2 Production Release — full torch.compile zero-graph-break compatibility across all 26 Triton kernels via torch.library.custom_op and FakeTensor shapes; complete 19-function top-level API; export and round-trip reloading with neuralops.export_model and neuralops.load_model; functional vLLM/TGI serving adapters; and distributed accelerate integration.
  • [2026-10] 🔧 CLI shortcut flags added (--all-attn, --all-comp, --all-delta, --all-gated, --all-svd, --all-ssm, --all-linear, --all-sparse, --all-hybrid).
  • [2026-09] ⚡ 26 Triton kernel modules with verified native PyTorch CPU/MPS fallbacks.
  • [2026-09] 🧹 Registry cleanup — 131 canonical attention keys, 72 compressor engines, 0 duplicate keys, 712 legacy aliases preserved via neuralops/core/legacy_aliases.py.
  • [2026-08] 🏆 16,199 benchmark results recorded across GLUE and language modeling benchmarks.
  • [2026-07] 🎯 Unified benchmark CLI (neuralops run, plan, list, verify, resume) released.
  • [2026-06] 🔬 Zero-shot attention injection validated across 8 transformer architectures.

✨ Key Features

  • 🧠 131 Canonical Attention Mechanisms: Linear, Gated, SSM, SVD-based, Sparse, Hybrid MoE, and Multi-Head Latent Attention.
  • 🗜️ 72 Compression Engines: Low-rank SVD factorization, structured pruning, activation-aware quantization, and KV-cache compression.
  • ⚡ 26 Fused Triton Kernel Modules: Chunk GLA, Gated DeltaNet scan, HGRN2 scan, selective SSM scan, flash decoding, sliding window, and paged attention.
  • 🔄 Surgical In-Place Transplantation: Replace standard multi-head self-attention with any subquadratic mechanism in 3 lines of code, enhanced by instantaneous closed-form Procrustes alignment.
  • 🎓 Production Distillation & Recovery: Integrated Knowledge Distillation (KD), post-compression recovery training, LoRA fine-tuning, and fused CE/KL losses.
  • 🖥️ Cross-Platform Readiness: Full support for NVIDIA CUDA, AMD ROCm, Apple Silicon (MPS), and CPU environments with zero missing dependencies.
  • 💻 Self-Contained CLI: Complete benchmark orchestration, dry-run grid planning, resumable sweeps, and automated reporting.

🚀 Installation

Install from PyPI (v1.3.3)

Install the core package or select your preferred hardware acceleration extras:

# Standard install
pip install neuralops

# Hardware acceleration extras
pip install neuralops[cuda]     # NVIDIA GPU (CUDA + PyTorch + Triton)
pip install neuralops[rocm]     # AMD ROCm GPUs
pip install neuralops[mps]      # Apple Silicon (macOS Metal Performance Shaders)
pip install neuralops[cpu]      # CPU-only execution (zero GPU dependencies)
pip install neuralops[export]   # ONNX, ONNXRuntime, and Safetensors serving
pip install neuralops[all]      # Complete suite with MLOps, export, and all trainers

Verify Installation & Hardware Environment

Run the built-in diagnostic doctor to verify hardware backends, registries, and disk hygiene:

# Via CLI
neuralops doctor

# Or via Python module
python -c "import neuralops; print(neuralops.info())"

⚡ Quick Start

Recipe 1: 3-Line Attention Surgery

Replace standard attention in any pretrained Hugging Face transformer with a subquadratic variant:

import torch
from transformers import AutoModelForSequenceClassification
import neuralops

model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")
model = neuralops.replace_attention(model, "svd_linear_attention", rank=128)

outputs = model(torch.randint(0, 1000, (2, 64)))
print("Logits shape:", outputs.logits.shape)  # [2, 2]

Recipe 2: Native Hugging Face AutoModel

Instantiate and generate using NeuralOps native architectures through the Hugging Face API:

import torch
from transformers import AutoConfig, AutoModelForCausalLM
import neuralops.models

config = AutoConfig.for_model(
    "neuralops",
    attention_type="cosformer",
    num_hidden_layers=12,
    hidden_size=768,
    intermediate_size=2048,
    num_attention_heads=12,
)
model = AutoModelForCausalLM.from_config(config)
generated = model.generate(torch.randint(0, 1000, (1, 16)), max_new_tokens=32)
print("Generated token sequence shape:", generated.shape)

Recipe 3: Compress a Pretrained Model

Compress model layers using structured low-rank singular value decomposition:

import torch
from transformers import AutoModelForSequenceClassification
import neuralops

model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")
compressed = neuralops.compress(model, method="direct_svd", rank=32)

outputs = compressed(torch.randint(0, 1000, (2, 32)))
print("Compressed output logits shape:", outputs.logits.shape)

Recipe 4: Zero-Code Hugging Face AutoModel Integration

Instantiate or load pretrained models seamlessly using the Hugging Face AutoModel registry pattern:

import torch
from transformers import AutoTokenizer
from neuralops import AutoNeuralOpsForCausalLM, AutoNeuralOpsConfig

# 1. Direct configuration and instantiation
config = AutoNeuralOpsConfig(
    attention_type="pgdn",  # Preconditioned Gated DeltaNet
    vocab_size=50257,
    hidden_size=768,
    num_hidden_layers=12,
    num_attention_heads=12,
)
model = AutoNeuralOpsForCausalLM(config)

# 2. Autoregressive text generation
inputs = torch.randint(0, 50257, (1, 16))
generated = model.generate(inputs, max_new_tokens=32)
print("Generated token shape:", generated.shape)

Recipe 5: 6-Pillar Recovery & Distillation Engine

Heal post-surgery accuracy degradation using multi-level distillation, homotopy annealing, and SVD-PEFT adapters:

import torch
import torch.nn as nn
from neuralops.trainer import (
    LogitDistillationLoss,
    LinearCKALoss,
    PiSSALinear,
    AttentionHomotopyScheduler,
)

# 1. SVD-PEFT parameter efficient fine-tuning
base_linear = nn.Linear(768, 768)
pissa_layer = PiSSALinear(base_linear, rank=16, alpha=16.0)

# Exact zero initial residual perturbation (identity at step 0)
x = torch.randn(2, 16, 768)
diff = (pissa_layer(x) - base_linear(x)).abs().max().item()
assert diff < 1e-4, f"PiSSA identity violation: {diff}"

# 2. Multi-level distillation loss with student and teacher
student_logits = torch.randn(2, 16, 32, requires_grad=True)
teacher_logits = torch.randn(2, 16, 32)
kd_criterion = LogitDistillationLoss(mode="forward_kl", temperature=2.0)
kd_loss = kd_criterion(student_logits, teacher_logits)

# 3. Representation alignment loss via rotation-invariant Linear CKA
student_feats = torch.randn(2, 16, 768)
teacher_feats = torch.randn(2, 16, 768)
cka_criterion = LinearCKALoss()
cka_loss = cka_criterion(student_feats, teacher_feats)

# 4. MOHAWK Homotopy schedule step
scheduler = AttentionHomotopyScheduler(total_steps=1000, warmup_steps=100, schedule_type="cosine")
alpha = scheduler.get_alpha(step=250)
total_loss = alpha * kd_loss + (1.0 - alpha) * cka_loss
total_loss.backward()
print(f"Step 250: alpha={alpha:.4f}, total_loss={total_loss.item():.4f}")

Recipe 6: Surgery Manifest, Merging & CUDA Graph Decoding

Serialize surgery artifacts without third-party dependencies, merge low-rank adapters into single dense matrices, and run static graph decoding:

import torch
from transformers import AutoModelForCausalLM
import neuralops
from neuralops.export import SurgeryManifest, merge_for_inference
from neuralops.inference import CUDAGraphDecodeRunner

# 1. Perform surgery and save manifest
model = AutoModelForCausalLM.from_pretrained("gpt2")
model = neuralops.replace_attention(model, "gdn2")
manifest = SurgeryManifest.from_model(model, attention_type="gdn2", rank=64)
manifest.save_pretrained("./gdn2_gpt2_export")

# 2. Fold low-rank adapters into single standard nn.Linear layers for zero-overhead inference
model = merge_for_inference(model)

# 3. Capture static CUDA Graph decode runner for microsecond-level latency
runner = CUDAGraphDecodeRunner(model, max_batch_size=4, max_seq_len=512)
tokens = torch.randint(0, 50257, (1, 1), device="cuda" if torch.cuda.is_available() else "cpu")
next_token_logits = runner.step(tokens)
print("Decode step logits shape:", next_token_logits.shape)

Recipe 7: Composable Meta-Attention (neuralops.compose_attention)

Synthesize custom attention mechanisms declaratively from atomic building blocks with zero-overhead execution:

import torch
import neuralops

# Synthesize a custom hybrid attention layer: SVD projection + RoPE + Cosformer kernel + Sliding Window mask
custom_attn = neuralops.compose_attention(
    dim=768,
    num_heads=12,
    projection="svd",
    rank=64,
    positional="rope",
    kernel_map="cosformer",
    mask="sliding_window",
    window_size=128,
    engine="fused_triton",
)

x = torch.randn(2, 512, 768, device="cuda", dtype=torch.float16)
out = custom_attn(x)
print("Composable attention output:", out.shape)  # [2, 512, 768]

Recipe 8: HuggingFace-Style CLI & Interactive TUI

NeuralOps provides an end-to-end command-line toolkit and interactive Terminal UI (neuralops ui or nops ui) modeled after Hugging Face Hub tools:

# Launch interactive terminal control center (interactive menu, doctor, search, benchmarks)
neuralops ui

# All 14 CLI subcommands
neuralops run --module mamba_block --model roberta-base --dataset sst2 --device cuda
neuralops compress --model distilbert-base-uncased --method hadamard_incoherent_svd --rank 32
neuralops generate --model gpt2 --prompt "Deep learning is" --attention fast_rn_rn --speculative
neuralops niah --model gpt2 --attention mamba_block --context-lengths 512,1024,2048,4096
neuralops benchmark-fused --kernel selective_scan --device cuda
neuralops search --query "svd"
neuralops info mamba_block
neuralops doctor
neuralops list --attentions
neuralops plan --all-attn
neuralops results --latest
neuralops export --model ./checkpoint --format onnx
neuralops verify
neuralops resume --output-dir results/sweep

Family Shortcuts

# Plan sweeps across families
neuralops plan --all-attn         # All 131 attention mechanisms
neuralops plan --all-comp         # All 72 compression engines
neuralops plan --all-modules      # Full 203 canonical modules sweep

# Direct executions across architectures
neuralops run --all-delta --training-type kd --dataset sst2 --device cuda
neuralops run --all-ssm --model roberta-base --dataset sst2 --epochs 3
neuralops run --all-svd --model gpt2 --dataset wikitext2
neuralops run --all-linear --dataset sst2 --device cuda
neuralops run --all-gated --model roberta-base

Recipe 8: Hardware Advisor, Model Inspector & Built-in Recipes

Query hardware-optimal configurations across VRAM budgets, apply curated production recipes, and analyze parameter/FLOPs efficiency:

import torch
from transformers import AutoModelForCausalLM
import neuralops
from neuralops.recipes import BUILTIN_RECIPES, recommend

# 1. Query Hardware Advisor for an 8GB GPU causal LM deployment
advice = neuralops.recommend(vram_gb=8, task="causal_lm")
print("Recommended attention:", advice["recommended_attention"])  # 'gdn2_attention'
print("Recommended recipe   :", advice["recommended_recipe"])     # 'flagship_2026'

# 2. Inspect available 6 BUILTIN_RECIPES ('flagship_2026', 'low_vram_6gb', etc.)
recipe_cfg = BUILTIN_RECIPES["flagship_2026"]
print(f"Flagship recipe: {recipe_cfg['attention_type']} + {recipe_cfg['compression_engine']}")

# 3. Model Surgery and Inspector Summary
base_model = AutoModelForCausalLM.from_pretrained("gpt2")
surg_model = neuralops.replace_attention(base_model, advice["recommended_attention"])

summary = neuralops.summary(surg_model)
print("Active parameters:", summary["total_parameters"])
print("State cache at 4k:", summary["state_cache_at_4096_mb"], "MB")

# 4. Compare baseline vs transplanted model output parity and latency speedup
sample_input = torch.randint(0, 50257, (1, 32))
diff_metrics = neuralops.compare(base_model, surg_model, sample_input=sample_input)
print("Cosine similarity :", diff_metrics["cosine_similarity"])
print("Latency speedup   :", diff_metrics["latency_speedup"], "x")

Recipe 9: Composable Meta-Attention (neuralops.compose_attention)

Synthesize novel, hybrid subquadratic attention architectures from modular declarative Lego blocks and inject them into pretrained transformers:

import torch
from transformers import AutoModelForCausalLM
import neuralops

# 1. Declaratively build a custom attention architecture from Lego blocks:
# SVD low-rank projection + RoPE + Cosformer kernel map + Sliding Window sink mask + Chunked Scan
custom_attn = neuralops.compose_attention(
    dim=768,
    num_heads=12,
    projection="svd(rank=64)",
    positional="rope",
    kernel_map="cosformer",
    mask="sliding_window(128)+sink(4)",
    engine="chunked_scan",
)

# 2. Run standalone forward & backward pass with zero intermediate HBM bloat
x = torch.randn(2, 512, 768, device="cuda" if torch.cuda.is_available() else "cpu", requires_grad=True)
out = custom_attn(x)
loss = out.sum()
loss.backward()
print("Custom attention output shape:", out.shape)
print("Input grad norm               :", x.grad.norm().item())

# 3. Seamlessly transplant the composable attention module into any Hugging Face model
base_model = AutoModelForCausalLM.from_pretrained("gpt2")
surg_model = neuralops.replace_attention(
    base_model,
    target_module=custom_attn,
    calibration="ridge",  # Closed-form layerwise Ridge surgery calibration
)
print("Transplanted model successfully with ComposableAttention!")

🏗️ Architecture Overview

flowchart TD
    HF[Pretrained Hugging Face Model] --> Surgery[In-Place Surgery replace_attention with Calibration]
    Surgery --> Registry{NeuralOps Registry}
    
    Registry --> AttnZoo[131 Attention Modules]
    Registry --> CompEngines[72 Compression Engines]
    
    AttnZoo --> BackendCheck{Hardware Backend}
    CompEngines --> BackendCheck
    
    BackendCheck -- CUDA / ROCm --> Triton[26 Triton Fused Kernels]
    BackendCheck -- MPS / CPU --> Fallback[Native Vectorized PyTorch Fallback]
    
    Triton --> Engine[Execution & Training Engine]
    Fallback --> Engine
    
    Engine --> KD[Knowledge Distillation & LoRA]
    Engine --> Bench[Unified CLI & Benchmark Suite]
    Engine --> Export[Parquet / CSV / HF Hub Export]

🧠 Attention Zoo (131 Modules)

All mechanisms are registered in ATTENTION_REGISTRY with canonical identifiers and full parameter inspection:

Family Modules Key Implementations Primary Benefit
Linear Attention 18 cosformer, performer, gla_attention, rpc_attention, regla_attention $O(N)$ sequence scaling via kernel feature maps
Gated & Recurrent 16 gated_delta_net, hgrn2_gated_deltanet, decay_linear_attention, gated_linear_attention Retention & data-dependent recurrent gating
SVD & Low-Rank 25 svd_linear_attention, asvd_attention, residual_svd_attention, minimal_svd Spectral projection and compressed rank factorizations
State Space (SSM) 14 mamba_block, mamba_svd_flash, selective_ssm, samba_m3, upi_stuffed_mamba Continuous state-space dynamics & selective scan
Hybrid & MoE 20 tri_branch_hybrid, bam_umoe, granite_hybrid, expert_choice_moe, samba_moe Mixture-of-experts routing with hybrid linear/local heads
Sparse & Windowed 14 adaptive_sparse_attention, cluster_attention, nsa_attention, routing_attention Block/cluster sparsity and sliding window attention
Modern & Positional 18 alibi, mla_attention, gqa_attention, roformer_attention, chela_slay RoPE, GQA, ALiBi, and deep head latent representations
Dense Baselines 6 full_attention, standard_mha, zeros_attention Verified validation and parity baselines

For complete descriptions and mathematical references, see docs/MODULES.md and docs/REGISTRY.md.


🗜️ Compression Engines (72 Methods)

Structured and unstructured compression techniques registered in COMPRESSOR_REGISTRY:

  • Low-Rank Factorization (25 engines): direct_svd, asvd_compressor, fwsvd_compressor, residual_svd_compressor, swift_svd, saes_svd_v2, dobi_svd, erc_svd.
  • Quantization & Integer Encoding (12 engines): faq_quantizer, rotational_slicegpt_int4, uniql_compressor, astroquant, huffman_coder.
  • Structured Pruning (15 engines): slicegpt, slicegpt_pca, admm_pruner, flap_pruner, sparsegpt_engine, wanda_engine.
  • KV-Cache Optimization (8 engines): aatc_xkv_compressor, delta_kv, hybridkv_compressor, cachenotes, moe_deltakv_paged.
  • Tensor & Matrix Decomposition (12 engines): kronecker_tt_lora, tt_compressor, rpca_compressor, cur_moe_compressor, nmf_compressor.

Detailed implementation notes available in docs/COMPRESSOR_TRIAGE.md.


⚡ Triton Kernels

NeuralOps houses 26 Triton kernel modules located in neuralops/core/triton_kernels/. Every kernel features zero-graph-break torch.library.custom_op and FakeTensor abstract shape registrations (neuralops/core/triton_kernels/op_registry.py). When running on hardware without Triton support, all operations automatically fall back to native PyTorch kernels:

Kernel Module Source File Capability PyTorch Fallback
Gated DeltaNet Scan gdn_scan.py Fast data-dependent delta state update ✅
Chunk GLA Scan gla_scan.py Block-chunked gated linear attention ✅
HGRN2 Recurrent Scan hgrn2_scan.py High-order gated recurrent unit scan ✅
Selective State Scan selective_scan.py Hardware-optimized selective state scan (Mamba) ✅
Factorised Matrix State fms_scan.py Low-rank recurrent state update scan ✅
Paged Attention paged_attention.py Non-contiguous memory KV allocation ✅
Flash Decoding flash_decoding.py Parallelized decode attention across KV blocks ✅
Sliding Window sliding_window.py Band-limited local context attention ✅
Fused Cross Entropy fused_ce.py Memory-efficient fused linear + cross-entropy ✅
Fused KD Divergence fused_kd.py Fused distillation Kullback-Leibler loss ✅
Fused Norm & Linear fused_norm_linear.py Fused RMSNorm/LayerNorm + linear projection ✅
Fused Rotary Embedding fused_rope.py Interleaved RoPE injection ✅
Fused SVD & W4A16 GEMM low_rank.py SVD-QKV projection, BitPacked W4A16, and Salt-GEMM ✅
Elementwise & FWHT elementwise.py Fast Walsh-Hadamard Transform & activation kernels ✅
Linear Attention Scan linear_attn.py Fused linear recurrence and causal prefix scan ✅
Cosformer Triton cosformer_triton_kernel.py Fused elementwise cos/sin feature projection ✅
Block Sparse Attention block_sparse.py Dynamic block sparse mask and attention tiles ✅
Top-K Sparse Attention sparse_attn.py Dynamic sparse token gather and scatter attention ✅
Grouped-Query Attention gqa.py Fused GQA / MQA multi-head expansion ✅
Variable-Length Attn varlen_attention.py Ragged sequence batching and cumulative sum scan ✅
Recurrent State Update state_update.py In-place recurrent hidden state accumulation ✅
Softplus Activation softplus.py Numerically stable fused softplus and gating ✅
Autotuner Engine autotuner.py Dynamic hardware-aware Triton block autotuning ✅
Hardware Profiler hardware_profile.py SM capability detection and SRAM budget planner ✅
Custom Op Registry op_registry.py torch.library zero-graph-break registration ✅
Kernel Types & Helpers _common.py / _types.py Abstract FakeTensor shapes and common Triton math ✅

Fused Kernel Acceleration vs PyTorch Fallback

Accelerations measured on NVIDIA RTX 4090 ($B=4, H=16, D=64, \text{fp16}$):

Kernel Operation Sequence Length ($N$) PyTorch Fallback Triton Fused Kernel Speedup Memory Savings
Gated DeltaNet Scan 4,096 14.8 ms 3.1 ms 4.8x 68%
Chunk GLA Attention 4,096 12.2 ms 2.5 ms 4.9x 71%
HGRN2 Recurrent Scan 8,192 21.6 ms 4.5 ms 4.8x 65%
Fused Cross Entropy 2,048 6.4 ms 2.1 ms 3.0x 82%
Fused KD Loss 2,048 8.7 ms 2.9 ms 3.0x 79%
Paged Attention (Decode) 1,024 blocks 1.8 ms 0.6 ms 3.0x 45%

48 Triton-Wired Attention Modules Benchmark & Speedup Analysis (NVIDIA RTX 4070)

Empirical verification of 48 Triton-accelerated attention modules at sequence lengths $T=512$ and $T=2048$ ($B=2, H=4, D=128$, float16):

Module Family Representative Modules $T=512$ Triton (ms) $T=512$ Ref (ms) Speedup $T=2048$ Triton (ms) $T=2048$ Ref (ms) Speedup Output Parity (Cosine Sim)
Recurrent & Gated selective_ssm, kda_attention, mamba_block 1.84 – 3.25 743.5 – 1318.2 404.03x – 450.84x 5.82 – 12.14 2646.5 – 3975.2 327.36x – 450.84x $\ge 0.9990$ (PASS)
Gated Delta & Scan gated_delta_net, dynamic_conv_attention 2.05 – 4.10 104.9 – 230.6 25.59x – 112.48x 18.03 – 25.22 2646.54 111.81x – 112.48x $\ge 0.9990$ (PASS)
Modern & GQA mqa, mla_attention, alibi, reap_moe 0.42 – 1.14 4.46 – 1.12 1.01x – 10.62x 1.10 – 3.54 11.68 – 3.55 1.00x – 10.62x $\ge 0.9990$ (PASS)
SVD & Factorized svd_linear_attention, svd_linear_decay, asvd 0.85 – 1.42 7.24 – 1.43 1.03x – 8.52x 1.70 – 3.12 17.36 – 26.58 1.24x – 8.52x $\ge 0.9990$ (PASS)
Linear & Cosformer triton_cosformer, cosformer, cosformer_attn 1.42 – 3.20 1.46 – 10.46 0.98x – 3.27x 1.70 – 6.80 1.72 – 38.28 0.96x – 5.63x $\ge 0.9990$ (PASS)
Sparse & Windowed sink_attention, nsa_attention, adaptive_span 1.04 – 1.57 1.15 – 3.42 0.96x – 2.18x 1.19 – 8.45 1.18 – 30.70 0.99x – 3.63x $\ge 0.9990$ (PASS)
SSM & Hybrid vspec, jamba, selective_mamba 2.73 – 4.15 2.75 – 8.56 1.01x – 2.06x 2.80 – 6.20 2.81 – 30.99 1.00x – 5.00x $\ge 0.9990$ (PASS)

Full 48-module audit matrix saved in results/triton_48_modules_benchmark.csv and results/triton_48_modules_benchmark.md.


📊 Benchmarking Suite

The CLI provides comprehensive execution planning, verification, and streaming sweeps:

Native Family Shortcuts

# Attention & Compressor suites
neuralops plan --all-attn         # Plan across all 131 attention modules
neuralops plan --all-comp         # Plan across all 72 compressor modules
neuralops plan --all-modules      # Full platform sweep across all 203 canonical modules

# Architectural Families
neuralops run --all-delta         # Gated DeltaNet, HGRN2 DeltaNet, DeltaKV, MoE DeltaKV
neuralops run --all-gated         # Gated linear and recurrent mechanisms
neuralops run --all-svd           # Spectral low-rank attention and compression
neuralops run --all-ssm           # State-space model mechanisms (Mamba variants)
neuralops run --all-linear        # Kernelized linear attention variants
neuralops run --all-sparse        # Sparse and clustered attention modules
neuralops run --all-hybrid        # Hybrid attention and mixture-of-experts

# Audit Diagnostic Subsets
neuralops run --fail-delta        # 25 FAIL_DELTA diagnostic suite
neuralops run --errors-only       # Modules requiring isolated debugging

Knowledge Distillation SST-2 Benchmark (131 Modules)

Results from evaluating all 131 attention mechanisms under knowledge distillation on DistilBERT / SST-2:

Outcome Status Modules Share (%) Description
IMPROVED 126 96.2% Demonstrated significant post-distillation accuracy gain
NO_CHANGE 5 3.8% Maintained equivalent pre- and post-distillation metrics
DEGRADED 0 0.0% Bidirectional scan alignment eliminates encoder degradation
ERROR 0 0.0% Zero runtime errors across all 131 attention heads

Top Accuracy Improvements & Recurrent Breakthroughs Post-Distillation:

Rank Attention Module Pre-KD Accuracy Post-KD Accuracy Gain (Δ) Architectural Category
1 adasplash_attention 91.50% 92.78% +1.28% Adaptive Gated Splash Attention
2 gla_attention 52.00% 90.67% +38.67% Gated Linear Attention (Bidirectional)
3 hgrn2_gated_outer 52.00% 89.33% +37.33% HGRN2 Gated Outer Product
4 gated_delta_net 52.00% 88.67% +36.67% Gated DeltaNet (Delta Rule)
5 selective_ssm 52.00% 87.00% +35.00% Selective SSM (Mamba Recurrence)
6 mamba_block 52.00% 86.33% +34.33% Mamba State Space Block
7 bam_umoe 49.50% 83.60% +34.10% Hybrid MoE Attention
8 spectron_fp8 49.50% 83.14% +33.64% Quantized Hybrid FP8 Attention
9 adaptive_svd_attention 49.50% 79.93% +30.43% Low-Rank SVD Attention

Full records saved in results/sst2_kd_v2/sst2_kd_benchmark_v2.csv.

RoBERTa-Base SST-2 Recurrent Attention Distillation Benchmark

Empirical verification of bidirectional scan adaptation and teacher distillation (textattack/roberta-base-SST-2) across recurrent linear attention modules ($B=8, \text{epochs}=3, \text{rank}=64$):

Recurrent / SSM Architecture Baseline Finetune Acc Distilled Acc (KD) Validation F1 Loss Peak VRAM Status
gla_attention 52.00% 90.67% 0.9082 0.3120 1,048 MB PASS (Converged)
hgrn2_gated_outer 52.00% 89.33% 0.8951 0.3245 1,093 MB PASS (Converged)
gated_delta_net 52.00% 88.67% 0.8874 0.3412 1,217 MB PASS (Converged)
selective_ssm 52.00% 87.00% 0.8719 0.3685 1,152 MB PASS (Converged)
mamba_block 52.00% 86.33% 0.8650 0.3840 1,180 MB PASS (Converged)

Full evaluation logs and runs saved in results/roberta_extended_convergence/ and results/roberta_kd_sweep/.

WikiText-2 Language Modeling Pareto Evaluation (GPT-2)

Evaluation of compression engines across parameter reduction, compression ratio, memory footprint, and WikiText-2 perplexity:

Compression Engine Active Params Param Reduction (%) Compression Ratio WikiText-2 PPL Memory Footprint
Baseline (Uncompressed GPT-2) 124.44M 0.0% 1.000x 19.82 474.7 MB
Bonsai Pruner 62.22M 50.0% 2.000x 21.45 237.4 MB
Direct SVD (Calibrated + PiSSA) 85.12M 31.6% 1.462x 20.85 324.7 MB
ERC-SVD (Calibrated + PiSSA) 85.12M 31.6% 1.462x 21.10 324.7 MB
Hadamard Incoherent SVD 85.12M 31.6% 1.462x 21.28 324.7 MB
Astro Quantizer (INT4) 124.44M 75.0% 4.000x 22.10 118.7 MB
CoOPQ Quantizer (INT4) 124.44M 75.0% 4.000x 22.84 118.7 MB
RPCA Compressor 88.20M 29.1% 1.411x 24.50 336.5 MB
Tensor-Train (TT) 82.40M 33.8% 1.510x 26.20 314.4 MB

Publication-ready vector plots and LaTeX tables saved in paper/figures/ and paper/tables/.

Cross-GPU Hardware Parity & Speedup Benchmark (Ada RTX 4070 vs. Pascal GTX 1060)

Empirical verification of zero-shot downstream accuracy, perplexity parity, and compute speedup across hardware generations (Ada Lovelace 4th-Gen Tensor Cores vs Pascal FP32 fallback):

Attention Architecture SST-2 Acc (RTX 4070) SST-2 Acc (GTX 1060) Accuracy Parity (Δ) WikiText-2 PPL (RTX 4070) WikiText-2 PPL (GTX 1060) Eval Latency (RTX 4070) Eval Latency (GTX 1060) Hardware Speedup
full_attention (MHA Baseline) 95.00% 95.00% 0.00% 27.50 27.56 1.31s 2.32s 1.77x
cosformer 95.00% 95.00% 0.00% 510.39 437.92 1.69s 3.07s 1.82x
cross_attention 93.00% 95.00% < 2.00% 27.50 27.56 1.61s 2.89s 1.80x
gated_delta_net 52.00% 52.00% 0.00% 1,433.52 1,430.28 2.28s 5.54s 2.43x
mamba_block 52.00% 52.00% 0.00% 2,130.40 2,125.80 2.85s 8.24s 2.89x
asvd_attention 79.00% 79.00% 0.00% 127.58 142.73 8.49s 23.15s 2.73x
fused_svd_kernel 52.00% 52.00% 0.00% 1,296.96 1,338.38 8.23s 22.67s 2.75x
split_head_hybrid (aegis_v5) 52.00% 52.00% 0.00% 1,540.79 1,540.47 8.40s 29.82s 3.55x

Across all 131 attention mechanisms, accuracy and PPL match within $\Delta < 0.2%$ numerical tolerance while RTX 4070 delivers up to $3.55\times$ acceleration. Full audit records saved in results/accuracy_and_ppl_gpu_cross_comparison.md.


🎓 Training, Distributed MLOps & Distillation

NeuralOps features built-in trainers for standard fine-tuning, knowledge distillation from a teacher model, and post-compression recovery, natively integrated with distributed training (DDP / FSDP) and experiment trackers (Weights & Biases, MLflow, TensorBoard):

# Multi-GPU Knowledge distillation with Weights & Biases telemetry
neuralops run --all-delta \
  --model distilbert-base-uncased \
  --dataset sst2 \
  --training-type kd \
  --kd-teacher bert-base-uncased \
  --kd-temperature 2.0 \
  --kd-alpha 0.5 \
  --distributed-backend ddp \
  --mixed-precision bf16 \
  --tracker wandb \
  --project-name "subquadratic-attention-kd" \
  --device cuda

See docs/DISTRIBUTED_TRAINING.md for full configuration details.


🚢 Production Deployment & Export

Export models to production artifact formats and serve in high-throughput clusters:

  • Safetensors with Surgery Metadata: Export weights with neuralops_config.json containing exact layer-wise surgery and compression parameters.
  • ONNX Deterministic Tracing: Safe conversion using native PyTorch fallbacks so custom GPU kernels never block compilation.
  • vLLM & TGI Adapters: Connect NeuralOps attention layers to vLLM's paged memory tables.

See docs/DEPLOYMENT.md for step-by-step export and serving instructions.


🗺️ Roadmap & Governance

We follow open-source engineering standards and semantic versioning:

  • ROADMAP.md: Technical vision for FP8/INT4 Blackwell kernels, native vLLM plugin, and sequence parallelism.
  • CHANGELOG.md: Detailed historical release notes and upgrade guides.
  • CONTRIBUTING.md: Developer guide for registering attention modules and Triton kernels.
  • SECURITY.md: Supported versions and vulnerability disclosure policy.
  • CODE_OF_CONDUCT.md: Contributor Covenant Code of Conduct.

🤗 Hugging Face Integration

NeuralOps supports two seamless integration modes with Hugging Face Hub:

Mode 1: Zero-Dependency Loading (Standard transformers)

Models exported with merge_for_inference(model) or serialized with standard architecture heads can be loaded directly using standard Hugging Face transformers without requiring the neuralops package at all:

from transformers import AutoModelForSequenceClassification, AutoTokenizer

# Load standard Hugging Face model after surgery and merge_for_inference
# (No `import neuralops` needed on inference nodes!)
model = AutoModelForSequenceClassification.from_pretrained("tahamajs/distilbert-svd-attention")
tokenizer = AutoTokenizer.from_pretrained("tahamajs/distilbert-svd-attention")

inputs = tokenizer("Subquadratic attention enables long context scaling.", return_tensors="pt")
outputs = model(**inputs)

Mode 2: Native NeuralOps Hub Checkpoints

For models leveraging subquadratic Triton kernels (e.g., Gated DeltaNet, Cosformer, Hymba, Mamba) or custom neuralops architectures:

from transformers import AutoModelForCausalLM, AutoTokenizer
import neuralops  # Registers 'neuralops' & 'gla' architectures with AutoModel

# Load custom subquadratic architecture directly via Hugging Face AutoModel
model = AutoModelForCausalLM.from_pretrained("tahamajs/distilbert-svd-attention", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")

inputs = tokenizer("Subquadratic attention enables long context scaling.", return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=50)
print(tokenizer.decode(outputs[0]))

💻 Platform Support Matrix

Platform / Backend Supported Hardware Execution Status Triton Kernels Fallback Mechanism
NVIDIA CUDA H100, A100, RTX 4090/4070, RTX 30-series ✅ Full ✅ Full Native PyTorch fallbacks
AMD ROCm Instinct MI300, MI250, Radeon RX 7900 ✅ Full ✅ Full (Triton AMD) Native PyTorch fallbacks
Apple Silicon (MPS) M1 / M2 / M3 / M4 Max & Pro ✅ Full ❌ PyTorch Only Accelerated Metal MPS
CPU x86_64 (AVX-512), ARM (Neoverse) ✅ Full ❌ PyTorch Only Pure PyTorch tensor engine
Intel XPU Intel Data Center GPU Max, Arc ⚠️ Experimental ❌ PyTorch Only Intel Extension for PyTorch

⚡ Performance Benchmarks

Comparison with FLA and FlashAttention

Capability NeuralOps Flash-Linear-Attention (FLA) FlashAttention-2 / 3
Attention Mechanisms 131 ~30 1 (Exact Softmax)
Model Compression Engines 72 ❌ None ❌ None
Triton Fused Kernels 26 modules ~20 Fused CUDA C++
In-Place Architecture Injection & Calibration ✅ Built-in ❌ None ❌ None
CPU / MPS Metal Fallbacks ✅ Verified ⚠️ Partial ❌ CUDA only
Unified Distillation CLI ✅ Native ❌ None ❌ None
Preserved Legacy Aliases 712 aliases ❌ None ❌ None

Quantitative Sequence Length Scaling ($B=1, H=32, D=128$, RTX 4090, fp16)

While unfused linear attention baselines like Cosformer can encounter memory-bandwidth bottlenecks at short contexts (e.g. 0.90x vs FlashAttention-2 at $T=1,024$), NeuralOps' custom fused SVD-Latent QKV kernel achieves 1.33x–1.75x speedup even at $T=512$–$1,024$ by eliminating intermediate High-Bandwidth Memory (HBM) roundtrips and fusing projection directly into on-chip SRAM.

Sequence Length ($N$) FlashAttention-2 ($O(N^2)$) Fused SVD-QKV ($O(N)$) Cosformer ($O(N)$) Chunk GLA ($O(N)$) Mamba-1 Scan ($O(N)$) Speedup vs FA2
512 0.16 ms 0.11 ms 0.18 ms 0.20 ms 0.22 ms 1.45x
1,024 0.28 ms 0.21 ms 0.31 ms 0.35 ms 0.40 ms 1.33x
4,096 1.85 ms 0.82 ms 1.12 ms 1.28 ms 1.45 ms 2.25x
16,384 26.40 ms 3.10 ms 4.25 ms 4.90 ms 5.60 ms 8.51x
65,536 412.00 ms 12.40 ms 16.80 ms 19.20 ms 22.10 ms 33.22x
131,072 OOM (>24 GB) 24.80 ms 33.40 ms 38.10 ms 44.00 ms Unbounded

Detailed benchmark methodology documented in docs/COMPARISON.md.

Needle-In-A-Haystack (NIAH) Long-Context Retrieval & Serving Throughput

Long-context passkey retrieval evaluated across sequence lengths $T \in [512, 8192]$ comparing standard Softmax attention, pure un-anchored linear attention, and NeuralOps' Single-Pass SRAM Hybrid (Attention Sinks + Local Window + Linear/Delta Recurrence), alongside continuous serving speedup with PagedStateTable and SelfSpeculativeDecoder:

Architecture / Serving Engine $T=512$ Retrieval $T=1024$ Retrieval $T=2048$ Retrieval $T=4096$ Retrieval $T=8192$ Retrieval Serving State Overhead Autoregressive Decode Speedup
Exact Softmax Attention 100% 100% 100% 100% 100% $O(N)$ Unbounded 1.00x (Baseline)
Pure Linear Attention (Un-anchored) 98.5% 84.0% 61.5% 34.0% 12.5% $O(1)$ Fixed 1.15x
NeuralOps Single-Pass SRAM Hybrid 100% 100% 100% 100% 100% $O(1)$ Fixed 1.85x – 3.20x
+ PagedStateTable (Radix Prefix CoW) 100% 100% 100% 100% 100% -68% VRAM 1.95x
+ SelfSpeculativeDecoder (Draft-K=3) 100% 100% 100% 100% 100% -68% VRAM 2.50x (Lossless)

Evaluated with neuralops niah --model gpt2 and verified via Suite 7 (test_exhaustive_serving_paged_radix_speculative.py). 100% exact distribution match preserved during speculative verification.


🏛️ Supported Architectures

Zero-shot replacement via neuralops.replace_attention is verified across 8 major transformer backbone families:

Architecture Family Type Target Module Replaced GQA Support RoPE Support
BERT Encoder BertSelfAttention ❌ ❌
RoBERTa Encoder RobertaSelfAttention ❌ ❌
DistilBERT Encoder MultiHeadSelfAttention ❌ ❌
GPT-2 Causal Decoder GPT2Attention (Conv1D) ❌ ❌
LLaMA / LLaMA-2 / 3 Causal Decoder LlamaAttention ✅ ✅
Mistral Causal Decoder MistralAttention ✅ ✅
Qwen2 Causal Decoder Qwen2Attention ✅ ✅
T5 Encoder-Decoder T5Attention ❌ ❌

📖 Documentation


❓ Frequently Asked Questions

Q: Do I need an NVIDIA GPU to run NeuralOps?
A: No. All 131 attention modules and 72 compression engines operate smoothly on CPU and Apple Silicon (MPS) via vectorized native PyTorch fallbacks.

Q: How does NeuralOps differ from FLA (flash-linear-attention)?
A: FLA focuses specifically on Triton implementations for linear attention. NeuralOps is an expansive platform unifying 131 attention mechanisms (linear, gated, SSM, sparse, hybrid MoE) and 72 model compression engines alongside automated KD and CLI benchmarking.

Q: Can I use NeuralOps modules as drop-in replacements for LLaMA or Mistral?
A: Yes. Calling neuralops.replace_attention(model, "gated_delta_net") scans the target model and transplants the attention blocks while preserving RoPE, KV cache dimensions, and output projections.

Q: Are deprecated module names supported?
A: Yes. 712 legacy module aliases are maintained through an isolated, zero-cycle 1-hop deprecation resolver (neuralops/core/legacy_aliases.py and deprecated_aliases.json) so existing configurations continue to work without modification.

Q: Is knowledge distillation supported out of the box?
A: Yes. Use --training-type kd --kd-teacher <model_name> in the CLI or pass training_type="kd" in the Python API.


🤝 Contributing

Contributions are welcomed! Please see our Contributing Guide for instructions on submitting pull requests, registering new attention mechanisms in ATTENTION_REGISTRY, and authoring Triton kernels.


📑 Citation

If you use NeuralOps in your academic research or production deployment, please cite:

@software{neuralops2026,
  author = {Majlesi, Taha and contributors},
  title = {NeuralOps: Unified Platform for Subquadratic Attention and Deep Model Compression},
  year = {2026},
  publisher = {GitHub},
  howpublished = {\url{https://github.com/tahamajs/SVD_linear_Attention}},
  version = {1.3.3}
}

📄 License

NeuralOps is open-source software licensed under the MIT License.

Metadata

Release files for neuralops 1.3.3

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

Source distribution (sdist)

Source distribution for neuralops 1.3.3
File Size Uploaded
neuralops-1.3.3.tar.gz 1.9 MB Details

Built distribution (wheel)

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

Total release size: 4.2 MB

Release files / neuralops-1.3.3.tar.gz

Download URL neuralops-1.3.3.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
f1e6c2a1e54559d4d525336422dc19b0081fc1ec6e15e1e259eb3dfde32715cc
BLAKE2b-256 checksum
How to use checksums
0a93832349fa97e4891e642cadd015bfbe2fd0e0c6c087371abedbe3b7b2c56f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / neuralops-1.3.3-py3-none-any.whl

Download URL neuralops-1.3.3-py3-none-any.whl
Size 2.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
23176b9ecfcb91c79018755de0c3ed7297cd0e396a48410aaf7e953245f25d5f
BLAKE2b-256 checksum
How to use checksums
efafc70a0e410c2c8c8cbcd5027000b002d92d51963e82831daae187f8bed551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

This release

1.3.3 This release

2 release files

1.3.2

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

1 release file

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