Advanced
Running models locally
Local inference is a capacity-planning problem across artifact compatibility, memory, bandwidth, context, runtime support, and privacy boundaries.
Updated
1
Concept
Running a model locally can reduce dependence on a network service, keep prompts on a controlled device, support offline work, and make experiments reproducible. It does not mean “download any model and double-click.” A successful setup aligns the checkpoint, runtime, hardware, memory budget, and workload.
Start with compatibility. Identify the architecture, tokenizer, chat template, context configuration, and license. Then choose an artifact the runtime actually supports: original framework tensors, a safetensors checkpoint, GGUF tensor types, or another documented format. A matching filename is not enough; model metadata, tensor shapes, positional encoding, multimodal projectors, and special tokens must agree.
Estimate weight memory from parameters, average stored bits, and metadata. Quantized models include scales and sometimes selected higher-precision tensors, so dividing the parameter count by a bit width is only a lower-order estimate. Runtime loaders may map the file, copy tensors, dequantize some layers, or split work between CPU and accelerator. Measure resident memory after load.
Then add dynamic memory. KV cache grows with retained context, layers, KV heads, head dimension, precision, and concurrent sequences. Activations and scratch workspaces depend on kernels and batch shape. Multimodal models add image or audio encoders and input buffers. The operating system and display also need headroom. A model whose file barely fits can fail on the first long prompt.
Capacity and speed are separate. Autoregressive decode often moves a large fraction of weights for each token step, so usable memory bandwidth strongly influences generation speed. Compute capability matters for prompt processing and specialized kernels. CPU vector instructions, GPU backend support, unified versus discrete memory, transfer links, power limits, and cooling all affect sustained performance.
Offloading extends capacity by placing layers or tensors across accelerator memory, system RAM, and sometimes storage. FlexGen, published in 2023, studied scheduled offloading for high-throughput generation on limited GPU memory. Offloading is not free: every boundary adds transfers, and storage is much slower than RAM. A configuration that technically runs can be unusable for interactive work.
Choose the runtime around the device and artifact. llama.cpp targets portable local inference across CPU and several acceleration backends and uses GGUF in its ecosystem. Other runtimes specialize in vendor GPUs or framework-native models. Confirm native kernels for the selected quantization; a fallback that expands weights can erase memory or speed benefits.
Benchmark the intended task, not a screenshot. Record runtime and model versions, device, thread count, backend, context, prompt and output lengths, batch settings, cache dtype, and thermal state. Measure load time, TTFT, output tokens per second, peak memory, energy if relevant, and answer quality. Warm and cold runs answer different questions.
Context settings deserve skepticism. A runtime may allow a large configured window while quality degrades beyond the model’s trained or adapted range. More context also consumes cache and prompt time. Use retrieval or deliberate context selection rather than treating the maximum as a target.
The durable planning order is: establish compatibility and rights; size weights plus dynamic state and headroom; verify backend kernels; estimate bandwidth and transfers; benchmark representative prompts; then secure the local data path. Local inference is rewarding precisely because every layer is visible—but that also makes you the serving operator.
2
Explain it like I am five
Planning a remote expedition means packing more than the tent's listed weight. You need food that grows with trip length, tools, fuel, spare space, and equipment suited to the terrain. A model's parameter file is only the tent. KV cache grows with context, runtimes need workspace, multimodal encoders add gear, and unsupported kernels are like bringing road tires onto ice. Local success comes from sizing the whole expedition.
3
Teach it back
Give a complete local-inference sizing checklist and explain why a model file fitting in RAM does not prove the model will run well.
Minimum: 80 characters and 15 words. Your text stays only in this browser.
Saved only on this device.
Show a model answer
Check architecture and tokenizer compatibility, weight format and quantization, resident weight bytes, KV cache at the intended context and concurrency, runtime workspace, multimodal components, and operating-system headroom. Then check memory bandwidth, accelerator support, CPU instruction sets, storage, thermal limits, and desired latency. A file can fit while runtime buffers or cache cause out-of-memory, or it can run slowly because weights move through insufficient bandwidth or the compact format lacks native kernels.
4
Check your understanding
Complete the teach-back and answer the quiz correctly to finish this lesson.
Sources
- Ying Sheng et al. (2023). FlexGen: High-Throughput Generative Inference of Large Language Models with a Single GPU.
- Georgi Gerganov and contributors (2023). llama.cpp.