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
taskfield - 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.Behavior
Dataset Concatenation
EnvGroup concatenates the datasets from all sub-environments:
- Automatically builds datasets from each environment
- Overrides the
taskcolumn to useenv_namesfor routing - Ensures unique
example_idacross all examples
Task Routing
Each rollout is routed based on thetask 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
input["task"].
get_env_for_task
str
Task identifier from the dataset.
vf.Environment - Environment for that task, or the first environment if task not found.
set_max_seq_len
set_score_rollouts
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
UseEnvGroup for:
- Multi-task training
- Curriculum learning with different task types
- Combining benchmarks into a single evaluation
- Training generalist models across diverse tasks
EnvGroup if:
- You only have one task
- Tasks require completely different model architectures
- You want to train separate models per task
See Also
- Environment - Base class reference
- SingleTurnEnv - Single-turn environments
- MultiTurnEnv - Multi-turn environments
- ToolEnv - Tool-calling environments