Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Volcengine Verl BaseConfig

From Leeroopedia
Revision as of 17:07, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Volcengine_Verl_BaseConfig.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Configuration, Data_Structures, API_Surface
Last Updated 2026-02-07 18:00 GMT

Overview

Concrete tool for creating frozen, dict-like dataclass configurations provided by the verl library.

Description

The BaseConfig class is a Python dataclass that implements collections.abc.Mapping, providing a dictionary-like interface for configuration objects. Key features:

  • Immutability by default — All fields are frozen after initialization. Attempting to modify a field raises FrozenInstanceError, unless the field name is listed in the class-level _mutable_fields set.
  • Dict-like access — Supports bracket notation (config["key"]), .get() with defaults, iteration over field names, and len().
  • Hydra compatibility — Includes a _target_ field for Hydra structured config instantiation.

All verl configuration dataclasses (RolloutConfig, ActorConfig, etc.) inherit from BaseConfig to get these safety and convenience features.

Usage

Use this class as the base when defining new configuration dataclasses in verl. Subclass BaseConfig and define fields with type annotations and defaults.

Code Reference

Source Location

Signature

@dataclass
class BaseConfig(collections.abc.Mapping):
    """The BaseConfig provides dict-like interface for a dataclass config.

    By default all fields in the config is not mutable, unless specified in
    "_mutable_fields". The BaseConfig class implements the Mapping Abstract Base Class.
    """

    _mutable_fields = set()
    _target_: str = ""

    def __setattr__(self, name: str, value): ...
    def get(self, key: str, default: Any = None) -> Any: ...
    def __getitem__(self, key: str): ...
    def __iter__(self): ...
    def __len__(self) -> int: ...

Import

from verl.base_config import BaseConfig

I/O Contract

Inputs

Name Type Required Description
_mutable_fields set No Class-level set of field names that can be modified after init
_target_ str No Hydra _target_ for structured config instantiation

Outputs

Name Type Description
instance BaseConfig A frozen, dict-like dataclass instance
__getitem__ Any Value of the requested field
__iter__ Iterator[str] Field names of the dataclass
__len__ int Number of fields in the dataclass

Usage Examples

Defining a Custom Config

from dataclasses import dataclass
from verl.base_config import BaseConfig

@dataclass
class MyTrainingConfig(BaseConfig):
    learning_rate: float = 1e-4
    batch_size: int = 32
    num_epochs: int = 3
    _mutable_fields = {"num_epochs"}  # Only num_epochs can be changed

config = MyTrainingConfig(learning_rate=2e-4, batch_size=64)

# Dict-like access
print(config["learning_rate"])  # 2e-4
print(config.get("missing_key", "default"))  # "default"
print(len(config))  # 4 (including _target_)

# Immutability
config.num_epochs = 5  # OK — in _mutable_fields
# config.learning_rate = 3e-4  # Raises FrozenInstanceError

Iterating Over Config

config = MyTrainingConfig()

for key in config:
    print(f"{key} = {config[key]}")
# _mutable_fields = set()
# _target_ =
# learning_rate = 0.0001
# batch_size = 32
# num_epochs = 3

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment