Universal, hardware-compiled, composable model container format enabling True RSI.
Project description
NeuronPack
A universal, hardware-compiled, composable model container format.
Enabling True Recursive Self-Improvement (RSI) via autonomous dynamic architecture compilation.
⚠️ NOTE: This framework is completely VIBE CODED. It is an experimental pursuit of meta-learning architectures. Improvements, forks, and pull requests are very much welcome and encouraged!
Read the full specification in the docs/neuronpack.txt.
🧠 The Problem with Monolithic Models
Standard PyTorch or Transformers architectures lock parameters into a single large state dictionary (.pt or .safetensors files) deeply entangled with a massive, rigid Autograd Execution Graph.
If you want to swap a single 100k-parameter Multi-Layer Perceptron (MLP) within a 10-Billion-parameter model, you traditionally have to:
- Reload all 10 Billion parameters into RAM.
- Unpack the monolithic state dictionary.
- Replace the sub-module.
- Reserialize and block Disk I/O to save the entire 10 Billion parameters back to disk.
This massive technical debt mathematically prevents True Recursive Self-Improvement (RSI)—systems that actively modify their own algorithm mid-training.
📦 The NeuronPack Solution
NeuronPack breaks down giant static Multi-Layer networks into thousands of isolated "Pieces".
Instead of one massive file, you get a highly scalable directory structure containing isolated Safetensors, Metadata, and AOT-Compiled kernel.pt2 machine-code binaries.
NeuronPack acts as an $O(1)$ isolated File-System Container wrapped by an ultra-low-latency CPU Numba Router.
Components
- Core Container (
NeuronPack): The isolated structural DAG layer enforcing the separation of metadata and parameters on disk. Hot-swappable zero-copy mechanics via Safetensors. @njitSearch Router (Router): A dedicated Exact Cosine-Similarity engine that dynamically selects components to load at runtime without dragging PyTorch GPU memory limits.- AOT Inductor Compilation: Utilizes PyTorch 2.x
torch.exportto freeze Python logic into raw C++ library binaries (.kernel.pt2) dynamically upon expert insertion. - NEURON-RSI Evolutionary Controller: The architecture search engine. A Meta-Objective Evaluator that autonomously controls spawning, mutating, and Safe-Replacement for dynamic component modules based on pure mathematical fitness tradeoffs (Performance vs. Bloat Penalties).
⚡ Performance Benchmarks
Benchmarked on a synthetic 10-Million-parameter environment across 100 experts. Targeting the replacement/swapping of a single 100k-parameter module (1% of the network).
| Metric | Traditional PyTorch Model | NeuronPack | Improvement |
|---|---|---|---|
| Disk I/O Saves (Evolution) | ~57.59 ms (Save 10M params) | ~1.54 ms (Save 100k params) | 37.4x Faster |
| Disk I/O Loads (Swap overhead) | ~65.03 ms (Load graph + unzip dict) | ~1.19 ms (Zero-copy single target) | 54.5x Faster |
| VRAM Locked Footprint (Idle) | ~38.15 MB (Full state embedded in graph) | ~0.38 MB (Swaps dynamically on disk) | 100x Reduction |
| Routing Registry Lookup | ~0.16 ms*(GPU VRAM Locked nn.Linear)* | ~4.41 ms*(Decoupled CPU Exact Match)* | Parity (avoids Autograd lock-in) |
NeuronPack unlocks $O(1)$ mutations, making True RSI viable locally. By decoupling the architecture lookup engine from the PyTorch Execution Graph, evolutionary training loops never throw Out-of-Memory exceptions.
🚀 How to Use
1. Initializing and Saving Pieces
import torch, torch.nn as nn
from neuronpack import NeuronPack
# Create a NeuronPack Workspace
pack = NeuronPack('/path/to/my_model.neuron')
# Define a piece of your network
class MLPExpert(nn.Module):
def __init__(self):
super().__init__()
self.w = nn.Linear(8, 8)
expert = MLPExpert()
# Metadata defines the piece contract and routing semantic vector
meta = {
"role": "mlp_expert",
"architecture": "MLPExpert",
"embedding": [0.1, -0.4, 0.9, ...], # Semantic positioning
"version": "1.0.0",
}
# The parameters and layout are saved safely to disk in isolation
pack.add_piece("unique_piece_id", expert.state_dict(), meta)
2. Live Pruning & AOT Compilation
# AOT Compile the piece to C++ machine code using torch._export
# This stores `unique_piece_id.kernel.pt2` next to the weights on disk
pack.compile_piece("unique_piece_id", MLPExpert(), dummy_inputs)
# Delete experts whose telemetry indicates they are never routed to
# (E.g. load_count falls below threshold)
pack.prune(role="mlp_expert", min_load_count=10)
3. Executing True RSI (Evolutionary Looping)
from neuronpack.rsi import Evaluator, Mutator, RSIController
# Create an Evaluator penalizing Architecture Size (C) against Performance (P)
evaluator = Evaluator(
performance_fn=my_accuracy_metric_function,
gamma=50.0 # Parameter bloat penalty
)
# Mutator can jump between different Archetypes entirely (Heterogeneous Search)
mutator = Mutator(piece_archetypes=[TinyRNN_Archetype, Transformer_Archetype])
controller = RSIController(pack, monolithic_base_model, evaluator, mutator)
# During training, autonomously evaluate permutations and safely mutate
for batch in train_loader:
# 1. Spawn clones with weight noise, or entirely new primitives
# 2. Evaluate fitness J(A')
# 3. Swap safely into the container if Performance > Bloat Penalty
# 4. Rollback and cleanup disk automatically if it fails!
controller.run_generation()
📂 Layout
When you initialize NeuronPack, it formats your directory reliably for both Python and Native implementations:
my_model.neuron/
├── manifest.json
├── router/
│ ├── embeddings.npy # Numba optimized vector map
│ └── registry.json # Vector ID hash matching
└── pieces/
├── attn_layer_04.meta # JSON Interface Contract & Telemetry
├── attn_layer_04.kernel.pt2# PyTorch AOT-compiled Binary
└── attn_layer_04.weights # Raw Isolated Safetensors
Examples
Check out the /examples directory for advanced implementations:
train_rsi_advanced.py: True RSI dynamically swapping between Recurrent layers and Transformer Attention Mechanisms based on compute tradeoffs.train_rsi_diffusion.py: Evolving sequential Denoising step architectures via the Mutator.benchmark_traditional.py: Benchmark utilities vs traditional PyTorch paradigms.
We Welcome Contributions
Since this is an experimental RSI architecture, feel free to open PRs for enhanced routing mechanisms, CUDA bindings, or more complex Mutator archetypes!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file neuronpack-1.0.1.tar.gz.
File metadata
- Download URL: neuronpack-1.0.1.tar.gz
- Upload date:
- Size: 203.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c69cb7289acaf260d9c4816982250e9fc86685ea44f292619573311bd3e51165
|
|
| MD5 |
191a2769eaad38b6bdde4076d3fcdd85
|
|
| BLAKE2b-256 |
9019ecedeefd0155c999952c1562ccb0f34899e0e74d6500195bd2aa9364b075
|
File details
Details for the file neuronpack-1.0.1-py3-none-any.whl.
File metadata
- Download URL: neuronpack-1.0.1-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60366cebd576bc53b2af39a966e2c3c6277ccb68f81864fa4aad6c319cba4770
|
|
| MD5 |
a95fd37b4aa7854f29679500d4e4cc17
|
|
| BLAKE2b-256 |
0dccf70fdca0fced186297bab629f87bd37b20b2d3d2df86656ed9742dd74a3c
|