Generate & Stream Your First Tokens
Everything so far has been preparation for one function call. The model and tokenizer from model loading and tokenization are live on the GPU; this lesson asks the model to continue text, watches the answer arrive token by token, and times it. It is the loop what inference is could only gesture at, run by you, on hardware you set up. The text outputs on this page are real captures; the throughput figure is a representative run from the box, and your sampled text will differ.
The first generation
That output is real, and the first thing to notice is that it never says " Paris". Three parts of the code carry inference prerequisites forward: return_tensors="pt" makes the tokenizer hand back a tensor rather than a Python list, .to(model.device) honors the same-device rule from Python and PyTorch setup, and the whole call sits inside torch.inference_mode(). Then generate runs the loop: 32 rounds, each consuming the sequence so far and appending one chosen ID, exactly the shape what inference is described. The first chosen token is a, ID 264.
The output is the base-model personality the model download lesson chose on purpose, showing itself immediately. The model continued a document that plausibly begins with that phrase, and " a city of many faces" outranks " Paris" as such a continuation. The famous answer sits second; the lesson on understanding one token will show the full ranked distribution behind this exact choice. And it stopped for no deeper reason than the budget: generation ends at max_new_tokens or at the model's end-of-text token, ID 128001, whichever comes first. A base model mid-ramble rarely emits the latter, so the budget is doing the stopping here.
Determinism and the draw
do_sample=False takes the heaviest token every round, the first policy from sampling and statistics: run it again and the same 32 tokens come back. Flip to sampling and pin the seed, and the whole section from sampling and statistics plays out on real hardware:
Run it without the seed and each execution drifts differently; rerun it with torch.manual_seed(7) and the drift repeats draw for draw. One honesty note about this card: the checkpoint ships default sampling settings in the small generation_config.json from the model download lesson, and generate picks them up silently, so this draw is already gently reshaped before the dice roll. What those settings do, and their names, is covered in understanding one token; here a pinned seed and the two selection policies cover everything this page does.
Streaming
Waiting for all 32 tokens and printing at the end hides the loop. Streaming shows it:
Run this and the continuation types itself into your terminal a piece at a time. That steady rhythm is the most instructive thing on this page: each fragment appearing is roughly one full trip through all 8 billion weights, the per-token cost from memory and throughput arithmetic playing out at watchable speed. Every chat product you have used streams for the same reason; the first token can arrive quickly while the rest are still being earned, one round each.
Timing honestly
Curiosity about that rhythm has a number:
Two honesty rules travel with that number. It is one run, and the lesson on sampling and statistics taught what one run is worth. The very first generate after a load runs slower than the calls that follow, so time from the second call onward; measuring properly is covered in inference benchmarking. And notice how far 39 sits below the roughly 200 per second that napkin from memory and throughput arithmetic allowed this GPU. The plain loading-and-generating stack you built is nowhere near the hardware's ceiling, and closing that gap, without giving up correctness or money, is more or less the rest of the course.
The model generates, streams, and can be timed. What generation does to the machine, memory, utilization, power, is sitting one nvidia-smi away, in the next lesson.