Context-Aware Precision Scheduling for Small Language Models
Organizations: Advanced Micro Devices Inc. (AMD) · Cornell University
Abstract
Small language models (SLMs) used as on-device agents must balance accuracy and latency as their context grows. Mixed precision helps manage this tradeoff by assigning different precisions to weight tensors according to their size and sensitivity. However, these choices depend on the operating conditions, so a configuration selected for a short context may no longer provide the best tradeoff at a longer one. We calibrate a timing model from measurements at different precisions and context lengths, and combine it with tensor sensitivities to choose configurations under a latency or accuracy budget. We argue that fewer bits do not always mean faster execution, so our predictor estimates latency from calibrated execution costs rather than weight bytes alone. Under a latency budget, reading the larger key-value (KV) cache leaves less time for weight operations, leading the allocator to select lower precisions. This gives a schedule of tensor changes that can be prepared before execution. Our runtime follows the schedule while retaining the session's KV cache. We evaluate executed schedules on a laptop GPU, including a longer-context schedule with three weight formats and a tool-use benchmark measuring full response time and correctness. Under an accuracy budget, measured error from a quantized KV cache determines the budget left for weights. The allocator can raise or lower weight precision as this estimate changes. These experiments show where context-aware precision helps and where accuracy recovery remains limited.
Figures & tables
Appendix figures & tables20 assets
Supplementary material from the paper’s appendix.
Appendix
| Quantity | Term | Value |
|---|---|---|
| Reference intercept (ms) | 46.94 | |
| Context growth (ms per 1024 tokens) | 1.738 | |
| Attention change at Q8 (ms) | ||
| Feed-forward change at Q8 (ms) | ||
| Output change at Q8 (ms) | ||
| Total reserve, including switching (ms) | 4.06 |
| Tensors changed | Median switch | First token: initial | First token: later |
|---|---|---|---|
| 27 | 1.68 | 36.58 | 22.50 |
| 44 | 1.60 | 23.15 | 22.19 |
| Group | Q6 | Q4 |
| Attention | ||
| Feed-forward | ||
| Embedding/output | ||
| Reference intercept (ms) | 41.474 | |
| Context growth (ms per 1024 tokens) | 3.045 | |
| Prediction-error allowance (ms) | 4.384 | |
| Policy | Mean | P99 | Joint KL | Perplexity | Within target (%) |
|---|---|---|---|---|---|
| Cost schedule | 58.12 | 72.86 | 0.00574 | 10.398 | 99.7 |
| Byte-aware | 53.81 | 76.35 | 0.00662 | 10.447 | 99.0 |
| Fixed final mix | 45.32 | 70.66 | 0.03785 | 10.946 | 100.0 |
| Fixed Q8 | 62.16 | 85.18 | 0.00000 | 10.365 | 83.1 |
| Fixed Q6 | 55.58 | 82.56 | 0.00753 | 10.436 | 90.9 |
| Fixed Q4 | 39.49 | 64.50 | 0.09345 | 11.814 | 100.0 |
| Policy | Correct turns | Median response (s) | Tokens within 85 ms (%) |
|---|---|---|---|
| Cost schedule | 13/19 | 6.74 | 99.2 |
| Byte-aware | 13/19 | 6.86 | 99.4 |
| Fixed Q8 | 13/19 | 7.52 | 59.8 |
| Fixed Q4 | 12/19 | 4.74 | 100.0 |
| Quantity | Value |
| Reference intercept (ms) | 78.036 |
| Context growth (ms per 1024 tokens) | 2.751 |
| Layers 1–6: time change (ms) | |
| Layers 7–12: time change (ms) | |
| Layers 13–18: time change (ms) | |
| Layers 19–24: time change (ms) |
| Decode target (ms) | Policy | P95 response (s) | Tokens within target (%) |
|---|---|---|---|
| 95 | Cost schedule | 44.40 | 99.96 |
| 95 | Byte-aware | 26.20 | 99.37 |
| 95 | Fixed Q8 | 28.17 | 99.84 |
| 95 | Fixed Q4 | 24.16 | 100.00 |
| 85 | Cost schedule | 26.21 | 99.20 |
| 85 | Byte-aware | 26.08 | 99.44 |
| Context | Cache KL | Weight KL budget | Q8 (%) | Q6 (%) | Q4 (%) |
|---|---|---|---|---|---|
| 512 | 0.0325 | 0.0175 | 1.4 | 35.6 | 63.0 |
| 2048 | 0.0308 | 0.0192 | 1.0 | 29.1 | 69.9 |
| 4096 | 0.0755 | -0.0255 | 100.0 | 0.0 | 0.0 |
| 8192 | 0.1355 | -0.0855 | 100.0 | 0.0 | 0.0 |
| 12288 | 0.0366 | 0.0134 | 3.0 | 49.4 | 47.6 |
| 16384 | 0.0361 | 0.0139 | 3.0 | 46.5 | 50.5 |
| Group | Q6 | Q4 |
|---|---|---|
| Attention weights | ||
| Feed-forward weights | ||
| Embedding/output |
| Policy | Mean ms | Joint KL | Perplexity | Within budget |
|---|---|---|---|---|
| Cost schedule | 35.10 | 0.0923 | 12.958 | 3/12 |
| Byte-aware | 33.59 | 0.0947 | 13.297 | 2/12 |
| Fixed initial mix | 28.74 | 0.1065 | 12.896 | 1/12 |
| Q8, Q4 cache | 44.45 | 0.0404 | 12.025 | 9/12 |
| Q8, F16 cache | – | 0.0000 | 11.199 | 12/12 |
| Process | Phase | Context | Attention | FFN | Output | |
|---|---|---|---|---|---|---|
| 1 | prefill | 512 | 476.455 | 47.044 | 556.637 | -2.066 |
| 1 | prefill | 2048 | 2211.277 | 110.744 | 2176.390 | 65.986 |
| 1 | decode | 512 | 31.444 | 4.679 | 6.572 | -2.569 |
| 1 | decode | 2048 | 33.461 | 1.620 | 6.536 | 1.109 |
| 2 | prefill | 512 | 447.866 | 39.177 | 593.509 | -15.915 |
| 2 | prefill | 2048 | 2124.196 | 92.931 | 2237.679 | 120.492 |
| Phase | Calibrated costs | Byte estimate | Constant estimate |
|---|---|---|---|
| Prefill | 3.51 | 5.92 | 17.62 |
| Decode | 2.71 | 2.24 | 5.16 |
Efficient Language Model Inference
Efficient language model inference reduces the compute, memory, latency, and energy needed to generate useful outputs.
See all 314 papers