Skip to content
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

Update rl_trainer.py #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions hw1/cs285/infrastructure/rl_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ def collect_training_trajectories(
# ``` return loaded_paths, 0, None ```

# (2) collect `self.params['batch_size']` transitions
if itr == 0:
with open(load_initial_expertdata, "rb") as f:
loaded_paths = pickle.load(f)
return loaded_paths, 0, None

# TODO collect `batch_size` samples to be used for training
# HINT1: use sample_trajectories from utils
Expand All @@ -187,12 +191,12 @@ def train_agent(self):
# TODO sample some data from the data buffer
# HINT1: use the agent's sample function
# HINT2: how much data = self.params['train_batch_size']
ob_batch, ac_batch, re_batch, next_ob_batch, terminal_batch = TODO
ob_batch, ac_batch, re_batch, next_ob_batch, terminal_batch = self.agent.sample(self.params['train_batch_size'])

# TODO use the sampled data to train an agent
# HINT: use the agent's train function
# HINT: keep the agent's training log for debugging
train_log = TODO
train_log = self.agent.train(ob_batch, ac_batch, re_batch, next_ob_batch, terminal_batch)
all_logs.append(train_log)
return all_logs

Expand All @@ -202,7 +206,8 @@ def do_relabel_with_expert(self, expert_policy, paths):
# TODO relabel collected obsevations (from our policy) with labels from an expert policy
# HINT: query the policy (using the get_action function) with paths[i]["observation"]
# and replace paths[i]["action"] with these expert labels

for i in range(len(paths)):
paths[i]["action"] = expert_policy.get_action(paths[i]["observation"]).detach().numpy()
return paths

####################################
Expand Down