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

Avoid unnecessary retracing #109

Merged
merged 2 commits into from
Nov 14, 2022
Merged

Avoid unnecessary retracing #109

merged 2 commits into from
Nov 14, 2022

Conversation

malihass
Copy link
Collaborator

@malihass malihass commented Nov 7, 2022

The calc_loss function should not be a tf.function since its behavior changes depending on whether discriminator or generator, or both are trained.
With the tf.function on, function retracing occurs (we see messages like WARNING:tensorflow:5 out of the last 18 calls to <function Sup3rGan.calc_loss at 0x7facf82f8290> triggered tf.function retracing...).

With tf.function off, no retracing occurs. I could also see a small speed up when running on my machine.

To reproduce results, run the following snippet in tests/

from test_train_gan import *


import time
time_start = time.time()
test_train_st_weight_update(n_epoch=5, log=True)
time_end = time.time()
print("Total Time = %g" % (time_end - time_start))

Copy link
Member

@grantbuster grantbuster left a comment

Choose a reason for hiding this comment

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

Fine by me! What kind of speedup are you seeing?

@bnb32 bnb32 assigned bnb32 and unassigned bnb32 Nov 11, 2022
@malihass
Copy link
Collaborator Author

I ran the snippet I showed 5 times to get statistics more rigorously about the execution time.
With the PR : 124.05 +/- 9.17 s
Without the PR: 133.199 +/- 7.47359s

@grantbuster
Copy link
Member

Gotcha, thanks! I keep hoping for a weird error i made that results in a 10x speedup lol.

@bnb32 bnb32 merged commit f8a3762 into NREL:main Nov 14, 2022
github-actions bot pushed a commit that referenced this pull request Nov 14, 2022
Avoid unnecessary retracing
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.

None yet

3 participants