21/29
Part 5 of 6 · The whole samplerLearn and do

Seeding: the same draws every run

Random draws make tests flaky unless you control the randomness.

g = torch.Generator().manual_seed(0)
print(sample(row.repeat(8, 1), generator=g))
print(sample(row.repeat(8, 1), generator=g))
g = torch.Generator().manual_seed(0)
print(sample(row.repeat(8, 1), generator=g))
Predict

Seed a generator with 0 and draw 8 tokens, twice. Then seed a fresh one with 0 and draw once more. Which lines match?

Pick one to see what it prints.
Pick an answer above to see the rest