From e07b509230a671dbff5fc571f4d2ddb72db6f41f Mon Sep 17 00:00:00 2001 From: guapisolo Date: Fri, 7 Aug 2026 03:46:51 +0000 Subject: [PATCH 1/2] fix: correct generated group type annotations generate_and_rm_group gathers per-sample results that may each expand to multiple samples. Describe the produced group and its direct consumer with the actual nested union type. --- miles/rollout/inference_rollout/inference_rollout_common.py | 2 +- miles/rollout/inference_rollout/inference_rollout_train.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/miles/rollout/inference_rollout/inference_rollout_common.py b/miles/rollout/inference_rollout/inference_rollout_common.py index ce1ffee73f..2fed07baab 100644 --- a/miles/rollout/inference_rollout/inference_rollout_common.py +++ b/miles/rollout/inference_rollout/inference_rollout_common.py @@ -126,7 +126,7 @@ async def generate_and_rm_group( sampling_params: dict[str, Any], evaluation: bool = False, sample_done_callback: Callable[[], None] | None = None, -) -> list[Sample]: +) -> list[Sample | list[Sample]]: args = state.args if state.aborted: diff --git a/miles/rollout/inference_rollout/inference_rollout_train.py b/miles/rollout/inference_rollout/inference_rollout_train.py index a486bb2fbc..5f390a267a 100644 --- a/miles/rollout/inference_rollout/inference_rollout_train.py +++ b/miles/rollout/inference_rollout/inference_rollout_train.py @@ -119,7 +119,7 @@ async def generate_rollout_async( logger.debug(f"[rollout] asyncio.wait returned: {len(done)} done, {len(pendings)} pending") for task in done: try: - group: list[Sample] = task.result() + group: list[Sample | list[Sample]] = task.result() except Exception as e: logger.error(f"[rollout] Task raised exception: {e!r}", exc_info=True) continue From 755c284c7cbce205b466c8f210ed8ae6ddcce52d Mon Sep 17 00:00:00 2001 From: yueming-yuan Date: Fri, 7 Aug 2026 15:11:28 -0700 Subject: [PATCH 2/2] converge the Group type alias next to Sample and fix the legacy annotation --- miles/rollout/fully_async_rollout.py | 6 +----- miles/rollout/inference_rollout/inference_rollout_common.py | 4 ++-- miles/rollout/inference_rollout/inference_rollout_train.py | 4 ++-- miles/rollout/multi_lora/async_rollout.py | 5 +---- miles/rollout/sglang_rollout.py | 4 ++-- miles/utils/types.py | 5 +++++ 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/miles/rollout/fully_async_rollout.py b/miles/rollout/fully_async_rollout.py index df850b8928..164303fcea 100644 --- a/miles/rollout/fully_async_rollout.py +++ b/miles/rollout/fully_async_rollout.py @@ -34,17 +34,13 @@ from miles.rollout.inference_rollout.inference_rollout_eval import run_eval_datasets from miles.rollout.submission_scheduler import make_submission_scheduler from miles.utils.misc import load_function -from miles.utils.types import Sample +from miles.utils.types import Group, Sample logger = logging.getLogger(__name__) OUTPUT_QUEUE_MAX_GROUPS = 1000 NO_PROGRESS_WARN_SECS = 30.0 -# A finished group is list[Sample], or list[list[Sample]] when a generate function -# returns multiple samples per trajectory (e.g. multi-agent). -Group = list[Sample | list[Sample]] - def _iter_samples(group: Group) -> Iterator[Sample]: for item in group: diff --git a/miles/rollout/inference_rollout/inference_rollout_common.py b/miles/rollout/inference_rollout/inference_rollout_common.py index 2fed07baab..2372272018 100644 --- a/miles/rollout/inference_rollout/inference_rollout_common.py +++ b/miles/rollout/inference_rollout/inference_rollout_common.py @@ -21,7 +21,7 @@ from miles.rollout.inference_rollout.compatibility import load_generate_function from miles.rollout.rm_hub import async_rm, batched_async_rm from miles.utils.processing_utils import load_processor, load_tokenizer -from miles.utils.types import Sample +from miles.utils.types import Group, Sample logger = logging.getLogger(__name__) @@ -126,7 +126,7 @@ async def generate_and_rm_group( sampling_params: dict[str, Any], evaluation: bool = False, sample_done_callback: Callable[[], None] | None = None, -) -> list[Sample | list[Sample]]: +) -> Group: args = state.args if state.aborted: diff --git a/miles/rollout/inference_rollout/inference_rollout_train.py b/miles/rollout/inference_rollout/inference_rollout_train.py index 5f390a267a..6e6050aa7d 100644 --- a/miles/rollout/inference_rollout/inference_rollout_train.py +++ b/miles/rollout/inference_rollout/inference_rollout_train.py @@ -15,7 +15,7 @@ from miles.utils import dumper_utils from miles.utils.http_utils import get, post, router_worker_base_urls from miles.utils.misc import as_completed_async, call_agent_abort_hook, load_function -from miles.utils.types import Sample +from miles.utils.types import Group, Sample logger = logging.getLogger(__name__) @@ -119,7 +119,7 @@ async def generate_rollout_async( logger.debug(f"[rollout] asyncio.wait returned: {len(done)} done, {len(pendings)} pending") for task in done: try: - group: list[Sample | list[Sample]] = task.result() + group: Group = task.result() except Exception as e: logger.error(f"[rollout] Task raised exception: {e!r}", exc_info=True) continue diff --git a/miles/rollout/multi_lora/async_rollout.py b/miles/rollout/multi_lora/async_rollout.py index 21bb36179c..d937621a8a 100644 --- a/miles/rollout/multi_lora/async_rollout.py +++ b/miles/rollout/multi_lora/async_rollout.py @@ -21,15 +21,12 @@ from miles.utils.misc import load_function from miles.utils.multi_lora import EmptyBatchTimeoutError, min_groups_per_dp_split from miles.utils.tracking_utils import tracking -from miles.utils.types import Sample +from miles.utils.types import Group, Sample logger = logging.getLogger(__name__) GenerateFn = Callable[..., Any] -# Generate fns may return several samples per rollout; the manager flattens later. -Group = list[Sample | list[Sample]] - def iter_group_samples(group: Group): return itertools.chain.from_iterable(item if isinstance(item, list) else (item,) for item in group) diff --git a/miles/rollout/sglang_rollout.py b/miles/rollout/sglang_rollout.py index 5c369e40da..adae5162c6 100644 --- a/miles/rollout/sglang_rollout.py +++ b/miles/rollout/sglang_rollout.py @@ -32,7 +32,7 @@ load_processor, load_tokenizer, ) -from miles.utils.types import Sample +from miles.utils.types import Group, Sample from .generate_utils.generate_endpoint_utils import ( compute_routing_headers, @@ -400,7 +400,7 @@ async def generate_and_rm( async def generate_and_rm_group( args: Namespace, group: list[Sample], sampling_params: dict[str, Any], evaluation: bool = False -) -> list[Sample]: +) -> Group: state = GenerateState(args) if state.aborted: diff --git a/miles/utils/types.py b/miles/utils/types.py index 78d24e49f1..dff61d26e0 100644 --- a/miles/utils/types.py +++ b/miles/utils/types.py @@ -297,6 +297,11 @@ def update_from_meta_info(self, args, meta_info: dict): self.status = Sample.Status.COMPLETED +# One prompt's finished trajectories. A generate function may expand one trajectory +# into several samples (e.g. multi-agent), so an element is a Sample or a list of them. +Group = list[Sample | list[Sample]] + + @dataclass(frozen=True) class ParamInfo: name: str