> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/gym/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/gym/_mcp/server.

# nemo_gym.rollout_collection

## Module Contents

### Classes

| Name                                                                                          | Description                                                                                                             |
| --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| [`E2ERolloutCollectionConfig`](#nemo_gym-rollout_collection-E2ERolloutCollectionConfig)       | Spin up all necessary servers and perform a batch of rollout collection using each dataset inside the provided configs. |
| [`RolloutAggregationConfig`](#nemo_gym-rollout_collection-RolloutAggregationConfig)           | Aggregate metrics across rollout shards produced by `ng_collect_rollouts +disable_aggregation=true`.                    |
| [`RolloutAggregationHelper`](#nemo_gym-rollout_collection-RolloutAggregationHelper)           | -                                                                                                                       |
| [`RolloutCollectionConfig`](#nemo_gym-rollout_collection-RolloutCollectionConfig)             | Perform a batch of rollout collection.                                                                                  |
| [`RolloutCollectionHelper`](#nemo_gym-rollout_collection-RolloutCollectionHelper)             | -                                                                                                                       |
| [`SharedRolloutCollectionConfig`](#nemo_gym-rollout_collection-SharedRolloutCollectionConfig) | -                                                                                                                       |

### Functions

| Name                                                                                            | Description                                                                              |
| ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| [`_expand_input_glob`](#nemo_gym-rollout_collection-_expand_input_glob)                         | Expand a glob-or-comma-separated-globs string into a sorted, deduplicated list of paths. |
| [`_failures_path_for`](#nemo_gym-rollout_collection-_failures_path_for)                         | Sidecar path used by the dispatcher and `_load_from_cache`.                              |
| [`_get_max_rollout_attempts`](#nemo_gym-rollout_collection-_get_max_rollout_attempts)           | Read `NEMO_GYM_MAX_ROLLOUT_ATTEMPTS` (positive int) or default to 3.                     |
| [`_rollout_request_debug_summary`](#nemo_gym-rollout_collection-_rollout_request_debug_summary) | -                                                                                        |
| [`aggregate_rollouts`](#nemo_gym-rollout_collection-aggregate_rollouts)                         | -                                                                                        |
| [`collect_rollouts`](#nemo_gym-rollout_collection-collect_rollouts)                             | -                                                                                        |

### Data

[`NG_FAILURE_CLASS_KEY`](#nemo_gym-rollout_collection-NG_FAILURE_CLASS_KEY)

[`NG_NO_PERSIST_KEY`](#nemo_gym-rollout_collection-NG_NO_PERSIST_KEY)

[`NG_TERMINAL_KEY`](#nemo_gym-rollout_collection-NG_TERMINAL_KEY)

[`_DEFAULT_MAX_ROLLOUT_ATTEMPTS`](#nemo_gym-rollout_collection-_DEFAULT_MAX_ROLLOUT_ATTEMPTS)

### API

```python
class nemo_gym.rollout_collection.E2ERolloutCollectionConfig()
```

**Bases:** [SharedRolloutCollectionConfig](#nemo_gym-rollout_collection-SharedRolloutCollectionConfig)

Spin up all necessary servers and perform a batch of rollout collection using each dataset inside the provided configs.

Examples:

```python
ng_collect_rollouts         +output_jsonl_fpath=weather_rollouts.jsonl         +num_samples_in_parallel=10
```

```python
class nemo_gym.rollout_collection.RolloutAggregationConfig()
```

**Bases:** [BaseNeMoGymCLIConfig](/nemo-gym/nemo_gym/config_types#nemo_gym-config_types-BaseNeMoGymCLIConfig)

Aggregate metrics across rollout shards produced by `ng_collect_rollouts +disable_aggregation=true`.

Reads every JSONL file matching `input_glob`, computes aggregate metrics by POSTing to each
agent server's `/aggregate_metrics` endpoint over the global union of records, and writes a
single `&lt;output_jsonl_fpath stem&gt;_aggregate_metrics.json` next to the rollouts. By default
also concatenates all shards into `output_jsonl_fpath`.

Examples:

```python
ng_aggregate_rollouts         "+config_paths=[benchmarks/aime24/config.yaml,responses_api_models/vllm_model/configs/vllm_model.yaml]"         +input_glob='results/rollouts-rs*-chunk*.jsonl'         +output_jsonl_fpath=results/rollouts.jsonl
```

```python
class nemo_gym.rollout_collection.RolloutAggregationHelper()
```

**Bases:** `BaseModel`

```python
nemo_gym.rollout_collection.RolloutAggregationHelper.run_from_config(
    config: nemo_gym.rollout_collection.RolloutAggregationConfig
) -> typing.Optional[pathlib.Path]
```

async

```python
class nemo_gym.rollout_collection.RolloutCollectionConfig()
```

**Bases:** [SharedRolloutCollectionConfig](#nemo_gym-rollout_collection-SharedRolloutCollectionConfig)

Perform a batch of rollout collection.

Examples:

```python
ng_collect_rollouts         +agent_name=example_single_tool_call_simple_agent         +input_jsonl_fpath=weather_query.jsonl         +output_jsonl_fpath=weather_rollouts.jsonl         +limit=100         +num_repeats=4         +num_samples_in_parallel=10
```

```python
class nemo_gym.rollout_collection.RolloutCollectionHelper()
```

**Bases:** `BaseModel`

```python
nemo_gym.rollout_collection.RolloutCollectionHelper._call_aggregate_metrics(
    results: typing.List[typing.Dict],
    rows: typing.List[typing.Dict],
    output_fpath: pathlib.Path
) -> typing.Optional[pathlib.Path]
```

async

Call /aggregate\_metrics on each agent server after rollouts complete.

Writes a single \_aggregate\_metrics.json with one entry per agent (same shape
as the old \_agent\_metrics.json). Returns the file path.

```python
nemo_gym.rollout_collection.RolloutCollectionHelper._load_from_cache(
    config: nemo_gym.rollout_collection.RolloutCollectionConfig
) -> typing.Tuple[typing.List[typing.Dict], typing.List[typing.Dict], typing.List[typing.Dict], typing.List[typing.List[str]]]
```

```python
nemo_gym.rollout_collection.RolloutCollectionHelper._preprocess_rows_from_config(
    config: nemo_gym.rollout_collection.RolloutCollectionConfig
) -> typing.List[typing.Dict]
```

```python
nemo_gym.rollout_collection.RolloutCollectionHelper.run_examples(
    examples: typing.List[typing.Dict],
    head_server_config: typing.Optional[nemo_gym.config_types.BaseServerConfig] = None,
    semaphore: typing.Optional[asyncio.Semaphore] = None
) -> typing.Iterator[asyncio.Future]
```

We provide this function as a lower level interface for running rollout collection.

```python
nemo_gym.rollout_collection.RolloutCollectionHelper.run_from_config(
    config: nemo_gym.rollout_collection.RolloutCollectionConfig
) -> typing.Tuple[typing.List[typing.Dict]]
```

async

```python
nemo_gym.rollout_collection.RolloutCollectionHelper.setup_server_client(
    head_server_config: typing.Optional[nemo_gym.config_types.BaseServerConfig] = None
) -> nemo_gym.server_utils.ServerClient
```

```python
class nemo_gym.rollout_collection.SharedRolloutCollectionConfig()
```

**Bases:** [BaseNeMoGymCLIConfig](/nemo-gym/nemo_gym/config_types#nemo_gym-config_types-BaseNeMoGymCLIConfig)

```python
nemo_gym.rollout_collection._expand_input_glob(
    input_glob: str
) -> typing.List[str]
```

Expand a glob-or-comma-separated-globs string into a sorted, deduplicated list of paths.

**Examples:**

```python
'results/rollouts.jsonl' -> ['results/rollouts.jsonl'] (if it exists)
'a/*.jsonl, b/*.jsonl'   -> matches of both patterns, deduplicated
```

```python
nemo_gym.rollout_collection._failures_path_for(
    output_fpath: pathlib.Path
) -> pathlib.Path
```

Sidecar path used by the dispatcher and `_load_from_cache`.

```python
nemo_gym.rollout_collection._get_max_rollout_attempts() -> int
```

Read `NEMO_GYM_MAX_ROLLOUT_ATTEMPTS` (positive int) or default to 3.

```python
nemo_gym.rollout_collection._rollout_request_debug_summary(
    row: typing.Dict[str, typing.Any]
) -> typing.Dict[str, typing.Any]
```

```python
nemo_gym.rollout_collection.aggregate_rollouts()
```

```python
nemo_gym.rollout_collection.collect_rollouts()
```

```python
nemo_gym.rollout_collection.NG_FAILURE_CLASS_KEY = '_ng_failure_class'
```

```python
nemo_gym.rollout_collection.NG_NO_PERSIST_KEY = '_ng_no_persist'
```

```python
nemo_gym.rollout_collection.NG_TERMINAL_KEY = '_ng_failure_terminal'
```

```python
nemo_gym.rollout_collection._DEFAULT_MAX_ROLLOUT_ATTEMPTS = 3
```