Skip to main content

ML Doctor (mldoct) 🩺

ML Doctor is an enterprise-grade AI developer tool designed to optimize PyTorch engineering workflows. It combines V2 Data-Flow AST analysis, C++ GPU VRAM profiling, and XGBoost-powered diagnostics to eliminate silent bugs, prevent OOM crashes, and save cloud compute costs.


🔥 Enterprise Features (v1.0.0)

  1. V2 Data-Flow Linter (check):

    • Detects missing optimization steps (optimizer.zero_grad(), model.eval()).
    • Identifies Semantic Logic Bugs (e.g., Double Softmax from CrossEntropyLoss).
    • Flags CPU Bottlenecks (e.g., num_workers=0 in DataLoaders).
    • Features an Automated Fix Engine (--fix) to dynamically patch source files.
  2. Smart GPU Watchdog (watch):

    • Spawns a background C++ profiling thread via nvidia-smi to catch "Staircase" VRAM leaks before an OOM crash occurs.
    • Intercepts NaN, Inf, and exploding loss spikes in real-time.
    • Cost-Saver (Early Stopping): Automatically terminates cloud instances if validation loss plateaus, saving expensive AWS/GCP bills.
  3. Pre-Flight Auto-Tuner API:

    • Employs a Binary Search algorithm to stress-test your GPU prior to training, locking in the absolute maximum safe batch size for 100% hardware utilization.
  4. Machine Learning Diagnoser (diagnose):

    • Uses an embedded scikit-learn HistGradientBoostingClassifier to analyze training CSV logs.
    • Diagnoses Vanishing/Exploding Gradients, Severe Overfitting, and Missing Gradients with 99% accuracy.
    • Exports professional Markdown post-mortem reports.

📦 Installation

pip install mldoct

💻 CLI Usage Guide

1. V2 Semantic Linting & Auto-Fixing

Scan a script for structural bugs, logic errors, and GPU bottlenecks.

mldoctor check train.py

# Automatically patch identified omissions in-place
mldoctor check train.py --fix

2. Live Watchdog & Memory Profiler

Launch training with live VRAM tracking and Smart Early Stopping active.

mldoctor watch train.py --epochs 100

3. ML Curve Diagnosis

Diagnose a specific metric log or let the tool auto-discover the latest run in a directory.

# Auto-discover CSV in logs/ and export a markdown report
mldoctor diagnose ./logs/ --export-report

🚀 API Usage: Pre-Flight Auto-Tuner

Maximize your GPU utilization by dynamically finding the perfect batch size before initializing your DataLoader. Add this to your PyTorch script:

from mldoctor.tuner import tune_batch_size
from torch.utils.data import DataLoader

# 1. Initialize your model
model = MyResNet().to('cuda')

# 2. Run the Pre-Flight Dry Run (Pass the shape of a single dataset item)
optimal_batch = tune_batch_size(model, dataset_sample_shape=(3, 224, 224))

# 3. Proceed with 100% hardware utilization
train_loader = DataLoader(dataset, batch_size=optimal_batch, num_workers=4)

👨‍💻 Author & Maintainer

Release files for mldoct 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mldoct 1.0.0
File Size Uploaded
mldoct-1.0.0.tar.gz 384.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mldoct 1.0.0
File Interpreter ABI Platform
mldoct-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 779.4 kB

Release files / mldoct-1.0.0.tar.gz

Download URL mldoct-1.0.0.tar.gz
Size 384.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1566b44596863207b43a7503fd5011cdfe8bd085050ee8ef205b9e2300242517
BLAKE2b-256 checksum
How to use checksums
6052466fe671ec654cba2308e0e7c2a9152adb825357a5518b809306cea1188e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.0

Release files / mldoct-1.0.0-py3-none-any.whl

Download URL mldoct-1.0.0-py3-none-any.whl
Size 394.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b77f676568b151029755c374c77577b3f48d22665d043fc4acad2c99ec80adb0
BLAKE2b-256 checksum
How to use checksums
0eec8dd2149a5e73c87c50ecb12056e36ecae799ca10196a9380f05a26b7a7d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page