Skip to content

Commit

Permalink
Small fixes for resampling (sorry, last change)
Browse files Browse the repository at this point in the history
  • Loading branch information
daphne-cornelisse committed Dec 13, 2024
1 parent b6532b8 commit a222b35
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
9 changes: 5 additions & 4 deletions baselines/ippo/config/ippo_ff_puffer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ environment: # Overrides default environment configs (see pygpudrive/env/config.
remove_non_vehicles: true # If false, all agents are included (vehicles, pedestrians, cyclists)
use_lidar_obs: false # NOTE: Setting this to true currently turns of the other observation types
reward_type: "weighted_combination"
collision_weight: -0.03
off_road_weight: -0.03
collision_weight: -0.035
off_road_weight: -0.035
goal_achieved_weight: 1.0
dynamics_model: "classic"
collision_behavior: "ignore" # Options: "remove", "stop"
Expand Down Expand Up @@ -48,12 +48,13 @@ train:
# # # Data sampling # # #
resample_scenes: false
resample_criterion: "global_step"
resample_interval: 3_000_000
resample_interval: 5_000_000
resample_limit: 10000 # Resample until the limit is reached; set to a large number to continue resampling indefinitely
resample_mode: "random" # Options: random

# # # PPO # # #
torch_deterministic: false
total_timesteps: 500_000_000
total_timesteps: 1_000_000_000
batch_size: 131_072
minibatch_size: 16_384
learning_rate: 3e-4
Expand Down
21 changes: 3 additions & 18 deletions integrations/rl/puffer/ppo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
from integrations.rl.puffer.c_gae import compute_gae
from integrations.rl.puffer.logging import print_dashboard, abbreviate

global_steps_list = []
perc_collisions_list = []
perc_offroad_list = []
perc_goal_achieved_list = []
time_list = []


def create(config, vecenv, policy, optimizer=None, wandb=None):
seed_everything(config.seed, config.torch_deterministic)
Expand Down Expand Up @@ -110,11 +104,11 @@ def evaluate(data):
# Resample data logic
if data.config.resample_scenes:
if (
(data.config.resample_limit is None or data.resample_counter < data.config.resample_limit)
data.resample_counter < int(data.config.resample_limit)
and data.config.resample_criterion == "global_step"
and data.resample_buffer >= data.config.resample_interval
):
print(f"Resampling scenarios: {data.resample_counter + 1}" +
print(f"Resampling scenarios: {data.resample_counter + 1:,}" +
(f" / {data.config.resample_limit}" if data.config.resample_limit is not None else ""))

# Sample new batch of scenarios
Expand All @@ -124,17 +118,8 @@ def evaluate(data):
if data.config.resample_limit is not None: # Increment counter only if there is a limit
data.resample_counter += 1

data.vecenv.rendering_in_progress = {
env_idx: False for env_idx in range(data.config.render_k_scenarios)
}
data.vecenv.was_rendered_in_rollout = {
env_idx: False for env_idx in range(data.config.render_k_scenarios)
}
data.vecenv.wandb_obj = data.wandb
data.vecenv.frames = {
env_idx: []
for env_idx in range(data.config.render_k_scenarios)
}
data.vecenv.clear_render_storage()

config, profile, experience = data.config, data.profile, data.experience

Expand Down
4 changes: 2 additions & 2 deletions integrations/rl/puffer/puffer_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ def render(self):
self.episode_lengths[render_env_idx, :][0] == 0
and not self.was_rendered_in_rollout[render_env_idx]
):
print(f"Render at iter: { self.iters}")
self.rendering_in_progress[render_env_idx] = True

# Continue rendering if in progress
Expand Down Expand Up @@ -491,4 +490,5 @@ def clear_render_storage(self):
for env_idx in range(self.train_config.render_k_scenarios):
self.frames[env_idx] = []
self.rendering_in_progress[env_idx] = False
self.was_rendered_in_rollout[env_idx] = True
self.was_rendered_in_rollout[env_idx] = False

0 comments on commit a222b35

Please sign in to comment.