Skip to content

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

Description

@yurekami

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions