Skip to main content

A ready-to-use implementation of Andrei Karpathhy's "recipe for training neural networks"

Project description

neural_net_checklist: A Codified Recipe for Training Neural Networks

This repository implements a set of diagnostic assertions based on Andrei Karpathy's blog post "A Recipe for Training Neural Networks". Instead of a manual checklist, we provide programmatic checks to diagnose and debug neural networks efficiently.

Why This Exists

Training neural networks can be tricky. This toolkit saves you time by automating common diagnostic steps, allowing you to focus on the interesting parts of your model development.

What's Included

We've implemented the following checks:

  1. Verify loss @ init (for balanced classification tasks)

    assert_balanced_classification_cross_entropy_loss_at_init
    
  2. Init well (for balanced classification tasks)

    assert_balanced_classification_cross_entropy_loss_at_init
    
  3. Non-zero gradients

    assert_non_zero_gradients
    
  4. Batch independence

    • Forward pass (memory-efficient, but note: batchnorm breaks this naturally)
      assert_batch_independence_forward
      
    • Backward pass (uses more memory, checks gradients)
      assert_batch_independence_backward
      
  5. Overfit one batch

    assert_overfit_one_batch
    
  6. Visualize just before the net

    patch_module_raise_inputs
    

Quick Start

To run all assertions:

  • For classification tasks (e.g., computer vision):

    assert_all_for_classification_cross_entropy_loss
    
  • For causal language models:

    assert_all_for_llm_cross_entropy_loss
    

Installation

pip install neural_net_checklist

Usage Example

import neural_net_checklist.torch_diagnostics as torch_diagnostics

# Assume you have a model and a DataLoader
model = YourModel()
train_loader = YourDataLoader()

# Run all checks
torch_diagnostics.assert_all_for_classification_cross_entropy_loss(model, train_loader)

Contributing

Contributions are welcome! If you have ideas for additional checks or improvements, please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Happy debugging! Remember, neural nets can be finicky, but with the right tools, we can tame them. 🧠🔧

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

neural_net_checklist-1.0.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

neural_net_checklist-1.0.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file neural_net_checklist-1.0.0.tar.gz.

File metadata

  • Download URL: neural_net_checklist-1.0.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for neural_net_checklist-1.0.0.tar.gz
Algorithm Hash digest
SHA256 95dacd52f32f1e7b9c25c5b3b9a1859c7613aa34aa6c16f5a3a2a264d80b0c31
MD5 419a352b37acd1b65ee38c6af391d252
BLAKE2b-256 24fb579bec038cf247041d74aa63cdd33c28fc3a5e77de783edb96729519eeb8

See more details on using hashes here.

File details

Details for the file neural_net_checklist-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for neural_net_checklist-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2f4f47e18b8595d20598d07a8063931c0a0ae39e9ae6c728340d6e7e5f24a0e
MD5 1b7ca791a35dd6ed9a5bc44acea33c01
BLAKE2b-256 f01f4c774641a38d151f5f587769c6779f57472e894e7aaf5392a27a994401f0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page