labmlai Annotated Deep Learning Paper Implementations
repository·master·Indexed 13 days ago
https://github.com/labmlai/annotated_deep_learning_paper_implementationsA collection of annotated PyTorch implementations of deep learning research papers. The repository covers a wide range of architectures, including PonderNet for adaptive computation, Capsule Networks, ConvMixer, DDPM, various GANs (CycleGAN, DCGAN, WGAN-GP), Graph Attention Networks (GAT and GATv2), GPT-NeoX, and normalization techniques like Batch Normalization and Group Normalization.
What's inside labmlai
- PonderNet is a PyTorch implementation of the paper PonderNet: Learning to Ponder. It is an adaptive computation mechanism that adjusts the number of steps a recurrent network takes based on the specific input provided. This allows the model to spend more computational resources on complex inputs and fewer on simpler ones. The stopping criteria and computation steps are learned end-to-end using gradient descent.
Overview of Cycle GAN implementation
masterThis repository provides a PyTorch implementation and tutorial for the paper Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks. It is designed to demonstrate how CycleGAN can perform image-to-image translation without requiring paired training examples.Overview of Vision Transformer (ViT) implementation
masterThis repository provides a PyTorch implementation of the Vision Transformer (ViT) architecture as described in the paper 'An Image Is Worth 16x16 Words: Transformers For Image Recognition At Scale'.
Unlike traditional computer vision models, ViT uses a pure transformer architecture without convolution layers. The core workflow is:
- Patch Splitting: The input image is split into patches.
- Patch Embeddings: Patches are flattened and transformed into embeddings via a linear transformation.
- Positional Embeddings: Learned positional embeddings are added to the patch embeddings to provide spatial context.
- Transformer Encoder: A standard transformer encoder processes the embeddings, including a special
[CLS](classification) token. - Classification: The final encoding of the
[CLS]token is passed through an MLP (Multi-Layer Perceptron) to perform image classification.
Overview of the Feedback Transformer
masterThe Feedback Transformer is a PyTorch implementation of the paper 'Accessing Higher-level Representations in Sequential Transformers with Feedback Memory'.
Unlike standard transformers that process tokens in parallel by attending only to the outputs of the previous layer, the Feedback Transformer introduces recurrence by allowing each layer to attend to the outputs of all previous layers from previous steps.
Key Characteristics:
- Training: Significantly slower (5X - 10X) than parallel transformers because tokens must be processed sequentially.
- Inference: Faster during prediction if memory vectors are cached, as the next token can be predicted efficiently.
- Memory Optimization: The implementation can use a weighted sum of outputs from all layers instead of keeping every layer's output, reducing memory usage during caching.
Overview of ResNet (Deep Residual Learning for Image Recognition)
masterThis repository provides a PyTorch implementation of the paper Deep Residual Learning for Image Recognition.
ResNets are designed to solve the degradation problem, where the accuracy of deep neural networks begins to degrade as the number of layers becomes very high. Instead of training layers to learn direct mappings, ResNets train layers as residual functions. This allows for much deeper architectures by ensuring that accuracy increases with depth before eventually saturating.
Explore available Optimizer implementations
masterThe
labml_nn.optimizersmodule provides annotated implementations of various deep learning optimizers. You can use these to update model parameters during training. Available implementations include:- Adam Optimizer: Standard Adam implementation.
- AMSGrad Optimizer: A variant of Adam that addresses convergence issues.
- Adam Optimizer with warmup: Adam with a learning rate warmup schedule.
- Noam Optimizer: Often used in Transformer architectures.
- Rectified Adam (RAdam) Optimizer: Provides a dynamic rectifier to adjust variance of the adaptive learning rate.
- AdaBelief Optimizer: Adapts step size according to the belief in the current gradient.
- Sophia-G Optimizer: A second-order optimizer designed for large-scale training.
Understand Gradient Penalty for Wasserstein GAN (WGAN-GP)
masterWGAN-GP is an implementation of the paper Improved Training of Wasserstein GANs.
In standard Wasserstein GANs (WGAN), the Lipschitz constraint on the discriminator (critic) is typically enforced via weight clipping. However, weight clipping (including L2 norm clipping, weight normalization, or L1/L2 weight decay) can lead to two major issues:
- Limiting Discriminator Capacity: It restricts the expressive power of the critic.
- Gradient Instability: It can cause exploding or vanishing gradients, especially when Batch Normalization is not used.
WGAN-GP solves these issues by using a gradient penalty to enforce the Lipschitz constraint, providing a more stable training process without the drawbacks of weight clipping.
Implement Evidential Deep Learning for Classification Uncertainty
masterThis implementation provides a PyTorch-based approach to Evidential Deep Learning (EDL) as described in the paper Evidential Deep Learning to Quantify Classification Uncertainty. It is designed to quantify uncertainty in classification tasks by treating the predicted class probabilities as parameters of a Dirichlet distribution.Deep Q Networks (DQN) Implementation Overview
masterThis repository provides a PyTorch implementation of the paper 'Playing Atari with Deep Reinforcement Learning'. The implementation includes several advanced reinforcement learning components that can be used together or separately:
- Dueling Network: An architecture modification to the Q-network.
- Prioritized Replay: An enhanced replay buffer mechanism.
- Double Q Network: A method to reduce overestimation bias in Q-learning.
For a complete walkthrough of how these components are integrated into a training loop, you can refer to the provided experiment notebook.
# Reference to the experiment notebook for a full implementation walkthrough # https://colab.research.google.com/assets/colab-badge.svgUse GPT-NeoX for inference and fine-tuning
masterThis implementation of Eleuther GPT-NeoX provides tools for model definition, tokenization, checkpoint management, and various usage samples.
Key components include:
- Model definition: The core architecture implementation.
- Tokenizer: Tools for converting text to tokens.
- Checkpoint helpers: Utilities for downloading and loading model checkpoints.
- Utilities: General helper functions.
Common tasks include:
- Generating text: Using the model for inference.
- Fine-tuning: Specifically, fine-tuning biases using pipeline-parallelism.
- Evaluation: Running evaluations, including half-precision models on a single GPU.
Instance Normalization implementation
masterThis repository provides a PyTorch implementation of Instance Normalization, as described in the paper "Instance Normalization: The Missing Ingredient for Fast Stylization".
Instance normalization is designed to improve style transfer tasks by performing contrast normalization. It addresses the difficulty convolutional networks face when trying to learn contrast normalization independently, ensuring that stylization results are not dependent on the contrast of the input content image.
Graph Attention Networks (GAT) Overview
masterGraph Attention Networks (GAT) are a PyTorch implementation of the paper Graph Attention Networks. GATs are designed to operate on graph data, where nodes represent entities (e.g., research papers in the Cora dataset) and edges represent connections (e.g., citations).
Key technical concepts:
- Masked Self-Attention: GAT utilizes a mechanism similar to Transformers to allow node embeddings to attend to the embeddings of their connected neighbors.
- Layered Architecture: The model consists of stacked graph attention layers. Each layer takes node embeddings as input and produces transformed embeddings as output.