Skip to main content

Dynamic Neural Organism (DNO): A self-evolving, growing, and pruning neural network framework.

Project description

DNO: Dynamic Neural Organism 🧬

PyPI version License: MIT

"Don't just train a model. Raise an organism."

DNO (Dynamic Neural Organism) is a next-generation PyTorch framework that treats neural networks as living, evolving biological entities. Unlike static architectures (Transformers, CNNs) that are fixed at initialization, a DNO grows, specializes, and adapts in real-time based on the complexity of the data it consumes.


📚 Table of Contents

  1. Core Philosophy
  2. Installation
  3. The DNO Lifecycle (User Guide)
  4. Advanced Mechanics
  5. API Reference

🧠 Core Philosophy

Traditional AI is like a Statue: You carve it (define architecture), polish it (train), and it stays that way forever. DNO is like a Tree: You plant a seed (Seed Cortex). If the environment is rich (complex data), it grows branches (Expert Lobes). If a branch is useless, it withers (Pruning).

Key Features (v0.2.x)

  • Neurogenesis (Mitosis): The network physically adds new layers when "confused" (High Entropy).
  • Specialized Organisms: The brain divides into a "General Core" and "Expert Lobes".
  • Dynamic Gradient Locking: Automatically freezes the General Core when training Experts, and vice versa.
  • Smart Routing: Routes "Familiar" data to the Core and "Novel" data to Experts.
  • Auto-Casting: Safely handles raw Token IDs (LongTensor) by auto-casting to Float32 where needed.

📦 Installation

pip install dno

Requires Python 3.8+ and PyTorch.


🧬 The DNO Lifecycle

Raising a DNO involves distinct biological phases.

1. DNA Configuration (DnoConfig)

Before birth, you must define the organism's genetic constraints.

from dno.config import DnoConfig

config = DnoConfig(
    # --- Lifecycle Control ---
    training_phase='scratch',   # Start in 'scratch' (Infancy) or 'adaptive' (Adulthood)
    
    # --- Growth Triggers ---
    entropy_threshold=0.6,      # If confusion > 0.6, consider growing
    evolution_cooldown_steps=100, # Wait 100 steps between growth events
    
    # --- Physical Constraints ---
    max_param_count=100_000_000, # Cap size at 100M parameters
    vram_limit_gb=4.0,           # Stop growing if VRAM exceeds 4GB
    
    # --- Architecture Defaults ---
    d_model=128,                 # Hidden dimension size
    n_heads=4                    # Attention heads (if using Transformer blocks)
)

2. Infancy (scratch Training)

Goal: Build a strong generalist core ("Seed Cortex"). Behavior: Growth is DISABLED. The model behaves like a standard, static PyTorch model.

from dno.core.organism import OrganismManager, BaseEvolvableModule
from dno.core.network import DynamicNetwork
import torch.nn as nn

# 1. Initialize
manager = OrganismManager()
network = DynamicNetwork(manager, config)

# 2. Add the Seed Cortex (Your base model)
# Wrap any PyTorch module in BaseEvolvableModule
seed_layer = nn.Sequential(
    nn.Linear(128, 128),
    nn.ReLU(),
    nn.Linear(128, 10)
)
seed = BaseEvolvableModule(seed_layer)
seed.dynamic_id = "seed_cortex"
seed.set_specialty("general") # IMPORTANT: Mark as General Core

network.add_layer(seed)

# 3. Train as usual (Standard PyTorch Loop)
# In this phase, NO growth happens.
output = network(input_data)
loss.backward()
optimizer.step()

3. Adulthood (adaptive Growth)

Goal: Adapt to new, complex tasks by growing specialized organs. Behavior: The model monitors its own entropy. If it encounters data it cannot understand (High Entropy), it triggers Mitosis.

from dno.core.growth import GrowthEngine

# 1. Switch Phase
network.config.training_phase = 'adaptive'

# 2. Initialize Growth Engine
growth_engine = GrowthEngine(network, config)

# ... inside training loop ...
outputs = network(inputs)

# The network automatically calculates 'Entropy' (Confusion) during forward pass.
# You can check this history or let the engine handle it.

# 3. Check for Growth Trigger
is_triggered, reason = growth_engine.check_growth_trigger(
    entropy_history=network.get_recent_entropy(), 
    current_step=step
)

if is_triggered:
    print(f"🌟 EPIPHANY! Growing new expert due to: {reason}")
    
    # TRIGGER MITOSIS
    # Clones the 'seed_cortex' to create a new 'expert_coding_v1' module
    growth_engine.mitosis(
        parent_uuid="seed_cortex", 
        optimizer=optimizer, 
        specialty_tag="expert_coding_v1"
    )

What happens during Mitosis?

  1. Cloning: The parent layer is duplicated.
  2. Mutation: Smart noise is added to the clone's weights to break symmetry.
  3. Rewiring: The clone is connected to the same inputs/outputs as the parent.
  4. Specialization: The clone is marked as an "Expert".

4. Fluid Serialization

Standard torch.save fails on DNOs because their architecture (topology) changes dynamically. Use .dno format.

# Save everything (Topology + Weights + Config + History)
network.save_dno("my_organism.dno")

# Load it back
new_network = DynamicNetwork.load_dno(
    "my_organism.dno", 
    module_factory=lambda t: nn.Linear(...) # Factory to reconstruct base layers
)

🔧 Advanced Mechanics

Dynamic Gradient Locking 🔒

DNO automatically manages requires_grad to prevent "Catastrophic Forgetting".

  • Familiar Data (CPT): The system freezes all Expert layers. Only the General Core updates.
  • Novel Data (SFT/High Entropy): The system freezes the General Core. Only the Expert layers update. This happens automatically inside network.forward() based on the data_type or entropy detection.

Auto-Casting 🛡️

DNO v0.2.6+ includes intelligent safety rails for input types.

  • If you pass raw LongTensor inputs (Token IDs) to a module that expects floats (like Linear), DNO automatically casts them to Float32.
  • It performs a Deep Scan to ensure no Embedding layers are hidden inside the module (e.g., inside a nested GPTBlock). If an Embedding is found, data is preserved as Long.

🤝 Contributing

DNO is an open-source experiment.

  • Bug Reports: Open an issue on GitHub.
  • Feature Requests: We are looking for new "Organs" (Memory modules, Attention blocks).

📜 License

MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dno-0.2.6.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dno-0.2.6-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file dno-0.2.6.tar.gz.

File metadata

  • Download URL: dno-0.2.6.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for dno-0.2.6.tar.gz
Algorithm Hash digest
SHA256 76a9b69179aa730fc43c0a20590ed4bf27a4a5bb99890708e83486c778c0cfac
MD5 c08cf8e56022b1806a9483dc5f72ea95
BLAKE2b-256 bf2d931a31eb7935304210d3e3d98eea8fcaca098faed06bb4bba0e9e5e257a2

See more details on using hashes here.

File details

Details for the file dno-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: dno-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for dno-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a6f7f6f3fa64ee68071cf30f9aee9a9063d4e8bfe3de24332e1bfd3b83500a6e
MD5 7c4321e16ed0956d20a40fe41a422ac0
BLAKE2b-256 1edbc549e9eac75db003fb7e7f36a74870c22386e122fd23929ce974a4818fb6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page