Search the guide

Start with a guide

Learn

Prompting versus Compilation for Repeated Tasks

Run the same email-urgency policy through a prompted model and a saved neural function.

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.

Email urgency test cases1 / 5
Please approve the submission by 5 p.m. today so we can meet the deadline.
Expected labelURGENT

The function reads the meaning of the request, including whether action is still needed.

Try the function in ProgramAsWeights

Download 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?#

PROMPT FOR EACH INPUT
InputSpecification + emailThe full instruction accompanies each email.
Base modelQwen3-0.6BUnadapted model, non-thinking mode.
OutputURGENT or ROUTINE
COMPILE ONCE WITH PAW
InputFunction specificationDescribe the behavior in words.
CompilerGenerate the programReadable task text + LoRA adapter
SaveReusable neural programKeep its ID and program artifact.
RUN ON NEW INPUTS
InputA new email
Interpreter + programExecute the function
OutputURGENT or ROUTINE
PAW separates constructing a program from executing it. The same interpreter is shared across programs.
StagePromptingPAW fast compilation
Before the first emailChoose a model and write the instructionCompile the specification, preserve its program ID, download and load its interpreter
For each emailRun the model with the instruction and emailRun the interpreter with the saved task text, adapter and email
Saved between callsInstruction and model configurationProgram identifier or .paw file, and cached runtime assets
Change the policyChange the instructionRevise the specification and compile a new program
Change routing or presentationChange application codeChange 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.

python
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.

python
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#

text
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.

Sources and resources

Read next