Skip to content

fix(tests/pytest_random_plugin.py): also seed Python's random#12

Open
yurekami wants to merge 1 commit intodeepseek-ai:mainfrom
yurekami:fix/seed-python-random
Open

fix(tests/pytest_random_plugin.py): also seed Python's random#12
yurekami wants to merge 1 commit intodeepseek-ai:mainfrom
yurekami:fix/seed-python-random

Conversation

@yurekami
Copy link
Copy Markdown

Closes #11.

What

Add random.seed(seed) next to torch.manual_seed(seed) in the autouse
seed fixture so the --seed CLI option reproduces test inputs that
flow through Python's stdlib random.

Why

tile_kernels/testing/generator.py:94 (generate_rand_float) picks the
magnitude exponent with random.randint(-110, 126). The plugin only
seeds torch, so this exponent — and therefore the input scale used by
tests like tests/quant/test_per_block_cast_lossless.py — varies
across runs even when --seed is passed.

Reproduction

The bug is in a pure-Python entropy source, so it reproduces without a
GPU. Mirroring the fixture and generator.py:94:

run 1 exponents: [97, -60, 98, -69, 102, -84, 119, 2]
run 2 exponents: [80, -68, -47, 94,   0,  33, -74, 77]
run 3 exponents: [-69, -29, -106, 39, 87, 97, 19, 92]

Three back-to-back invocations with the same simulated --seed=0 and
the same node id produce three different sequences. With the patch,
both invocations within one process produce identical sequences.

Scope

  • One import + one line. No behavior change for tests that don't touch
    Python's random.
  • Does not touch NumPy — grep -r 'np\.random\|numpy.*random' is
    empty in this repo.

The autouse `seed` fixture seeds torch but not Python's `random`. Tests
that go through `tile_kernels/testing/generator.py:generate_rand_float`
draw the magnitude exponent from `random.randint(-110, 126)`, so the
input scale varies across runs even when --seed is fixed.

Add `random.seed(seed)` so --seed is fully reproducible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests/pytest_random_plugin.py: --seed does not seed Python's random module

1 participant