Menu

Gemma 4 on a 4 GB GPU in Plain PyTorch: From Out of Memory to Faster Than llama.cpp
πŸ“°

Gemma 4 on a 4 GB GPU in Plain PyTorch: From Out of Memory to Faster Than llama.cpp

DEV Community: pytorchΒ·xbillΒ·2 days ago
#mal3JuAW
#devtopytorch#devto#dev#pytorch#llama
Reading 0:00
15s threshold

This article provides a step by step guide to running Gemma 4 E2B, Google's quantization-aware trained (QAT) build, on a 4 GB NVIDIA GTX 1650 Ti laptop GPU with plain PyTorch and Hugging Face Transformers. A small OpenAI-compatible server is built to run the result like any other local model server.

https://github.com/xbill9/gemma4-dev

Can plain PyTorch run Gemma 4 on a 4 GB GPU? Yes, and faster than llama.cpp at chat-length context , once the model stays 4-bit from disk to arithmetic:

GTX 1650 Ti, 4 GB, Gemma 4 E2B Decode Fits the card

16-bit weights β€” ❌ no, 3.58 GiB of layers alone

Transformers' own 4-bit path β€” ❌ no, out of memory on the first forward pass

4-bit layers, unpacked by PyTorch one layer at a time 0.58 tok/s βœ… yes

4-bit end to end, this article 87.8 tok/s βœ… yes, with the full 131,072-token context

llama.cpp, same card, same day 82.1 tok/s βœ… yes

Every weight stays on the 4-bit grid Google trained, and the speed comes from doing the 4-bit arithmetic in kernels that read the packed…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.