โ† All Projects

Machine Learning & AI Research

NanoAlign

Distributed Transformer Pre-Training & DPO Alignment from Scratch

TransformerPre-trainingDPORoPEGQADistributed TrainingAlignment
๐Ÿ”’ Private Repo

Problem

Most practitioners treat foundation models as black boxes consumed through fine-tuning APIs. Very few understand the architectural innovations (RoPE, GQA, SwiGLU) that underpin modern LLMs or how to align them without brittle reward model training.

Solution

Implemented a complete decoder-only Transformer from scratch with Rotary Position Embeddings, Grouped Query Attention, SwiGLU activations, and RMSNorm. Pre-trained on a curated corpus, then aligned using SFT + DPO with the closed-form loss.

Architecture

350M params, 24 layers, GQA with 8 KV heads and 32 Q heads, 2048 context length, SwiGLU FFN, RoPE theta=10000, RMSNorm. DDP across 4 GPUs, bf16 mixed precision, gradient checkpointing, cosine LR. DPO beta=0.1 on (prompt, chosen, rejected) triples.

Real-World Impact

Achieved 38% MFU (comparable to published LLaMA-2 training efficiency), PPL of 14.2 on held-out validation corpus. DPO alignment produced 61% win-rate vs SFT baseline.

Challenges Faced

Numerically stable RoPE at extended context lengths; gradient accumulation correctness across DDP ranks; DPO numerical stability with beta annealing.

Key Learnings

Full mechanistic understanding of modern LLM internals, distributed training primitives, alignment without RLHF complexity, and infrastructure-from-scratch mindset.

Engineering Metrics

350M params trained from scratch38% MFU Model FLOPs UtilizationValidation PPL: 14.2DPO win-rate: 61% vs SFT baseline

Demo / Screenshots

Screenshots coming soon: contact me for a demo

โ† Previous

KernelForge

Next โ†’

Vectra