modded-nanogpt

repository·master·Indexed 26 days ago

https://github.com/kellerjordan/modded-nanogpt

A repository dedicated to the 'NanoGPT speedrun', a collaborative effort to find the fastest algorithms for training language models on the FineWeb dataset using 8 NVIDIA H100 GPUs. It includes implementations of the Muon optimizer, world record history for training speed, and various architectural optimizations such as Value Residual and Embed Shortcuts to achieve target validation loss thresholds.

Tokens
61.8K
Snippets
128
Records
299
Agent score
90%

What's inside modded-nanogpt

  1. Overview of MUDD-gated & Lightweight DC iterations

    master

    This project tracks three iterations of a MUDD-gated and Lightweight DC (Direct Correction) architecture for NanoGPT.

    • v1: Combines a lightweight layer-10 DC correction with a MUDD-style gate stack that generates per-token coefficients for XSA gates, attention gates, x0/bigram injections, and layer skips.
    • v2: Makes the DC tensors directly generated by the MUDD gate instead of using a standalone parameter path.
    • v3 (Current Version): Rebases the architecture onto an upstream base featuring the bigram sign trick and FP8 MLP changes. It optimizes the bigram dimension and vocabulary size to ensure the MUDD gate can effectively utilize the bigram embedding path.
  2. Overview of PyTorch Distributed Shampoo

    master

    Distributed Shampoo is a preconditioned stochastic gradient optimizer in the adaptive gradient (Adagrad) family. It is designed to converge faster by leveraging neural network-specific structures, achieving comparable model quality in fewer iterations or epochs. It supports homogeneous multi-node multi-GPU training and specializes in dense parameters.

    Key capabilities include:

    • Support for Serial, DDP, FSDP, HSDP, FSDP2, and HSDP2 training.
    • Learning rate grafting (specifically for the second moment/diagonal preconditioner).
    • Support for both normal and AdamW (decoupled) weight decay.
    • Exponential moving averaging (EMA) for first moment estimation.
    • Multiple root inverse computation methods (Symmetric eigendecomposition, QR algorithm, Coupled inverse Newton iteration, etc.).
    • Support for SOAP (running Adam in the eigenbasis of Shampoo's preconditioner).
    • Spectral descent via reduced SVD or Newton-Schulz iteration (can be used to implement Muon).
  3. Overview of AsyncDataLoadAttnFinalWindow features

    master

    The AsyncDataLoadAttnFinalWindow implementation introduces several optimizations to reduce training bottlenecks and improve validation accuracy:

    • Asynchronous Data Prefetching: Immediately starts prefetching and indexing the next shard on the CPU during GPU-heavy workloads to prevent CPU data indexing from bottlenecking the GPU.
    • Partial Shard Indexing: Partially indexes the first shard before training begins, using a parallel thread to finish indexing by the 5th training step.
    • Extended Final Layer Attention: Extends the final layer attention window to 20 for validation purposes. This does not require applying YaRN for this specific layer and has been shown to drop loss by approximately 0.001.
  4. Overview of 50B-token training runs

    master

    This directory contains experimental results from training runs extended to 50B FineWeb tokens. The experiments evaluate the generalization of speedrun configurations to long durations, specifically comparing the performance of the Muon optimizer against Adam for the transformer body (while the head and embedding remain optimized by Adam).

    Key comparisons include:

    1. Optimizer Performance: Muon vs. Adam at 50B tokens.
    2. Training Duration: 5 epochs of 10B tokens vs. a single run of 50B tokens.

    Results are documented in individual text files within this folder.

  5. Overview of Muown + NorMuon + Contra optimization

    master

    This specific optimization track combines three mechanisms to achieve low loss in a reduced number of steps (2995 steps). The combination includes:

    • Muown: The base architecture.
    • NorMuon: An optimization mechanism.
    • Contra-Muon: An additional mechanism.
    • Power-law cooldown LR: A learning rate mechanism.

    The performance is measured by loss across different seeds, with the goal of passing a specific margin threshold after 2995 steps.

  6. Understand the GPT-2 Medium Speedrun Track

    master
    The GPT-2 Medium track targets a loss of 2.92 (based on the Andrej Karpathy 350M-parameter llm.c baseline). This track aims for performance similar to the original GPT-2 Medium. All other standard rules from the project apply.
  7. Understand the Modded-NanoGPT Optimization Benchmark

    master

    The Modded-NanoGPT Optimization Benchmark is a competitive effort to find efficient neural network optimizers. Unlike speedruns focused on wallclock time, this benchmark aims to minimize the step count required to reach a specific performance target.

    Benchmark Goal: Achieve a validation loss below 3.28 in the fewest number of steps possible.

    Validation Rules:

    • Do not modify the dataset, batch size, or architecture used by the baseline.
    • Do not perform more than one forward-backward pass per step.
    • You are free to modify the optimization algorithm and hyperparameters arbitrarily.
  8. Dampen radial gradient component

    master
    This component implements post-step radial damping, building upon the Contra-Muon to Soft-Muon setup from PR291. After an optimizer update is applied, the hidden matrix parameter norm is rescaled. This process dampens outward radial movement while preserving inward movement, controlled by specific constants logged during each run.
  9. Use the Unified, Zero-Copy Optimizer (NorMuonAndAdam)

    master

    The NorMuonAndAdam optimizer is a combined optimizer designed for per-parameter configuration rather than per-optimizer groups. It utilizes a 'parameter bank' strategy to consolidate weight matrices (like Attention and MLP) into single large parameters. This eliminates the need for time-consuming memcpys associated with stacking and unstacking gradients during the optimizer window.

    Key benefits include:

    • Zero-Copy: Uses parameter banks to allow reshaping without memory movement.
    • Balanced Workloads: Distributes attention and MLP matrices evenly across GPUs.
    • Simplified Configuration: Replaces complex optimizer groups with a direct mapping of individual parameters to specific optimizer settings and communication strategies.