fix: report failed rollout requests

- Return structured finish and error reasons for synchronous generation
- Reject failed online rollout batches instead of training on empty responses
- Verify allocation and extension failures release metrics and KV state
This commit is contained in:
0z5a
2026-09-02 12:52:50 +08:00
parent c36846c8a4
commit 90de5bc1bd
6 changed files with 185 additions and 24 deletions
+20
View File
@@ -4,6 +4,7 @@ import pytest
import torch
from astrai.inference.scheduler import InferenceScheduler
from astrai.inference.task import GenerationResult
from astrai.trainer.rollout import (
BaseRewardModel,
RawRollout,
@@ -173,6 +174,25 @@ def test_rollout_generator_logprobs_are_nonpositive(device):
assert torch.all(lp <= 1e-5)
def test_rollout_generator_rejects_failed_requests(device):
gen, _ = _make_generator(device, group_size=2, max_tokens=4)
def failed_run_batch(*_args, **kwargs):
assert kwargs["return_details"] is True
return [
GenerationResult([1], [-0.1], "length"),
GenerationResult([], [], "rejected", "kv_cache_allocation_failed"),
]
gen.scheduler.run_batch = failed_run_batch
with pytest.raises(
RuntimeError,
match="Rollout generation failed: request 1: kv_cache_allocation_failed",
):
gen.generate(_make_instruction_batch(n=1))
def test_rollout_generator_instruction_role_mapping(device):
"""instruction -> system, input -> user, output -> assistant."""
gen, _ = _make_generator(device, group_size=1, max_tokens=4)