Hybrid Edge-Cloud Inference › Routing: deciding where a request runs
Language AI HandbookAll chapters For whole-request routing, estimate whether the edge answer will meet the task’s quality requirement and whether the cloud improvement is worth the extra cost when transfer is allowed. A classifier can estimate edge success. You can also estimate the expected quality difference directly. Track the errors of both approaches alongside their costs on the traffic where they will run.
What signal should drive the decision
The router observes cheap, available-at-request-time features and outputs a decision. Candidate signals fall into a few families:
- Prompt-intrinsic features: length in tokens, language, presence of code or math, task-type keywords ("translate", "summarize", "prove"), readability, estimated difficulty. Cheap and privacy-preserving (computed on device). Computing these features locally requires no generation call. Measure their cost with your tokenizer and deployed request sizes.
- Edge-model confidence: an available proxy such as mean token log probability over a short local candidate, or self-reported uncertainty. Measure how it relates to task correctness and account for any local generation the score requires.
- Device and network context: battery level, thermal state, connection type (Wi-Fi vs. cellular), measured round-trip time, data-cap status. Cheap and directly actionable. These do not say anything about the request itself, but they determine the cost of the cloud path, which is half of the routing inequality.
- Learned difficulty score: a small classifier trained on (request, did-edge-succeed?) labels, where "succeed" is a judged label or a reward-model score. This requires a labeling pipeline. Compare it with inexpensive baselines on held-out traffic before committing to retraining as the model or traffic changes.
- User or policy priors: user opted into cloud for certain apps, enterprise policy forbids cloud for this document, jurisdiction rules. These are hard constraints, not soft signals. They are not evidence about difficulty at all; they are constraints on feasibility, and they override every other signal.
A router can combine a learned score with a hard transfer policy.
The hard constraints override everything: if policy says "this document may not leave the device," no score sends it to the cloud. The score only governs the discretionary middle. This two-layer structure, a hard gate followed by a soft classifier, is what lets the same codebase serve both a privacy-strict enterprise deployment and a user who has explicitly opted into cloud processing, without maintaining two divergent routing implementations.
The routing math
Let be the request and a predicted difficulty. Let and be expected quality of each path (say, a reward-model score or task success probability). Let and be expected cost (latency, dollars, battery). A reasonable routing rule is to send to cloud when the value of the quality gain exceeds the extra cost. The indicator returns 1 (route to cloud) when that inequality holds and 0 otherwise:
where:
- : the incoming request
- : the expected quality gain from serving on the cloud rather than the edge
- : the extra expected cost (latency, dollars, battery) of the cloud path
- : indicator function, equal to 1 when the condition holds (route to cloud) and 0 otherwise
- : a scalar that trades quality against cost, set by product policy (e.g., "one extra point of quality is worth one extra dollar" or, more commonly, "we will tolerate 300 ms extra for ≥5% quality gain")
The quality multiplier assigns a value to each unit of expected quality. When the cloud offers a positive quality gain and the cost and eligibility stay fixed, increasing the multiplier can only increase or preserve the set of requests selected for the cloud. The inequality has a natural interpretation as a marginal analysis. The left side is the benefit of the cloud, measured in quality units and converted to some common currency by . The right side is the extra cost in that same currency. Route to the cloud when the benefit exceeds the cost, and only then. A length or confidence cutoff can approximate this rule when that feature predicts the marginal value of the cloud path. Compare its measured weighted loss with the baseline routes.
In practice and are unknown at request time, so we proxy them. A common practical proxy is to train a router that predicts the quality gap directly by regressing on labeled comparisons, and threshold it with a latency-aware margin.
For a latency-only objective, express in milliseconds. If price or energy can alter the decision, compare the dimensions separately or choose weights to express them in a common cost unit.
Measure calibration, ranking, and routing costs
Overall routing accuracy gives each error the same weight. The costs can differ:
- Serving a hard request on edge can lower answer quality.
- Sending an easy request to the cloud can incur extra serving cost without improving the answer.
If quality loss is far more expensive than cost loss, bias toward the cloud; if cost and privacy dominate, bias toward the edge. The threshold in the rule above is how you express this, and both error types must be measured on held-out data, never just overall accuracy. Say 10 of 100 eligible requests are hard. A 90% accurate router misses all 10 hard requests. An 80% accurate router misses 2 hard requests and sends 18 easy requests to the cloud. If a hard miss costs and an unnecessary cloud trip costs , the two losses are and . The 90% router loses more when .
If the router estimates a probability, check whether requests scored near a value have the corresponding observed event rate. Check ranking separately. The cloud fraction at a threshold depends on the score distribution and its ties. Ten requests can all have score 0.7 with seven positive labels. This group is calibrated at the observed score, yet a strict threshold crossing 0.7 switches all ten decisions at once.
The deeper trap is that the errors the router cares about are unlabeled in production. When an easy request is needlessly routed to the cloud, nobody complains, because the answer was fine. When a hard request is routed to the edge and answered poorly, the user may simply abandon the app rather than report a bad answer. Both error types are silent, which means the router's offline measurements are the primary evidence you have, and they must be constructed with care: deliberate labels, deliberate slices, deliberate cost weights that reflect the product's actual priorities.
The curve of achieved quality versus fraction of requests routed to the cloud (or versus average latency/cost), traced by sweeping the routing threshold. It is the routing analog of a precision-recall curve and is the right way to choose the operating point.
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!