🧬 NeuralOps
Unified Platform for Subquadratic Attention and Deep Model Compression
131 canonical attention mechanisms · 72 compression engines · 26 Triton kernel modules · 8 transformer architectures
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
- Key Features
- Installation
- Quick Start
- Architecture Overview
- Attention Zoo
- Compression Engines
- Triton Kernels
- Benchmarking Suite
- Training, Distributed MLOps & Distillation
- Production Deployment & Export
- Roadmap & Governance
- Hugging Face Integration
- Platform Support Matrix
- Performance Benchmarks
- Supported Architectures
- Documentation
- FAQ
- Contributing
- Citation
- License
📰 News
- [2026-10] 🧪 11 Exhaustive Mathematical Test Suites (1,718+ Tests Passed): 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 (
gated_delta_net,hgrn2_gated_outer,sink_attention) achieve 76.0%–83.1% validation accuracy 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 packeduint8weights 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.0 Tier-1 Production Release — full
torch.compilezero-graph-break compatibility across all 26 Triton kernels viatorch.library.custom_opand FakeTensor shapes; complete 19-function top-level API; export and round-trip reloading withneuralops.export_modelandneuralops.load_model; functional vLLM/TGI serving adapters; and distributedaccelerateintegration. - [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, 657 legacy aliases preserved.
- [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.0)
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: 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
🏗️ 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) | ✅ |
| 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 | ✅ |
| W4A16 Dequant GEMM | w4a16_gemm.py |
In-SRAM packed 4-bit dequantization & matrix multiply | ✅ |
| FWHT Transform | fwht.py |
Fast Walsh-Hadamard orthogonal rotation | ✅ |
| Decay Linear Scan | decay_linear_scan.py |
Data-independent continuous decay scan | ✅ |
| SVD Linear Scan | svd_linear_scan.py |
Spectral projection fused state recurrence | ✅ |
| Cosine Feature Map | cosformer_kernel.py |
Fused elementwise cos/sin feature projection | ✅ |
| Sparse Block Routing | sparse_attention.py |
Dynamic Top-K block sparse scatter-gather | ✅ |
| Sink Attention Scan | sink_attention.py |
Learnable initial token sink preservation | ✅ |
| Multi-Scale Retention | retention_kernel.py |
Fused multi-head decay recurrence | ✅ |
| RWKV-6 Time-Mixing | rwkv6_scan.py |
Continuous dynamic time-decay state update | ✅ |
| Lightning Attention | lightning_scan.py |
Tiling-efficient linear causal attention | ✅ |
| Spectron Spectral | spectron_kernel.py |
Orthogonal Chebyshev/Fourier spectral filtering | ✅ |
| BitNet Quantization | bitnet_kernel.py |
Ternary (-1, 0, 1) and 1.58-bit fused GEMM | ✅ |
| Flash Linear State | flash_linear_state.py |
Fused outer-product recurrent state accumulation | ✅ |
| MoE Routing Scan | moe_scan.py |
Differentiable Gumbel-Softmax expert dispatch | ✅ |
| TTT Layer Scan | ttt_kernel.py |
Test-Time Training online gradient step in forward | ✅ |
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) |
|---|---|---|---|---|---|---|---|---|
| Sparse & Windowed | sink_attention, nsa_attention, adaptive_span |
0.94 – 1.69 | 3.44 – 4.19 | 2.48x – 3.66x | 1.21 – 57.45 | 3.71 – 106.28 | 1.85x – 3.07x | $\ge 0.9990$ (PASS) |
| Modern & GQA | mla_attention, mqa, alibi, reap_moe |
1.13 – 1.67 | 3.63 – 4.17 | 2.50x – 3.21x | 1.55 – 7.45 | 4.05 – 13.78 | 1.85x – 2.61x | $\ge 0.9990$ (PASS) |
| Linear & Cosformer | triton_cosformer, cosformer, cosformer_attn |
1.48 – 2.67 | 3.98 – 5.17 | 1.94x – 2.69x | 4.10 – 5.14 | 7.58 – 9.51 | 1.85x | $\ge 0.9990$ (PASS) |
| SVD & Factorized | svd_linear_attention, svd_linear_decay, asvd |
1.15 – 1.79 | 3.65 – 4.29 | 2.40x – 3.17x | 2.07 – 26.97 | 4.57 – 49.89 | 1.85x – 2.21x | $\ge 0.9990$ (PASS) |
| Recurrent & Gated | gated_delta_net, hgrn2_gated_layer, gla_attn |
2.85 – 10.60 | 5.35 – 19.61 | 1.85x – 1.88x | 4.50 – 49.75 | 8.33 – 92.04 | 1.85x | $\ge 0.9990$ (PASS) |
| SSM & Hybrid | vspec, jamba, selective_mamba, mamba_block |
2.54 – 12.37 | 5.04 – 22.88 | 1.85x – 1.98x | 2.93 – 34.75 | 5.43 – 64.29 | 1.85x | $\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 | 110 | 84.0% | Demonstrated significant post-distillation accuracy gain |
| NO_CHANGE | 5 | 3.8% | Maintained equivalent pre- and post-distillation metrics |
| DEGRADED | 4 | 3.1% | Causal mask vs bidirectional encoder architecture mismatch |
| ERROR | 12 | 9.2% | Shape or runtime incompatibility with sequence classification head |
Top 5 Accuracy Improvements Post-Distillation:
| Rank | Attention Module | Pre-KD Accuracy | Post-KD Accuracy | Gain (Δ) | Architectural Category |
|---|---|---|---|---|---|
| 1 | bam_umoe |
49.50% | 83.60% | +34.10% | Hybrid MoE Attention |
| 2 | aegis_spectron_fp8 |
49.50% | 83.14% | +33.64% | Quantized Hybrid Attention |
| 3 | aegis_v6 |
49.50% | 82.57% | +33.07% | Gated Hybrid Attention |
| 4 | adaptive_svd_attention |
49.50% | 79.93% | +30.43% | Low-Rank SVD Attention |
| 5 | adasplash_attention |
91.50% | 92.78% | +1.28% | Adaptive Gated Splash 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 |
|---|---|---|---|---|---|---|
sink_attention |
52.00% | 83.00% | 0.8571 | 0.3759 | 947 MB | PASS (Converged) |
hgrn2_gated_outer |
52.00% | 81.00% | 0.8081 | 0.4445 | 1,093 MB | PASS (Converged) |
hgrn2_outer |
52.00% | 81.00% | 0.8081 | 0.4445 | 1,093 MB | PASS (Converged) |
gated_delta_net |
52.00% | 76.00% | 0.7616 | 1.0020 | 1,217 MB | PASS (Converged) |
gla_attention |
52.00% | 76.00% | 0.7616 | 1.0020 | 1,217 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/.
🎓 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.jsoncontaining 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.
🏛️ 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
- Tier-1 Framework Evolution Blueprint — Architectural roadmap to enterprise scale: Dynamo/AOTInductor, continuous batching, vLLM plugins, and TP/PP/CP distributed engines.
- Framework Overview & Developer Manual — Unified framework topology, step decoding, hybrid caching, and serving adapters.
- Quick Start Guide — 5-minute onboarding and setup.
- Module Reference — Complete inventory of all 131 attention mechanisms.
- Compression Guide — Guide to 72 model compression algorithms.
- API Reference — Complete Python API reference and docstrings.
- Architecture Manual — Framework internals and system design.
- Library Comparison — Feature matrix and benchmark comparisons.
- Troubleshooting & FAQ — Common error resolutions and platform configuration.
❓ 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/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.2}
}
📄 License
NeuralOps is open-source software licensed under the MIT License.
Metadata
Release files for neuralops 1.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| neuralops-1.3.2.tar.gz | 1.9 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| neuralops-1.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 4.2 MB
Release files / neuralops-1.3.2.tar.gz
| Download URL | neuralops-1.3.2.tar.gz |
|---|---|
| Size | 1.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4f3cf379736891ab9a415fcde5c1ae3cc1a604a72872365e0fb93b457ee2721
|
|
BLAKE2b-256 checksum How to use checksums |
766753f0070638d5f9e70b205f8d01b65033fb26d50408310f63def3257b5b45
|
| 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.2-py3-none-any.whl
| Download URL | neuralops-1.3.2-py3-none-any.whl |
|---|---|
| Size | 2.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
65aaab953dc30ea041068f0353dc7a9af18512187012880aa9d6ccc8eff7b2f5
|
|
BLAKE2b-256 checksum How to use checksums |
000c2c2f749d0ccb5bf304e869e1c52385e8d2d5605476b90fb1984eee53e0a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|