During generation, the model receives a prefix, produces scores for its next token, selects one token, appends it, and repeats. Unlike training, the later continuation is not available as input before it has been generated. A context limit may require a defined truncation policy or termination.
Greedy selection chooses the largest probability. Sampling draws from the distribution, so repeated outputs can differ. For probabilities [0.6,0.3,0.1], greedy always chooses the first entry under the stated ordering, while sampling can choose any entry with nonzero probability. Temperature divides scores before normalization. For scores [2,0], temperature two gives [1,0], making probabilities about [0.731,0.269] instead of [0.881,0.119] at temperature one. The flatter distribution gives the alternative more chance without adding factual evidence.
Set a maximum number of generated tokens and a stop condition. An end marker is useful only if the model and tokenizer define it. A tiny randomly initialized decoder can execute all generation steps and still produce nonsense. A runnable loop is evidence about implementation, while useful language requires training and evaluation.