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

Open Beginner friendly
#11 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
92/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, pytorch
Domain
testing

Research direction

Start in tests/pytest_random_plugin.py at the autouse seed fixture and compare its seeding behavior with tile_kernels/testing/generator.py:94, where generate_rand_float uses Python's random module. Verify the fix with tests/quant/test_per_block_cast_lossless.py and confirm repeated seeded runs produce the same generated inputs.

Written by the indexing model from the issue text.

Description

The autouse seed fixture in tests/pytest_random_plugin.py calls
torch.manual_seed(seed) but does not call random.seed(seed).

tile_kernels/testing/generator.py:94 (generate_rand_float) picks the
magnitude exponent via random.randint(-110, 126). So the input scale
used by tests like tests/quant/test_per_block_cast_lossless.py varies
across runs even when the user passes --seed. That defeats the
plugin's stated purpose.

Reproduction

A torch-free reproduction (the entropy source in question is pure
Python stdlib):

import hashlib, random

def fixture(node_id, base=0):
    h = int(hashlib.sha256(node_id.encode()).hexdigest(), 16) % (2**31)
    return base + h  # plugin currently seeds torch here, not random

node = 'tests/quant/test_per_block_cast_lossless.py::test[num_tokens=4001-hidden=2048]'
fixture(node, base=0)
run1 = [random.randint(-110, 126) for _ in range(8)]
fixture(node, base=0)
run2 = [random.randint(-110, 126) for _ in range(8)]
print(run1); print(run2)

Three back-to-back invocations on this machine produced three different
exponent sequences, e.g. [97, -60, 98, -69, 102, -84, 119, 2] then
[80, -68, -47, 94, 0, 33, -74, 77].

Suggested fix

Add random.seed(seed) immediately after torch.manual_seed(seed) in
the fixture (and import random at the top). PR follows.

Dominant language
Python
Stars
1.8k
Forks
163
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from deepseek-ai/TileKernels

All issues in deepseek-ai/TileKernels

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.