Skip to main content

EnvGroup

Environment that combines multiple environments into a single mixture, routing rollouts to the appropriate environment based on the task field.

Overview

EnvGroup enables:
  • Training on multiple tasks: Combine different environments into one training dataset
  • Task-based routing: Each rollout is routed to the correct environment based on task field
  • Unified metrics: Aggregate metrics across all environments
  • Shared configuration: Apply settings to all sub-environments at once

Inheritance

Constructor

Parameters

list[vf.Environment]
required
List of environment instances to combine. Must contain at least one environment.
list[str] | None
Optional names for each environment used for task routing. If not provided, uses "env_0", "env_1", etc.
dict
default:"{}"
Keyword arguments passed to HuggingFace dataset .map() operations.
All other parameters are inherited from Environment.

Behavior

Dataset Concatenation

EnvGroup concatenates the datasets from all sub-environments:
  • Automatically builds datasets from each environment
  • Overrides the task column to use env_names for routing
  • Ensures unique example_id across all examples

Task Routing

Each rollout is routed based on the task field in the input:

Metric Aggregation

All environments’ reward functions are tracked:
  • If an environment doesn’t have a metric, it gets 0.0 for that metric
  • All states include all metric names across all environments
  • Enables fair comparison across different task types

Core Methods

rollout

Routes to the appropriate environment based on input["task"].

get_env_for_task

Get the environment instance for a given task name.
str
Task identifier from the dataset.
Returns: vf.Environment - Environment for that task, or the first environment if task not found.

set_max_seq_len

Set max sequence length for the group and all sub-environments.

set_score_rollouts

Set score_rollouts flag for the group and all sub-environments.

Example Usage

Combining Q&A and Math

Different Environment Types

With Custom Reward Functions

Shared Configuration

Weighted Sampling (Manual)

Dataset Builders with EnvGroup

Built-in Rubric

EnvGroup includes EnvGroupRubric which:
  • Routes scoring to the appropriate environment’s rubric based on task
  • Aggregates all reward function names across all environments
  • Ensures all states have all metric names (0.0 for missing metrics)

Common Patterns

Task Distribution Analysis

Filter by Task

Dynamic Environment Creation

When to Use

Use EnvGroup for:
  • Multi-task training
  • Curriculum learning with different task types
  • Combining benchmarks into a single evaluation
  • Training generalist models across diverse tasks
Avoid EnvGroup if:
  • You only have one task
  • Tasks require completely different model architectures
  • You want to train separate models per task

See Also