A next-generation framework for automated discovery and optimization of neural network architectures.
Unlike traditional NAS (Neural Architecture Search), SDNN combines evolutionary algorithms with logic-based reasoning to design architectures optimized for specific hardware constraints and tasks.
Getting Started Β· Examples Β· Documentation Β· Contributing
| Feature | Description |
|---|---|
| Graph-Based DSL | Define and compose neural architectures using a fluent, chainable API built on DAG primitives |
| Evolutionary Search | Multi-objective optimization balancing accuracy, latency, and energy efficiency |
| Hardware-Aware | Constrain search by parameter count, memory budget, and target device (CPU/GPU/edge) |
| Reasoning Engine | Logic-based pruning to eliminate invalid architectures and guide the search process |
| PyTorch Code Generation | Automatically compile discovered architectures into runnable PyTorch modules |
| REST API | Serve architecture discovery as a service via FastAPI |
| CLI | Full command-line interface for running discovery pipelines |
| Visualization | Plot evolution progress, architecture graphs, and Pareto fronts |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ArchitectAI β
ββββββββββββ¬ββββββββββββ¬βββββββββββββ¬ββββββββββββ¬βββββββββββ€
β Core β Evolution β Reasoning β CodeGen β Hardware β
β ββββββ β βββββββ β ββββββββ β ββββββββ β ββββββββ β
β DSL β Search β Engine β Compiler β Profiler β
β Graph β Space β Rules β PyTorch β Constr. β
β Prims β Populat. β Knowl.Base β Optimizer β Evaluatorβ
ββββββββββββ΄ββββββββββββ΄βββββββββββββ΄ββββββββββββ΄βββββββββββ€
β CLI Β· REST API Β· Visualization β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The framework is built around a DAG-based architecture graph where nodes represent neural network operations (Conv2D, ReLU, Linear, BatchNorm, etc.) and edges represent data flow. The evolutionary engine samples candidate architectures from a configurable search space, evaluates them against hardware constraints, and iteratively refines the population toward optimal designs.
- Python 3.9 or higher
- PyTorch 2.0+
# Clone the repository
git clone https://github.com/ZitouniNidhal/Self-Designing-Neural-Networks--SDNN-.git
cd Self-Designing-Neural-Networks--SDNN-
# Install in editable mode
pip install -e .
# Install dev dependencies (for testing & linting)
pip install -r requirements-dev.txtfrom architectai import Architect
from architectai.hardware.constraints import HardwareConstraints
# Initialize the architect
architect = Architect()
# Define hardware constraints
constraints = HardwareConstraints(
max_params=500_000,
max_memory_mb=256,
target_device="cpu",
)
# Run architecture discovery
best_architecture = architect.discover(
task="image_classification",
iterations=50,
constraints=constraints,
)
# Export to PyTorch code
architect.export(best_architecture, "my_model.py")The fluent DSL API lets you define architectures as chained operations:
from architectai.core.dsl import ArchitectureDSL
# Build a simple CNN
model = (
ArchitectureDSL("my_cnn")
.input([3, 32, 32])
.conv2d(32, kernel_size=3, stride=1)
.relu()
.conv2d(64)
.relu()
.linear(10)
.build()
)
# Inspect the architecture graph
print(model.to_dict())from architectai.evolution.search_space import SearchSpace
space = SearchSpace()
# Sample a random architecture with depth 6
candidate = space.sample_random_architecture(depth=6)The architect CLI is installed as a console script:
# Run architecture discovery
architect discover --task image_classification --iterations 100 --output model.py
# Show help
architect --help| Option | Default | Description |
|---|---|---|
--task |
image_classification |
Discovery task type |
--iterations |
10 |
Number of search iterations |
--output |
output_architecture.py |
Path to save the exported architecture |
Start the API server to expose discovery as a service:
uvicorn architectai.api.server:app --reloadcd docker
docker-compose up --buildSelf-Designing-Neural-Networks--SDNN-/
βββ src/architectai/
β βββ __init__.py # Package exports
β βββ core/ # Foundation layer
β β βββ primitives.py # Operation types, NodeConfig, Primitive
β β βββ graph.py # ArchitectureGraph (NetworkX DAG)
β β βββ dsl.py # Fluent DSL for building architectures
β βββ evolution/ # Evolutionary search
β β βββ search_space.py # Defines available ops & sampling
β β βββ population.py # Population management
β βββ reasoning/ # Logic-based guidance
β β βββ engine.py # Reasoning engine
β β βββ rules.py # Architecture validity rules
β β βββ knowledge_base.py # Domain knowledge store
β β βββ explainer.py # Decision explanations
β βββ codegen/ # Code generation
β β βββ compiler.py # Graph β file export (JSON / Python)
β β βββ pytorch_generator.py # Graph β PyTorch nn.Module source
β β βββ optimizer.py # Graph-level optimizations
β βββ hardware/ # Hardware awareness
β β βββ constraints.py # HardwareConstraints & evaluator
β β βββ profiler.py # Runtime profiling
β βββ evaluation/ # Model evaluation
β βββ viz/ # Visualization utilities
β β βββ graph_viz.py # Architecture graph plots
β β βββ evolution_viz.py # Evolution progress charts
β β βββ pareto_viz.py # Multi-objective Pareto fronts
β β βββ report_generator.py # HTML/PDF report generation
β βββ cli/ # Command-line interface
β β βββ main.py # Click CLI entry point
β β βββ commands.py # CLI commands (discover)
β β βββ args.py # Default arguments
β βββ api/ # REST API
β β βββ server.py # FastAPI application
β β βββ endpoints.py # API routes
β β βββ schemas.py # Request/response models
β βββ system/ # System coordination
β β βββ architectai.py # Architect (main entry class)
β β βββ config.py # ArchitectConfig (pydantic-settings)
β β βββ logger.py # Rich-powered logging
β βββ utils/ # Shared utilities
βββ examples/
β βββ image_classification/ # CIFAR-10, ImageNet examples
β βββ nlp/ # NLP task examples
β βββ multimodal/ # Vision-language examples
β βββ edge/ # Edge deployment examples
βββ tests/ # Pytest test suite
βββ docs/ # Documentation
βββ docker/ # Docker & Compose config
βββ experiments/ # Experiment outputs
βββ models/ # Saved models
βββ .github/workflows/ # CI: lint, test, publish
βββ pyproject.toml # Build config & tool settings
βββ requirements.txt # Runtime dependencies
βββ requirements-dev.txt # Dev/test dependencies
Ready-to-run examples are provided for multiple domains:
| Example | Path | Description |
|---|---|---|
| CIFAR-10 Classification | examples/image_classification/discover_cifar10.py |
Discover a CNN for CIFAR-10 with parameter & memory constraints |
| ImageNet Discovery | examples/image_classification/discover_imagenet.py |
Large-scale image classification architecture search |
| Vision-Language | examples/multimodal/discover_vision_language.py |
Multimodal architecture discovery |
| Edge Deployment | examples/edge/ |
Hardware-constrained search for edge devices |
# Run the CIFAR-10 example
python examples/image_classification/discover_cifar10.py# Run all tests
pytest
# Run with coverage
pytest --cov=architectai
# Run a specific test file
pytest tests/test_graph.py -v# Linting
flake8 src tests
# Type checking
mypy src
# Formatting
black src tests
isort src testsArchitectAI uses pydantic-settings for configuration. You can configure the framework via environment variables or by passing an ArchitectConfig object:
from architectai import Architect, ArchitectConfig
config = ArchitectConfig(
project_name="my_experiment",
debug=True,
)
architect = Architect(config_override=config)| Environment Variable | Default | Description |
|---|---|---|
ARCHITECTAI_PROJECT_NAME |
sdnn_project |
Name of the project/experiment |
ARCHITECTAI_DEBUG |
false |
Enable debug logging |
- Core DSL and graph representation
- Evolutionary search with random sampling
- Hardware-aware constraint evaluation
- PyTorch code generation
- CLI and REST API
- CI/CD pipeline (lint, test, publish)
- NSGA-II multi-objective evolution
- Full reasoning engine with architecture validity rules
- Training loop integration with real accuracy evaluation
- Latency and memory profiling on real hardware
- Visualization dashboards (graph, evolution, Pareto)
- ONNX and TensorFlow export backends
- Distributed search across multiple GPUs/nodes
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Ensure all checks pass:
flake8 src tests && mypy src && pytest
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License β see the LICENSE file for details.
Built with β€οΈ by ZitouniNidhal