Writing & Engineering Notes

Technical Articles & Deep Dives

Hands-on technical explorations into building LLMs from scratch, implementing attention mechanisms, computer vision pipelines, and full-stack software architecture.

Showing 30 of 30 articles
2025-12-19•3 min read

Build gpt oss from scratch

A technical guide for university students on building a truly open GPT-OSS model from scratch. We explain the core components: data handling, advanced tokenization, the specialized architecture blocks, and the training pipeline.

Read article
2025-12-19•3 min read

Build gemma from scratch

Learn the core technical steps: from data preparation and tokenization to understanding the architecture of Gemma 3 270M, using simple, clear explanations for AI students.

Read article
2025-12-18•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 21: Mixed Precision and Fine-Grained Quantization

This part explains how DeepSeek reduces memory use and speeds up training by using two smart quantization methods: Mixed Precision and Fine-Grained Quantization.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 11: Sinusoidal Positional Encoding

We study Sinusoidal Positional Encodings (SPE). We learn why they create smooth position values, how the sin and cos functions enable mathematical rotations, and why understanding rotation is key to building DeepSeek's advanced RoPE system.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 12: Rotary Positional Encoding (RoPE)

Learn the core technical idea of Rotary Positional Encoding (RoPE) and why it is essential for modern large language models like DeepSeek. We focus on injecting position via rotation without changing vector magnitude.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 13: Decoupling Attention and Position

This part explains DeepSeek’s advanced method (Decoupled RoPE) for merging Multi-Head Latent Attention (MLA) and Rotary Positional Encoding (RoPE). This technique drastically reduces memory needs while keeping high model performance.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 14: Mixture of Experts (MoE)

DeepSeek uses Mixture of Experts (MoE) to train faster and run quicker. This part explains how MoE works by using specialized, sparsely activated neural networks.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 15: DeepSeek's MoE Innovations

This part explains the foundational architecture of Mixture of Experts (MoE), focusing on how sparsity and routing make large language models faster and more efficient.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 16: Understanding Mixture of Experts

This part explains key methods—Auxiliary Loss, Load Balancing, and Capacity Factor—used in DeepSeek's Mixture of Experts (MoE) architecture to ensure experts are used equally and efficiently during training.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 17: DeepSeek's MoE Innovations

Learn the three key technical innovations DeepSeek used to make the Mixture of Experts (MoE) architecture better: loss-free load balancing, shared experts, and fine-grained segmentation.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 18: Multi-Token Prediction Foundation

We explore Multi-Token Prediction (MTP), a core technical innovation in DeepSeek V3. Learn how predicting multiple tokens at once improves training efficiency and model planning.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 19: DeepSeek's Multi-Token Prediction (MTP)

We explore the core technical innovation in DeepSeek's pre-training: Multi-Token Prediction (MTP). We detail how the causal chain is maintained across prediction steps and the exact operations within each prediction head.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 20: The Foundation of Quantization

This part explains the final major pillar of DeepSeek: Quantization. Learn why we reduce the precision of model parameters and how it saves massive amounts of memory.

Read article
2025-12-17•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 22: Advanced Quantization Techniques

Learn three key technical methods DeepSeek uses to keep AI models fast and accurate: increasing accumulation precision, choosing mantisa over exponents, and online quantization.

Read article
2025-12-16•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 10: Positional Encodings (Integer and Binary)

We explain the crucial role of positional encodings in DeepSeek's architecture, exploring integer and binary methods to understand how large language models track word order.

Read article
2025-12-16•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 7: The KV Cache Memory Problem

We explore the core memory problem in large language models caused by the Key-Value (KV) Cache and learn about Multi-Query Attention (MQA), the first innovation used to solve this issue.

Read article
2025-12-16•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 8: Grouped Query Attention (GQA)

We explore Grouped Query Attention (GQA), a smart technique that helps large AI models save memory while keeping strong performance. This is key for efficient system design.

Read article
2025-12-16•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 9: Multi-Head Latent Attention (MHLA)

Understand the core technical innovation: Multi-Head Latent Attention. Learn how DeepSeek reduced memory cost (KV Cache size) while keeping high performance.

Read article
2025-12-15•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 4: Causal Attention

Read article
2025-12-15•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 5: Multi-Head Attention

Learn the core component of modern LLMs: Multi-Head Attention. We cover why it is needed and the step-by-step mathematical process to implement it.

Read article
2025-12-15•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 6: The KV Cache Memory Problem

Understand the technical foundation of the Key Value Cache (KV Cache) and why it is essential for making Large Language Model (LLM) inference quick and efficient.

Read article
2025-12-13•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 1: The Foundation

Salam everyone! In this first article, we break down what DeepSeek is, why it is different from ChatGPT, and the smart tricks it uses to be powerful and efficient. Let's dive in!

Read article
2025-12-13•3 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 2: Opening the hood of the DeepSeek engine

Salam Alikoum! Today we are opening the hood of the DeepSeek engine. We will follow one word to see how an LLM actually works from the inside. No complex math, just logic.

Read article
2025-12-13•4 min read•DEEPSEEK SERIES

Build DeepSeek from scratch - Part 3: The Attention Mechanism

We all love context! But old AI models were terrible at it. We dive into the 'Context Bottleneck'—the major historical problem that nearly stopped AI progress—and discover how the brilliant Attention Mechanism saved the day and gave LLMs their true power.

Read article
2025-04-19•8 min read

RAG vs. CAG: Comparing Approaches to Enhance LLM Knowledge

This report provides a detailed comparison of Retrieval-Augmented Generation (RAG) and Cache-Augmented Generation (CAG), two key techniques for addressing knowledge limitations in Large Language Models (LLMs). It explains the distinct mechanisms of each approach—RAG's on-demand retrieval from indexed knowledge versus CAG's preloading of knowledge into a KV cache. The analysis covers critical factors including scalability, latency, data freshness, accuracy considerations, and suitability for different use cases, including potential hybrid implementations. The goal is to clarify how each method enhances LLMs with external information and guide the selection process.

Read article
2025-04-16•6 min read

Optimizing Large Language Models: RAG vs. Fine-Tuning vs. Prompt Engineering

This report provides a detailed analysis of three key techniques for enhancing Large Language Model (LLM) outputs: Retrieval-Augmented Generation (RAG), Fine-Tuning, and Prompt Engineering. It explains the core mechanisms, benefits (e.g., up-to-date info via RAG, deep expertise via Fine-Tuning, immediate flexibility via Prompt Engineering), and limitations (e.g., latency, training costs, knowledge boundaries) of each method, comparing their effectiveness and discussing how they can be combined.

Read article
2025-04-16•7 min read

YOLO Object Detection: From Training to Prediction

This report presents a comprehensive breakdown of how YOLO (You Only Look Once) object detection works, from training with labeled data and anchor box assignment to inference on unseen images. It explains key concepts including one-stage detection, anchor box generation using K-Means, grid cells, IoU matching, and Non-Maximum Suppression (NMS). The differences between training and prediction phases are highlighted with examples, and the meaning of 'one single pass of a neural network' is thoroughly explored and compared to other detection paradigms.

Read article
2025-04-10•7 min read

Application Permission Systems: A Deep Dive into RBAC, ABAC, and Best Practices

This guide explores various application permission strategies, starting with the pitfalls of direct role checking. It provides a detailed look at Role-Based Access Control (RBAC), covering its implementation, advantages, and limitations (like handling ownership). The report then introduces Attribute-Based Access Control (ABAC) as a more flexible solution for complex, fine-grained permissions, explaining its core concepts and benefits. Includes comparisons, discussions on scalability, maintainability, and integration with authentication providers, supported by conceptual code examples.

Read article
2025-04-09•5 min read

Deep Dive into 5 Essential Sorting Algorithms

This deep dive explains and analyzes five common sorting algorithms: Bubble Sort, Insertion Sort, Selection Sort, Quick Sort, and Merge Sort. Key aspects covered include their core logic, implementation details (with code examples), time and space complexity analysis (Big O notation for best, average, worst cases), and a comparison of their pros and cons.

Read article
2025-03-20•3 min read

Deep Dive into LLMs like ChatGPT

This extensive deep dive into Large Language Models (LLMs) like ChatGPT explains how they work, their capabilities, limitations, and future potential, targeting a general audience. Here's a breakdown of the key points:

Read article