Hardware-Aware Model Optimization › Co-Design for Phones, Browsers, and Edge
Language AI HandbookAll chapters Choose the architecture, representation, and runtime together. Estimate capacity and traffic first, then use the actual kernels to check which resource is limiting each workload.
Architecture choices that are device-friendly
Architecture choices change both traffic and kernel shapes.
- Grouped-query attention shares one set of keys and values across query heads in a group. At fixed head dimension and context length, reducing the KV-head count reduces the raw KV payload in proportion. The original paper reports its quality comparison for specific trained models. Ainslie et al., GQA
- Layer geometry changes kernel shapes. Test narrower or wider projections with the same evaluation protocol if the architecture is still open to change.
- Operator fusion can keep intermediate values within a kernel. If the runtime implements an activation and its adjacent operations as separate kernels, measure any additional intermediate traffic.
- Tied embeddings share the input and output weights. At vocabulary size 32,000 and width 2,048, this removes one 65,536,000-parameter matrix from the separate-storage budget.
These choices change both model behavior and executed shapes. Evaluate the resulting model on the same tasks before attributing an improvement to hardware co-design.
Thermal and power envelopes
Sustained load may change a device’s available performance as it heats. Record the device state and benchmark over a representative workload duration. Android’s thermal guidance describes monitoring available thermal headroom. Android Thermal API
- Measure both the initial response and sustained generation under a workload that resembles actual use.
- Compare the latency and task quality of the candidate formats after warm-up.
- Where the runtime offers several execution paths, measure elapsed time and energy for each.
Record how rate changes over the intended session, including its warm-up and steady state where present. Repeat the comparison under a comparable starting thermal condition.
The co-design checklist
Work through the model and runtime in this order.
- Pick the target and runtime. Record the hardware, operating system, and runtime version.
- Choose the format the runtime accelerates. Query the runtime's supported operators and fused kernels before deciding bit-width.
- Size the model against caps. Weights + KV cache + runtime buffers must fit the per-app memory limit with headroom.
- Verify the executed kernel. Inspect dispatch or profiling evidence. Low bandwidth alone cannot identify a fallback.
- Benchmark sustained, not burst. Run for the duration a real user would.
- Time the full local path. Include tokenization, prompt processing, decode, and sampling.
A kernel timing starts after some preparation and ends before some output processing. Profile those operations separately when they account for a meaningful share of the requested latency. Keep the denominator explicit. Generated tokens divided by the elapsed decode interval measures a different quantity from generated tokens divided by time for the whole request. If concurrent requests share a batch, report individual response speed and the aggregate rate as separate measurements. The same aggregate figure can hide differences in how quickly each request receives tokens.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!