Skip to main content

AI-powered ML code analysis and optimization suggestions

Project description

DeepOptimizer: Pre-flight Checks for ML Code ✈️

Python 3.9+ 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 from TestPyPI (release candidate)
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ deepoptimizer==0.1.0rc1

# 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 Documentation

Visit willynilsson.github.io/deepoptimizer for project documentation and examples.

Development Setup

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

# CLI development
pip install -e ".[dev]"
pytest  # Run tests

# Website development
cd website
npm install
npm run dev  # Start dev server at localhost:5173

🎯 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

  • 55+ 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.1.tar.gz (61.8 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.1-py3-none-any.whl (68.9 kB view details)

Uploaded Python 3

File details

Details for the file deepoptimizer-0.1.1.tar.gz.

File metadata

  • Download URL: deepoptimizer-0.1.1.tar.gz
  • Upload date:
  • Size: 61.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for deepoptimizer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ed1f11b401898ffb4ff5fe44a2e1535f394f38e5d74a50ec2d09e5720831b867
MD5 8a5068d97281be5c8c2bec8571809e26
BLAKE2b-256 02cc2242ba21c846a2c77b47ad50776ebb16d94748d85e020414b618600ba27f

See more details on using hashes here.

File details

Details for the file deepoptimizer-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: deepoptimizer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 68.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for deepoptimizer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed1dd80dcaf3db616abbf9a8ade10c415f9d5c0500dc70cdc32c80e15ad6f147
MD5 c9a75d87328bafdc516ef2129532d61f
BLAKE2b-256 8f589f3d7d4cc7257800d698250e6e9a23a0d027de17fb1ee13f61fa8df2c002

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