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

Speed up the policy optimization by @tf.function #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ikamensh
Copy link

Using @tf.function allowed for at 2-3 times speedup of policy optimization (longest step) on 'Pendulum-v0' environment. This works by pre-compiling the tensorflow graph on first execution of the function. Please let me know if you need more careful speedup analysis.

@nrontsis
Copy link
Owner

@kyr-pol what do you think?

@kyr-pol
Copy link
Collaborator

kyr-pol commented Feb 15, 2021

That sounds good to me, could you test whether the change is compatible with the safety extension too (like the safe_cars_run script in the examples)? I think I had tried the tf.function decorator when moving the project to tensorflow 2.x, and I faced some issues, which might have been on my part or patched by now. If there are no issues there and the tests are successful, we can go ahead.

@ikamensh
Copy link
Author

I don't have Mujoco license, so I can only test the safe_cars_run.py. From high-level examination it seems not to show much of a difference for two versions: see output per links

https://justpaste.it/5ozx8 vs https://justpaste.it/2ebz3

I must say I am not very sure how to read this output, but the final reward is same order of magnitude. Speedup is not that obvious in that environment.

@kyr-pol
Copy link
Collaborator

kyr-pol commented Feb 18, 2021

Great, that looks totally fine to me, I was mostly worried for tensorflow errors/crashes, this looks reasonable!

@gitAugust
Copy link

Using @tf.function will transfor EagerTensor to Tensor with can't iterate automatically, so there will be errors with safe_swimmer_run.py. Do you gays have some solutions?

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.

4 participants