Skip to main content

AI-powered ML code analysis and optimization suggestions

Project description

DeepOptimizer: Pre-flight Checks for ML Code ✈️

Python 3.8+ License: Apache 2.0 Code style: black

Created by Willy Nilsson

Inspired by how pilots use checklists to ensure safety, DeepOptimizer provides systematic analysis of ML code before training. It combines fast pattern detection with Gemini AI insights to catch issues and suggest optimizations.

🚀 Project Components

1. CLI Tool (deepoptimizer/)

A command-line tool that analyzes Python ML code:

  • Fast rule-based detection of common ML bugs
  • Gemini AI-powered deep analysis
  • 70+ optimization techniques in knowledge base
  • Beautiful terminal output with multiple export formats

2. Web Interface (website/)

Static showcase site with:

  • Project overview and installation guide
  • Interactive technique demonstrations
  • Examples of detected issues
  • Author information

📦 Quick Start

CLI Tool (Recommended for developers)

# Install
pip install deepoptimizer  # Coming soon to PyPI

# Or install from source
git clone https://github.com/willynilsson/deepoptimizer.git
cd deepoptimizer
pip install -e .

# Set up API key
echo 'GEMINI_API_KEY=your-api-key-here' > .env

# Analyze code
deepoptimizer analyze model.py
deepoptimizer analyze ./my_project --no-llm  # Fast, rule-based only
deepoptimizer techniques --search attention   # Browse optimization techniques

Web Demo

Visit the live demo to see the optimization process in action.

Full Stack Development

# Clone repository
git clone https://github.com/willynilsson/deepoptimizer.git
cd deepoptimizer

# Backend setup
cd backend
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver

# Frontend setup (new terminal)
cd website
npm install
npm run dev

🎯 What It Does

DeepOptimizer helps ML engineers by:

  1. Finding Bugs: Detects common issues like missing model.eval(), memory leaks, wrong loss functions
  2. Improving Performance: Suggests optimizations like mixed precision, better batch sizes, efficient attention
  3. Teaching Best Practices: Provides research-backed suggestions with implementation examples
  4. Saving Time: Automated analysis that would take hours to do manually

Example Issues Detected

# ❌ Missing model.eval() during validation
def validate(model, dataloader):
    for batch in dataloader:  # model still in training mode!
        output = model(batch)

# ❌ Memory leak from accumulating tensors
total_loss = 0
for batch in dataloader:
    loss = criterion(model(batch), target)
    total_loss += loss  # Keeps computation graph!

# ❌ Wrong loss function
loss = F.mse_loss(output, labels)  # MSE for classification!

# ✅ DeepOptimizer detects these and provides fixes

📊 Features

CLI Features

  • Multi-severity analysis: Errors, warnings, and suggestions
  • Project-wide analysis: Analyze entire codebases
  • Export formats: Terminal, JSON, Markdown
  • Configuration files: .deepoptimizer for project settings
  • Offline mode: Use --no-llm for fast rule-based analysis

Detection Capabilities

  • Training/validation bugs (missing eval mode, no_grad)
  • Memory leaks and inefficiencies
  • Wrong loss functions for tasks
  • Suboptimal hyperparameters
  • Missing optimizations (mixed precision, etc.)
  • Architecture issues (no skip connections, etc.)

Knowledge Base

  • 70+ optimization techniques
  • Conflict detection between techniques
  • Framework-specific implementations
  • Hardware-specific optimizations
  • Research paper citations

🛠️ Architecture

DeepOptimizer/
├── deepoptimizer/          # CLI tool (main package)
│   ├── analyzer.py         # Main analysis orchestrator
│   ├── llm_analyzer.py     # Gemini AI integration
│   ├── rule_detector.py    # Fast pattern matching
│   ├── knowledge_base.py   # Optimization techniques
│   └── fixtures/           # 55+ ML optimization techniques
└── website/                # Static React showcase site
    └── src/components/     # Interactive demos

The CLI tool runs completely standalone with user-provided Gemini API keys.

💡 Use Cases

  1. Code Reviews: Automatically catch ML-specific issues
  2. Performance Tuning: Get suggestions for faster training/inference
  3. Learning: Understand optimization techniques with examples
  4. CI/CD Integration: Add to pipelines for automated checks

🤝 Contributing

This is a portfolio project, but contributions are welcome! Areas of interest:

  • Adding more detection rules
  • Expanding the knowledge base
  • Improving LLM prompts
  • Adding support for more frameworks

📝 License

Apache License 2.0 - see LICENSE file. Created by Willy Nilsson.

This license provides patent protection and ensures proper attribution while remaining business-friendly and open source.

🧠 About the Author

Built by Willy Nilsson. The concept was inspired by aviation psychology - how pilots use checklists to manage complex systems safely. My background in psychology and programming led to applying these principles to ML development.

Currently seeking opportunities in AI/ML tooling development.

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

deepoptimizer-0.1.0rc1.tar.gz (75.5 kB view details)

Uploaded Source

Built Distribution

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

deepoptimizer-0.1.0rc1-py3-none-any.whl (67.9 kB view details)

Uploaded Python 3

File details

Details for the file deepoptimizer-0.1.0rc1.tar.gz.

File metadata

  • Download URL: deepoptimizer-0.1.0rc1.tar.gz
  • Upload date:
  • Size: 75.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for deepoptimizer-0.1.0rc1.tar.gz
Algorithm Hash digest
SHA256 001280bea81bce4094029a215eb76cdcf68fa50b4d9337b04b7c198cb436c6bb
MD5 0da4d70284d67e4fda61f42831464795
BLAKE2b-256 de9e1d7d759d8985aafd294df8e68cd4372a33d0ac7ad3452f80d7a784bf8662

See more details on using hashes here.

File details

Details for the file deepoptimizer-0.1.0rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for deepoptimizer-0.1.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 ced68bc3b3d24ffa635e5e9dbe24a02dd12dff0b95140d19e1eb0ab03f3f0f5d
MD5 3f7ab2fb2ec602d6527f9e3b225099e9
BLAKE2b-256 df7bd01011eda7431ff59fa789edb5e912e211399afbeac2ee8486489fa71571

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