Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions envs/harbor_env/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,6 @@ def tasks(self) -> list[dict[str, Any]]:
continue
self._by_instruction[key] = index
if collisions:
# Last-write-wins here would be invisible and wrong: two tasks with identical
# instructions produce two dataset rows that both resolve to one index, so a group
# trains on a task it was not given while every log line looks normal. Keeping the
# first and saying how many were shadowed at least makes it findable.
logger.warning(
"%d task(s) share an instruction with an earlier task and are unreachable "
"through prompt lookup; the first occurrence wins",
Expand All @@ -548,16 +544,23 @@ def prompt_rows(self) -> list[dict[str, Any]]:
"""Dataset rows for a trainer: the instruction as the prompt, plus columns worth logging.

All `num_generations` of a group share a row, so they all get the same task and the group
baseline is well formed without any seed plumbing.
baseline is well formed without any seed plumbing. When tasks share an instruction, only
the task that `create()` resolves is included. `tasks()` still lists every selected task.
"""
return [
{
"prompt": [{"role": "user", "content": t.get("instruction") or ""}],
"task_name": t.get("task_name") or "",
"task_index": int(t.get("index", i)),
}
for i, t in enumerate(self.tasks())
]
rows = []
for i, task in enumerate(self.tasks()):
instruction = task.get("instruction") or ""
task_index = int(task.get("index", i))
if self._by_instruction.get(instruction_id(instruction)) != task_index:
continue
rows.append(
{
"prompt": [{"role": "user", "content": instruction}],
"task_name": task.get("task_name") or "",
"task_index": task_index,
}
)
return rows

def create(
self,
Expand Down
15 changes: 10 additions & 5 deletions tests/envs/test_harbor_session_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,23 +351,28 @@ def test_the_factory_survives_pickling():


def test_duplicate_instructions_do_not_silently_shadow_each_other(caplog):
"""Two tasks with one instruction produced two rows that both resolved to the LAST index, so a
group trained on a task it was never given and nothing said so."""
"""Each trainer row must resolve to the task named in that row."""
env = FakeEnv(
result(),
tasks=[
{"index": 0, "task_name": "a", "instruction": "same text"},
{"index": 1, "task_name": "b", "instruction": "same text"},
{"index": 2, "task_name": "c", "instruction": "unique text"},
],
)
f = factory_with(env)
with caplog.at_level("WARNING"):
f.tasks()
rows = f.prompt_rows()
assert any("share an instruction" in r.message for r in caplog.records), (
"a collision that changes which task runs must be said out loud"
)
# First occurrence wins, deterministically, rather than whichever happened to be last.
assert f.create([{"role": "user", "content": "same text"}])._task_index == 0
assert [task["index"] for task in f.tasks()] == [0, 1, 2]
assert [(row["task_index"], row["task_name"]) for row in rows] == [
(0, "a"),
(2, "c"),
]
for row in rows:
assert f.create(row["prompt"])._task_index == row["task_index"]


def test_a_zero_timeout_defers_to_the_task_file():
Expand Down