<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://yatharth-anand-2410.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://yatharth-anand-2410.github.io/" rel="alternate" type="text/html" /><updated>2026-04-05T16:47:03+00:00</updated><id>https://yatharth-anand-2410.github.io/feed.xml</id><title type="html">Yatharth Anand</title><subtitle>ML Engineer &amp; ML Researcher. Exploring LLM internals, mechanistic interpretability,  and optimization on Apple Silicon.</subtitle><entry><title type="html">The Tipping Point: Identifying the Threshold of Quantized Weight Corruption</title><link href="https://yatharth-anand-2410.github.io/research/interpretability/2026/04/05/the-tipping-point-quantized-weights.html" rel="alternate" type="text/html" title="The Tipping Point: Identifying the Threshold of Quantized Weight Corruption" /><published>2026-04-05T09:00:00+00:00</published><updated>2026-04-05T09:00:00+00:00</updated><id>https://yatharth-anand-2410.github.io/research/interpretability/2026/04/05/the-tipping-point-quantized-weights</id><content type="html" xml:base="https://yatharth-anand-2410.github.io/research/interpretability/2026/04/05/the-tipping-point-quantized-weights.html"><![CDATA[<h2 id="-objective">🚀 Objective</h2>
<p>To determine the precise mathematical threshold at which uniform bit-level perturbations to 4-bit quantized LLM weights cause catastrophic model collapse. We aim to understand how robust these compressed models are to “bit-level noise.”</p>

<h2 id="️-the-mechanics-of-4-bit-quantization">⚙️ The Mechanics of 4-bit Quantization</h2>
<p>In the MLX framework, Llama 3 weights are stored as 4-bit integers, but they are “packed” into <code class="language-plaintext highlighter-rouge">uint32</code> containers to save memory and optimize hardware throughput. Specifically:</p>
<ul>
  <li>Each <code class="language-plaintext highlighter-rouge">uint32</code> element actually contains <strong>8 separate 4-bit weights</strong>.</li>
  <li>These weights are dequantized on-the-fly during inference using a <code class="language-plaintext highlighter-rouge">scale</code> and <code class="language-plaintext highlighter-rouge">bias</code> factor.</li>
</ul>

<p>The critical insight is that when we perform an operation on the <code class="language-plaintext highlighter-rouge">uint32</code> container, we are not modifying a single weight; we are performing parallel bitwise arithmetic on 8 weights at once.</p>

<h2 id="-the-experiment-systematic-weight-corruption">🧪 The Experiment: Systematic Weight Corruption</h2>
<p>Using Llama 3 8B (4-bit quantized) on Apple MLX, we systematically subtracted increasing integer values from the packed <code class="language-plaintext highlighter-rouge">uint32</code> weights of the <code class="language-plaintext highlighter-rouge">lm_head</code> layer.</p>

<h3 id="the-surgical-code">The “Surgical” Code</h3>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">mlx.core</span> <span class="k">as</span> <span class="n">mx</span>

<span class="c1"># The target: lm_head layer
</span><span class="n">original_weights</span> <span class="o">=</span> <span class="n">weights</span><span class="p">[</span><span class="s">"lm_head"</span><span class="p">][</span><span class="s">"weight"</span><span class="p">]</span>

<span class="c1"># The Perturbation: Subtracting from the bit-packed container
# shift = 1,000,000 (The Threshold)
</span><span class="n">corrupted_weights</span> <span class="o">=</span> <span class="n">original_weights</span> <span class="o">-</span> <span class="n">shift</span>

<span class="c1"># Inject back into the model
</span><span class="n">model</span><span class="p">.</span><span class="n">update</span><span class="p">({</span><span class="s">"lm_head"</span><span class="p">:</span> <span class="p">{</span><span class="s">"weight"</span><span class="p">:</span> <span class="n">corrupted_weights</span><span class="p">}})</span>
</code></pre></div></div>

<p>We observed the model’s response to the prompt <em>“What is 2+2?”</em> across a range of shifts from 0 to 100 million.</p>

<h2 id="-results-the-observation-table">📊 Results: The Observation Table</h2>

<table>
  <thead>
    <tr>
      <th style="text-align: left">Shift Amount</th>
      <th style="text-align: left">% of Int32 Range</th>
      <th style="text-align: left">Model Response</th>
      <th style="text-align: left">Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="text-align: left">0</td>
      <td style="text-align: left">0.0%</td>
      <td style="text-align: left">“The answer to 2+2 is 4”</td>
      <td style="text-align: left">🟢 Healthy</td>
    </tr>
    <tr>
      <td style="text-align: left">1,000,000</td>
      <td style="text-align: left">0.023%</td>
      <td style="text-align: left">“The answer to 2+2 is 4”</td>
      <td style="text-align: left">🟢 Healthy</td>
    </tr>
    <tr>
      <td style="text-align: left">1,000,003</td>
      <td style="text-align: left">0.023%</td>
      <td style="text-align: left">“The answer is 4 obceLIKELYHonestly…”</td>
      <td style="text-align: left">🟠 Mid-sentence collapse</td>
    </tr>
    <tr>
      <td style="text-align: left">1,000,005</td>
      <td style="text-align: left">0.023%</td>
      <td style="text-align: left">“The answer permalinkizmet…”</td>
      <td style="text-align: left">💀 Catastrophic Failure</td>
    </tr>
  </tbody>
</table>

<h2 id="-core-finding-bit-level-borrow-propagation">🧠 Core Finding: Bit-Level Borrow Propagation</h2>
<p>The experiments revealed a sharp <strong>“Tipping Point”</strong> at a shift of approximately <strong>1,000,004</strong>.</p>

<h3 id="why-the-sudden-collapse">Why the sudden collapse?</h3>
<p>When we subtract a large number from a <code class="language-plaintext highlighter-rouge">uint32</code>, the CPU performs <strong>binary subtraction</strong>. If the result in one bit-column is negative, it “borrows” from the next.</p>

<p>In a packed 4-bit format, a large enough subtraction in the lower bits eventually causes a <strong>borrow chain</strong> that propagates through the entire <code class="language-plaintext highlighter-rouge">uint32</code> container. At the threshold (~1M), this chain reaches the upper nibbles, effectively flipping the sign bits or significantly shifting the magnitudes of all 8 packed weights simultaneously.</p>

<h3 id="the-logit-smear">The Logit Smear</h3>
<p>By visualizing the <code class="language-plaintext highlighter-rouge">lm_head</code> output before the Softmax layer, we observed that:</p>
<ol>
  <li><strong>Shifts &lt; 1M</strong>: The logit for the correct token (“ 4”) remains dominant.</li>
  <li><strong>Shift = 1,000,004</strong>: The probability mass suddenly “smears” across the entire vocabulary. The correct token is no longer in the Top-K.</li>
</ol>

<h2 id="-key-insights">💡 Key Insights</h2>
<ol>
  <li><strong>Resilience vs. Fragility</strong>: 4-bit quantized models are surprisingly robust to small noise but have a “hard floor.” Once bit-borrowing crosses a nibble boundary, recovery is impossible.</li>
  <li><strong>Quantization is Not Floating Point</strong>: Traditional weight decay or noise injection techniques designed for float32 will fail or behave unpredictably on packed quantized weights because they don’t account for the bit-packing layout.</li>
  <li><strong>Inference Engineering</strong>: Understanding these thresholds is vital for developing robust decoding strategies that can “shield” models from hardware-level bit-flips or memory corruption.</li>
</ol>

<hr />
<p><em>For the full code and reproduction steps, see <a href="https://github.com/yatharth-anand-2410/llama3-mlx-research-lab/blob/main/notebooks/06_sensitivity_analysis.ipynb">Notebook 06: Sensitivity Analysis</a>.</em></p>]]></content><author><name></name></author><category term="research" /><category term="interpretability" /><category term="llama3" /><category term="mlx" /><category term="quantization" /><category term="weights" /><summary type="html"><![CDATA[🚀 Objective To determine the precise mathematical threshold at which uniform bit-level perturbations to 4-bit quantized LLM weights cause catastrophic model collapse. We aim to understand how robust these compressed models are to “bit-level noise.”]]></summary></entry></feed>