-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Support customizing trainer and daemon in VERL #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,16 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| # Copyright (c) Microsoft. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # type: ignore | ||||||||||||||||||||||||||||||||||||||||||||
| # pyright: reportUnknownVariableType=false | ||||||||||||||||||||||||||||||||||||||||||||
| # pyright: reportUnknownMemberType=false | ||||||||||||||||||||||||||||||||||||||||||||
| # pyright: reportUnknownArgumentType=false | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from importlib.metadata import version | ||||||||||||||||||||||||||||||||||||||||||||
| from typing import Any | ||||||||||||||||||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from typing import TYPE_CHECKING, Any, Type | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import hydra | ||||||||||||||||||||||||||||||||||||||||||||
| import ray | ||||||||||||||||||||||||||||||||||||||||||||
| from packaging import version as packaging_version | ||||||||||||||||||||||||||||||||||||||||||||
| from ray.actor import ActorClass | ||||||||||||||||||||||||||||||||||||||||||||
| from verl.trainer.main_ppo import create_rl_sampler | ||||||||||||||||||||||||||||||||||||||||||||
| from verl.trainer.ppo.reward import load_reward_manager | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -17,7 +20,10 @@ | |||||||||||||||||||||||||||||||||||||||||||
| from agentlightning.types import Dataset | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from .dataset import AgentDataset, LoadedDataset | ||||||||||||||||||||||||||||||||||||||||||||
| from .trainer import AgentLightningTrainer | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if TYPE_CHECKING: | ||||||||||||||||||||||||||||||||||||||||||||
| from .daemon import AgentModeDaemon | ||||||||||||||||||||||||||||||||||||||||||||
| from .trainer import AgentLightningTrainer | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| __all__ = [ | ||||||||||||||||||||||||||||||||||||||||||||
| "main", | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -27,8 +33,17 @@ | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| @hydra.main(config_path="pkg://agentlightning/verl", config_name="config", version_base=None) | ||||||||||||||||||||||||||||||||||||||||||||
| def main(config): | ||||||||||||||||||||||||||||||||||||||||||||
| run_ppo(config, train_dataset=None, val_dataset=None, store=None, llm_proxy=None, adapter=None) | ||||||||||||||||||||||||||||||||||||||||||||
| def main(config: Any): | ||||||||||||||||||||||||||||||||||||||||||||
| run_ppo( | ||||||||||||||||||||||||||||||||||||||||||||
| config, | ||||||||||||||||||||||||||||||||||||||||||||
| train_dataset=None, | ||||||||||||||||||||||||||||||||||||||||||||
| val_dataset=None, | ||||||||||||||||||||||||||||||||||||||||||||
| store=None, | ||||||||||||||||||||||||||||||||||||||||||||
| llm_proxy=None, | ||||||||||||||||||||||||||||||||||||||||||||
| adapter=None, | ||||||||||||||||||||||||||||||||||||||||||||
| trainer_cls=AgentLightningTrainer, | ||||||||||||||||||||||||||||||||||||||||||||
| daemon_cls=AgentModeDaemon, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def run_ppo( | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -38,6 +53,8 @@ def run_ppo( | |||||||||||||||||||||||||||||||||||||||||||
| store: LightningStore | None, | ||||||||||||||||||||||||||||||||||||||||||||
| llm_proxy: LLMProxy | None, | ||||||||||||||||||||||||||||||||||||||||||||
| adapter: TraceAdapter[Any] | None, | ||||||||||||||||||||||||||||||||||||||||||||
| trainer_cls: Type[AgentLightningTrainer], | ||||||||||||||||||||||||||||||||||||||||||||
| daemon_cls: Type[AgentModeDaemon], | ||||||||||||||||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| ) -> None: | |
| ) -> None: | |
| """ | |
| Run the PPO (Proximal Policy Optimization) training loop using the provided configuration and components. | |
| Parameters: | |
| config (Any): The configuration object for the training run, typically loaded via Hydra. | |
| train_dataset (Dataset[Any] | None): The training dataset to use, or None if not provided. | |
| val_dataset (Dataset[Any] | None): The validation dataset to use, or None if not provided. | |
| store (LightningStore | None): The LightningStore instance for storing and retrieving data, or None. | |
| llm_proxy (LLMProxy | None): The LLMProxy instance for model inference, or None. | |
| adapter (TraceAdapter[Any] | None): The TraceAdapter for logging or tracing, or None. | |
| trainer_cls (Type[AgentLightningTrainer]): The class to use for creating the PPO trainer. This allows customization of the training logic by providing a different trainer class. | |
| daemon_cls (Type[AgentModeDaemon]): The class to use for creating the agent mode daemon. This allows customization of the agent's runtime behavior by providing a different daemon class. | |
| Returns: | |
| None | |
| This function initializes Ray if necessary, then launches the PPO training process using the provided datasets, | |
| store, LLM proxy, adapter, and customizable trainer and daemon classes. | |
| """ |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TaskRunner.run method has new parameters daemon_cls and trainer_cls but lacks a docstring to document what these parameters are for. Add a docstring that describes all parameters, especially the new ones.
| ): | |
| ): | |
| """ | |
| Run the main training or evaluation task using the provided configuration and components. | |
| Args: | |
| config (Any): The configuration object for the experiment, typically an OmegaConf config. | |
| train_dataset (Dataset[Any] | None): The training dataset to use, or None if not provided. | |
| val_dataset (Dataset[Any] | None): The validation dataset to use, or None if not provided. | |
| store (LightningStore | None): The LightningStore instance for storing experiment data, or None. | |
| llm_proxy (LLMProxy | None): The LLMProxy instance for model inference, or None. | |
| adapter (TraceAdapter[Any] | None): The TraceAdapter for logging or tracing, or None. | |
| daemon_cls (Type[AgentModeDaemon]): The class to use for creating the agent mode daemon. This should be a subclass of AgentModeDaemon and is responsible for managing agent modes during training or evaluation. | |
| trainer_cls (Type[AgentLightningTrainer]): The class to use for creating the trainer. This should be a subclass of AgentLightningTrainer and is responsible for orchestrating the training or evaluation process. | |
| Returns: | |
| None | |
| """ |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |||||||||||||||||||||||||
| from contextlib import contextmanager | ||||||||||||||||||||||||||
| from copy import deepcopy | ||||||||||||||||||||||||||
| from pprint import pprint | ||||||||||||||||||||||||||
| from typing import Dict, Tuple | ||||||||||||||||||||||||||
| from typing import Dict, Tuple, Type | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||
| import torch | ||||||||||||||||||||||||||
|
|
@@ -174,12 +174,18 @@ class AgentLightningTrainer(RayPPOTrainer): | |||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def __init__( | ||||||||||||||||||||||||||
| self, store: LightningStore | None, llm_proxy: LLMProxy | None, adapter: TraceAdapter | None, **kwargs | ||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||
| store: LightningStore | None, | ||||||||||||||||||||||||||
| llm_proxy: LLMProxy | None, | ||||||||||||||||||||||||||
| adapter: TraceAdapter | None, | ||||||||||||||||||||||||||
| daemon_cls: Type[AgentModeDaemon], | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| **kwargs, | ||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| ): | |
| ): | |
| """ | |
| Initialize the AgentLightningTrainer. | |
| Args: | |
| store (LightningStore | None): The storage backend for logging and data persistence. | |
| llm_proxy (LLMProxy | None): Proxy for interacting with the language model. | |
| adapter (TraceAdapter | None): Adapter for converting traces to the required format. | |
| daemon_cls (Type[AgentModeDaemon]): The class to use for creating the agent mode daemon responsible for server communication and agent orchestration. | |
| **kwargs: Additional keyword arguments passed to the base RayPPOTrainer. | |
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
AgentLightningTrainerandAgentModeDaemonclasses are imported insideTYPE_CHECKINGbut are used at runtime in themainfunction. This will cause aNameErrorat runtime because these names are not available outside of type checking. Move these imports outside theTYPE_CHECKINGblock or use string literals for the default values.