Skip to content

Commit dd0626a

Browse files
committed
pre commit fix
1 parent 03435c0 commit dd0626a

14 files changed

Lines changed: 411 additions & 366 deletions

claw_r1/agent_flow/agent_flow.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,18 @@ async def gateway_compute_reward(
231231
resp.raise_for_status()
232232
return resp.json()
233233

234-
async def gateway_submit_steps(self, steps: list[Step]) -> int:
234+
async def gateway_submit_steps(
235+
self,
236+
steps: list[Step],
237+
channel: str | None = None,
238+
) -> int:
235239
"""Submit Steps to DataPool via ``POST /submit_steps``.
236240
241+
Args:
242+
steps: Steps to submit.
243+
channel: DataPool channel name. When *None* the Gateway uses
244+
its default (``"train"``).
245+
237246
Returns the number of accepted steps.
238247
"""
239248
client = _get_http_client()
@@ -253,10 +262,9 @@ async def gateway_submit_steps(self, steps: list[Step]) -> int:
253262
"metadata": _json_safe(s.metadata),
254263
}
255264
)
256-
resp = await client.post(
257-
f"{self.gateway_url}/submit_steps",
258-
json={"steps": payloads},
259-
)
265+
url = f"{self.gateway_url}/submit_steps"
266+
params = {"channel": channel} if channel else None
267+
resp = await client.post(url, json={"steps": payloads}, params=params)
260268
resp.raise_for_status()
261269
return resp.json()["accepted"]
262270

claw_r1/agent_flow/multi_step_agent_flow.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
logger = logging.getLogger(__file__)
1919
logger.setLevel(os.getenv("VERL_LOGGING_LEVEL", "WARN"))
2020

21-
FEEDBACK_PROMPT = "Please verify your answer step by step and provide the final answer again in the format #### <number>."
21+
FEEDBACK_PROMPT = (
22+
"Please verify your answer step by step and provide the final answer again in the format #### <number>."
23+
)
2224

2325

2426
@register("multi_step_agent")
@@ -35,10 +37,9 @@ async def run(self, sampling_params: dict[str, Any], **kwargs) -> int:
3537
trajectory_uid = uuid4().hex
3638
prompt_uid = str(kwargs.get("uid", uuid4().hex))
3739
messages = list(kwargs["raw_prompt"])
40+
channel = kwargs.pop("channel", None)
3841
metadata = {k: v for k, v in kwargs.items() if k != "agent_name"}
3942

40-
steps: list[Step] = []
41-
4243
for turn in range(self.max_turns):
4344
prompt_ids = await self.apply_chat_template(messages)
4445
prompt_ids = prompt_ids[-self.prompt_length :]
@@ -66,9 +67,10 @@ async def run(self, sampling_params: dict[str, Any], **kwargs) -> int:
6667
)
6768

6869
if not is_last:
69-
await self.gateway_submit_steps([step])
70+
await self.gateway_submit_steps([step], channel=channel)
7071
response_text = self.tokenizer.decode(
71-
response_ids, skip_special_tokens=True,
72+
response_ids,
73+
skip_special_tokens=True,
7274
)
7375
messages.append({"role": "assistant", "content": response_text})
7476
messages.append({"role": "user", "content": FEEDBACK_PROMPT})
@@ -81,6 +83,6 @@ async def run(self, sampling_params: dict[str, Any], **kwargs) -> int:
8183
dataset_fields=dataset_fields,
8284
)
8385
step.reward = reward_result["reward_score"]
84-
await self.gateway_submit_steps([step])
86+
await self.gateway_submit_steps([step], channel=channel)
8587

8688
return self.max_turns

claw_r1/agent_flow/single_step_single_turn_agent_flow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ async def run(self, sampling_params: dict[str, Any], **kwargs) -> int:
6363
trajectory_uid = uuid4().hex
6464
prompt_uid = str(kwargs.get("uid", uuid4().hex))
6565

66+
channel = kwargs.pop("channel", None)
6667
metadata = {k: v for k, v in kwargs.items() if k != "agent_name"}
6768

6869
step = Step(
@@ -75,5 +76,5 @@ async def run(self, sampling_params: dict[str, Any], **kwargs) -> int:
7576
is_last=True,
7677
metadata=metadata,
7778
)
78-
await self.gateway_submit_steps([step])
79+
await self.gateway_submit_steps([step], channel=channel)
7980
return 1

claw_r1/async_main.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
from verl.trainer.ppo.utils import Role
2727
from verl.utils.device import auto_set_device
2828

29-
3029
# -- Resource pool helpers ------------------------------------------------
3130

31+
3232
def _create_resource_pool_manager(config, roles: list[Role]) -> ResourcePoolManager:
3333
"""Build separate resource pools for trainer vs. rollout roles."""
3434
resource_pool_spec = {}
@@ -74,6 +74,7 @@ def _create_role_worker_mapping(config):
7474

7575
# -- AsyncTaskRunner ------------------------------------------------------
7676

77+
7778
@ray.remote(num_cpus=1)
7879
class AsyncTaskRunner:
7980
"""Orchestrates async training: creates components, wires them, starts loops."""
@@ -93,8 +94,8 @@ def _initialize(self, config):
9394
pprint(OmegaConf.to_container(config, resolve=True))
9495
OmegaConf.resolve(config)
9596

96-
from verl.utils.fs import copy_to_local
9797
from verl.utils import hf_processor, hf_tokenizer
98+
from verl.utils.fs import copy_to_local
9899

99100
local_path = copy_to_local(
100101
config.actor_rollout_ref.model.path,
@@ -103,7 +104,9 @@ def _initialize(self, config):
103104
trust_remote_code = config.data.get("trust_remote_code", False)
104105
tokenizer = hf_tokenizer(local_path, trust_remote_code=trust_remote_code)
105106
processor = hf_processor(
106-
local_path, trust_remote_code=trust_remote_code, use_fast=True,
107+
local_path,
108+
trust_remote_code=trust_remote_code,
109+
use_fast=True,
107110
)
108111

109112
role_worker_mapping, ray_worker_group_cls = _create_role_worker_mapping(config)
@@ -139,7 +142,9 @@ def _initialize(self, config):
139142
max_queue_size = config.async_training.get("max_queue_size", None)
140143
data_pool_name = "data_pool"
141144
data_pool = DataPool.options(name=data_pool_name).remote(
142-
data_pool_config, verl_backend, max_queue_size=max_queue_size,
145+
data_pool_config,
146+
verl_backend,
147+
max_queue_size=max_queue_size,
143148
)
144149
self.components["data_pool"] = data_pool
145150
self.components["data_pool_name"] = data_pool_name
@@ -213,17 +218,12 @@ def _create_rollouter(self, config):
213218
def _create_trainer(self, config):
214219
from claw_r1.async_trainer import AsyncTrainer
215220

216-
trainer_roles = [
217-
role for role in self.components["role_worker_mapping"]
218-
if role != Role.Rollout
219-
]
221+
trainer_roles = [role for role in self.components["role_worker_mapping"] if role != Role.Rollout]
220222
trainer = AsyncTrainer.remote(
221223
config=config,
222224
tokenizer=self.components["tokenizer"],
223225
role_worker_mapping={
224-
role: cls
225-
for role, cls in self.components["role_worker_mapping"].items()
226-
if role != Role.Rollout
226+
role: cls for role, cls in self.components["role_worker_mapping"].items() if role != Role.Rollout
227227
},
228228
resource_pool_manager=_create_resource_pool_manager(config, trainer_roles),
229229
ray_worker_group_cls=self.components["ray_worker_group_cls"],
@@ -266,6 +266,7 @@ def _run(self):
266266

267267
# -- Hydra entry point ----------------------------------------------------
268268

269+
269270
@hydra.main(config_path="config", config_name="async_ppo_trainer", version_base=None)
270271
def main(config):
271272
auto_set_device(config)
@@ -275,9 +276,7 @@ def main(config):
275276
ray_init_kwargs = config.ray_kwargs.get("ray_init", {})
276277
runtime_env_kwargs = ray_init_kwargs.get("runtime_env", {})
277278
runtime_env = OmegaConf.merge(default_runtime_env, runtime_env_kwargs)
278-
ray_init_kwargs = OmegaConf.create(
279-
{**ray_init_kwargs, "runtime_env": runtime_env}
280-
)
279+
ray_init_kwargs = OmegaConf.create({**ray_init_kwargs, "runtime_env": runtime_env})
281280
ray.init(namespace="claw_r1_async", **OmegaConf.to_container(ray_init_kwargs))
282281

283282
if not hasattr(config, "async_training"):

0 commit comments

Comments
 (0)