Spaces:
Running on Zero
Running on Zero
| """Temperature wiring for LocalBrain — verified WITHOUT a model load. | |
| `LocalBrain._sampler_kwargs` is a pure staticmethod and brain.py imports torch | |
| only inside `LocalBrain.__init__`/`_generate`, so this runs at zero GPU / no torch. | |
| """ | |
| from __future__ import annotations | |
| from game.brain import LocalBrain | |
| def test_defaults_come_from_bakeoff_when_env_unset(): | |
| # DEFAULT_* read MODEL_ID / LOCALBRAIN_TEMPERATURE at import; unset here. | |
| # Values are the 2026-06 bake-off picks (see the comment block in brain.py). | |
| assert LocalBrain.DEFAULT_MODEL == "Qwen/Qwen2.5-14B-Instruct" | |
| assert LocalBrain.DEFAULT_TEMPERATURE == 0.9 | |
| def test_modal_default_temperature_matches_local(): | |
| # Both brains read the same env knob; their fallbacks must not drift apart. | |
| from game.brain import ModalBrain | |
| assert ModalBrain.DEFAULT_TEMPERATURE == LocalBrain.DEFAULT_TEMPERATURE | |
| def test_sampler_kwargs_greedy_at_zero_and_below(): | |
| # temperature 0 must be GREEDY (do_sample=False, no temperature passed) — | |
| # transformers misbehaves if you sample at temperature 0. | |
| assert LocalBrain._sampler_kwargs(0.0) == {"do_sample": False} | |
| assert LocalBrain._sampler_kwargs(-1.0) == {"do_sample": False} | |
| assert "temperature" not in LocalBrain._sampler_kwargs(0.0) | |
| def test_sampler_kwargs_samples_when_warm(): | |
| k = LocalBrain._sampler_kwargs(0.7) | |
| assert k["do_sample"] is True | |
| assert k["temperature"] == 0.7 | |
| assert k["top_p"] == 0.9 | |
| def test_brain_import_does_not_pull_torch(): | |
| # Importing the module (and referencing LocalBrain) must not import torch — | |
| # the SPEC §6 lazy-import discipline the temperature change must preserve. | |
| import sys | |
| assert "torch" not in sys.modules | |