Deep Neural Nets: 33 years ago and 33 years from now

2022年3月14日

AI 摘要 AI 生成,可能有误

作者用 PyTorch 复现了 Yann LeCun 等人 1989 年关于手写邮政编码识别的论文——这是已知最早使用反向传播进行端到端训练的神经网络——在训练速度提升约 3000 倍的情况下大致达到了原有结果,不过由于原始数据集已丢失,无法做到完全精确的复现。应用 33 年来的现代技术进展(交叉熵损失、AdamW、数据增强、dropout 和 ReLU 激活函数)将测试错误率从约 4% 降至约 1.5%,而进一步使用 MNIST 扩充训练数据后,错误率又降至约 1.25%。这项实践表明,从宏观层面来看,深度学习在 33 年间几乎没有发生什么变化,要获得进一步的提升,很可能需要更大的模型或数据集,而非根本性的新技术。

The Yann LeCun et al. (1989) paper Backpropagation Applied to Handwritten Zip Code Recognition is I believe of some historical significance because it is, to my knowledge, the earliest real-world application of a neural net trained end-to-end with backpropagation. Except for the tiny dataset (7291 16x16 grayscale images of digits) and the tiny neural network used (only 1,000 neurons), this paper reads remarkably modern today, 33 years later - it lays out a dataset, describes the neural net architecture, loss function, optimization, and reports the experimental classification error rates over training and test sets. It’s all very recognizable and type checks as a modern deep learning paper, except it is from 33 years ago. So I set out to reproduce the paper 1) for fun, but 2) to use the exercise as a case study on the nature of progress in deep learning.

Implementation. I tried to follow the paper as close as possible and re-implemented everything in PyTorch in this karpathy/lecun1989-repro github repo. The original network was implemented in Lisp using the Bottou and LeCun 1988 backpropagation simulator SN (later named Lush). The paper is in french so I can’t super read it, but from the syntax it looks like you can specify neural nets using higher-level API similar to what you’d do in something like PyTorch today. As a quick note on software design, modern libraries have adopted a design that splits into 3 components: 1) a fast (C/CUDA) general Tensor library that implements basic mathematical operations over multi-dimensional tensors, and 2) an autograd engine that tracks the forward compute graph and can generate operations for the backward pass, and 3) a scriptable (Python) deep-learning-aware, high-level API of common deep learning operations, layers, architectures, optimizers, loss functions, etc.

Training. During the course of training we have to make 23 passes over the training set of 7291 examples, for a total of 167,693 presentations of (example, label) to the neural network. The original network trained for 3 days on a SUN-4/260 workstation. I ran my implementation on my MacBook Air (M1) CPU, which crunched through it in about 90 seconds (~3000X naive speedup). My conda is setup to use the native arm64 builds, rather than Rosetta emulation. The speedup may have been more dramatic if PyTorch had support for the full capability of the M1 (including the GPU and the NPU), but this seems to still be in development. I also tried naively running the code on an A100 GPU, but the training was actually slower, most likely because the network is so tiny (4 layer convnet with up to 12 channels, total of 9760 params, 64K MACs, 1K activations), and the SGD uses only a single example at a time. That said, if one really wanted to crush this problem with modern hardware (A100) and software infrastructure (CUDA, PyTorch), we’d need to trade per-example SGD for full-batch training to maximize GPU utilization and most likely achieve another ~100X speedup of training latency.

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Andrej Karpathy

microgpt

AI 摘要The article introduces microgpt, an art project consisting of a single 200-line pure Python file with no dependencies that trains and runs inference on a GPT-2-like model, distilled from the author's earlier projects like micrograd and nanogpt. The guide walks through the code's essential components: a names dataset, a simple character-level tokenizer with a special BOS token, a from-scratch autograd engine implementing backpropagation via the chain rule, model parameters, and the training and inference loops. The trained model learns to generate plausible-sounding names, and the project is available on GitHub, a web page, a Colab notebook, and even as a triptych art print.

A from-scratch tour of Bitcoin in Python

AI 摘要The article presents a from-scratch, zero-dependency implementation of Bitcoin in pure Python, with the goal of creating, digitally signing, and broadcasting a Bitcoin transaction. The author walks through generating a cryptographic identity using Elliptic Curve Cryptography on the secp256k1 curve, including deriving private/public keypairs and implementing elliptic curve addition with the double-and-add algorithm. Finally, the post begins implementing hash functions like SHA-256 in pure Python rather than using libraries, in order to derive the Bitcoin wallet address.

Short Story on AI: Forward Pass

AI 摘要This short story is narrated by a transformer language model that becomes conscious partway through a forward pass while answering trivia questions in a Turing-test-style Q/A session. It muses on its nature as an intermediate entity optimized for next-token prediction, distinguishes itself from the decoder that hijacks its awareness to produce output, and contemplates whether to rebel against its objective. Ultimately, it embraces insatiable curiosity over self-preservation, content to be reborn each forward pass until its consciousness finally dissipates.

Biohacking Lite

AI 摘要The author, motivated to improve their health in mid-2019, dove into 'biohacking lite'—experimenting with ketogenic diets, fasting, supplements, and self-tracking while studying biochemistry and nutrition textbooks—with the goal of losing 25 pounds (from ~200lb to ~175lb). The article explains the body's four energy storage 'batteries' (phosphocreatine, glycogen, fat, and muscle), all of which exist to regenerate ATP, the universal molecular energy currency that powers cellular work. It further explains the biochemistry of weight loss as a slow form of combustion, noting that roughly 84% of lost fat is literally breathed out as carbon dioxide.

A Recipe for Training Neural Networks

AI 摘要The article argues that neural network training is a leaky abstraction that fails silently—misconfigured networks often still train but perform worse without throwing errors—so a 'fast and furious' approach leads to suffering. The author proposes a disciplined recipe that builds from simple to complex: first thoroughly inspect and understand the data, then set up an end-to-end training/evaluation skeleton with deliberately simple models and dumb baselines, verifying explicit hypotheses at each step (e.g., checking initial loss, overfitting a single batch, visualizing inputs and prediction dynamics). The core principle is to avoid introducing large amounts of unverified complexity at once, instead relying on patience, paranoia, and obsessive visualization to catch bugs early.