Trace bounded generation
Optional arithmetic and percentage refresher — return to this activity
The loop takes token IDs, calculates scores, selects one token and appends it. EOS means end of sequence: a special selected token signals stopping. A length limit prevents unbounded work even when EOS is never selected. These are different stopping reasons.
Instrumented generator: local teaching model contract
All people, records and numbers in this pack are authored teaching examples. They are not records or performance claims about real organizations.
- G1 · The downloadable Python generator uses four token IDs and fixed authored two-number embeddings with causal attention. It is untrained and is not a pretrained language model. It demonstrates execution and cache equivalence, not text quality.
- G2 · Input is 1–16 token IDs; output limit is 0–16 tokens. EOS is token 3. Greedy selection chooses the lowest ID on a tie. Reaching a limit and emitting EOS are reported separately.
- G3 · The clock starts after imports. Validation/token preparation, prefill, first-token selection, decode steps and total generation are timed with a monotonic high-resolution clock. Report serialization and disk writing are outside total generation. Loading/import/terminal display are not measured.
- G4 · Cached attention retains projected keys and values for exactly the prior token prefix. Changed prefixes require a fresh cache or rejection. Every step’s scores, not just chosen IDs, must agree with uncached execution within 1e-12.
- G5 · Timing varies by machine and run. Compare the same prompt, output limit and stopping behavior, repeat runs, report all outcomes and the measurement boundary. Projection and attention-term counts are not milliseconds.
A limit guards every model call
- Start with a copy of the prompt and zero output tokens.
- Before calling the scorer: stop if cancelled or if the output count has reached the limit.
- Check that all four scores are finite numbers. Select the largest; ties use the lowest token ID.
- Append the selected ID. If it is 3 (EOS), stop. Otherwise return to the guard.
Example: with limit 2 and successive choices 1, 0, the accepted output is [1, 0], reason “limit”. There is no third call. If the first choice is 3, the output is [3], reason “eos”. These are authored traces, not a live scorer.
Worked example
With output limit two, at most two tokens can be appended. With limit zero, no prefill or token selection is necessary in this implementation. If the first selected token is EOS, the trace contains that one token and stops with reason eos.
Check the boundary
A finite cap bounds runtime work; it does not certify output correctness. The supplied model is untrained. Keep the learner implementation separate from the reference and disclose help used.