diff --git a/404.html b/404.html index 43db4d1..a52d79f 100644 --- a/404.html +++ b/404.html @@ -4,4 +4,4 @@ 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/about/index.html b/about/index.html index 5d5e13a..29f7360 100644 --- a/about/index.html +++ b/about/index.html @@ -4,4 +4,4 @@ 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/categories/index.html b/categories/index.html index 39026ab..3a4a75a 100644 --- a/categories/index.html +++ b/categories/index.html @@ -4,4 +4,4 @@ 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/images/ppo-for-language-models/.png b/images/ppo-for-language-models/.png new file mode 100644 index 0000000..2d74573 Binary files /dev/null and b/images/ppo-for-language-models/.png differ diff --git a/images/transformer-s-core-mechanics/.png b/images/transformer-s-core-mechanics/.png new file mode 100644 index 0000000..a7d5e5d Binary files /dev/null and b/images/transformer-s-core-mechanics/.png differ diff --git a/index.html b/index.html index b39061a..52ddc34 100644 --- a/index.html +++ b/index.html @@ -4,4 +4,4 @@ 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/index.xml b/index.xml index 111d1bf..9939ea3 100644 --- a/index.xml +++ b/index.xml @@ -1,4 +1,4 @@ -Eric X. Liu's Personal Page/Recent content on Eric X. Liu's Personal PageHugoenWed, 20 Aug 2025 06:02:35 +0000A Technical Deep Dive into the Transformer's Core Mechanics/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/Tue, 19 Aug 2025 00:00:00 +0000/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/<p>The Transformer architecture is the bedrock of modern Large Language Models (LLMs). While its high-level success is widely known, a deeper understanding requires dissecting its core components. This article provides a detailed, technical breakdown of the fundamental concepts within a Transformer block, from the notion of &ldquo;channels&rdquo; to the intricate workings of the attention mechanism and its relationship with other advanced architectures like Mixture of Experts.</p> +Eric X. Liu's Personal Page/Recent content on Eric X. Liu's Personal PageHugoenWed, 20 Aug 2025 06:04:36 +0000A Technical Deep Dive into the Transformer's Core Mechanics/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/Tue, 19 Aug 2025 00:00:00 +0000/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/<p>The Transformer architecture is the bedrock of modern Large Language Models (LLMs). While its high-level success is widely known, a deeper understanding requires dissecting its core components. This article provides a detailed, technical breakdown of the fundamental concepts within a Transformer block, from the notion of &ldquo;channels&rdquo; to the intricate workings of the attention mechanism and its relationship with other advanced architectures like Mixture of Experts.</p> <h3 id="1-the-channel-a-foundational-view-of-d_model"> 1. The &ldquo;Channel&rdquo;: A Foundational View of <code>d_model</code> <a class="heading-link" href="#1-the-channel-a-foundational-view-of-d_model"> @@ -6,7 +6,23 @@ <span class="sr-only">Link to heading</span> </a> </h3> -<p>In deep learning, a &ldquo;channel&rdquo; can be thought of as a feature dimension. While this term is common in Convolutional Neural Networks for images (e.g., Red, Green, Blue channels), in LLMs, the analogous concept is the model&rsquo;s primary embedding dimension, commonly referred to as <code>d_model</code>.</p>Quantization in LLMs/posts/quantization-in-llms/Tue, 19 Aug 2025 00:00:00 +0000/posts/quantization-in-llms/<p>The burgeoning scale of Large Language Models (LLMs) has necessitated a paradigm shift in their deployment, moving beyond full-precision floating-point arithmetic towards lower-precision representations. Quantization, the process of mapping a wide range of continuous values to a smaller, discrete set, has emerged as a critical technique to reduce model size, accelerate inference, and lower energy consumption. This article provides a technical overview of quantization theories, their application in modern LLMs, and highlights the ongoing innovations in this domain.</p>A Comprehensive Guide to Breville Barista Pro Maintenance/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/Sat, 16 Aug 2025 00:00:00 +0000/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/<p>Proper maintenance is critical for the longevity and performance of a Breville Barista Pro espresso machine. Consistent cleaning not only ensures the machine functions correctly but also directly impacts the quality of the espresso produced. This guide provides a detailed, technical breakdown of the essential maintenance routines, from automated cycles to daily upkeep.</p> +<p>In deep learning, a &ldquo;channel&rdquo; can be thought of as a feature dimension. While this term is common in Convolutional Neural Networks for images (e.g., Red, Green, Blue channels), in LLMs, the analogous concept is the model&rsquo;s primary embedding dimension, commonly referred to as <code>d_model</code>.</p>Quantization in LLMs/posts/quantization-in-llms/Tue, 19 Aug 2025 00:00:00 +0000/posts/quantization-in-llms/<p>The burgeoning scale of Large Language Models (LLMs) has necessitated a paradigm shift in their deployment, moving beyond full-precision floating-point arithmetic towards lower-precision representations. Quantization, the process of mapping a wide range of continuous values to a smaller, discrete set, has emerged as a critical technique to reduce model size, accelerate inference, and lower energy consumption. This article provides a technical overview of quantization theories, their application in modern LLMs, and highlights the ongoing innovations in this domain.</p>Transformer's Core Mechanics/posts/transformer-s-core-mechanics/Tue, 19 Aug 2025 00:00:00 +0000/posts/transformer-s-core-mechanics/<p>The Transformer architecture is the bedrock of modern Large Language Models (LLMs). While its high-level success is widely known, a deeper understanding requires dissecting its core components. This article provides a detailed, technical breakdown of the fundamental concepts within a Transformer block, from the notion of &ldquo;channels&rdquo; to the intricate workings of the attention mechanism and its relationship with other advanced architectures like Mixture of Experts.</p> +<h3 id="1-the-channel-a-foundational-view-of-d_model"> + 1. The &ldquo;Channel&rdquo;: A Foundational View of <code>d_model</code> + <a class="heading-link" href="#1-the-channel-a-foundational-view-of-d_model"> + <i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"></i> + <span class="sr-only">Link to heading</span> + </a> +</h3> +<p>In deep learning, a &ldquo;channel&rdquo; can be thought of as a feature dimension. While this term is common in Convolutional Neural Networks for images (e.g., Red, Green, Blue channels), in LLMs, the analogous concept is the model&rsquo;s primary embedding dimension, commonly referred to as <code>d_model</code>.</p>A Comprehensive Guide to Breville Barista Pro Maintenance/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/Sat, 16 Aug 2025 00:00:00 +0000/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/<p>Proper maintenance is critical for the longevity and performance of a Breville Barista Pro espresso machine. Consistent cleaning not only ensures the machine functions correctly but also directly impacts the quality of the espresso produced. This guide provides a detailed, technical breakdown of the essential maintenance routines, from automated cycles to daily upkeep.</p> +<h4 id="understanding-the-two-primary-maintenance-cycles"> + <strong>Understanding the Two Primary Maintenance Cycles</strong> + <a class="heading-link" href="#understanding-the-two-primary-maintenance-cycles"> + <i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"></i> + <span class="sr-only">Link to heading</span> + </a> +</h4> +<p>The Breville Barista Pro has two distinct, automated maintenance procedures: the <strong>Cleaning (Flush) Cycle</strong> and the <strong>Descale Cycle</strong>. It is important to understand that these are not interchangeable, as they address different types of buildup within the machine.</p>Breville Barista Pro Maintenance/posts/breville-barista-pro-maintenance/Sat, 16 Aug 2025 00:00:00 +0000/posts/breville-barista-pro-maintenance/<p>Proper maintenance is critical for the longevity and performance of a Breville Barista Pro espresso machine. Consistent cleaning not only ensures the machine functions correctly but also directly impacts the quality of the espresso produced. This guide provides a detailed, technical breakdown of the essential maintenance routines, from automated cycles to daily upkeep.</p> <h4 id="understanding-the-two-primary-maintenance-cycles"> <strong>Understanding the Two Primary Maintenance Cycles</strong> <a class="heading-link" href="#understanding-the-two-primary-maintenance-cycles"> @@ -22,6 +38,7 @@ <p>That message is the tell: Secure Boot is enabled and the kernel refuses to load modules not signed by a trusted key.</p>Beyond Words: How RVQ Teaches LLMs to See and Hear/posts/how-rvq-teaches-llms-to-see-and-hear/Thu, 07 Aug 2025 00:00:00 +0000/posts/how-rvq-teaches-llms-to-see-and-hear/<p>Large Language Models (LLMs) are masters of text, but the world is not made of text alone. It’s a symphony of sights, sounds, and experiences. The ultimate goal for AI is to understand this rich, multi-modal world as we do. But how do you teach a model that thinks in words to understand a picture of a sunset or the melody of a song?</p> <p>The answer lies in creating a universal language—a bridge between the continuous, messy world of pixels and audio waves and the discrete, structured world of language tokens. One of the most elegant and powerful tools for building this bridge is <strong>Residual Vector Quantization (RVQ)</strong>.</p>Supabase Deep Dive: It's Not Magic, It's Just Postgres/posts/supabase-deep-dive/Sun, 03 Aug 2025 00:00:00 +0000/posts/supabase-deep-dive/<p>In the world of Backend-as-a-Service (BaaS), platforms are often treated as magic boxes. You push data in, you get data out, and you hope the magic inside scales. While this simplicity is powerful, it can obscure the underlying mechanics, leaving developers wondering what&rsquo;s really going on.</p> <p>Supabase enters this space with a radically different philosophy: <strong>transparency</strong>. It provides the convenience of a BaaS, but it’s built on the world&rsquo;s most trusted relational database: PostgreSQL. The &ldquo;magic&rdquo; isn&rsquo;t a proprietary black box; it&rsquo;s a carefully assembled suite of open-source tools that enhance Postgres, not hide it.</p>A Deep Dive into PPO for Language Models/posts/a-deep-dive-into-ppo-for-language-models/Sat, 02 Aug 2025 00:00:00 +0000/posts/a-deep-dive-into-ppo-for-language-models/<p>Large Language Models (LLMs) have demonstrated astonishing capabilities, but out-of-the-box, they are simply powerful text predictors. They don&rsquo;t inherently understand what makes a response helpful, harmless, or aligned with human values. The technique that has proven most effective at bridging this gap is Reinforcement Learning from Human Feedback (RLHF), and at its heart lies a powerful algorithm: Proximal Policy Optimization (PPO).</p> +<p>You may have seen diagrams like the one below, which outlines the RLHF training process. It can look intimidating, with a web of interconnected models, losses, and data flows.</p>A Deep Dive into PPO for Language Models/posts/ppo-for-language-models/Sat, 02 Aug 2025 00:00:00 +0000/posts/ppo-for-language-models/<p>Large Language Models (LLMs) have demonstrated astonishing capabilities, but out-of-the-box, they are simply powerful text predictors. They don&rsquo;t inherently understand what makes a response helpful, harmless, or aligned with human values. The technique that has proven most effective at bridging this gap is Reinforcement Learning from Human Feedback (RLHF), and at its heart lies a powerful algorithm: Proximal Policy Optimization (PPO).</p> <p>You may have seen diagrams like the one below, which outlines the RLHF training process. It can look intimidating, with a web of interconnected models, losses, and data flows.</p>Mixture-of-Experts (MoE) Models Challenges & Solutions in Practice/posts/mixture-of-experts-moe-models-challenges-solutions-in-practice/Wed, 02 Jul 2025 00:00:00 +0000/posts/mixture-of-experts-moe-models-challenges-solutions-in-practice/<p>Mixture-of-Experts (MoEs) are neural network architectures that allow different parts of the model (called &ldquo;experts&rdquo;) to specialize in different types of inputs. A &ldquo;gating network&rdquo; or &ldquo;router&rdquo; learns to dispatch each input (or &ldquo;token&rdquo;) to a subset of these experts. While powerful for scaling models, MoEs introduce several practical challenges.</p> <h3 id="1-challenge-non-differentiability-of-routing-functions"> 1. Challenge: Non-Differentiability of Routing Functions diff --git a/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/index.html b/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/index.html index 39671da..1d67f42 100644 --- a/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/index.html +++ b/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/index.html @@ -25,4 +25,4 @@ Understanding the Two Primary Maintenance Cycles Link to heading The Breville Ba 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/a-deep-dive-into-ppo-for-language-models/index.html b/posts/a-deep-dive-into-ppo-for-language-models/index.html index e31a38e..47df78d 100644 --- a/posts/a-deep-dive-into-ppo-for-language-models/index.html +++ b/posts/a-deep-dive-into-ppo-for-language-models/index.html @@ -23,4 +23,4 @@ where δ_t = r_t + γV(s_{t+1}) - V(s_t)

  • γ (gam 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/index.html b/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/index.html index 4a34494..0063340 100644 --- a/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/index.html +++ b/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/index.html @@ -36,4 +36,4 @@ In deep learning, a “channel” can be thought of as a feature dimensi 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/breville-barista-pro-maintenance/index.html b/posts/breville-barista-pro-maintenance/index.html new file mode 100644 index 0000000..24c269f --- /dev/null +++ b/posts/breville-barista-pro-maintenance/index.html @@ -0,0 +1,28 @@ +Breville Barista Pro Maintenance · Eric X. Liu's Personal Page

    Breville Barista Pro Maintenance

    Proper maintenance is critical for the longevity and performance of a Breville Barista Pro espresso machine. Consistent cleaning not only ensures the machine functions correctly but also directly impacts the quality of the espresso produced. This guide provides a detailed, technical breakdown of the essential maintenance routines, from automated cycles to daily upkeep.

    Understanding the Two Primary Maintenance Cycles + +Link to heading

    The Breville Barista Pro has two distinct, automated maintenance procedures: the Cleaning (Flush) Cycle and the Descale Cycle. It is important to understand that these are not interchangeable, as they address different types of buildup within the machine.

    • Cleaning Cycle (Flush): This process is designed to remove coffee oils and granulated residue from the group head, shower screen, and portafilter system.
    • Descale Cycle: This process targets the internal components of the machine, such as the thermocoil and water lines, to remove mineral and limescale deposits from water.

    Procedure 1: The Cleaning (Flush) Cycle + +Link to heading

    The machine will indicate when a cleaning cycle is needed by displaying a “FLUSH” alert on the LCD screen. This typically occurs after approximately 200 extractions.

    Required Materials:

    • 1-Cup filter basket
    • Grey silicone cleaning disc (provided with the machine)
    • One cleaning tablet

    Step-by-Step Instructions:

    1. Insert the 1-cup filter basket into the portafilter.
    2. Place the grey silicone cleaning disc inside the basket.
    3. Position one cleaning tablet in the center of the disc.
    4. Lock the portafilter firmly into the group head.
    5. Ensure the drip tray is empty and the water tank is filled.
    6. Press the ‘MENU’ button and use the ‘Grind Amount’ dial to navigate to the ‘FLUSH’ option. Press the dial to select it.
    7. The ‘1 CUP’ button will illuminate. Press it to initiate the cycle.
    8. The cleaning process will last approximately five minutes, with the machine backflushing water under pressure. The remaining time will be displayed on the screen.
    9. Upon completion, the machine will beep and return to its ready state.
    10. Remove the portafilter and discard the water and dissolved tablet residue. Thoroughly rinse the portafilter, cleaning disc, and filter basket.
    11. Re-insert the portafilter (without the disc or tablet) and run a shot of hot water through the group head to rinse any remaining cleaning solution.

    Procedure 2: The Descale Cycle + +Link to heading

    The machine will alert you when descaling is required. The frequency depends on water hardness and usage but is generally recommended every 2-3 months.

    Required Materials:

    • Breville-recommended descaling solution
    • A large container (minimum 2-liter capacity)

    Step-by-Step Instructions:

    Part A: Preparation

    1. Empty the drip tray and re-insert it.
    2. Remove the water filter from the water tank.
    3. Pour the descaling solution into the empty water tank and add fresh water up to the indicated “DESCALE” line.
    4. Place a large container under the group head, hot water outlet, and steam wand.

    Part B: The Descaling Process

    1. Turn the machine on and press the ‘MENU’ button. Navigate to the ‘DESCALE’ option and select it by pressing the dial.
    2. Press the illuminated ‘1 CUP’ button to begin.
    3. The cycle proceeds in three stages. You must manually advance through them using the steam dial based on the LCD prompts:
      • Group Head (d3): The machine descales the coffee brewing components.
      • Hot Water (d2): After a beep, the LCD shows “d2”. Turn the steam dial to the hot water position.
      • Steam (d1): After another beep, the display reads “d1”. Turn the dial to the steam position.

    Part C: The Rinse Cycle

    1. Once the descaling solution is expended, the machine will beep and prompt for a rinse cycle (“r”).
    2. Empty the large container and rinse the water tank thoroughly.
    3. Fill the water tank with fresh, cold water to the MAX line and re-insert it.
    4. Place the empty container back under the outlets and press the ‘1 CUP’ button.
    5. The rinse cycle will mirror the descaling process, prompting you to engage the group head (“r3”), hot water (“r2”), and steam wand (“r1”) in sequence.
    6. After the rinse is complete, the machine will exit the maintenance mode and return to its ready state.

    Routine and Preventative Maintenance Schedule + +Link to heading

    In addition to the automated cycles, regular manual cleaning is essential for machine health.

    Daily Tasks:

    • Purge Group Head: After the final use of the day, run hot water through the group head (without the portafilter) to clear grounds.
    • Clean Portafilter & Baskets: Do not let used coffee grounds sit in the portafilter. Rinse with hot water after every use.
    • Clean Steam Wand: Immediately after texturing milk, wipe the wand with a damp cloth and purge steam for 2-3 seconds to clear internal passages.
    • Empty Drip Tray: Empty and rinse the drip tray regularly.

    Weekly Tasks:

    • Soak Components: Remove the filter basket from the portafilter. Soak both components in a solution of hot water and a cleaning tablet (or specific espresso cleaner) for 20-30 minutes to dissolve accumulated coffee oils. Rinse thoroughly.
    • Clean Grinder: Empty the bean hopper. Run the grinder to clear any remaining beans, then use a brush and/or vacuum to clean out fines and oil residue from the burrs and chute.

    Periodic Tasks (Every 2-3 Months):

    • Replace Water Filter: The water filter located inside the water tank should be replaced every 3 months. This reduces the rate of scale buildup.
    • Inspect Shower Screen: Use a brush to gently scrub the shower screen inside the group head to remove any stubborn coffee grounds.

    By adhering to this comprehensive maintenance schedule, you can ensure your Breville Barista Pro operates at peak performance and consistently produces high-quality espresso.


    Reference:

    • Breville Barista Pro Instruction Manual and official manufacturer guidelines.
    \ No newline at end of file diff --git a/posts/espresso-theory-application-a-guide-for-the-breville-barista-pro/index.html b/posts/espresso-theory-application-a-guide-for-the-breville-barista-pro/index.html index eced718..9e06fd2 100644 --- a/posts/espresso-theory-application-a-guide-for-the-breville-barista-pro/index.html +++ b/posts/espresso-theory-application-a-guide-for-the-breville-barista-pro/index.html @@ -20,4 +20,4 @@ Our overarching philosophy is simple: isolate and change only one variable at a 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/how-rvq-teaches-llms-to-see-and-hear/index.html b/posts/how-rvq-teaches-llms-to-see-and-hear/index.html index ef5b34b..1b649d9 100644 --- a/posts/how-rvq-teaches-llms-to-see-and-hear/index.html +++ b/posts/how-rvq-teaches-llms-to-see-and-hear/index.html @@ -18,4 +18,4 @@ The answer lies in creating a universal language—a bridge between the continuo 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/index.html b/posts/index.html index 6b32107..82336d7 100644 --- a/posts/index.html +++ b/posts/index.html @@ -2,16 +2,16 @@
  • August 2, 2025 +A Deep Dive into PPO for Language Models
\ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/index.xml b/posts/index.xml index 19e4d70..83e757c 100644 --- a/posts/index.xml +++ b/posts/index.xml @@ -1,4 +1,4 @@ -Posts on Eric X. Liu's Personal Page/posts/Recent content in Posts on Eric X. Liu's Personal PageHugoenWed, 20 Aug 2025 06:02:35 +0000A Technical Deep Dive into the Transformer's Core Mechanics/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/Tue, 19 Aug 2025 00:00:00 +0000/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/<p>The Transformer architecture is the bedrock of modern Large Language Models (LLMs). While its high-level success is widely known, a deeper understanding requires dissecting its core components. This article provides a detailed, technical breakdown of the fundamental concepts within a Transformer block, from the notion of &ldquo;channels&rdquo; to the intricate workings of the attention mechanism and its relationship with other advanced architectures like Mixture of Experts.</p> +Posts on Eric X. Liu's Personal Page/posts/Recent content in Posts on Eric X. Liu's Personal PageHugoenWed, 20 Aug 2025 06:04:36 +0000A Technical Deep Dive into the Transformer's Core Mechanics/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/Tue, 19 Aug 2025 00:00:00 +0000/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/<p>The Transformer architecture is the bedrock of modern Large Language Models (LLMs). While its high-level success is widely known, a deeper understanding requires dissecting its core components. This article provides a detailed, technical breakdown of the fundamental concepts within a Transformer block, from the notion of &ldquo;channels&rdquo; to the intricate workings of the attention mechanism and its relationship with other advanced architectures like Mixture of Experts.</p> <h3 id="1-the-channel-a-foundational-view-of-d_model"> 1. The &ldquo;Channel&rdquo;: A Foundational View of <code>d_model</code> <a class="heading-link" href="#1-the-channel-a-foundational-view-of-d_model"> @@ -6,7 +6,23 @@ <span class="sr-only">Link to heading</span> </a> </h3> -<p>In deep learning, a &ldquo;channel&rdquo; can be thought of as a feature dimension. While this term is common in Convolutional Neural Networks for images (e.g., Red, Green, Blue channels), in LLMs, the analogous concept is the model&rsquo;s primary embedding dimension, commonly referred to as <code>d_model</code>.</p>Quantization in LLMs/posts/quantization-in-llms/Tue, 19 Aug 2025 00:00:00 +0000/posts/quantization-in-llms/<p>The burgeoning scale of Large Language Models (LLMs) has necessitated a paradigm shift in their deployment, moving beyond full-precision floating-point arithmetic towards lower-precision representations. Quantization, the process of mapping a wide range of continuous values to a smaller, discrete set, has emerged as a critical technique to reduce model size, accelerate inference, and lower energy consumption. This article provides a technical overview of quantization theories, their application in modern LLMs, and highlights the ongoing innovations in this domain.</p>A Comprehensive Guide to Breville Barista Pro Maintenance/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/Sat, 16 Aug 2025 00:00:00 +0000/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/<p>Proper maintenance is critical for the longevity and performance of a Breville Barista Pro espresso machine. Consistent cleaning not only ensures the machine functions correctly but also directly impacts the quality of the espresso produced. This guide provides a detailed, technical breakdown of the essential maintenance routines, from automated cycles to daily upkeep.</p> +<p>In deep learning, a &ldquo;channel&rdquo; can be thought of as a feature dimension. While this term is common in Convolutional Neural Networks for images (e.g., Red, Green, Blue channels), in LLMs, the analogous concept is the model&rsquo;s primary embedding dimension, commonly referred to as <code>d_model</code>.</p>Quantization in LLMs/posts/quantization-in-llms/Tue, 19 Aug 2025 00:00:00 +0000/posts/quantization-in-llms/<p>The burgeoning scale of Large Language Models (LLMs) has necessitated a paradigm shift in their deployment, moving beyond full-precision floating-point arithmetic towards lower-precision representations. Quantization, the process of mapping a wide range of continuous values to a smaller, discrete set, has emerged as a critical technique to reduce model size, accelerate inference, and lower energy consumption. This article provides a technical overview of quantization theories, their application in modern LLMs, and highlights the ongoing innovations in this domain.</p>Transformer's Core Mechanics/posts/transformer-s-core-mechanics/Tue, 19 Aug 2025 00:00:00 +0000/posts/transformer-s-core-mechanics/<p>The Transformer architecture is the bedrock of modern Large Language Models (LLMs). While its high-level success is widely known, a deeper understanding requires dissecting its core components. This article provides a detailed, technical breakdown of the fundamental concepts within a Transformer block, from the notion of &ldquo;channels&rdquo; to the intricate workings of the attention mechanism and its relationship with other advanced architectures like Mixture of Experts.</p> +<h3 id="1-the-channel-a-foundational-view-of-d_model"> + 1. The &ldquo;Channel&rdquo;: A Foundational View of <code>d_model</code> + <a class="heading-link" href="#1-the-channel-a-foundational-view-of-d_model"> + <i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"></i> + <span class="sr-only">Link to heading</span> + </a> +</h3> +<p>In deep learning, a &ldquo;channel&rdquo; can be thought of as a feature dimension. While this term is common in Convolutional Neural Networks for images (e.g., Red, Green, Blue channels), in LLMs, the analogous concept is the model&rsquo;s primary embedding dimension, commonly referred to as <code>d_model</code>.</p>A Comprehensive Guide to Breville Barista Pro Maintenance/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/Sat, 16 Aug 2025 00:00:00 +0000/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/<p>Proper maintenance is critical for the longevity and performance of a Breville Barista Pro espresso machine. Consistent cleaning not only ensures the machine functions correctly but also directly impacts the quality of the espresso produced. This guide provides a detailed, technical breakdown of the essential maintenance routines, from automated cycles to daily upkeep.</p> +<h4 id="understanding-the-two-primary-maintenance-cycles"> + <strong>Understanding the Two Primary Maintenance Cycles</strong> + <a class="heading-link" href="#understanding-the-two-primary-maintenance-cycles"> + <i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"></i> + <span class="sr-only">Link to heading</span> + </a> +</h4> +<p>The Breville Barista Pro has two distinct, automated maintenance procedures: the <strong>Cleaning (Flush) Cycle</strong> and the <strong>Descale Cycle</strong>. It is important to understand that these are not interchangeable, as they address different types of buildup within the machine.</p>Breville Barista Pro Maintenance/posts/breville-barista-pro-maintenance/Sat, 16 Aug 2025 00:00:00 +0000/posts/breville-barista-pro-maintenance/<p>Proper maintenance is critical for the longevity and performance of a Breville Barista Pro espresso machine. Consistent cleaning not only ensures the machine functions correctly but also directly impacts the quality of the espresso produced. This guide provides a detailed, technical breakdown of the essential maintenance routines, from automated cycles to daily upkeep.</p> <h4 id="understanding-the-two-primary-maintenance-cycles"> <strong>Understanding the Two Primary Maintenance Cycles</strong> <a class="heading-link" href="#understanding-the-two-primary-maintenance-cycles"> @@ -22,6 +38,7 @@ <p>That message is the tell: Secure Boot is enabled and the kernel refuses to load modules not signed by a trusted key.</p>Beyond Words: How RVQ Teaches LLMs to See and Hear/posts/how-rvq-teaches-llms-to-see-and-hear/Thu, 07 Aug 2025 00:00:00 +0000/posts/how-rvq-teaches-llms-to-see-and-hear/<p>Large Language Models (LLMs) are masters of text, but the world is not made of text alone. It’s a symphony of sights, sounds, and experiences. The ultimate goal for AI is to understand this rich, multi-modal world as we do. But how do you teach a model that thinks in words to understand a picture of a sunset or the melody of a song?</p> <p>The answer lies in creating a universal language—a bridge between the continuous, messy world of pixels and audio waves and the discrete, structured world of language tokens. One of the most elegant and powerful tools for building this bridge is <strong>Residual Vector Quantization (RVQ)</strong>.</p>Supabase Deep Dive: It's Not Magic, It's Just Postgres/posts/supabase-deep-dive/Sun, 03 Aug 2025 00:00:00 +0000/posts/supabase-deep-dive/<p>In the world of Backend-as-a-Service (BaaS), platforms are often treated as magic boxes. You push data in, you get data out, and you hope the magic inside scales. While this simplicity is powerful, it can obscure the underlying mechanics, leaving developers wondering what&rsquo;s really going on.</p> <p>Supabase enters this space with a radically different philosophy: <strong>transparency</strong>. It provides the convenience of a BaaS, but it’s built on the world&rsquo;s most trusted relational database: PostgreSQL. The &ldquo;magic&rdquo; isn&rsquo;t a proprietary black box; it&rsquo;s a carefully assembled suite of open-source tools that enhance Postgres, not hide it.</p>A Deep Dive into PPO for Language Models/posts/a-deep-dive-into-ppo-for-language-models/Sat, 02 Aug 2025 00:00:00 +0000/posts/a-deep-dive-into-ppo-for-language-models/<p>Large Language Models (LLMs) have demonstrated astonishing capabilities, but out-of-the-box, they are simply powerful text predictors. They don&rsquo;t inherently understand what makes a response helpful, harmless, or aligned with human values. The technique that has proven most effective at bridging this gap is Reinforcement Learning from Human Feedback (RLHF), and at its heart lies a powerful algorithm: Proximal Policy Optimization (PPO).</p> +<p>You may have seen diagrams like the one below, which outlines the RLHF training process. It can look intimidating, with a web of interconnected models, losses, and data flows.</p>A Deep Dive into PPO for Language Models/posts/ppo-for-language-models/Sat, 02 Aug 2025 00:00:00 +0000/posts/ppo-for-language-models/<p>Large Language Models (LLMs) have demonstrated astonishing capabilities, but out-of-the-box, they are simply powerful text predictors. They don&rsquo;t inherently understand what makes a response helpful, harmless, or aligned with human values. The technique that has proven most effective at bridging this gap is Reinforcement Learning from Human Feedback (RLHF), and at its heart lies a powerful algorithm: Proximal Policy Optimization (PPO).</p> <p>You may have seen diagrams like the one below, which outlines the RLHF training process. It can look intimidating, with a web of interconnected models, losses, and data flows.</p>Mixture-of-Experts (MoE) Models Challenges & Solutions in Practice/posts/mixture-of-experts-moe-models-challenges-solutions-in-practice/Wed, 02 Jul 2025 00:00:00 +0000/posts/mixture-of-experts-moe-models-challenges-solutions-in-practice/<p>Mixture-of-Experts (MoEs) are neural network architectures that allow different parts of the model (called &ldquo;experts&rdquo;) to specialize in different types of inputs. A &ldquo;gating network&rdquo; or &ldquo;router&rdquo; learns to dispatch each input (or &ldquo;token&rdquo;) to a subset of these experts. While powerful for scaling models, MoEs introduce several practical challenges.</p> <h3 id="1-challenge-non-differentiability-of-routing-functions"> 1. Challenge: Non-Differentiability of Routing Functions diff --git a/posts/mixture-of-experts-moe-models-challenges-solutions-in-practice/index.html b/posts/mixture-of-experts-moe-models-challenges-solutions-in-practice/index.html index b4e5a7e..aee9e37 100644 --- a/posts/mixture-of-experts-moe-models-challenges-solutions-in-practice/index.html +++ b/posts/mixture-of-experts-moe-models-challenges-solutions-in-practice/index.html @@ -44,4 +44,4 @@ The Top-K routing mechanism, as illustrated in the provided ima 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/page/2/index.html b/posts/page/2/index.html index 73c9206..5b1d63a 100644 --- a/posts/page/2/index.html +++ b/posts/page/2/index.html @@ -1,8 +1,11 @@ Posts · Eric X. Liu's Personal Page
\ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/ppo-for-language-models/index.html b/posts/ppo-for-language-models/index.html new file mode 100644 index 0000000..711837d --- /dev/null +++ b/posts/ppo-for-language-models/index.html @@ -0,0 +1,26 @@ +A Deep Dive into PPO for Language Models · Eric X. Liu's Personal Page

A Deep Dive into PPO for Language Models

Large Language Models (LLMs) have demonstrated astonishing capabilities, but out-of-the-box, they are simply powerful text predictors. They don’t inherently understand what makes a response helpful, harmless, or aligned with human values. The technique that has proven most effective at bridging this gap is Reinforcement Learning from Human Feedback (RLHF), and at its heart lies a powerful algorithm: Proximal Policy Optimization (PPO).

You may have seen diagrams like the one below, which outlines the RLHF training process. It can look intimidating, with a web of interconnected models, losses, and data flows.

This post will decode that diagram, piece by piece. We’ll explore the “why” behind each component, moving from high-level concepts to the deep technical reasoning that makes this process work.

Translating RL to a Conversation + +Link to heading

The first step is to understand how the traditional language of reinforcement learning maps to the world of text generation.

  • State (s_t): In a chat setting, the “state” is the context of the conversation so far. It’s the initial prompt (x) plus all the text the model has generated up to the current moment (y₁, ..., y_{t-1}).
  • Action (a_t): The “action” is the model’s decision at each step. For an LLM, this means generating the very next token (y_t). A full response is a sequence of these actions.blob:https://aistudio.google.com/872e746f-88c1-40ec-8e45-fa0efce97299
  • Reward (r): The “reward” is a numeric score that tells the model how good its full response (y) was. This score comes from a separate Reward Model, which has been trained on a large dataset of human preference comparisons (e.g., humans rating which of two responses is better). This reward is often only awarded at the end of the entire generated sequence.

Let’s make this concrete. If a user provides the prompt (x): “The best thing about AI is”, and the model generates the response (y): “its potential to solve problems.”, here is how it’s broken down for training:

  • State 1: “The best thing about AI is”
    • Action 1: “its”
  • State 2: “The best thing about AI is its”
    • Action 2: " potential"
  • State 3: “The best thing about AI is its potential”
    • Action 3: " to"
  • …and so on for every generated token.

This breakdown transforms a single prompt-response pair into a rich trajectory of state-action pairs, which becomes the raw data for our learning algorithm.

The Cast of Models: An Actor-Critic Ensemble + +Link to heading

The PPO process doesn’t rely on a single model but an ensemble where each member has a distinct role.

  1. The Actor (Policy LM): This is the star of the show—the LLM we are actively fine-tuning. Its role is to take a state (the current text) and decide on an action (the next token). We refer to its decision-making process as its “policy” (π).
  2. The Critic (Value Model): This is the Actor’s coach. The Critic doesn’t generate text. Instead, it observes a state and estimates the potential future reward the Actor is likely to receive from that point onward. This estimate is called the “value” (V(s_t)). The Critic’s feedback helps the Actor understand whether it’s in a promising or a dead-end situation, which is a much more immediate learning signal than waiting for the final reward.
  3. The Reward Model: This is the ultimate judge. As mentioned, it’s a separate model trained on human preference data that provides the final score for a complete generation. Its judgment is treated as the ground truth for training both the Actor and the Critic.

The Challenge of Credit Assignment: Generalized Advantage Estimation (GAE) + +Link to heading

A key problem in RL is assigning credit. If a 20-token response gets a high reward, was it because of the first token, the last one, or all of them? The Critic helps solve this. By comparing the reward at each step with the Critic’s value estimate, we can calculate the Advantage (Â).

A simple advantage calculation might be: Advantage = reward + Value_of_next_state - Value_of_current_state.

However, this can be noisy. PPO uses a more sophisticated technique called Generalized Advantage Estimation (GAE). The formula looks complex, but the idea is intuitive:

Â(s_t, a_t) = Σ(γλ)^l * δ_{t+l} +where δ_t = r_t + γV(s_{t+1}) - V(s_t)

  • γ (gamma) is a discount factor (e.g., 0.99), which values immediate rewards slightly more than distant ones.
  • λ (lambda) is a smoothing parameter that balances the trade-off between bias and variance. It creates a weighted average of advantages over multiple future time steps.

In essence, GAE provides a more stable and accurate estimate of how much better a specific action was compared to the policy’s average behavior in that state.

The Heart of PPO: The Quest for Stable Updates + +Link to heading

Now we arrive at the core innovation of PPO. We want to update our Actor model to take actions with higher advantages. The naive way to do this is to re-weight our training objective by an importance sampling ratio: (π_new / π_old). This corrects for the fact that the data we are learning from was generated by a slightly older version of our policy.

However, this ratio is incredibly dangerous. If the new policy becomes very different from the old one, the ratio can explode, leading to massive, unstable gradient updates that destroy the model.

PPO solves this with its signature Clipped Surrogate Objective. The PPO loss function is:

L_CLIP(θ) = Ê_t [ min( r_t(θ)Â_t, clip(r_t(θ), 1 - ε, 1 + ε)Â_t ) ]

Let’s translate this from math to English:

  • r_t(θ) is the probability ratio π_new(a_t|s_t) / π_old(a_t|s_t).
  • The goal is to increase the objective by an amount proportional to the advantage Â_t.
  • The clip function is the crucial safeguard. It forbids the probability ratio from moving outside a small window (e.g., [0.8, 1.2]).

This means the algorithm says: “Let’s update our policy to favor this good action. But if the required update would change the policy too drastically from the old one, we’ll ‘clip’ the update to a more modest size.” This creates a “trust region,” ensuring stable, incremental improvements.

Avoiding Amnesia: The Pretraining Loss + +Link to heading

There’s one final problem. If we only optimize for the PPO loss, the model might learn to “hack” the reward model by generating repetitive or nonsensical text that gets a high score. In doing so, it could suffer from catastrophic forgetting, losing its fundamental grasp of grammar and facts.

To prevent this, we introduce a second loss term. As seen in the diagram, we mix in data from the original Pretraining Data (or the dataset used for Supervised Fine-Tuning). We calculate a standard next-token prediction loss (LM Loss) on this high-quality data.

The final loss for the Actor is a combination of both objectives:

Total Loss = Loss_PPO + λ_ptx * Loss_LM

This brilliantly balances two goals:

  1. The Loss_PPO pushes the model towards behaviors that align with human preferences.
  2. The Loss_LM acts as a regularizer, pulling the model back towards its core language capabilities and preventing it from drifting into gibberish.

The Full Training Loop + +Link to heading

Now, we can assemble the entire process into a clear, iterative loop:

  1. Collect: The current Actor policy π_k generates responses to a batch of prompts. These experiences—(state, action, probability, reward, value)—are stored in an Experience Buffer.
  2. Calculate: Once the buffer is full, we use the collected data to compute the advantage estimates Â_t for every single token-generation step.
  3. Optimize: For a few epochs, we repeatedly sample mini-batches from the buffer and update the Actor and Critic models. The Actor is updated using the combined PPO-clip Loss and LM Loss. The Critic is updated to improve its value predictions.
  4. Flush and Repeat: After the optimization phase, the entire experience buffer is discarded. The data is now “stale” because our policy has changed. The newly updated policy π_{k+1} becomes the new Actor, and we return to step 1 to collect fresh data.

This cycle of collection and optimization allows the language model to gradually and safely steer its behavior towards human-defined goals, creating the helpful and aligned AI assistants we interact with today.


References:

  1. Schulman, J., Wolski, F., Dhariwal, P., Radford, A., & Klimov, O. (2017). Proximal Policy Optimization Algorithms. arXiv preprint arXiv:1707.06347.
  2. Schulman, J., Moritz, P., Levine, S., Jordan, M., & Abbeel, P. (2015). High-Dimensional Continuous Control Using Generalized Advantage Estimation. arXiv preprint arXiv:1506.02438.
  3. Ouyang, L., et al. (2022). Training language models to follow instructions with human feedback. Advances in Neural Information Processing Systems 35.
\ No newline at end of file diff --git a/posts/quantization-in-llms/index.html b/posts/quantization-in-llms/index.html index 6dd8bdb..b822f0b 100644 --- a/posts/quantization-in-llms/index.html +++ b/posts/quantization-in-llms/index.html @@ -7,4 +7,4 @@ 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/secure-boot-dkms-and-mok-on-proxmox-debian/index.html b/posts/secure-boot-dkms-and-mok-on-proxmox-debian/index.html index 22090fe..e3054af 100644 --- a/posts/secure-boot-dkms-and-mok-on-proxmox-debian/index.html +++ b/posts/secure-boot-dkms-and-mok-on-proxmox-debian/index.html @@ -59,4 +59,4 @@ nvidia-smi failed to communicate with the NVIDIA driver modprobe nvidia → “K 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/supabase-deep-dive/index.html b/posts/supabase-deep-dive/index.html index 4d3ab8a..d7a9992 100644 --- a/posts/supabase-deep-dive/index.html +++ b/posts/supabase-deep-dive/index.html @@ -90,4 +90,4 @@ Supabase enters this space with a radically different philosophy: transparency. 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/t5-the-transformer-that-zigged-when-others-zagged-an-architectural-deep-dive/index.html b/posts/t5-the-transformer-that-zigged-when-others-zagged-an-architectural-deep-dive/index.html index f10df58..64d239b 100644 --- a/posts/t5-the-transformer-that-zigged-when-others-zagged-an-architectural-deep-dive/index.html +++ b/posts/t5-the-transformer-that-zigged-when-others-zagged-an-architectural-deep-dive/index.html @@ -30,4 +30,4 @@ But to truly understand the field, we must look at the pivotal models that explo 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/posts/transformer-s-core-mechanics/index.html b/posts/transformer-s-core-mechanics/index.html new file mode 100644 index 0000000..dbd3b08 --- /dev/null +++ b/posts/transformer-s-core-mechanics/index.html @@ -0,0 +1,39 @@ +Transformer's Core Mechanics · Eric X. Liu's Personal Page

Transformer's Core Mechanics

The Transformer architecture is the bedrock of modern Large Language Models (LLMs). While its high-level success is widely known, a deeper understanding requires dissecting its core components. This article provides a detailed, technical breakdown of the fundamental concepts within a Transformer block, from the notion of “channels” to the intricate workings of the attention mechanism and its relationship with other advanced architectures like Mixture of Experts.

1. The “Channel”: A Foundational View of d_model + +Link to heading

In deep learning, a “channel” can be thought of as a feature dimension. While this term is common in Convolutional Neural Networks for images (e.g., Red, Green, Blue channels), in LLMs, the analogous concept is the model’s primary embedding dimension, commonly referred to as d_model.

An input text is first tokenized, and each token is mapped to a vector of size d_model (e.g., 4096). Each of the 4096 dimensions in this vector can be considered a “channel,” representing a different semantic or syntactic feature of the token.

As this data, represented by a tensor of shape [batch_size, sequence_length, d_model], progresses through the layers of the Transformer, these channels are continuously transformed. However, a critical design choice is that the output dimension of every main sub-layer (like the attention block or the FFN block) is also d_model. This consistency is essential for enabling residual connections, where the input to a block is added to its output (output = input + SubLayer(input)). This technique is vital for training the extremely deep networks common today.

2. The Building Blocks: Dimensions of Key Layers + +Link to heading

A Transformer layer is primarily composed of two sub-layers: a Multi-Head Attention block and a position-wise Feed-Forward Network (FFN). The parameters for these are stored in several key weight matrices. Understanding their dimensions is crucial.

Let’s define our variables:

  • d_model: The core embedding dimension.
  • d_ff: The inner dimension of the FFN, typically 4 * d_model.
  • h: The number of attention heads.
  • d_head: The dimension of each attention head, where d_model = h * d_head.

The dimensions of the weight matrices are as follows:

LayerWeight MatrixInput Vector ShapeOutput Vector ShapeWeight Matrix Dimension
Attention Projections
QueryW_Qd_modeld_model[d_model, d_model]
KeyW_Kd_modeld_model[d_model, d_model]
ValueW_Vd_modeld_model[d_model, d_model]
OutputW_Od_modeld_model[d_model, d_model]
Feed-Forward Network
Layer 1 (Up-projection)W_ff1d_modeld_ff[d_model, d_ff]
Layer 2 (Down-projection)W_ff2d_ffd_model[d_ff, d_model]

3. Deconstructing Multi-Head Attention (MHA) + +Link to heading

The core innovation of the Transformer is Multi-Head Attention. It allows the model to weigh the importance of different tokens in the sequence from multiple perspectives simultaneously. +

3.1. The “Why”: Beyond a Single Attention + +Link to heading

A single attention mechanism would force the model to average all types of linguistic relationships into one pattern. MHA avoids this by creating h parallel subspaces. Each “head” can specialize, with one head learning syntactic dependencies, another tracking semantic similarity, and so on. This creates a much richer representation.

3.2. An Encoding/Decoding Analogy + +Link to heading

A powerful way to conceptualize the attention calculation is as a two-stage process:

  1. Encoding Relationships: The first part of the calculation, softmax(Q @ K.T), can be seen as an encoding step. It does not use the actual “content” of the tokens (the V vectors). Instead, it uses the Queries and Keys to build a dynamic “relationship map” between tokens in the sequence. This map, a matrix of attention scores, answers the question: “For each token, how important is every other token right now?”
  2. Decoding via Information Retrieval: The second part, scores @ V, acts as a decoding step. It uses the relationship map to retrieve and synthesize information. For each token, it creates a new vector by taking a weighted sum of all the V vectors in the sequence, using the scores as the precise mixing recipe. It decodes the relational structure into a new, context-aware representation.

3.3. The “How”: A Step-by-Step Flow + +Link to heading

The MHA process is designed for maximum computational efficiency.

  1. Initial Projections: The input vectors (shape [seq_len, d_model]) are multiplied by W_Q, W_K, and W_V. These matrices are all [d_model, d_model] not to create one large query, but to efficiently compute the vectors for all h heads at once. The single large output vector is then reshaped into h separate vectors, each of size d_head.
  2. Attention Score Calculation: For each head i, a score matrix is calculated: scores_i = softmax( (Q_i @ K_i.T) / sqrt(d_head) ). Note that Q_i and K_i have dimensions [seq_len, d_head], so the resulting scores_i matrix has a dimension of [seq_len, seq_len].
  3. Weighted Value Calculation: The scores are used to create a weighted sum of the Value vectors for each head: output_i = scores_i @ V_i. Since scores_i is [seq_len, seq_len] and V_i is [seq_len, d_head], the resulting output_i has a dimension of [seq_len, d_head]. This is the final output of a single head.
  4. Concatenation and Final Projection: The outputs of all h heads are concatenated along the last dimension. This produces a single large matrix of shape [seq_len, h * d_head], which is equivalent to [seq_len, d_model]. This matrix is then passed through the final output projection layer, W_O (shape [d_model, d_model]), to produce the attention block’s final output. The W_O matrix learns the optimal way to mix the information from all the specialized heads into a single, unified representation.

4. Optimizing Attention: GQA and MQA + +Link to heading

During inference, storing the Key and Value vectors for all previous tokens (the KV Cache) is a major memory bottleneck. Grouped-Query Attention (GQA) and Multi-Query Attention (MQA) are architectural modifications that address this by allowing multiple Query heads to share the same Key and Value heads.

Let’s use a concrete example, similar to Llama 2 7B:

  • d_model = 4096
  • h = 32 Q heads
  • d_head = 128
  • g = 8 KV head groups for GQA

The key insight is that only the dimensions of the W_K and W_V matrices change, which in turn reduces the size of the KV cache. The W_Q and W_O matrices remain [4096, 4096].

Attention TypeNo. of Q HeadsNo. of KV HeadsW_K & W_V DimensionRelative KV Cache Size
MHA (Multi-Head)3232[4096, 32*128] = [4096, 4096]1x (Baseline)
GQA (Grouped)328[4096, 8*128] = [4096, 1024]1/4x
MQA (Multi-Query)321[4096, 1*128] = [4096, 128]1/32x

GQA provides a robust balance, significantly reducing the memory and bandwidth requirements for the KV cache with negligible impact on model performance, making it a popular choice in modern LLMs.

5. MHA vs. Mixture of Experts (MoE): A Clarification + +Link to heading

While both MHA and MoE use the concept of “experts,” they are functionally and architecturally distinct.

  • MHA: The “experts” are the attention heads. All heads are active for every token to build a rich representation within the attention layer. This is akin to a board meeting where every member analyzes and contributes to every decision.
  • MoE: The “experts” are full Feed-Forward Networks. A routing network selects a small subset of these FFNs for each token. This is a scaling strategy to increase a model’s parameter count for greater capacity while keeping the computational cost fixed. It replaces the standard FFN block, whereas MHA is the attention block.

By understanding these technical details, from the basic concept of a channel to the sophisticated interplay of heads and experts, one can build a more complete and accurate mental model of how LLMs truly operate.


References + +Link to heading

  1. Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., … & Polosukhin, I. (2017). Attention is all you need. Advances in neural information processing systems, 30.
  2. Shazeer, N., Mirhoseini, A., Maziarz, K., Davis, A., Le, Q., Hinton, G., & Dean, J. (2017). Outrageously large neural networks: The sparsely-gated mixture-of-experts layer. arXiv preprint arXiv:1701.06538.
  3. Ainslie, J., Ontanon, J., Cakka, E., Dosovitskiy, A., & Le, Q. V. (2023). GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints. arXiv preprint arXiv:2305.13245.
\ No newline at end of file diff --git a/posts/useful/index.html b/posts/useful/index.html index 2d4da63..e42e5c9 100644 --- a/posts/useful/index.html +++ b/posts/useful/index.html @@ -9,4 +9,4 @@ One-minute read
  • [ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml index af9ccf6..51d27e8 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -1 +1 @@ -/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/2025-08-20T04:48:53+00:00weekly0.5/2025-08-20T06:02:35+00:00weekly0.5/posts/2025-08-20T06:02:35+00:00weekly0.5/posts/quantization-in-llms/2025-08-20T06:02:35+00:00weekly0.5/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/2025-08-20T04:48:53+00:00weekly0.5/posts/secure-boot-dkms-and-mok-on-proxmox-debian/2025-08-14T06:50:22+00:00weekly0.5/posts/how-rvq-teaches-llms-to-see-and-hear/2025-08-08T17:36:52+00:00weekly0.5/posts/supabase-deep-dive/2025-08-04T03:59:37+00:00weekly0.5/posts/a-deep-dive-into-ppo-for-language-models/2025-08-16T21:13:18+00:00weekly0.5/posts/mixture-of-experts-moe-models-challenges-solutions-in-practice/2025-08-03T06:02:48+00:00weekly0.5/posts/t5-the-transformer-that-zigged-when-others-zagged-an-architectural-deep-dive/2025-08-03T03:41:10+00:00weekly0.5/posts/espresso-theory-application-a-guide-for-the-breville-barista-pro/2025-08-03T04:20:20+00:00weekly0.5/posts/useful/2025-08-03T08:37:28-07:00weekly0.5/about/2020-06-16T23:30:17-07:00weekly0.5/categories/weekly0.5/tags/weekly0.5 \ No newline at end of file +/posts/a-technical-deep-dive-into-the-transformer-s-core-mechanics/2025-08-20T04:48:53+00:00weekly0.5/2025-08-20T06:04:36+00:00weekly0.5/posts/2025-08-20T06:04:36+00:00weekly0.5/posts/quantization-in-llms/2025-08-20T06:02:35+00:00weekly0.5/posts/transformer-s-core-mechanics/2025-08-20T06:04:36+00:00weekly0.5/posts/a-comprehensive-guide-to-breville-barista-pro-maintenance/2025-08-20T04:48:53+00:00weekly0.5/posts/breville-barista-pro-maintenance/2025-08-20T06:04:36+00:00weekly0.5/posts/secure-boot-dkms-and-mok-on-proxmox-debian/2025-08-14T06:50:22+00:00weekly0.5/posts/how-rvq-teaches-llms-to-see-and-hear/2025-08-08T17:36:52+00:00weekly0.5/posts/supabase-deep-dive/2025-08-04T03:59:37+00:00weekly0.5/posts/a-deep-dive-into-ppo-for-language-models/2025-08-16T21:13:18+00:00weekly0.5/posts/ppo-for-language-models/2025-08-20T06:04:36+00:00weekly0.5/posts/mixture-of-experts-moe-models-challenges-solutions-in-practice/2025-08-03T06:02:48+00:00weekly0.5/posts/t5-the-transformer-that-zigged-when-others-zagged-an-architectural-deep-dive/2025-08-03T03:41:10+00:00weekly0.5/posts/espresso-theory-application-a-guide-for-the-breville-barista-pro/2025-08-03T04:20:20+00:00weekly0.5/posts/useful/2025-08-03T08:37:28-07:00weekly0.5/about/2020-06-16T23:30:17-07:00weekly0.5/categories/weekly0.5/tags/weekly0.5 \ No newline at end of file diff --git a/tags/index.html b/tags/index.html index 10de90e..b65b4d5 100644 --- a/tags/index.html +++ b/tags/index.html @@ -4,4 +4,4 @@ 2016 - 2025 Eric X. Liu -[ba596e7] \ No newline at end of file +[3ee20f1] \ No newline at end of file