ByteSampler ("Sampling from Your Language Model One Byte at a Time", arXiv 2506.14123) fixes the prompt boundary problem by working with the Valid Covering Tree: every token sequence that a BPE tokenizer could actually produce and that covers the prompt. Build it for a small BPE tokenizer with no pretokenization.
A tokenizer is a merge list merges of (left, right) pairs of bytes, as produced by BPE training. Its vocabulary is the 256 single bytes plus left + right for every merge, and each merge only uses tokens created before it.
bpe_encode(data, merges)
bytes tokens.is_valid_pair(left, right, merges)
bpe_encode of its bytes gives back exactly . Return True if the two-token sequence [left, right] is valid.is_valid(tokens, merges)
valid_covering_tree(prefix, merges)
prefix is non-empty bytes; raise ValueError if it is empty.bytes) from the vocabulary such that:
prefix is a prefix of the bytes of ;prefix and strictly shorter than it, so only the last token reaches the end and it may run past it;trunk(leaves)
[] for an empty list of leaves).