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

Reinitialize GAIL dataloader after saving #847

Merged
merged 12 commits into from
May 14, 2020
Merged

Conversation

araffin
Copy link
Collaborator

@araffin araffin commented May 9, 2020

Description

Motivation and Context

  • I have raised an issue to propose this change (required for new features and bug fixes)

closes #830

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)

Checklist:

  • I've read the CONTRIBUTION guide (required)
  • I have updated the changelog accordingly (required).
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.
  • I have ensured pytest and pytype both pass (by running make pytest and make type).

AdamGleave
AdamGleave previously approved these changes May 10, 2020
Copy link
Collaborator

@AdamGleave AdamGleave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative approach would be to implement a custom pickler in ExpertDataset and drop the prepare_pickle method entirely.

I think something like this should do the trick in ExpertDataset:

def __getstate__(self):
    state = dict(__dict__)
    del state['dataloader']
    del state['train_loader']
    del state['val_loader']
    return state

That said, since I believe the intention is to drop TRPO MPI and GAIL in Stable Baselines3, I'm coding this as approve -- up to you if you want to spend the time to refactor this.

@araffin
Copy link
Collaborator Author

araffin commented May 11, 2020

An alternative approach would be to implement a custom pickler in ExpertDataset and drop the prepare_pickle method entirely.

very good point and much cleaner, I will do that ;)

Copy link
Collaborator

@AdamGleave AdamGleave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the revision, few minor suggested changes.

Excludes processes that are not pickleable
"""
# Remove processes in order to pickle the dataset.
excluded = {'dataloader', 'train_loader', 'val_loader'}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making this a module or class constant since it's used in __getstate__ and __setstate__?

"""
# Remove processes in order to pickle the dataset.
excluded = {'dataloader', 'train_loader', 'val_loader'}
state = {key:val for key, val in self.__dict__.items() if key not in excluded}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our codebase normally has spaces after :

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, but I'm not sure for list comprehension... I will check

dataset = ExpertDataset(expert_path=EXPERT_PATH_PENDULUM, traj_limitation=10,
sequential_preprocessing=True, verbose=0)
model = GAIL("MlpPolicy", "Pendulum-v0", dataset)
checkpoint_callback = CheckpointCallback(save_freq=500, save_path='./logs/gail/', name_prefix='gail')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe use a TemporaryDirectory instance rather than a hardcoded path? This would remove the need to rmtree afterwards as the contextmanager automatically cleans it up.

We use hardcoded paths all over the tests, but one day I dream of changing this -- it's caused me headaches in the past from race conditions between tests when trying to parallelize.

@araffin
Copy link
Collaborator Author

araffin commented May 12, 2020

@AdamGleave I took advantage of your comments to reformat some part of the code (using flake8 to spot the issues ;))

I may do a PR soon to sync what I'm doing with SB3.

Copy link
Collaborator

@AdamGleave AdamGleave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM apart from the test failure

@araffin
Copy link
Collaborator Author

araffin commented May 13, 2020

Tests fail because of python 3.5 :/ (it runs locally with python 3.6). Will fix that...

Copy link
Collaborator

@AdamGleave AdamGleave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@araffin araffin merged commit c4c31cb into master May 14, 2020
@araffin araffin deleted the fix/gail-callbacks branch May 14, 2020 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Question] Callback for GAIL
2 participants