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 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.0.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.0-py3-none-any.whl (67.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: deepoptimizer-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 8396fd4ec97b01e64719b287fcd45ae4962d363c936de724ecfb56c7606e32d5
MD5 02dcc7b37fa8000e6d542aab800e655f
BLAKE2b-256 408d9a6619fc3ff0cf9defd038ce328da25db16469173ab2f82810ee07b8d6a7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for deepoptimizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58565b0c33dc78b3f9861d9961f9db0c2376d0e854520b3fe78e11fab41a7e4e
MD5 03235b28f869cff089f2b499c0f288cb
BLAKE2b-256 2d073a4b910ccd0098b75ba901cef4f7278333aa9862077ea90cfead434e58be

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