test: port test_value_temperature from slime #1928 (mirror-slime gap) - #158
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds a new test file tests/test_value_temperature.py to verify that get_values does not apply rollout temperature. The review feedback suggests a more idiomatic and less error-prone approach to mock and restore sys.modules using pytest's monkeypatch.delitem instead of manual try...finally blocks.
Comment on lines
+13
to
+50
| previous_loss = sys.modules.pop("vime.backends.megatron_utils.loss", None) | ||
| previous_cp_utils = sys.modules.pop("vime.backends.megatron_utils.cp_utils", None) | ||
|
|
||
| mpu_stub = types.SimpleNamespace( | ||
| get_context_parallel_world_size=lambda: 1, | ||
| get_context_parallel_rank=lambda: 0, | ||
| ) | ||
| megatron_mod = types.ModuleType("megatron") | ||
| core_mod = types.ModuleType("megatron.core") | ||
| core_mod.mpu = mpu_stub | ||
| monkeypatch.setitem(sys.modules, "megatron", megatron_mod) | ||
| monkeypatch.setitem(sys.modules, "megatron.core", core_mod) | ||
|
|
||
| try: | ||
| from vime.backends.megatron_utils.loss import get_values | ||
|
|
||
| args = Namespace(qkv_format="thd", rollout_temperature=0.5, allgather_cp=False) | ||
| logits = torch.tensor([[[1.0], [2.0], [3.0], [4.0]]], dtype=torch.float32) | ||
| tokens = [torch.tensor([10, 11, 12, 13], dtype=torch.long)] | ||
|
|
||
| _, result = get_values( | ||
| logits, | ||
| args=args, | ||
| unconcat_tokens=tokens, | ||
| total_lengths=[4], | ||
| response_lengths=[2], | ||
| ) | ||
|
|
||
| torch.testing.assert_close(result["values"][0], torch.tensor([2.0, 3.0])) | ||
| finally: | ||
| if previous_loss is None: | ||
| sys.modules.pop("vime.backends.megatron_utils.loss", None) | ||
| else: | ||
| sys.modules["vime.backends.megatron_utils.loss"] = previous_loss | ||
| if previous_cp_utils is None: | ||
| sys.modules.pop("vime.backends.megatron_utils.cp_utils", None) | ||
| else: | ||
| sys.modules["vime.backends.megatron_utils.cp_utils"] = previous_cp_utils |
Contributor
There was a problem hiding this comment.
Instead of manually popping modules from sys.modules and restoring them in a try...finally block, you can use pytest's monkeypatch.delitem with raising=False. This is more idiomatic, less error-prone, and automatically handles the cleanup/restoration of sys.modules after the test completes.
monkeypatch.delitem(sys.modules, "vime.backends.megatron_utils.loss", raising=False)
monkeypatch.delitem(sys.modules, "vime.backends.megatron_utils.cp_utils", raising=False)
mpu_stub = types.SimpleNamespace(
get_context_parallel_world_size=lambda: 1,
get_context_parallel_rank=lambda: 0,
)
megatron_mod = types.ModuleType("megatron")
core_mod = types.ModuleType("megatron.core")
core_mod.mpu = mpu_stub
monkeypatch.setitem(sys.modules, "megatron", megatron_mod)
monkeypatch.setitem(sys.modules, "megatron.core", core_mod)
from vime.backends.megatron_utils.loss import get_values
args = Namespace(qkv_format="thd", rollout_temperature=0.5, allgather_cp=False)
logits = torch.tensor([[[1.0], [2.0], [3.0], [4.0]]], dtype=torch.float32)
tokens = [torch.tensor([10, 11, 12, 13], dtype=torch.long)]
_, result = get_values(
logits,
args=args,
unconcat_tokens=tokens,
total_lengths=[4],
response_lengths=[2],
)
torch.testing.assert_close(result["values"][0], torch.tensor([2.0, 3.0]))
aoshen02
marked this pull request as ready for review
June 7, 2026 13:06
aoshen02
force-pushed
the
sync/test-value-temperature
branch
2 times, most recently
from
June 7, 2026 14:09
32c80db to
b695e6b
Compare
slime #1928 landed both the fix (loss.py: don't apply rollout temperature to critic values) AND tests/test_value_temperature.py. vime #95 ported only the fix; the test was missed. Restore it to match slime. - tests/test_value_temperature.py: slime verbatim, slime.→vime. only (import + sys.modules paths). NUM_GPUS=0, 0 sglang refs. Passes locally (1 passed). - wire into the num_gpus:0 unit matrix in pr-test.yml + pr-test.yml.j2 (vime CI runs explicit per-file matrix entries, not bare pytest — an unlisted test would be dead). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
aoshen02
force-pushed
the
sync/test-value-temperature
branch
from
June 7, 2026 14:19
b695e6b to
911498e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
slime #1928 landed both the critic-temperature fix (
loss.py) andtests/test_value_temperature.py. vime #95 ported only the fix — the test was missed. This restores it (mirror-slime).tests/test_value_temperature.py: slime verbatim, onlyslime.→vime.(import +sys.modulespaths).NUM_GPUS=0, 0 sglang refs. Passes locally (1 passed).num_gpus:0unit matrix inpr-test.yml+pr-test.yml.j2. vime CI runs explicit per-file matrix entries (not barepytest), so an unlisted test would never run.AI-assisted. Signoff item 3.