Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Performance issue in baselines/train.py #246

Open
DLPerf opened this issue Feb 24, 2023 · 1 comment
Open

Performance issue in baselines/train.py #246

DLPerf opened this issue Feb 24, 2023 · 1 comment

Comments

@DLPerf
Copy link

DLPerf commented Feb 24, 2023

Hello! Our static bug checker has found a performance issue in baselines/train.py: train_step is repeatedly called in a for loop, but there is a tf.function decorated function train_inner_step defined and called in train_step.

In that case, when train_step is called in a loop, the function train_inner_step will create a new graph every time, and that can trigger tf.function retracing warning.

Similarly,
train_inner_step is defined in train_model and the outer function is repeatedly called here and here.

Here is the tensorflow document to support it.

Briefly, for better efficiency, it's better to use:

@tf.function
def inner():
    pass

def outer():
    inner()  

than:

def outer():
    @tf.function
    def inner():
        pass
    inner()

Looking forward to your reply.

@DLPerf
Copy link
Author

DLPerf commented Mar 6, 2023

But there are some variables in the inner function depending on the outer function, code may be more complex if changes are made. Is it necessary? Do you have any idea?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant