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

Optimized polyak updates #106

Merged
merged 16 commits into from
Jul 17, 2020
Merged

Optimized polyak updates #106

merged 16 commits into from
Jul 17, 2020

Conversation

m-rph
Copy link
Contributor

@m-rph m-rph commented Jul 16, 2020

Optimized Polyak updates through in-place operations.

Description

Used th.no_grad to avoid storing the graph. Used in-place th.Tensor.mul and th.add operations to avoid creating extra tensors.

Achieves a speedup of 1.5 and 1.95 for cpus and gpus in google colab over the old version.

Motivation and Context

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

Closes #93

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)
  • Optimization

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 checked the codestyle using make lint
  • [] I have ensured make pytest and make type both pass.

tests/test_utils.py Outdated Show resolved Hide resolved
"""
params = list(params)
target_params = list(target_params)
if params:
Copy link
Member

Choose a reason for hiding this comment

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

maybe an assert instead? "assert len(params) > 0" + meaningful error message?

Copy link
Member

Choose a reason for hiding this comment

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

"the if is simply to get the device" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never mind my previous reply, the if was garbage left from a different implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous implementation used the first parameter to get the device and create a tensor with tau, but this version doesn't need it. I forgot about it and accidentally left it in.

Copy link
Member

@araffin araffin left a comment

Choose a reason for hiding this comment

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

Mostly LGTM ;)
Just minor remark and waiting for the num_threads=1 case ;)

Co-authored-by: Antonin RAFFIN <antonin.raffin@ensta.org>
@araffin
Copy link
Member

araffin commented Jul 17, 2020

@partiallytyped i think we are done with that one, no?

@m-rph
Copy link
Contributor Author

m-rph commented Jul 17, 2020

LGTM :)

@araffin
Copy link
Member

araffin commented Jul 17, 2020

I will just do a quick performance check (one seed on two bullet env with SAC) and then merge ;)

Copy link
Member

@araffin araffin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks =)

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.

[enhancement] Polyak Averaging could be done faster
2 participants