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 ppo.save to include iteration in "current" save file content. #46

Open
wants to merge 1 commit into
base: master
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
9 changes: 5 additions & 4 deletions rocket_learn/ppo.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _iter():
iteration += 1

if save_dir:
self.save(os.path.join(save_dir, self.logger.project + "_" + "latest"), -1, save_jit)
self.save(os.path.join(save_dir, self.logger.project + "_" + "latest"), iteration, save_actor_jit=save_jit, is_latest=True)
if iteration % iterations_per_save == 0:
self.save(current_run_dir, iteration, save_jit) # noqa

Expand Down Expand Up @@ -485,18 +485,19 @@ def load(self, load_location, continue_iterations=True):
self.total_steps = checkpoint["total_steps"]
print("Continuing training at iteration " + str(self.starting_iteration))

def save(self, save_location, current_step, save_actor_jit=False):
def save(self, save_location, current_step, save_actor_jit=False, is_latest=False,):
"""
Save the model weights, optimizer values, and metadata
:param save_location: where to save
:param current_step: the current iteration when saved. Use to later continue training
:param save_actor_jit: save the policy network as a torch jit file for rlbot use
:param is_latest: if this file is the "latest" checkpoint, used to decide if real checkpoint number should be used in filename
"""

version_str = str(self.logger.project) + "_" + str(current_step)
version_str = str(self.logger.project) + "_" + (str(current_step) if not is_latest else "c")
version_dir = save_location + "\\" + version_str

os.makedirs(version_dir, exist_ok=current_step == -1)
os.makedirs(version_dir, exist_ok=is_latest)

torch.save({
'epoch': current_step,
Expand Down