{"slug": "gemma-4-on-an-old-4-gb-laptop-gpu-qat-takes-it-from-9-5-gib-to-1-6", "title": "Gemma 4 on an Old 4 GB Laptop GPU: QAT Takes It From 9.5 GiB to 1.6", "summary": "A developer deployed Google's Gemma 4 E2B quantization-aware-trained (QAT) checkpoint on a 4 GB GTX 1650 Ti laptop GPU, shrinking the model from 9.5 GiB in bfloat16 to a 3.35 GB Q4_0 GGUF file with only 1.31 GiB resident on the GPU. The setup loaded in 1618 MiB and decodes at 73.75 tok/s, with a suite of Python MCP tools built to manage the llama.cpp deployment. The developer notes that QAT preserves quality close to bfloat16 by training the model for 4-bit storage rather than compressing it afterward.", "body_md": "This article provides a step by step deployment guide for Gemma 4 E2B's quantization-aware-trained (QAT) checkpoint to a local, laptop hosted GPU enabled system — a much older Lenovo Yoga 9 with a 4 GB GTX 1650 Ti. A suite of Python MCP tools is built to simplify management of the llama.cpp hosted deployment.\n\n[https://github.com/xbill9/gemma4-dev/tree/main/local-llamacpp-1650ti-2b-q4_0](https://github.com/xbill9/gemma4-dev/tree/main/local-llamacpp-1650ti-2b-q4_0)\n\nGemma 4 E2B in bfloat16 is 9.5 GiB of weights. This laptop's GPU has 4 GiB. Even a plain int8 conversion would not fit. **The QAT release closes that gap: the same model, trained knowing it would be stored at 4 bits, in a 3.35 GB file of which only 1.31 GiB ever has to be on the GPU.** It loaded in 1618 MiB, left more than half the card free, and decodes at 73.75 tok/s.\n\nEvery other rig in this repository serves Gemma 4 from rented hardware: Cloud TPU, Compute Engine, EC2, Cloud Run. I wanted to know whether the same model would run on the laptop I already had — a 10th-generation Core i7 with a GTX 16-series GPU, no tensor cores and a 4 GB ceiling that no quota request can raise.\n\nIt does, and QAT is the reason. The rest of this article is how, and what the old hardware changes about running it.\n\n`nvcc` 13.3 here`python3`, no virtualenv` local-llamacpp-1650ti-2b-q4_0/` as your working directory\n| Machine | Lenovo Yoga 9 15IMH5 | \n| CPU | Intel Core i7-10750H, 10th generation (Comet Lake), 12 threads | \n| RAM | 15 GiB, as `free` reports it | \n| GPU | GeForce GTX 1650 Ti with Max-Q Design, 4096 MiB | \n| GPU power | 40 W limit | \n\nThe MCP server reports the GPU the same way:\n\n```\ngpu_status\n📡 **GPU** — `local-llamacpp-1650ti-2b-q4_0`\n\nNVIDIA GeForce GTX 1650 Ti with Max-Q Design, 7.5, 4096 MiB, 1606 MiB, 2127 MiB, 615.71.09\n\n⚠️  GTX 16-series (TU116/TU117): compute capability 7.5 but **no tensor cores**. Do not compare throughput against the T4-based `g4dn`/` g5g` rigs on the strength of a matching compute capability.\n```\n\n**Compute capability 7.5 is a trap.** A T4 is also 7.5 and has tensor cores; the GTX 16-series is a cut-down Turing die with the tensor cores removed. llama.cpp notices on its own at init:\n\n```\nThe following devices will have suboptimal performance due to a lack of tensor cores:\n  Device 0: NVIDIA GeForce GTX 1650 Ti with Max-Q Design\n```\n\nThe sizes, from this repository's model reference:\n\n| Gemma 4 E2B as | Weights | Fits 4096 MiB? | \n|---|---|---|\n| bfloat16 | 9.5 GiB | ❌ no | \n| int8 | ~4.8 GiB | ❌ no | \n| QAT Q4_0 GGUF, whole file | 3.35 GB | barely, on paper | \n| QAT Q4_0 GGUF, GPU-resident part | **1.31 GiB** | ✅ yes | \n\nThe bf16 checkpoint is more than twice the card. Halving it to int8 is still larger than the card. Only a 4-bit model is in range, and that is where QAT comes in.\n\nQuantization-aware training simulates quantization *during* training rather than compressing a finished model afterwards. The 4-bit weights are not a post-hoc approximation of a bf16 model: the model was trained knowing it would be stored this way. Google's model card puts the goal plainly:\n\nThis model card is for the new versions of the Gemma 4 family optimized with Quantization-Aware Training (QAT), which allows preserving similar quality to bfloat16 while dramatically reducing the memory requirements to load the model.\n\nThat is the difference that matters on a 4 GB card. **Rounding the bf16 model down to 4 bits after the fact would fit too, but nothing in its training would have prepared it for that.** QAT is the version of \"fits\" that was designed to keep the model's quality close to bf16 on the way there.\n\nGoogle ships the QAT weights four ways:\n\n| Artifact | What it is | For | \n|---|---|---|\n| `-qat-q4_0-unquantized` | QAT values in a half-precision container | custom compilation | \n| `-qat-q4_0-gguf` | the same values, packed Q4_0 | **llama.cpp — this rig** | \n| `-qat-w4a16-ct` | compressed-tensors | vLLM | \n| mobile | on-device runtimes | phones | \n\nThe GGUF is not a lesser copy. This repository checked it: four norm tensors read out of the GGUF are bit-identical to the ones in the `-unquantized` release, so it is the same QAT model in its native packing.\n\n`google/gemma-4-E2B-it-qat-q4_0-gguf`, which llama.cpp opens directly. The agent reads it off disk:\n\n```\nmodel_info\n📡 **Model** — `local-llamacpp-1650ti-2b-q4_0`\n\n- **Name:** `google/gemma-4-E2B-it-qat-q4_0-gguf`\n- **Path:** `/home/xbill/models/gemma-4-E2B-it-qat-q4_0/gemma-4-E2B_q4_0-it.gguf`\n- **On disk:** 3.35 GB\n- **Quantization slot:** `q4_0` — but the dominant tensor type is **Q6_K**. Both embedding tensors are Q6_K (2.257 GB of 3.334 GB); only the ~1.08 GB transformer body is actually Q4_0.\n- **Resident on GPU:** ~1.31 GiB. `per_layer_token_embd` (1.93 GB, 58% of the file) is `TENSOR_READ_LAZY` and is served by GET_ROWS out of the mmap.\n\nRun `inspect_gguf.py` to re-derive the split from the artifact rather than trusting these numbers.\n```\n\nTwo lines in that output explain why a 3.35 GB file fits in far less than 3.35 GB.\n\nA 3.35 GB file against 3724 MiB free reads as \"barely fits.\" It is better than that. `make info` reads the tensor table out of the GGUF:\n\n```\nmake info\ngemma-4-E2B_q4_0-it.gguf\n  tensors:  541\n  total:    3.334 GB\n\n  largest tensors:\n      1926.8 MB  per_layer_token_embd.weight  Q6_K    [8960, 262144]  <- LAZY, host-resident\n       330.3 MB  token_embd.weight            Q6_K    [1536, 262144]\n        27.5 MB  per_layer_model_proj.weight  F16     [1536, 8960]\n        10.6 MB  blk.34.ffn_up.weight         Q4_0    [1536, 12288]\n\n  lazy (never on GPU):        1.927 GB  (58% of file)\n  must be resident:           1.407 GB = 1.31 GiB\n\n  by tensor type (the slot-5 token is q4_0; the file mostly is not):\n    Q6_K      2.257 GB  (67.7%)\n    Q4_0      1.048 GB  (31.4%)\n    F16       0.028 GB  ( 0.8%)\n```\n\n**One tensor is 58% of the file, and none of it has to be on the GPU.** `per_layer_token_embd` is Gemma 4's per-layer embedding table — the \"E\" in E2B, and why the model has about 5B parameters in total but 2B effective. llama.cpp creates it with `TENSOR_READ_LAZY` and uses it as a row lookup, not a matmul, so the rows a token needs are read out of the memory-mapped file on the host.\n\nQAT and the lazy table stack. QAT puts the 35 transformer blocks at Q4_0, 1.05 GB where half precision would be 3.7 GB; the lazy table keeps the biggest remaining tensor off the card entirely. **What decode actually streams per token drops from 4.514 GB at half precision to 1.407 GB, a 3.2x cut.**\n\nTwo rules follow, and both are the opposite of what a memory-anxious setup would do:\n\n`-ngl` to save memory.`--no-mmap`.\nA standard CUDA build, pinned to this card's architecture:\n\n```\ngrep -E \"^(GGML_CUDA|CMAKE_CUDA_ARCHITECTURES|CMAKE_BUILD_TYPE)[:=]\" ~/llama.cpp/build/CMakeCache.txt\n~/llama.cpp/build/bin/llama-server --version\nCMAKE_BUILD_TYPE:STRING=Release\nCMAKE_CUDA_ARCHITECTURES:UNINITIALIZED=75\nGGML_CUDA:BOOL=ON\nversion: 0.3.0-dev (build 1, commit 95ef7fc)\n```\n\n`tpu.env`\nOne committed env file drives both the `Makefile` and the MCP server. It is called `tpu.env` for consistency with its siblings; there is no TPU here.\n\n```\ngrep -E \"^(MODEL_PATH|ENDPOINT|N_GPU_LAYERS|CONTEXT_SIZE|KV_CACHE_TYPE|FLASH_ATTENTION|THREADS|PARALLEL_SLOTS|METRICS)=\" tpu.env\nMODEL_PATH=/home/xbill/models/gemma-4-E2B-it-qat-q4_0/gemma-4-E2B_q4_0-it.gguf\nENDPOINT=http://127.0.0.1:8080\nN_GPU_LAYERS=99\nCONTEXT_SIZE=8192\nKV_CACHE_TYPE=f16\nFLASH_ATTENTION=1\nMETRICS=1\nTHREADS=4\nPARALLEL_SLOTS=1\n```\n\n`N_GPU_LAYERS=99` is full offload. Every value was measured on this card rather than copied from a cloud rig.\n\n```\nmake serve\n```\n\n`make serve` runs in the foreground on purpose: this is a laptop, nothing is billed, and Ctrl-C is a complete teardown. From another shell:\n\n```\nnvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv,noheader\n37073, /home/xbill/llama.cpp/build/bin/llama-server, 1618 MiB\n```\n\n**1618 MiB of 4096.** Weights, an 8192-token context and CUDA's own overhead, with more than half the card to spare. Had the lazy table been resident the requirement would have been about 3.5 GB, and the model would have failed to load.\n\nThe agent confirms it is serving:\n\n```\nmodel_server_status\n✅ Serving at http://127.0.0.1:8080 (pid 83619). `/health` → 200.\n```\n\nThe endpoint is a fixed local address, so there is nothing to discover. An early version of this tool read a missing pid file as \"not running\" and reported ❌ against a healthy server; it now checks which process owns port 8080, and `/health` makes the final call.\n\nThe allocation, as printed by the engine when a sibling rig loaded the same file on this same card through Ollama:\n\n| term | MiB | \n|---|---|\n| model buffer (weights) | 1341.78 | \n| KV, 3 full-attention layers × 8192 cells | 48.00 | \n| KV, 12 sliding-window layers × 1024 cells | 12.00 | \n| compute buffer | 122.52 | \n| CUDA context + slack | ~94 | \n\nThe weights are the QAT body plus the resident embeddings. The KV cache is only 60 MiB, because llama.cpp caps Gemma 4's sliding-window layers at the 1024-token window regardless of context size.\n\nMy own derivation before the run predicted 1616 MiB — two MiB off — with 144 MiB of KV and ~130 of overhead. **Both of those terms were wrong, in opposite directions, and the total still matched.** A total that agrees with the hardware does not confirm the terms; read the engine's allocation log.\n\n```\nquery_model \"In one sentence, what is a TPU?\"\n✅ **Reply**\n\nA TPU is a specialized hardware accelerator designed by Google specifically to speed up the computationally intensive operations required for training and running machine learning models and deep learning tasks.\n\n---\n_(plus 1167 chars of reasoning, suppressed)_\nprompt 25 tok · completion 308 tok · 70.5 tok/s\n```\n\nA 4-bit Gemma 4 answering on a laptop GPU with no tensor cores, through Claude Code, over MCP. **A one-sentence answer cost 308 completion tokens**, and most of them were thinking.\n\nGemma 4 emits a thinking block. llama.cpp routes it to `reasoning_content` and leaves `content` empty until the block closes, so a caller that reads only `content` with a modest budget gets `\"\"` and concludes the server is broken. `query_model` defaults to `max_tokens=1024`, and reports the empty case as what it is:\n\n```\nquery_model \"Name three TPU generations.\" max_tokens=64\n📡 **Reasoning only — no answer yet.** `finish_reason: length` after 64 tokens, all of them thinking.\n\nThis is Gemma 4 reasoning, not a broken server. Re-run with a larger `max_tokens` (currently 64).\n```\n\nThe same applies to benchmarks: **a 128-token generation limit on this model measures the thinking phase and nothing else.**\n\n`llama-bench -p 512 -n 128 -r 3`, all layers on the GPU:\n\n|  | config | prefill t/s | decode t/s | \n|---|---|---|---|\n| 🥇 | `-fa 1` , f16 KV,`-t 4` | 340.33 | 73.75 | \n| 🥈 | `-fa 1` , f16 KV,`-t 6` | 340.39 | 73.74 | \n| 🥉 | `-fa 1` , f16 KV,`-t 8` | 338.49 | 72.97 | \n|  | `-fa 0` , f16 KV,`-t 6` | 338.74 | 70.39 | \n|  | `-fa 1` , f16 K, q8_0 V | 202.66 | 65.55 | \n|  | `-fa 1` , q8_0 K, f16 V | 239.09 | 64.91 | \n\n`q8_0` costs 11–12% of decode and 30–40% of prefill. With no tensor cores to hide the dequantization, and a KV cache of 60 MiB, it buys memory that was never scarce. `GGML_CUDA_FORCE_MMQ` does not pay\nFor decode, yes: `llama-batched-bench` goes from 73.33 to 277.61 tok/s between one and 64 parallel sequences. But that is the decode phase in isolation. Through the HTTP endpoint with 512-token prompts, prefill runs one request at a time — time to first token doubles exactly with every doubling of clients — and aggregate output tops out near 48 tok/s, 1.47x from one client. With short prompts and long answers it reaches 2.6x at 16 clients, but every level between 1 and 16 flips between two speeds from trial to trial.\n\n**For one person on one laptop, concurrency one is the right setting**, and that is what `PARALLEL_SLOTS=1` carries.\n\n`server.py` is a single-file MCP server with seven tools: `gpu_status`, `model_info`, `start_model_server`, `stop_model_server`, `model_server_status`, `query_model` and `get_help`. There is no provisioning tool, because there is nothing to provision. It registers under its directory name, so every tool reaches Claude Code as `mcp__local-llamacpp-1650ti-2b-q4_0__<tool>`.\n\nA stdio check confirms the handshake independently of any client:\n\n```\n{ printf '%s\\n' \\\n  '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2025-06-18\",\"capabilities\":{},\"clientInfo\":{\"name\":\"probe\",\"version\":\"0\"}}}' \\\n  '{\"jsonrpc\":\"2.0\",\"method\":\"notifications/initialized\"}' \\\n  '{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/list\",\"params\":{}}'; sleep 4; } \\\n  | python3 server.py 2>/dev/null\ninitialize OK: name='local-llamacpp-1650ti-2b-q4_0' version='' proto 2025-06-18\ntools/list OK: 7 tools -> get_help, gpu_status, model_info, model_server_status, query_model, start_model_server, stop_model_server\n```\n\nMidway through, the server stopped loading. Another project on the machine needed the MCP Python SDK 2.x, all of these projects share one system Python, and 2.x renamed the class this server imports:\n\n``` python\npython3 -c \"from mcp.server.fastmcp import FastMCP\"\nraise ModuleNotFoundError(_MESSAGE, name=__name__)\nModuleNotFoundError: No module named 'mcp.server.fastmcp'. This is mcp 2.x, where FastMCP was renamed to MCPServer (from mcp.server.mcpserver import MCPServer) and other APIs changed; see the migration guide at https://py.sdk.modelcontextprotocol.io/v2/migration/#fastmcp-renamed-to-mcpserver or pin 'mcp<2' to keep running v1 code.\n```\n\nPinning back was not an option with a shared interpreter. The fix was two lines, the requirement bound, and the test mock's module path:\n\n``` python\n-from mcp.server.fastmcp import FastMCP\n+from mcp.server.mcpserver import MCPServer\n-mcp = FastMCP(MCP_SERVER_NAME)\n+mcp = MCPServer(MCP_SERVER_NAME)\n\n-mcp>=1.2.0,<2\n+mcp>=2\n\n-sys.modules[\"mcp.server.fastmcp\"] = _fastmcp_module\n+sys.modules[\"mcp.server.mcpserver\"] = _mcpserver_module\n```\n\nTouching `start_model_server` for the rename surfaced an older bug: the tool launched `llama-server` without `-fa`, `-t` or `--parallel`, so an MCP-started server came up with **4 slots and 6 threads** instead of the measured configuration — and llama.cpp splits the context across slots. The argv now lives in one function, a test holds it to the `Makefile`, and the running server's real command line matches:\n\n```\ntr '\\0' ' ' < /proc/$(pidof llama-server)/cmdline\n/home/xbill/llama.cpp/build/bin/llama-server -m /home/xbill/models/gemma-4-E2B-it-qat-q4_0/gemma-4-E2B_q4_0-it.gguf --host 127.0.0.1 --port 8080 -ngl 99 -c 8192 -ctk f16 -ctv f16 -fa 1 -t 4 --parallel 1 --metrics\nmake lint\nmake test\nAll checks passed!\nlint OK\n----------------------------------------------------------------------\nRan 30 tests in 0.035s\n\nOK\n```\n\nThere is no price. The laptop was already on the desk: nothing is billed, nothing is reserved, and there is no idle cost to optimise.\n\nWhat QAT bought is capability, not a discount. Without it this GPU cannot hold Gemma 4 E2B at all. With it, the model takes 1618 MiB and a single conversation decodes at 73.75 tok/s.\n\n```\n# make serve is in the foreground:\nCtrl-C\n```\n\nOr ask the agent for `stop_model_server`, which sends SIGTERM to whichever process owns port 8080, including one started by `make serve`. Not run for this article; the server is still up.\n\n**Output quality was not measured here.** The claim that QAT holds quality close to bfloat16 is Google's, from the model card; this article measured memory and speed, not accuracy, and never compared the QAT model's answers against a bf16 run.\n\n**No benchmark completed a task.** Every sweep generation hit its token cap inside Gemma 4's thinking block, so the throughput figures are real and the tasks are not.\n\n**Nothing here transfers to a T4.** Same compute capability, different silicon.\n\nThe goal of this article was to run Gemma 4 on a much older laptop whose GPU has 4 GB of memory. The key to the solution was Google's quantization-aware-trained checkpoint, packed as a GGUF, plus llama.cpp leaving its largest tensor in host memory. The measured results were:\n\nScope: one Lenovo Yoga 9 15IMH5 (Core i7-10750H, 15 GiB RAM, GTX 1650 Ti Max-Q with 4096 MiB and a 40 W cap), llama.cpp `95ef7fc` built for sm_75 with CUDA 13.3, `google/gemma-4-E2B-it-qat-q4_0-gguf`, and the MCP server on mcp 2.2.0 under Python 3.14.7. `llama-bench` rows are three repeats; serving sweeps are three repeats per level with the prompt cache defeated. The memory split comes from a sibling rig running the same engine through Ollama on the same card. Model quality was not measured.\n\nThe strategy for using MCP for a local GPU deployment was validated with an incremental step by step approach.", "url": "https://wpnews.pro/news/gemma-4-on-an-old-4-gb-laptop-gpu-qat-takes-it-from-9-5-gib-to-1-6", "canonical_source": "https://dev.to/gde/gemma-4-on-an-old-4-gb-laptop-gpu-qat-takes-it-from-95-gib-to-16-b5l", "published_at": "2026-09-10 18:51:51+00:00", "updated_at": "2026-09-10 19:05:44.329555+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "ai-infrastructure", "machine-learning"], "entities": ["Gemma 4", "Google", "llama.cpp", "NVIDIA GeForce GTX 1650 Ti", "Lenovo Yoga 9", "Intel Core i7-10750H"], "alternates": {"html": "https://wpnews.pro/news/gemma-4-on-an-old-4-gb-laptop-gpu-qat-takes-it-from-9-5-gib-to-1-6", "markdown": "https://wpnews.pro/news/gemma-4-on-an-old-4-gb-laptop-gpu-qat-takes-it-from-9-5-gib-to-1-6.md", "text": "https://wpnews.pro/news/gemma-4-on-an-old-4-gb-laptop-gpu-qat-takes-it-from-9-5-gib-to-1-6.txt", "jsonld": "https://wpnews.pro/news/gemma-4-on-an-old-4-gb-laptop-gpu-qat-takes-it-from-9-5-gib-to-1-6.jsonld"}}