Run beam search on a tiny Markov language model: transition_logits[last_token] supplies next-token logits. Start with one empty generated sequence at score 0; use start_token as its previous token. Every step expands each unfinished hypothesis with every vocabulary token. Finished hypotheses are carried forward unchanged and never expanded.
Rank the combined candidates by decreasing summed log probability, then lexicographically increasing generated token sequence. Keep at most beam_width. Stop after max_steps or when all retained hypotheses are finished. Return the best retained hypothesis as {"tokens": generated IDs including EOS if present, "score": summed log probability, "finished": boolean}. No length normalization or preference for finished hypotheses is applied; the start token is excluded.