AlgoViz

On-device and hybrid inference

medium 6 min

Device inference brings weights and computation close to personal data, but memory, battery, thermals and model availability vary by device.

Video lesson · Chapter 1 of 4

The note that must stay on the train

0:00 / 3:20

Theory

Read or listen first. About 2 min.

What it is

Device inference brings weights and computation close to personal data, but memory, battery, thermals and model availability vary by device. Hybrid applications choose among local inference, permitted cloud execution and a reduced-function offline path. Define which fields may leave the device before routing; a user’s private input cannot become cloud-eligible simply because a local attempt was slow.

Why it exists

Measure cold start, sustained latency after the device warms, peak memory and accuracy for the required languages. Quantization can reduce weights, but context memory and temporary buffers still matter. In a hybrid system the boundary also governs telemetry, retries and cached responses. Provide an intelligible outcome when an eligible model is unavailable.

Summarize a private note while offline

Privacy policy → Model runtime (eligible local input). Model runtime → Fallback controller (capacity result). Privacy policy → Fallback controller (permitted destinations)
Privacy policy → Model runtime (eligible local input). Model runtime → Fallback controller (capacity result). Privacy policy → Fallback controller (permitted destinations)

Inside this chapter

Chapter sources
Device eligibility
Check model availability, supported features, context limit and available resources before execution. Choose a bounded task shape and retain a deterministic fallback for basic product functions.

Phones, tablets and laptops differ in memory, accelerators, operating-system version and whether a model has been downloaded yet. Check each condition before starting rather than discovering failure halfway. Shape tasks to fit: tagging a short note or rewriting a sentence is realistic on device; summarising an hour-long transcript may not be. Keep a non-model path for essential features so the app still works.

Example. A tablet can tag a short note locally but cannot process the full meeting transcript within its context window.

Another example. A notes app tags notes locally with an on-device model. On older devices without the model, it falls back to keyword rules so tags still appear, just less precisely.

Checks before any local run
  1. 1Model available?downloaded and supported
  2. 2Features supported?task, language, format
  3. 3Input fits context?short note yes, transcript no
  4. 4Resources free?memory, battery, thermals
  5. 5Run or fall backdeterministic basic path

A failed check leads to a defined fallback, never to a crash or a silent cloud call.

Local versus cloud policy
Separate technical feasibility from data policy. A cloud model may be faster or more capable while remaining ineligible for one document. Decide whether a redacted fragment can leave the device under the product’s explicit contract.

Two separate questions decide routing. Is the request allowed to leave the device under the product's contract? Can each eligible route technically handle it? Mixing them leads to quiet privacy failures, such as falling back to the cloud when the local model is slow. Encode the data classification with the request so every later component, including retries, can enforce it.

Example. A private journal entry is local-only. If the engine is unavailable, preserve editing and defer summarization.

Policy first, feasibility second

Speed and capability are asked only after the data question is answered.
Profiling beyond first request
Cold start reflects model loading, while repeated generation can reveal thermal or memory pressure. Compare equivalent inputs and report quality as well as latency, energy and failure behavior.

Mobile chips can run fast briefly and then reduce clock speeds as they heat up, and memory pressure from other apps can evict a loaded model. A single benchmark captures the best case. Measure cold start separately, then generate continuously on representative inputs, and record latency, quality, battery drain and any failures over time on a range of real devices.

Example. A phone completes its first summary quickly but slows after the fifth minute of continuous generation. Use sustained measurements for an always-on application.

Sustained test

  • Runs for many minutes of continuous generation
  • Reveals thermal throttling and memory pressure
  • Records energy use and failures alongside latency
  • Matches how an always-on feature is used

First-request test

  • Measures load time and one warm reply
  • Misses slowdown after the device heats up
  • Often run on a plugged-in, cool device
  • Overstates real-world speed
Telemetry and retry boundaries
The data boundary covers more than the main request. Logs, crash reports, analytics events, retries and cached responses must respect the same classification as the input, or private content can leak through side channels.

Teams often get the main path right and leak through the edges: a debug log that includes the prompt, a crash report with the input attached, or a generic retry helper that falls back to a cloud endpoint. Review every path that handles the request, and test by monitoring network traffic while forcing failures.

Example. A local-only journal summary fails. The error report sends an error code and device model, not the journal text, and the retry runs locally again rather than on a cloud endpoint.

What may cross the device boundary

Content never crosses; only aggregate, content-free signals do.
Memory budget on device
On a device, the model shares memory with the operating system and other apps. The working set is the weights plus the KV cache for the chosen context plus temporary buffers, and it must fit with headroom or the system may terminate the app.

Available memory on a phone is not the advertised RAM: the operating system and other apps hold much of it and the amount changes moment to moment. Cap context length for device runs, reuse loaded models across features, and treat a memory warning as a signal to shorten or defer work.

Example. A 4-bit model whose weights fit easily can still fail on a phone when the app requests a long context, because the cache grows with every token.

Fit check before loading

Mweights+MKV(context)+Mbuffers+Mheadroom≤MavailableM_{\text{weights}}+M_{\text{KV}}(\text{context})+M_{\text{buffers}}+M_{\text{headroom}}\le M_{\text{available}}
Quantisation shrinks only the first term.

How it works

Step through the idea, or press Play.

Step 1 of 3

Privacy policy. Classify the note as local-only

Understand it

Worked example

Summarize a private note while offline

  1. 1

    Classify the note as local-only

    The user has chosen offline processing and the note cannot be routed to an external endpoint.

  2. 2

    Check model and memory

    The runtime loads supported weights and checks the requested context against the available budget.

  3. 3

    Preserve the note if the model is absent

    Offer deferred local processing or a shorter user-selected input. Only eligible requests can take a cloud route.

Follow the handoffs

Measure cold start, sustained latency after the device warms, peak memory and accuracy for the required languages. Quantization can reduce weights, but context memory and temporary buffers still matter. In a hybrid system the boundary also governs telemetry, retries and cached responses. Provide an intelligible outcome when an eligible model is unavailable.

The offline note through its states

There is no transition to a cloud state: the note is local-only throughout.

Summary

The whole topic in one minute.

Failure changes feasibility. It does not change the user’s permission for data movement.

Measure cold start, sustained latency after the device warms, peak memory and accuracy for the required languages. Quantization can reduce weights, but context memory and temporary buffers still matter. In a hybrid system the boundary also governs telemetry, retries and cached responses. Provide an intelligible outcome when an eligible model is unavailable.

Sources