tenseleyflow/sway / 07fbed3

Browse files

tests/unit: fix bootstrap-CI-narrowing flake — use hashlib over PYTHONHASHSEED-salted hash()

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
07fbed3a32145db5e52c248c8c1cf2d9fed0bca2
Parents
edbb9e3
Tree
9e7d8cf

1 changed file

StatusFile+-
M tests/unit/test_bootstrap_ci_narrowing.py 7 1
tests/unit/test_bootstrap_ci_narrowing.pymodified
@@ -42,7 +42,13 @@ class _VariableFtView(_DummyView):
4242
 
4343
     def next_token_dist(self, prompt: str, *, top_k: int = 256) -> TokenDist:
4444
         base_dist = super().next_token_dist(prompt, top_k=top_k)
45
-        rng = np.random.default_rng(abs(hash(prompt)) % 1_000_003)
45
+        # Use a stable hash (hashlib) instead of Python's built-in
46
+        # ``hash()``, which salts per-process via PYTHONHASHSEED and
47
+        # would make per-prompt dispersion vary across pytest runs.
48
+        import hashlib
49
+
50
+        seed = int(hashlib.md5(prompt.encode("utf-8")).hexdigest()[:8], 16)
51
+        rng = np.random.default_rng(seed)
4652
         noise = rng.normal(0.0, 0.5, size=base_dist.logprobs.shape).astype(np.float32)
4753
         perturbed = base_dist.logprobs + noise
4854
         # Renormalize (within the top-k slice).