Compare commits

...
Author SHA1 Message Date
halleriteandGitHub 2e29c66fd7 fix(orchestrator): align gibberish/repetition filters to v1 branch streams (#2872)
Docker Push / Push CUDA image to Docker (push) Canceled after 0s
2026-06-25 06:02:41 +02:00
2 changed files with 44 additions and 9 deletions
+11 -9
View File
@@ -51,10 +51,11 @@ class GibberishFilter:
def check(self, rollout: Rollout) -> FilterResult:
global_idx = 0
for node in rollout.nodes:
# token_ids / logprobs / mask are per-token aligned; check only the
# sampled completion tokens, pairing each with its own logprob.
for token_id, logprob, sampled in zip(node.token_ids, node.logprobs, node.mask):
for branch in rollout.branches:
# branch.{token_ids,logprobs,sampled_mask} are flat and mutually aligned; the raw
# node arrays are not (node.logprobs covers only the sampled suffix, not the
# generation-prompt scaffold that token_ids/mask also span).
for token_id, logprob, sampled in zip(branch.token_ids, branch.logprobs, branch.sampled_mask):
if not sampled:
continue
if token_id > self.token_id_threshold and logprob < self.logprob_threshold:
@@ -81,12 +82,13 @@ class RepetitionFilter:
enforce: bool = False
def check(self, rollout: Rollout) -> FilterResult:
consecutive = 0
global_idx = 0
for node in rollout.nodes:
# Streak only over sampled completion tokens — context/prompt tokens
# (mask=False) are not model-generated and must not feed the loop count.
for logprob, sampled in zip(node.logprobs, node.mask):
for branch in rollout.branches:
# Aligned branch streams (see GibberishFilter), and reset the streak per branch:
# flat rollout.nodes interleaves distinct root->leaf paths (compaction/subagents),
# so a per-node walk would run a streak across a branch boundary.
consecutive = 0
for logprob, sampled in zip(branch.logprobs, branch.sampled_mask):
if not sampled:
continue
if logprob > self.logprob_threshold:
+33
View File
@@ -25,6 +25,21 @@ def _assistant_node(token_ids: list[int], logprobs: list[float]) -> vf.MessageNo
)
def _scaffold_assistant_node(
completion_ids: list[int], completion_logprobs: list[float], *, scaffold: int = 2
) -> vf.MessageNode:
"""A realistic v1 assistant node: a leading generation-prompt scaffold (mask=False, not
model-sampled) then the sampled completion. ``logprobs`` cover only the completion suffix
(vLLM returns logprobs for generated tokens only) — the exact layout where per-node
``zip(token_ids, logprobs, mask)`` mispairs and the branch streams normalize."""
return vf.MessageNode(
message=vf.AssistantMessage(content="x"),
token_ids=[1] * scaffold + completion_ids,
mask=[False] * scaffold + [True] * len(completion_ids),
logprobs=completion_logprobs,
)
def _make_rollout(
completion_ids: list[int],
completion_logprobs: list[float],
@@ -116,6 +131,24 @@ def test_gibberish_works_across_trajectory_steps():
assert result.detection_index == 2
def test_gibberish_aligns_logprobs_under_generation_prompt_scaffold():
"""Regression: the assistant node carries a generation-prompt scaffold (mask=False) and
suffix-only logprobs, and the gibberish token is the LAST completion token. The old
per-node ``zip(token_ids, logprobs, mask)`` truncated at len(logprobs) and never examined
it; reading the aligned branch streams detects it."""
gibberish_filter = _make_gibberish_filter()
rollout = Rollout[vf.Task](
task=vf.Task(idx=0, prompt=""),
nodes=[_scaffold_assistant_node([50, 80, 120_000], [-1.0, -0.5, gibberish_filter.logprob_threshold - 1.0])],
rewards={"reward": 1.0},
)
result = gibberish_filter.check(rollout)
assert result.detected is True
assert result.detection_index == 2 # third sampled completion token (scaffold skipped)
# --- RepetitionFilter tests ---