Skip to content

Commit b173f53

Browse files
jingyushenPanAndy
authored andcommitted
(feat): add sokoban sandbox env and scripts
1 parent d790bf5 commit b173f53

6 files changed

Lines changed: 522 additions & 0 deletions

File tree

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
defaults:
2+
- ../config/traj_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"
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}_sokoban
26+
# notes: "agentic_pipeline"
27+
# tags:
28+
# - agentic
29+
# - roll
30+
# - baseline
31+
32+
track_with: tensorboard
33+
tracker_kwargs:
34+
log_dir: /data/tensorboard/roll_exp/agentic_sandbox
35+
36+
checkpoint_config:
37+
type: file_system
38+
output_dir: /data/cpfs_0/rl_examples/models/${exp_name}
39+
40+
num_gpus_per_node: 8
41+
42+
max_steps: 1024
43+
save_steps: 10000
44+
logging_steps: 1
45+
eval_steps: 10
46+
resume_from_checkpoint: false
47+
48+
rollout_batch_size: 32
49+
val_batch_size: 32
50+
sequence_length: 4096
51+
52+
advantage_clip: 0.2
53+
ppo_epochs: 1
54+
adv_estimator: "grpo"
55+
#pg_clip: 0.1
56+
#dual_clip_loss: True
57+
init_kl_coef: 0.0
58+
whiten_advantages: true
59+
entropy_loss_coef: 0
60+
max_grad_norm: 1.0
61+
62+
pretrain: Qwen/Qwen2.5-0.5B-Instruct
63+
reward_pretrain: Qwen/Qwen2.5-0.5B-Instruct
64+
65+
actor_train:
66+
model_args:
67+
attn_implementation: fa2
68+
disable_gradient_checkpointing: false
69+
dtype: bf16
70+
model_type: ~
71+
training_args:
72+
learning_rate: 1.0e-6
73+
weight_decay: 0
74+
per_device_train_batch_size: 1
75+
gradient_accumulation_steps: 16
76+
warmup_steps: 10
77+
lr_scheduler_type: cosine
78+
data_args:
79+
template: qwen2_5
80+
strategy_args:
81+
# strategy_name: deepspeed_train
82+
# strategy_config: ${deepspeed_zero3}
83+
strategy_name: megatron_train
84+
strategy_config:
85+
tensor_model_parallel_size: 1
86+
pipeline_model_parallel_size: 1
87+
expert_model_parallel_size: 1
88+
use_distributed_optimizer: true
89+
recompute_granularity: full
90+
device_mapping: list(range(1,2))
91+
infer_batch_size: 1
92+
93+
actor_infer:
94+
model_args:
95+
disable_gradient_checkpointing: true
96+
dtype: bf16
97+
generating_args:
98+
max_new_tokens: 32 # single-turn response length
99+
top_p: 0.99
100+
top_k: 100
101+
num_beams: 1
102+
temperature: 0.99
103+
num_return_sequences: 1
104+
data_args:
105+
template: qwen2_5
106+
strategy_args:
107+
strategy_name: vllm
108+
strategy_config:
109+
gpu_memory_utilization: 0.8
110+
block_size: 16
111+
load_format: auto
112+
device_mapping: list(range(1,2))
113+
114+
reference:
115+
model_args:
116+
attn_implementation: fa2
117+
disable_gradient_checkpointing: true
118+
dtype: bf16
119+
model_type: ~
120+
data_args:
121+
template: qwen2_5
122+
strategy_args:
123+
strategy_name: hf_infer
124+
strategy_config: ~
125+
device_mapping: list(range(1,2))
126+
infer_batch_size: 1
127+
128+
reward_normalization:
129+
grouping: traj_group_id # 可以tags(env_type)/traj_group_id(group)/batch(rollout_batch)... group_by计算reward/adv
130+
method: mean_std # asym_clip / identity / mean_std
131+
132+
train_env_manager:
133+
format_penalty: -0.15 # sokoban env penalty_for_step=-0.1
134+
max_env_num_per_worker: 16
135+
num_env_groups: 2
136+
# under the same group, the env config and env seed are ensured to be equal
137+
group_size: 8
138+
tags: [SokobanSandbox]
139+
num_groups_partition: [2] # 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
140+
141+
val_env_manager:
142+
max_env_num_per_worker: 1
143+
num_env_groups: 2
144+
group_size: 1 # should be set to 1 because val temperature is set to 0 and same prompt leads to same output
145+
tags: [SimpleSokoban, LargerSokoban]
146+
num_groups_partition: [1, 1] # 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
147+
148+
# Here, you can override variables defined in the imported envs. max_tokens_per_step: 128 in custom_env.SimpleSokoban, here replaced by 64
149+
max_tokens_per_step: 64
150+
151+
custom_envs:
152+
SimpleSokoban:
153+
${custom_env.SimpleSokoban}
154+
LargerSokoban:
155+
${custom_env.LargerSokoban}
156+
SokobanDifferentGridVocab:
157+
${custom_env.SokobanDifferentGridVocab}
158+
FrozenLake:
159+
${custom_env.FrozenLake}
160+
FrozenLakeThink:
161+
${custom_env.FrozenLakeThink}
162+
SokobanSandbox:
163+
env_type: sokoban_sandbox
164+
env_config:
165+
base_url: 'http://localhost:8080' # change to your own service address if needed
166+
max_steps: ${max_actions_per_traj}
167+
max_tokens_per_step: ${max_tokens_per_step}
168+
env_manager_cls: ${env_manager_cls}
169+
use_thread_lock: true
170+
agent_system_template: "You are an expert Sokoban-playing agent. Your only task is to output the next action like <answer>Right</answer>. Do not output any other text, reasoning, or explanations."
171+
agent_template: |
172+
Current State:
173+
{observation}
174+
Turn {turn_idx}:
175+
{suffix}
176+
Respond with one action from the available list.
177+
Format: <answer>ACTION</answer>
178+
Choose your action.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set +x
3+
4+
CONFIG_PATH=$(basename $(dirname $0))
5+
export PYTHONPATH="$PWD:$PYTHONPATH"
6+
python examples/start_agentic_pipeline.py --config_path $CONFIG_PATH --config_name agent_val_sokoban_sandbox
7+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set +x
3+
4+
5+
echo "Stopping existing services..."
6+
pkill -9 -f "admin --env local" 2>/dev/null || true
7+
lsof -ti:8080 | xargs kill -9 2>/dev/null || true
8+
sleep 2
9+
10+
echo "Starting ROCK service..."
11+
cd /workspace/ROCK && nohup admin --env local > /tmp/rock_service.log 2>&1 &
12+
13+
echo "Waiting for ROCK service to be ready..."
14+
sleep 5
15+
16+
cd $PWD
17+
18+
CONFIG_PATH=$(basename $(dirname $0))
19+
export PYTHONPATH="$PWD:$PYTHONPATH"
20+
python examples/start_agentic_pipeline.py --config_path $CONFIG_PATH --config_name agent_val_sokoban_sandbox
21+

roll/pipeline/agentic/env/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
gem.register("roll_math", entry_point="roll.pipeline.agentic.env.gem.math_env:MathEnv")
1212
gem.register("roll_code", entry_point="roll.pipeline.agentic.env.gem.code_env:CodeEnv")
1313
gem.register("roll_qa", entry_point="roll.pipeline.agentic.env.gem.qa_env:QaEnv")
14+
gem.register("sokoban_sandbox", entry_point="roll.pipeline.agentic.env.sandbox:SokobanSandboxEnv")
1415

1516

1617
try:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .sokoban_sandbox_env import SokobanSandboxEnv
2+
3+
__all__ = ["SokobanSandboxEnv"]

0 commit comments

Comments
 (0)