Dynamic Neural Organism (DNO): A self-evolving, growing, and pruning neural network framework.
Project description
DNO: Dynamic Neural Organism 🧬
DNO (Dynamic Neural Organism) is a PyTorch-based framework for creating biological neural networks that grow, think, and evolve at runtime.
Unlike static deep learning models (like Transformers or CNNs) which are "architectural statues", a DNO is a living organism. It starts small (as a single seed cortex), physically grows new neural pathways when confused, and prunes away useless connections when they are no longer needed.
"Don't just train a model. Raise an organism."
🌟 Core Concepts: Biology Meets AI
DNO introduces several biological mechanisms into the deep learning workflow:
1. Neurogenesis (Mitosis) 📈
Traditional models have a fixed capacity. If the problem is too hard, they fail. DNO monitors its own Entropy (state of confusion).
- If the organism is consistently "confused" (High Entropy) by incoming data, it triggers Mitosis.
- It interacts with the optimizer to clone its most active functional units (layers).
- It adds microscopic noise (mutation) to the clone to encourage specialization.
- The result: The model physically grows larger to accommodate the difficulty of the task.
2. Natural Selection (Apoptosis) ✂️
Growth without check is cancer. DNO implements Apoptosis (Programmed Cell Death).
- The
SurvivalEnginetracks the Utility Score of every neuron group. - Utility is calculated based on "Information Gain" (KL-Divergence between input and output).
- If a layer is just passing data through without adding value (Identity mapping), it starves.
- Eventually, efficient sub-structures emerge while useless ones die off.
3. Training Phases: Life Stages ⏳
DNO models go through distinct life stages, controlled by the training_phase config:
Phase 1: scratch (Infancy)
- Goal: Build a strong foundation.
- Mechanism: Growth is LOCKED. The model behaves like a standard static network.
- Focus: Train the "Seed Cortex" (the core brain) to understand basic patterns.
- Logic: A baby shouldn't try to grow complex specialized organs before it can digest basic food. All data is treated as "Familiar" (CPT).
Phase 2: adaptive (Adulthood)
- Goal: Specialization and Adaptation.
- Mechanism: Growth is UNLOCKED.
- Focus: The model detects "Novelty".
- Familiar Data (CPT): The core brain handles it. Specialized lobes are frozen to save energy.
- Novel Data (SFT): The core brain is frozen. A new "Expert Lobe" is grown or activated to handle this specific new type of difficulty.
- Logic: This enables Continual Learning without Catastrophic Forgetting.
📦 Installation
pip install dno
🚀 Usage Guide
1. The "Hello World" of Life
Create a brain, give it a DNA configuration, and process data.
import torch
import torch.nn as nn
from dno.core.organism import OrganismManager, BaseEvolvableModule
from dno.core.network import DynamicNetwork
from dno.config import DnoConfig
from dno.utils.dashboard import print_organism_status
# 1. DNA Configuration
# training_phase='scratch': Start as a fixed seed (recommended for first epoch)
config = DnoConfig(
training_phase='scratch',
entropy_threshold=0.6,
d_model=128
)
# 2. Birth (Initialize Manager & Body)
manager = OrganismManager()
network = DynamicNetwork(manager, config)
# 3. Seed Layer (The first neuron block - The Core)
seed_layer = nn.Sequential(
nn.Linear(128, 128),
nn.ReLU(),
nn.Linear(128, 128)
)
# Wrap it in a biological shell
seed = BaseEvolvableModule(seed_layer)
seed.dynamic_id = "seed_cortex"
seed.set_specialty("general") # Mark as General Purpose Core
network.add_layer(seed)
# 4. Live (Forward Pass)
input_data = torch.randn(1, 128)
output = network(input_data)
print(f"Output shape: {output.shape}")
print_organism_status(manager)
2. Evolving (Adaptive Phase)
After pre-training (Phase 1), switch to Adaptive Mode to allow the model to grow specialized experts.
from dno.core.growth import GrowthEngine
import torch.optim as optim
# Switch to Adulthood
network.config.training_phase = 'adaptive'
optimizer = optim.SGD(network.parameters(), lr=0.01)
growth_engine = GrowthEngine(network, config)
# ... inside your training loop ...
outputs = network(inputs)
loss = criterion(outputs, targets)
# 1. Update Biology (Entropy tracking)
# network._detect_novelty is called automatically in forward()
# 2. Check for Growth
# If model is confused (High Entropy) -> Mitosis
is_triggered, reason = growth_engine.check_growth_trigger(entropy_history, step)
if is_triggered:
print(f"🌟 Epiphany! Growing new expert due to: {reason}")
# Clone the seed cortex to create a new 'Expert Lobe'
growth_engine.mitosis(
parent_uuid="seed_cortex",
optimizer=optimizer,
specialty_tag="expert_coding" # Label the new organ
)
loss.backward()
optimizer.step()
3. Saving & Loading (Fluid Serialization)
DNO models cannot be saved with just torch.save() because their architecture changes appropriately. Use .dno format.
# Save the entire organism (Topology + Weights + Config + History)
network.save_dno("my_brain.dno")
# Resurrect it exactly as it was
new_network = DynamicNetwork.load_dno("my_brain.dno", module_factory=lambda t: nn.Linear(128, 128))
🔧 Advanced Configuration (DnoConfig)
| Parameter | Default | Description |
|---|---|---|
training_phase |
'scratch' |
'scratch' (Fixed topology) or 'adaptive' (Dynamic growth). |
entropy_threshold |
0.6 |
How confused the model needs to be to trigger growth (0.0-1.0). |
evolution_cooldown_steps |
100 |
Minimum steps between growth events to prevent explosion. |
pruning_decay_constant |
0.001 |
How fast unused neurons die off. |
max_param_count |
1B |
Hard limit on organism size to prevent OOM. |
🤝 Contributing
DNO is an open-source experiment in Artificial Life.
- Found a bug? Open an issue.
- Have an idea for a new organ? Submit a PR.
📜 License
MIT License. Go build something alive.
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 dno-0.2.4.tar.gz.
File metadata
- Download URL: dno-0.2.4.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e37084b1b28843d4fb60d8a98b4276e353d67279de8ef2890703c30923c9c4e7
|
|
| MD5 |
f55f8947f0067d237bcd6811646679b2
|
|
| BLAKE2b-256 |
23491597ca2ba9689c086d76fbece9b1c1ffe24ce1e0e5c318e9f7036ccf7bc9
|
File details
Details for the file dno-0.2.4-py3-none-any.whl.
File metadata
- Download URL: dno-0.2.4-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d14f464d7b19ccf4eaf118ab7162cfd89bb15e7a10a8a096cd7acf16a2056c22
|
|
| MD5 |
6f1ca1b5382c5d29635a672aa4a2e73a
|
|
| BLAKE2b-256 |
9cc3218ab9ce407a634929146674e22774d9b49dc99e0dd3d20d23fb9e0c1cff
|