Edge AI: Run LLMs Locally Without Cloud Costs
Learn how edge AI runs LLMs on phones and PCs, what runtimes and hardware delegates do, and how to balance privacy, speed, cost, and accuracy.

How Edge AI Runs LLMs Locally - and When It Makes Sense
Many teams send every AI request to a big cloud model, even when the job is narrow enough to handle with a smaller model running on a phone or laptop. Cloud is often the easy choice - more capacity, managed APIs, and less deployment work. But if your product depends on a reliable network, pays per request, mishandles data, or needs low latency, those "small" trade-offs start showing up fast.
Edge AI isn't just "put a smaller model on the device and hope." You have to pick the right model and runtime for the hardware you're targeting, then test accuracy, speed, memory use, battery impact, and failure behavior on the devices your users actually carry. A 4-billion-parameter model might be workable on one machine and a non-starter on another.
This guide walks through on-device inference, what CPU/GPU/NPU delegates do, where quantization helps, and when a hybrid cloud-and-edge setup is more sensible than trying to run everything locally. The goal is a deployment decision you can justify in production - not a blanket rule to abandon cloud models.
Why move an LLM from cloud to edge?
Local inference makes the most sense when the product has a constraint that cloud inference handles poorly. You'll usually see it in cases like intermittent connectivity, sensitive inputs, high request volume, or a need for responses that don't tolerate network round trips. In those situations, a smaller local model can be the better product decision - even if it's not as capable as a frontier model.
Start with the constraint, not the model
Think about voice commands in an industrial setting, offline support in a field-service app, or transcription on-device. A local model can keep running when the connection drops, and it avoids sending raw audio to a remote service. In an XR product, putting parts of the voice pipeline on-device can also cut down the back-and-forth between speech and response.
But the benefits don't automatically translate to privacy, security, or compliance. Local inference might reduce how often you send data over the network, but you still need to answer what the app stores, what it logs, how consent works, and whether data later syncs somewhere else. Privacy is an end-to-end system choice, not a magic setting on the model.
Compare the full operating cost
Cloud costs are easy to tally as API spend. The harder part is making a fair comparison that includes more than the bill. Consider network reliability, engineering and operations effort, device hardware, battery use, model update workflows, and ongoing support across device types. Running locally can reduce marginal API usage, while increasing your testing and maintenance burden.
Also, a small model can be the wrong answer if your use case needs complex reasoning or broad factual knowledge. In those cases, local responses can create more correction work than the cloud cost would have. Measure the end-to-end task, not just token counts.
A practical first checklist:
- Latency: Can the user wait for a cloud round trip?
- Connectivity: Do you need offline behavior or support on unreliable networks?
- Data sensitivity: Is there a real reason to keep inputs on the device?
- Volume: Will local inference change your operating economics at your usage level?
- Task quality: Can the smaller model hit a defined accuracy threshold?
If none of that matters, a managed cloud model may be simpler and more reliable. Edge AI is a design choice, not a goal.
How does on-device inference use CPU, GPU, and NPU?
A trained model isn't automatically ready to run fast on a phone or laptop. First, you need to export it into something the runtime can load. Then you have to map the model's operations to the hardware that can execute them. That's where runtimes and hardware delegates come in.
Runtime and delegate have different jobs
Tools like PyTorch ExecuTorch, Google LiteRT, and ONNX Runtime help you run exported models in constrained environments. ExecuTorch, for example, can package an exported model into a .pte file. The exact export process and which operations are supported depend on both the model and the toolchain - so choosing a runtime doesn't guarantee the model will use an accelerator.
A delegate maps supported operations to a specific hardware backend. XNNPACK is commonly used for CPU execution, Vulkan can provide a GPU path, and Qualcomm's QNN can target supported Qualcomm hardware, including NPUs. The delegate translates model operations into something the device can run. You don't usually write low-level device code for every operation, but you do need to verify what the backend actually supports.
Some operations run on the accelerator and others fall back to the CPU. Those handoffs can reduce the payoff from acceleration - especially when the graph contains many unsupported operations or involves expensive transfers. Profiling the entire inference path matters more than seeing an NPU mentioned in a device spec sheet.
A device is not one uniform target
Phones, laptops, and workstations differ in memory limits, thermal behavior, and accelerator support. Even if a device advertises an NPU, the supported data types, operator support, driver maturity, and runtime integration can vary a lot. NPU fragmentation is a real deployment issue: a model that performs well on one chip may require a different backend or a fallback-heavy path on another.
Cloudflare Workers and WebAssembly are also sometimes grouped under "edge," but they solve a different problem from on-device inference. A worker runs code closer to users in a distributed server setup. An on-device runtime runs on the user's own CPU, GPU, or NPU. Both can reduce distance to a user or service, but only the second option lets you run inference without relying on a server connection.
Static model graphs are not agent workflows
A model inference graph describes model-level operations - things like normalization and attention. An agent graph describes application-level steps - selecting tools, calling a model, and deciding what to do next. A static model graph is often easier to optimize for a specific device, while a more flexible agent workflow can adapt to new situations but is harder to constrain. They sit at different layers, so swapping one doesn't automatically replace the other.
What happens inside an LLM inference request?
Inference performance is why a model can feel slow even when the parameter count sounds reasonable. A typical text request starts with tokenization: the input text becomes token IDs the model can process. Then the model runs a prefill pass over the prompt before generating output tokens one at a time.
Prefill, generation, and the KV cache
During prefill, the model processes the input sequence and computes intermediate values used by later attention operations. During generation, it predicts the next token, appends it to the sequence, and repeats. That "generate one token at a time" loop is a big reason output latency behaves differently from how quickly it can process a prompt in a single pass.
The key-value (KV) cache stores attention information from earlier tokens so the model doesn't have to recompute the entire history for every new token. That improves generation efficiency, but it costs memory. Longer prompts and longer conversations increase memory pressure - even if the model weights themselves fit on the device.
An inference graph can include operations like RMS normalization and self-attention. These aren't just abstract labels: their implementation and supported precision affect how much work the processor does and whether the operation can use a particular delegate. A graph walkthrough (like the CodingCat.dev episode featuring Alex Patterson and Shivay Lamba) makes it easier to connect model operations to real deployment constraints.
Measure the whole request
A good performance test breaks time and resources into clear stages:
- Time to load the model and set up the runtime.
- Time to process the prompt (tokenization + prefill).
- Time to generate each output token.
- Peak memory use (weights + KV cache).
- Power and temperature during sustained use.
A model that feels fast on a short prompt may slow down with a long context. A demo may also miss thermal throttling that shows up after repeated runs. Test realistic inputs and session lengths on devices that match your target - not just one quick prompt on a developer workstation.
Task boundaries matter here too. A local model might be great at classification, summarizing a short note, or explaining code already available on the device, while a cloud model handles open-ended requests. The product should route requests based on needed capability, not treat every prompt like it's the same job.
How do quantization and model size change the trade-off?
Quantization changes the precision used for model weights and computations. Lower precision can cut memory use and speed up execution on hardware that supports the chosen format. It can also reduce output quality. The catch is that results vary based on the specific model, quantization method, runtime, and task - so labels like INT4 don't tell you whether the deployment will meet your bar.
Understand the precision choices
FP32 uses 32-bit floating-point values and is often a baseline, but it can require more memory and compute than many edge devices can handle. Common lower-precision options include INT8 and INT4. Mixed approaches like W8A16 use 8-bit weights and 16-bit activations, and W8A8 uses 8-bit weights and activations. Ultra-low-bit methods (including 1-bit quantization) can shrink storage further, but they aren't a free ticket to equivalent quality or broad hardware support.
The real question isn't "which format is smallest." It's which combination of model, precision, runtime, and device hits your application's quality and performance targets.
PTQ and QAT solve different problems
Post-training quantization (PTQ) applies quantization after training. It's often the first experiment because it avoids retraining. Depending on the model and method, the quality change might be acceptable - or it might hurt exactly the cases you care about.
Quantization-aware training (QAT) includes quantization effects during training or fine-tuning. It can preserve quality when PTQ isn't enough, but it takes more training work and requires a suitable pipeline. If you're using a third-party model, QAT might not even be an option.
A sensible evaluation loop is to keep a fixed set of representative prompts and expected outcomes, then compare candidate formats to a baseline. Measure task success and failure modes along with latency and memory. If the model explains code, for example, check whether the explanations stay accurate and useful - not only whether generation gets faster.
Avoid optimizing a number in isolation
Quantization can make a model fit where it didn't before. But a "barely fits" model can still leave too little room for the KV cache, your application, and the operating system. And faster token generation won't fix a model that struggles with prompt processing or repeatedly fails the task.
Use the least aggressive quantization that meets your device and quality targets. Move lower only when measurement shows a real win and evaluation confirms outputs remain acceptable. TorchAO is one toolkit in the PyTorch ecosystem for working with lower-precision formats, but you still need to validate against your target runtime and hardware.
How do you choose and ship an edge AI architecture?
The most reliable way to choose an architecture is to start from user requirements and work toward hardware - not start from a device demo and hope it becomes a product later. A local 4B model may fit a constrained task, but parameter count alone doesn't settle memory needs, quality expectations, or operator support. Bigger local models, like 12B, generally demand more resources and often require devices with enough memory and compute headroom.
Use a decision sequence
- Define the task and failure cost. What does "correct" mean, what does an unacceptable error look like, and do you require human review?
- Set product constraints. Decide acceptable latency, offline behavior, data handling, and which devices you must support.
- Test the smallest plausible model. Run it on real inputs. Move up (bigger local or cloud) only if it misses the quality target.
- Choose a runtime and backend. Check operator coverage, device support, export requirements, and fallback behavior for your actual model.
- Profile sustained use. Measure prompt processing, generation, memory, battery, and thermal performance on real target devices.
- Plan a failure path. Decide what happens when the model is unavailable, too slow, uncertain, or unable to handle a request.
This sequence helps you avoid a common time sink: picking hardware or a runtime first, then discovering the model doesn't fit the supported operator set or the quality budget.
Hybrid inference is often the practical answer
A hybrid design can send routine or privacy-sensitive tasks to a local model while routing harder requests to a cloud model. A small router or explicit state machine can choose the path based on task type, confidence, connectivity, or user settings. Keep that logic observable and testable. Hidden routing rules are hard to debug when users see inconsistent results.
For instance, a local model can classify requests, summarize a short document, or explain code already present on a laptop. The cloud model can handle requests that need broader context or stronger reasoning. In offline mode, the app can still offer a limited set of features instead of silently failing when the network disappears.
Hybrid systems add their own costs. You maintain multiple models or providers, routing logic, evaluation sets, and possibly different privacy disclosures. Cloud fallback can also undercut a "local-first" promise unless you clearly explain when data leaves the device. Make the boundary explicit in behavior and documentation.
Pilot with a real workload
A local workstation with a capable GPU - like an RTX-class PC or a Mac Studio - can be useful for evaluating 4B-to-12B models, running LLM-as-a-judge experiments, explaining local code, or transcribing audio with a model such as Whisper. Those workflows can help, but workstation results don't predict phone performance. Your target device, runtime, and thermal envelope still drive the real outcome.
Before broad release, test on a small but representative device matrix. Track quality regressions, crashes, memory failures, and fallback rates after model or runtime updates. If your team can't support that matrix, it's usually better to narrow the device list than to claim universal on-device compatibility.
Key takeaways: Move inference to the edge when it solves a measurable product constraint. Validate the complete runtime and hardware path, not just model compatibility. Measure quality, latency, memory, and power together. Use hybrid routing when local and cloud models cover different parts of the workload.
Conclusion
Edge AI works when the model, runtime, device, and user needs all line up. A smaller local model can improve offline availability, reduce network dependence, and keep some data on-device - but it also brings hardware variation, memory limits, evaluation effort, and ongoing maintenance.
Start with the constraint you're trying to solve, measure against a realistic workload, and keep cloud inference available when it clearly adds value. Often the right architecture isn't "cloud vs edge." It's the boundary you draw between the two.