Cookbook

More than fifty complete inferlets you can run, read, and copy.

Every recipe below is a complete inferlet in the Pie repository. Clone the repository to run any recipe by name, or copy its source as a starting point for your own inferlet:

git clone https://github.com/pie-project/pie && cd pie/examples
pie run top-a-sampling-py -- --prompt "Once upon a time" --a 0.2

The colored dot marks which layer of the stack the recipe uses: ● uses the Program layer, and ● uses Invent primitives such as multi-lane passes, custom attention masks, or device loops. The language tags link to each implementation on GitHub.

Basics

quickstart

Greedy completion, one pass per token, driven from the host.

text-completion

Greedy completion with the decode loop carried on the device.

chat-completion

A chat reply with temperature and top-p, streamed.

naive-baseline

Plain sampling, the performance control for the other recipes.

Sampling

top-a-sampling

Keep tokens above a · p_max², a floor that tracks confidence.

xtc-sampling

Exclude top choices, for more varied text.

tail-free-sampling

Cut the tail where the sorted probabilities flatten.

locally-typical-sampling

Keep tokens close to the expected surprise.

mirostat-v2-sampling

Steer the surprise of the output toward a target.

eta-epsilon-sampling

Epsilon and eta truncation.

entropy-adaptive-temperature

Raise or lower the temperature with the entropy.

repetition-penalty

Frequency, presence and repetition penalties.

dry-repetition-penalty

Penalize tokens that would extend a repeated sequence.

Guidance

classifier-free-guidance

Two lanes per pass: with and without the prompt.

contrastive-decoding

Contrastive decoding with a single model.

context-aware-decoding

Trust the given context over the model’s prior.

Search and branching

beam-search

Beam search on the device, with ancestry masks.

consensus-decoding

Generate N answers from one prefix and pick the most central.

prefix-tree-kv-cache

A tree of prompts sharing their common prefixes.

Speculative decoding

mtp-speculative-decoding

Draft from the model’s own MTP head; verify and commit on the device.

cacheback-speculative-decoding

Prompt-lookup drafts from earlier in the context.

constrained-speculative-decoding

Speculation under a JSON Schema.

dflash-speculative-bench

A block drafter’s draft-then-verify loop.

KV cache

attention-sink

Attention sinks plus a sliding window.

snapkv-eviction

Use the prompt’s attention to shrink the cache.

tova-attention

Drop the entry attended to least.

trackb-h2o

Keep the heavy hitters.

trackb-snapkv

SnapKV from an observation window.

Constrained output

json-schema-constrained-decoding

JSON that always matches a schema.

asap-grammar-aligned-decoding

Grammar-constrained sampling without the distribution bias.

token-healing

Repair prompts that end mid-token.

Watermarking

greenlist-watermarking

Bias a keyed greenlist of tokens.

gumbel-watermark

A distortion-free watermark (Aaronson).

synthid-tournament-sampling

SynthID-Text tournament sampling.

Images, video and diffusion

text-to-media

Text to image or video with any diffusion model.

image-captioning

Describe an image.

diffusion-baseline

A text diffusion model’s reference sampler.