Build a Loop That Stops
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.
Authored explanation · fixed examples, not a live experiment.
Validated 1–16 input IDs
→Score → select → append, at most 16 times
→Stop on EOS or limit; keep reason
What guarantees that generation stops? Name the evidence for your answer.
By the end of this lesson
Implement a generation loop with distinct EOS, length and invalid-input behavior.
Inside the lesson
- Trace bounded generation
- Predict the zero-limit case
- Implement and test stopping
- Explain a failed boundary test
- Handle a model without EOS
- Keep runtime bounds
The reproducibility tasks require running the supplied Python starter. Setup instructions and examples are included.