The policy stays fixed while the emails change. Prompting puts that policy into the selected model’s context. Compilation produces a reusable program before the stream of emails arrives. Both routes execute a neural model for each email.
Use one policy and the same five emails#
Classify whether an email needs prompt action from its recipient. Return URGENT for an imminent deadline or immediate blocker, and ROUTINE for newsletters, completed work and FYI updates. The five cases below specify the intended labels.
Please approve the submission by 5 p.m. today so we can meet the deadline.
The function reads the meaning of the request, including whether action is still needed.
Try the function in ProgramAsWeightsDownload the comparison and tutorial script. Its output includes the expected label, actual returned text, validity check and elapsed call time.
What happens once, and what repeats?#
| Stage | Prompting | PAW fast compilation |
|---|---|---|
| Before the first email | Choose a model and write the instruction | Compile the specification, preserve its program ID, download and load its interpreter |
| For each email | Run the model with the instruction and email | Run the interpreter with the saved task text, adapter and email |
| Saved between calls | Instruction and model configuration | Program identifier or .paw file, and cached runtime assets |
| Change the policy | Change the instruction | Revise the specification and compile a new program |
| Change routing or presentation | Change application code | Change application code |
The prompted implementation#
This example prompts the unadapted Qwen3-0.6B Q6_K interpreter locally, with no LoRA adapter. It uses the identical base-model file as the compiled Standard program. The first load downloads the base-model assets. Each subsequent call supplies the instruction and email.
import programasweights as paw
spec = "Classify whether this email needs prompt action from its recipient. Return exactly URGENT or ROUTINE. An imminent deadline or an immediate blocker is URGENT. Newsletters, completed work, and FYI updates are ROUTINE."
email = "The release is waiting on your approval. Please unblock it now."
with paw.function(None, interpreter="Qwen/Qwen3-0.6B") as model:
print(model(spec + "\n\nEmail:\n" + email + "\n\nLabel:"))Run all five cases with python paw_email_urgency.py prompt.
The compiled implementation#
Compile once and preserve the program identifier. Load the saved program when the application starts, then reuse the callable for new emails. The compiler is not invoked by these later function calls.
import programasweights as paw
spec = "Classify whether this email needs prompt action from its recipient. Return exactly URGENT or ROUTINE. An imminent deadline or an immediate blocker is URGENT. Newsletters, completed work, and FYI updates are ROUTINE."
program = paw.compile(spec, compiler="paw-4b-qwen3-0.6b")
print(program.id)
print(program.compiler_snapshot)
with paw.function(program.id) as urgency:
print(urgency("The release is waiting on your approval. Please unblock it now."))The full tutorial saves this identifier, reloads it in a fresh session, downloads the program file and prepares offline execution. The generated program includes text as well as LoRA weights; the interpreter receives both when it handles an email.
Why separate construction from execution?#
A repeated task has two sources of work: defining the function and applying it. PAW moves the trained compiler’s work to function construction. The saved program then uses the smaller interpreter at every call. This is useful when a fixed function is reused across inputs, sessions or machines.
Prompt-prefix caching saves intermediate state for repeated instruction text. A PAW program saves generated LoRA weights and task text; later calls load that program and pass in a new input.
Local versus hosted execution is another decision. The examples here use local inference for both routes; the PAW compilation request is hosted. The local compiler supplies a separate construction path for a machine with a supported GPU.
Measure the entire workload#
Prompted workload = initial setup + sum(prompted call times)
Compiled workload = compilation + downloads + loading + sum(compiled call times)Measure compilation, cold loading and warm calls separately. Record the actual labels and total time for the same batch.
- Save the specification, expected labels, actual outputs and compiler/model version.
- Record hardware, input lengths, output lengths, generation settings and the number of calls.
- Separate first downloads from a run whose assets are already cached.
- Record whether prompt-prefix caching is enabled and whether requests are local or remote.
Use python paw_email_urgency.py run urgency-program.json and python paw_email_urgency.py prompt to collect the two sets of actual outputs. The script records loading and call durations; construction time is recorded in the saved compilation metadata.