Skip to content

Commit b63149f

Browse files
committed
(feat): refactor webshop env.
1 parent 6263e37 commit b63149f

8 files changed

Lines changed: 286 additions & 75 deletions

File tree

examples/qwen2.5-7B-agentic_megatron/agentic_val_webshop.yaml

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ hydra:
1010
dir: .
1111
output_subdir: null
1212

13-
exp_name: "agentic_pipeline"
13+
exp_name: "agentic_pipeline_webshop"
1414
seed: 42
1515
logging_dir: ./output/logs
1616
output_dir: ./output
@@ -29,9 +29,21 @@ system_envs:
2929
# - roll
3030
# - baseline
3131

32+
#track_with: swanlab
33+
#tracker_kwargs:
34+
# login_kwargs:
35+
# api_key: your_api_key
36+
# project: roll-agentic
37+
# logdir: debug
38+
# experiment_name: ${exp_name}
39+
# tags:
40+
# - roll
41+
# - agentic
42+
# - debug
43+
3244
track_with: tensorboard
3345
tracker_kwargs:
34-
log_dir: /data/oss_bucket_0/yali/llm/tensorboard/roll_exp/agentic_sokoban
46+
log_dir: /data/oss_bucket_0/yali/llm/tensorboard/roll_exp/agentic_webshop
3547

3648
num_gpus_per_node: 8
3749

@@ -48,8 +60,8 @@ sequence_length: 8192
4860
reward_clip: 20
4961
advantage_clip: 0.2 # 0.1-0.3
5062
ppo_epochs: 1
51-
adv_estimator: "reinforce"
52-
pg_clip: 0.1
63+
adv_estimator: "grpo"
64+
#pg_clip: 0.1
5365
max_grad_norm: 1.0
5466
#dual_clip_loss: True
5567
init_kl_coef: 0.0
@@ -69,7 +81,7 @@ actor_train:
6981
learning_rate: 1.0e-6
7082
weight_decay: 0
7183
per_device_train_batch_size: 1
72-
gradient_accumulation_steps: 4
84+
gradient_accumulation_steps: 8
7385
warmup_steps: 10
7486
data_args:
7587
template: qwen2_5
@@ -123,51 +135,42 @@ reference:
123135
device_mapping: list(range(0,8))
124136
infer_batch_size: 1
125137

126-
enable_response_mask: True
127-
action_sep: "||"
128-
use_turn_scores: False # important to GAE when applying token-level rewards to token-level advantages. If False, will take the sum of scores as the reward for the last turn.
129-
enable_think: False # False -> no think RL
130-
max_actions_per_traj: 20
131138
reward_normalization:
132-
grouping: tags # 可以tags(env_type)/traj_group_id(group)/batch(rollout_batch)... group_by计算reward/adv
133-
method: identity # asym_clip / identity / mean_std
134-
135-
custom_envs:
136-
WebShopEnv:
137-
env_type: webshop
138-
max_actions_per_traj: ${max_actions_per_traj}
139-
max_steps_per_traj: ${max_actions_per_traj}
140-
env_instruction: |
141-
You are web shopping.
142-
I will give you instructions about what to do.
143-
You have to follow the instructions.
144-
Every round I will give you an observation and a list of available actions, you have to respond an action based on the state and instruction.
145-
You can use search action if search is available.
146-
You can click one of the buttons in clickables.
147-
An action should be of the following structure:
148-
search[keywords]
149-
click[value]
150-
If the action is not valid, perform nothing.
151-
Keywords in search are up to you, but the value in click must be a value in the list of available actions.
152-
Remember that your keywords in search should be carefully designed.
153-
Your response should use the following format:
154-
155-
Thought: I think ...
156-
Action: click[something]
157-
max_tokens: 1024
158-
env_config:
159-
observation_mode: text
139+
grouping: traj_group_id # 可以tags(env_type)/traj_group_id(group)/batch(rollout_batch)... group_by计算reward/adv
140+
method: mean_std # asym_clip / identity / mean_std
160141

161142
train_env_manager:
162143
format_penalty: -0.05
163-
num_env_groups: 64
164-
group_size: 1
144+
num_env_groups: 8
145+
group_size: 8
146+
max_env_num_per_worker: 4
165147
tags: [WebShopEnv]
166-
num_groups_partition: [64] # If not set, all env names divide nums equally. Under the same group, the env config and env seed (prompt) are equal in each generation
148+
num_groups_partition: [8] # If not set, all env names divide nums equally. Under the same group, the env config and env seed (prompt) are equal in each generation
167149

168150
val_env_manager:
169151
num_env_groups: 64
170152
group_size: 1 # should be set to 1 because val temperature is set to 0 and same prompt leads to same output
153+
max_env_num_per_worker: 4
171154
tags: [WebShopEnv]
172155
num_groups_partition: [64] # TODO: If not set, all env names divide nums equally. Under the same group, the env config and env seed (prompt) are equal in each generation
173156

157+
max_tokens_per_step: 128
158+
max_actions_per_traj: 20
159+
action_pattern: <answer>(.*?)</answer>
160+
think_action_pattern: <think>(.*?)</think>\s*<answer>(.*?)</answer>
161+
user_prompt_no_think_format: <answer> [your answer] </answer>
162+
user_prompt_think_format: <think> [Your thoughts] </think> <answer> [your answer] </answer>
163+
added_text_no_think: <answer>
164+
added_text_think: <think>
165+
166+
custom_envs:
167+
WebShopEnv:
168+
env_type: webshop
169+
max_tokens_per_step: ${max_tokens_per_step}
170+
user_prompt_format: ${user_prompt_no_think_format}
171+
added_text: ${added_text_no_think}
172+
env_manager_cls: roll.pipeline.agentic.env_manager.traj_env_manager.TrajEnvManager
173+
use_thread_lock: true
174+
env_config:
175+
observation_mode: text
176+
max_steps: ${max_actions_per_traj}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
defaults:
2+
- ../config/envs@_here_
3+
- ../config/deepspeed_zero@_here_
4+
- ../config/deepspeed_zero2@_here_
5+
- ../config/deepspeed_zero3@_here_
6+
- ../config/deepspeed_zero3_cpuoffload@_here_
7+
8+
hydra:
9+
run:
10+
dir: .
11+
output_subdir: null
12+
13+
exp_name: "agentic_pipeline_webshop_async"
14+
seed: 42
15+
logging_dir: ./output/logs
16+
output_dir: ./output
17+
render_save_dir: ./output/render
18+
system_envs:
19+
USE_MODELSCOPE: '1'
20+
21+
#track_with: wandb
22+
#tracker_kwargs:
23+
# api_key:
24+
# project: roll-agentic
25+
# name: ${exp_name}_webshop
26+
# notes: "agentic_pipeline"
27+
# tags:
28+
# - agentic
29+
# - roll
30+
# - baseline
31+
32+
#track_with: swanlab
33+
#tracker_kwargs:
34+
# login_kwargs:
35+
# api_key: your_api_key
36+
# project: roll-agentic
37+
# logdir: debug
38+
# experiment_name: ${exp_name}
39+
# tags:
40+
# - roll
41+
# - agentic
42+
# - debug
43+
44+
track_with: tensorboard
45+
tracker_kwargs:
46+
log_dir: /data/oss_bucket_0/yali/llm/tensorboard/roll_exp/agentic_webshop
47+
48+
num_gpus_per_node: 8
49+
50+
max_steps: 1024
51+
save_steps: 10000
52+
logging_steps: 1
53+
eval_steps: 10
54+
resume_from_checkpoint: false
55+
56+
async_generation_ratio: 1
57+
58+
rollout_batch_size: 64
59+
val_batch_size: 64
60+
sequence_length: 8192
61+
62+
reward_clip: 20
63+
advantage_clip: 0.2 # 0.1-0.3
64+
ppo_epochs: 1
65+
adv_estimator: "grpo"
66+
#pg_clip: 0.1
67+
max_grad_norm: 1.0
68+
#dual_clip_loss: True
69+
init_kl_coef: 0.0
70+
whiten_advantages: true
71+
entropy_loss_coef: 0
72+
73+
pretrain: Qwen/Qwen2.5-7B-Instruct
74+
reward_pretrain: Qwen/Qwen2.5-7B-Instruct
75+
76+
actor_train:
77+
model_args:
78+
attn_implementation: fa2
79+
disable_gradient_checkpointing: false
80+
dtype: bf16
81+
model_type: ~
82+
training_args:
83+
learning_rate: 1.0e-6
84+
weight_decay: 0
85+
per_device_train_batch_size: 1
86+
gradient_accumulation_steps: 16
87+
warmup_steps: 10
88+
data_args:
89+
template: qwen2_5
90+
strategy_args:
91+
strategy_name: megatron_train
92+
strategy_config:
93+
tensor_model_parallel_size: 1
94+
context_parallel_size: 1
95+
pipeline_model_parallel_size: 1
96+
expert_model_parallel_size: 1
97+
use_distributed_optimizer: true
98+
recompute_granularity: full
99+
max_grad_norm: ${max_grad_norm}
100+
device_mapping: list(range(0,4))
101+
infer_batch_size: 1
102+
103+
actor_infer:
104+
model_args:
105+
disable_gradient_checkpointing: true
106+
dtype: bf16
107+
generating_args:
108+
max_new_tokens: 1024 # single-turn response length
109+
top_p: 0.99
110+
top_k: 100
111+
num_beams: 1
112+
temperature: 0.99
113+
num_return_sequences: 1
114+
data_args:
115+
template: qwen2_5
116+
strategy_args:
117+
strategy_name: vllm
118+
strategy_config:
119+
gpu_memory_utilization: 0.8
120+
block_size: 16
121+
load_format: auto
122+
device_mapping: list(range(4,8))
123+
infer_batch_size: 1
124+
125+
reference:
126+
model_args:
127+
attn_implementation: fa2
128+
disable_gradient_checkpointing: true
129+
dtype: bf16
130+
model_type: ~
131+
data_args:
132+
template: qwen2_5
133+
strategy_args:
134+
strategy_name: hf_infer
135+
strategy_config: ~
136+
device_mapping: list(range(0,4))
137+
infer_batch_size: 1
138+
139+
reward_normalization:
140+
grouping: traj_group_id # 可以tags(env_type)/traj_group_id(group)/batch(rollout_batch)... group_by计算reward/adv
141+
method: mean_std # asym_clip / identity / mean_std
142+
143+
train_env_manager:
144+
format_penalty: -0.05
145+
num_env_groups: 8
146+
group_size: 8
147+
max_env_num_per_worker: 4
148+
tags: [WebShopEnv]
149+
num_groups_partition: [8] # If not set, all env names divide nums equally. Under the same group, the env config and env seed (prompt) are equal in each generation
150+
151+
val_env_manager:
152+
num_env_groups: 64
153+
group_size: 1 # should be set to 1 because val temperature is set to 0 and same prompt leads to same output
154+
max_env_num_per_worker: 4
155+
tags: [WebShopEnv]
156+
num_groups_partition: [64] # TODO: If not set, all env names divide nums equally. Under the same group, the env config and env seed (prompt) are equal in each generation
157+
158+
max_tokens_per_step: 128
159+
max_actions_per_traj: 20
160+
action_pattern: <answer>(.*?)</answer>
161+
think_action_pattern: <think>(.*?)</think>\s*<answer>(.*?)</answer>
162+
user_prompt_no_think_format: <answer> [your answer] </answer>
163+
user_prompt_think_format: <think> [Your thoughts] </think> <answer> [your answer] </answer>
164+
added_text_no_think: <answer>
165+
added_text_think: <think>
166+
167+
custom_envs:
168+
WebShopEnv:
169+
env_type: webshop
170+
max_tokens_per_step: ${max_tokens_per_step}
171+
user_prompt_format: ${user_prompt_no_think_format}
172+
added_text: ${added_text_no_think}
173+
env_manager_cls: roll.pipeline.agentic.env_manager.traj_env_manager.TrajEnvManager
174+
use_thread_lock: true
175+
env_config:
176+
observation_mode: text
177+
max_steps: ${max_actions_per_traj}

requirements_common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ codetiming
2323
more_itertools
2424

2525
wandb
26+
swanlab
2627

2728
math-verify
2829
openai

roll/agentic/env/parse_action_utils.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ def default_parser_action_func(text, action_pattern, action_lookup, special_toke
1515
think_content, action_content = "", match.group(1)
1616
else:
1717
think_content, action_content = match.group(1), match.group(2)
18-
action_content_strip = action_content
19-
think_content_strip = think_content
20-
for special_token in special_token_list:
21-
action_content_strip = action_content.replace(special_token, "").strip()
22-
think_content_strip = think_content.replace(special_token, "").strip()
18+
action_content_strip = action_content.strip()
19+
think_content_strip = think_content.strip()
2320

24-
rev_action_lookup = {v.lower(): k for k, v in action_lookup.items()}
21+
if special_token_list is not None:
22+
for special_token in special_token_list:
23+
action_content_strip = action_content.replace(special_token, "").strip()
24+
think_content_strip = think_content.replace(special_token, "").strip()
2525

26-
if action_content_strip.lower() in rev_action_lookup:
27-
action = rev_action_lookup[action_content_strip.lower()]
26+
action = action_content_strip
27+
if action_lookup is not None:
28+
action = None
29+
rev_action_lookup = {v.lower(): k for k, v in action_lookup.items()}
30+
if action_content_strip.lower() in rev_action_lookup:
31+
action = rev_action_lookup[action_content_strip.lower()]
2832

2933
action_info = {
3034
"action": action,

roll/agentic/env/webshop/config.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
from webshop_minimal import init_basedir
66
from webshop_minimal.utils import DEFAULT_FILE_PATH
77

8+
from roll.agentic.env.base import BaseEnvConfig
9+
810
init_basedir() # init DEFAULT_FILE_PATH, hardcoded dataset to small
911

1012

1113
@dataclass
12-
class WebShopEnvConfig:
14+
class WebShopEnvConfig(BaseEnvConfig):
1315
"""Configuration for WebAgentText environment"""
1416

1517
# dataset: str = field(default="small", metadata={"description": "Small or full dataset"})
@@ -34,3 +36,14 @@ class WebShopEnvConfig:
3436
show_attrs: bool = field(
3537
default=False, metadata={"description": "SimServer arg: Whether to show additional attributes"}
3638
)
39+
40+
max_steps: int = 10
41+
env_instruction: str = ("You are web shopping. I will give you instructions about what to do. "
42+
"You have to follow the instructions. Every round I will give you an observation and "
43+
"a list of available actions, you have to respond an action based on the state and instruction. "
44+
"You can use search action if search is available. You can click one of the buttons in clickables. "
45+
"An action should be of the following structure: search[keywords] click[value] If the action is not valid, perform nothing. "
46+
"Keywords in search are up to you, but the value in click must be a value in the list of available actions. "
47+
"Remember that your keywords in search should be carefully designed. "
48+
"Your response should use the following format Thought: I think ... Action: click[something]")
49+
action_pattern: str = r"<answer>(.*?)</answer>"

0 commit comments

Comments
 (0)