# Keep On-Device LLMs Alive on Real Phones: Lesson 03. Plan for heat: burst vs sustained

Lesson id: `on-device-llm-survival/03-thermal-sustained-vs-burst`
Human lesson: https://edgefde.dev/courses/on-device-llm-survival/03-thermal-sustained-vs-burst.html

## Goal

Map device thermal state to a generation policy on iOS and Android, and log it for every answer.

## Prerequisites

- Lesson 02 model owner
- A real device for a 20 minute test

## Inputs

- Your speed log from a sustained test

## Outputs and artifacts

- `ThermalWatcher` (Swift)
- `ThermalPolicy` (Kotlin)
- Policy table in the feature spec

## Steps

1. Run 20 minutes of back-to-back answers. Log tokens per second and thermal state each answer.
2. On iOS, write `policy(for:)` for `.nominal`, `.fair`, `.serious`, `.critical`, plus `@unknown default`.
3. Observe `ProcessInfo.thermalStateDidChangeNotification` and publish the new policy.
4. On Android, read `PowerManager.getThermalHeadroom(10)` no more than every 10 seconds and map it to a policy. Treat `NaN` as unsupported.
5. Apply the policy: max output tokens, small-model preference, and background job switch.
6. Show a short line in the UI when sustained mode is on.

## Constraints

- Do not call getThermalHeadroom more often than every 10 seconds.
- Policy numbers must come from your own test, not this lesson's examples.

## Acceptance checks

- Logs show the thermal state with each answer.
- On a warm device the max output tokens drop and background jobs stop.
- The UI shows the sustained mode line.

## Key concepts

- Heat lowers clock speed over minutes. A short benchmark hides it.
- iOS gives four thermal states and a change notification.
- Android gives a 0.0 to 1.0 headroom value. Read it at most once every 10 seconds.
- A policy maps heat to output length, model size, and background work.

## Takeaways

- Run a 20 minute sustained test and log speed and thermal state per answer.
- Switch to a sustained mode on purpose and tell the user why answers are shorter.
- Stop background AI jobs first when the device gets hot.
