GPU and Hardware Basics for AI Engineers
Enough about GPUs, VRAM, precision and cloud options to estimate what hardware a model needs and what it will cost.
Intermediate · about 3 hours · difficulty 3/5
Learn first: Running Open-Weight Models Locally
You do not need to write CUDA kernels, but you should be able to answer "can we run this model, on what, and for how much?".
Why GPUs
Model inference is dominated by large matrix multiplications and, for generation, by memory bandwidth: every generated token reads the model's weights from memory. GPUs have thousands of cores and very fast memory, which is why they dominate.
Estimating memory
- Weights: parameters times bytes per parameter. A 7 billion parameter model needs about 14 GB in 16-bit precision, about 7 GB in 8-bit and about 4 GB in 4-bit.
- KV cache: grows with context length and number of concurrent sequences; long contexts can need as much memory as the weights.
- Overhead: activations and framework buffers, so leave headroom.
- Training and fine-tuning need far more memory than inference because of gradients and optimizer state, which is why LoRA and QLoRA matter.
Hardware landscape
- NVIDIA data centre GPUs dominate cloud inference and training; consumer GPUs are fine for learning and small models.
- Apple Silicon's unified memory runs surprisingly large quantized models locally.
- Alternatives include AMD GPUs, Google TPUs and custom inference chips offered through cloud APIs.
Cloud options
Hyperscalers, specialist GPU clouds and serverless GPU platforms rent by the hour or second. Compare price per hour, availability, and whether you pay for idle time.
Good enough to move on
Given a model size, precision and context length, you can estimate the VRAM needed, pick a suitable GPU, and compare the monthly cost to a hosted API for a given traffic level.
Key concepts
- Why inference is memory bound
- Estimating VRAM for weights
- KV cache memory
- Precision: FP16, INT8, 4-bit
- Training vs inference memory
- Cloud and serverless GPUs
- Apple Silicon and local hardware
Mini project
Write a small calculator script that estimates VRAM for a model given parameters, precision, context length and concurrency, then check its predictions against real memory usage in Ollama or vLLM.
Check yourself
Roughly how much memory does a 13 billion parameter model need in 4-bit precision, before KV cache?
Free resources
- Hugging Face: GPU inference (Hugging Face)
- Hugging Face: quantization overview (Hugging Face)
- NVIDIA CUDA documentation (NVIDIA)