deepseek-ai / deepseek-ai/TileKernels
tests/pytest_random_plugin.py: --seed does not seed Python's `random` module
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 162
- PR merge metrics
- No merged PRs in 30d
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):
```python
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.