<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ethanlin</title>
    <description>The latest articles on DEV Community by ethanlin (@ethanjlin).</description>
    <link>https://dev.to/ethanjlin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4046015%2F44eea633-e6e6-4e33-b45a-839c0eef8e49.png</url>
      <title>DEV Community: ethanlin</title>
      <link>https://dev.to/ethanjlin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ethanjlin"/>
    <language>en</language>
    <item>
      <title>Picking a Gemma 4 Quantization: VRAM Math That Actually Matters</title>
      <dc:creator>ethanlin</dc:creator>
      <pubDate>Fri, 24 Jul 2026 19:00:12 +0000</pubDate>
      <link>https://dev.to/ethanjlin/picking-a-gemma-4-quantization-vram-math-that-actually-matters-1f0b</link>
      <guid>https://dev.to/ethanjlin/picking-a-gemma-4-quantization-vram-math-that-actually-matters-1f0b</guid>
      <description>&lt;p&gt;Every "run this model locally" guide tells you to grab a Q4 GGUF and move on. That advice is fine right up until you try a long-context run and your machine starts swapping.&lt;/p&gt;

&lt;h2&gt;
  
  
  The weights are the part everyone budgets for
&lt;/h2&gt;

&lt;p&gt;Quantization maths is straightforward. A model's weight footprint is roughly &lt;code&gt;params x bits / 8&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Quant&lt;/th&gt;
&lt;th&gt;Bits/param&lt;/th&gt;
&lt;th&gt;12B model&lt;/th&gt;
&lt;th&gt;Quality note&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Q8_0&lt;/td&gt;
&lt;td&gt;~8.5&lt;/td&gt;
&lt;td&gt;~12.8 GB&lt;/td&gt;
&lt;td&gt;Near-lossless, rarely worth it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q6_K&lt;/td&gt;
&lt;td&gt;~6.6&lt;/td&gt;
&lt;td&gt;~9.9 GB&lt;/td&gt;
&lt;td&gt;Very close to Q8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q4_K_M&lt;/td&gt;
&lt;td&gt;~4.8&lt;/td&gt;
&lt;td&gt;~7.2 GB&lt;/td&gt;
&lt;td&gt;The usual sweet spot&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q3_K_M&lt;/td&gt;
&lt;td&gt;~3.9&lt;/td&gt;
&lt;td&gt;~5.9 GB&lt;/td&gt;
&lt;td&gt;Noticeable degradation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Below Q4 the loss stops being subtle. Instruction-following degrades before raw perplexity does, which is why benchmark numbers can look fine while the model quietly stops respecting your system prompt.&lt;/p&gt;

&lt;h2&gt;
  
  
  The KV cache is the part that bites
&lt;/h2&gt;

&lt;p&gt;Here is what the guides skip. The KV cache scales with &lt;strong&gt;context length&lt;/strong&gt;, and it is not quantized by default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kv_bytes ~= 2 (K and V) x layers x kv_heads x head_dim x seq_len x dtype_bytes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The practical consequence: a model that loads in 7 GB can need well over twice that at long context. Grouped-query attention helps a lot — &lt;code&gt;kv_heads&lt;/code&gt; is much smaller than attention heads — but the term still grows linearly with sequence length while your weights stay fixed.&lt;/p&gt;

&lt;p&gt;Two knobs matter more than picking a fancier quant:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;--ctx-size&lt;/code&gt;&lt;/strong&gt;: do not allocate 128K if your prompts are 8K. You are reserving memory you will never touch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;KV cache quantization&lt;/strong&gt; (&lt;code&gt;q8_0&lt;/code&gt; for K/V): roughly halves cache memory for a quality hit most workloads never notice. Underused.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A decision order that works
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Start at Q4_K_M&lt;/li&gt;
&lt;li&gt;Set context to what you actually use, not the model maximum&lt;/li&gt;
&lt;li&gt;If you are still tight, quantize the KV cache before dropping to Q3&lt;/li&gt;
&lt;li&gt;Only move up to Q6/Q8 if you have headroom left over&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That ordering matters: dropping to Q3 to buy context is the most common mistake, and it trades a permanent quality loss for memory you could have gotten from the cache instead.&lt;/p&gt;

&lt;p&gt;Per-quantization benchmarks and deployment notes for the Gemma 4 family are collected at &lt;a href="https://gemma-4.net" rel="noopener noreferrer"&gt;gemma-4.net&lt;/a&gt; — every number self-run, raw data published.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveat
&lt;/h2&gt;

&lt;p&gt;These are rules of thumb, not guarantees. Backends differ in how they allocate, and Apple Silicon unified memory behaves differently from discrete VRAM. Measure on your own hardware before trusting any table, including mine.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>opensource</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
  </channel>
</rss>
