Skip to main content

Evolutionary Neural Architecture Search — compress any PyTorch model with one function call

Project description

dNATY logo

dNATY

Evolutionary AI Model Compression

46.5% fewer FLOPs • 1.6× faster inference • 98.85% accuracy retained

PyPI version Python 3.10+ PyTorch 2.0+ License: BSL-1.1

Automated model compression using multi-objective evolutionary search. Zero manual engineering. One function call: compress(model, dataset).

dNATY Architecture


Why dNATY?

Problem: Most production models are oversized — too slow for real-time inference, too expensive to run.

Existing solutions require:

  • Manual architecture tuning
  • Days of hyperparameter search
  • Accuracy/speed trade-offs

dNATY solves this with episodic memory-guided evolutionary search — operators that worked before are tried more often. Finds Pareto-optimal solutions in minutes.

Proven Results (CIFAR-100)

Model FLOPs Reduction Speedup Accuracy Time
ResNet-50 -46.5% 1.6× 98.85% 5min
EfficientNet-B0 -40% 1.4× 98.85% 6min
MobileNetV3-Large -98% 1.8× 97.2% 4min

Project Structure

dNATY/
├── dnaty/              # Core compression framework
├── dnaty_saas/         # Production API (FastAPI)
├── frontend/           # Web UI (React + TypeScript)
├── notebooks/          # Experiments & benchmarks
├── scripts/            # Demo & utilities
├── tests/              # Unit tests
└── pyproject.toml      # Package config

Quick Start

pip install dnaty
from dnaty import compress
from dnaty.experiments.fast_dataset import FastDataset

# Your existing model (any PyTorch model with Linear layers)
model = your_trained_model

# Your data
ds = FastDataset("MNIST", device="cpu", train_subset=10_000)

# Compress
result = compress(model, ds, target_flops=0.5, n_generations=30)

print(result.summary())
# CompressResult | arch=[128, 64] | FLOPs -46.5% (327680 -> 175104) |
#   params -52.3% (328K -> 156K) | acc=0.9821

How It Works

dNATY runs a population of candidate architectures through an evolution loop:

  1. Mutate — apply structural operators (add/remove neurons, merge layers, etc.)
  2. Train — locally train each candidate for a few epochs
  3. Select — NSGA-II Pareto selection: maximize accuracy, minimize FLOPs
  4. Remember — episodic memory records which operators helped most; they get picked more often next round

The memory mechanism is dNATY's core innovation. Over generations, the search becomes smarter — not random.


API

compress(model, train_data, **kwargs) -> CompressResult

Parameter Default Description
model required Any nn.Module with Linear layers
train_data required DataLoader or FastDataset
target_flops 0.5 Target fraction of original FLOPs (0.5 = 50% less)
n_generations 30 Evolutionary generations
n_pop 15 Population size
device auto 'cpu' or 'cuda'
seed None Fix for reproducibility

CompressResult

result.model              # compressed nn.Module, ready to use
result.accuracy           # validation accuracy
result.flops_reduction    # e.g. 0.465 = 46.5% fewer FLOPs
result.flops_reduction_pct  # same as percentage
result.params_reduction_pct
result.arch               # hidden layer sizes found  [128, 64]
result.summary()          # one-line human-readable summary

SaaS API

dNATY ships with a production-ready FastAPI backend.

cd dnaty_saas
cp .env.example .env   # fill DATABASE_URL, JWT_SECRET, ANTHROPIC_API_KEY
uvicorn main:app --reload

POST /api/v1/compress

{
  "description": "classifica defeitos em pecas, precisa rodar no Raspberry Pi",
  "dataset": "MNIST",
  "target_flops": 0.5,
  "n_generations": 30
}

Response 202:

{ "job_id": "a3f2c1b0", "status": "queued", "message": "..." }

GET /api/v1/compress/{job_id}

{
  "status": "completed",
  "result": {
    "accuracy": 0.9821,
    "flops_reduction": 0.465,
    "arch": [128, 64],
    "explanation": "...",        // Claude-generated explanation
    "deployment_code": "..."     // ready-to-use Python code
  }
}

Set ANTHROPIC_API_KEY in .env to enable Claude explanations.
Without it, the endpoint still works — returns template text instead.


Getting Started

Web UI

cd frontend
npm install
npm run dev

Open http://localhost:5173

Jupyter Notebooks

CLI Demo

python scripts/demo_compress.py           # 20 gens, MNIST (~5 min CPU)
python scripts/demo_compress.py --full    # 30 gens, more accurate
python scripts/demo_compress.py --dataset FashionMNIST

Benchmarks

Metric Value
FLOPs reduction vs. initial arch -46.5%
FLOPs reduction vs. RandomNAS better in Pareto front
Speedup to target accuracy 1.6x fewer generations
CL: BWT vs. EWC 6.9x less forgetting

All numbers reproducible with python scripts/prove_it.py.


License

BSL 1.1 — free for non-commercial use; contact pedrol.vergueiro@gmail.com for commercial licensing.

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

dnaty-1.0.1.tar.gz (50.2 kB view details)

Uploaded Source

Built Distribution

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

dnaty-1.0.1-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file dnaty-1.0.1.tar.gz.

File metadata

  • Download URL: dnaty-1.0.1.tar.gz
  • Upload date:
  • Size: 50.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for dnaty-1.0.1.tar.gz
Algorithm Hash digest
SHA256 aa8fa63e4371cdb0fbcad85d37cc1110a78ce82230d6e96b184a3924acd7bfb7
MD5 63862975af4411662ee6a00137c17ea5
BLAKE2b-256 e56dff5cbd733674d5fcb78328c2898cf865d2aeba2245d871f10fc31f1a371d

See more details on using hashes here.

File details

Details for the file dnaty-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: dnaty-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for dnaty-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59c437e051c97edf49b51b88e24b53857dc3f62f6bbe311f8926def6d2ae2fd6
MD5 8d2c6e6f5093cf35744ffede803c3bc4
BLAKE2b-256 b4436b72d5cf7aa491311420d64d3623072c56e1dcf449d8d1c49323dbe06c23

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