To the best of my knowledge, a combination of special flags and fine tuning is used to let models "know" when to stop generating output:
Basically during pre-training/fine-tuning, for every sequence you'd like your model to generate (for example a multi-turn chat instruct model like chatGPT), you have a flag at the end of the expected output (like end of string, <|something like this|>, or some random hash to prevent users from doing weird "sql-injection style" prompt hacking (ex: https://twitter.com/nostalgebraist/status/168657604180309606...)
Then, during inference, if the model generates the special flag, it terminates the function and the string is returned.
Comments
To the best of my knowledge, a combination of special flags and fine tuning is used to let models "know" when to stop generating output:
Basically during pre-training/fine-tuning, for every sequence you'd like your model to generate (for example a multi-turn chat instruct model like chatGPT), you have a flag at the end of the expected output (like end of string, <|something like this|>, or some random hash to prevent users from doing weird "sql-injection style" prompt hacking (ex: https://twitter.com/nostalgebraist/status/168657604180309606...)
Then, during inference, if the model generates the special flag, it terminates the function and the string is returned.
Also on your note about multiple passes a second, it's absolutely wild how much compute modern computers have. My 3090 goes on full blast during inference on 13B llama models. To think that GPT 3.5 is 10 times the size of that https://en.wikipedia.org/wiki/GPT-3, and that GPT 4 is 10 times the size of THAT https://www.semianalysis.com/p/gpt-4-architecture-infrastruc...