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

Replace print with tf.print to prevent side effects in tf.function #21

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

Conversation

allrob23
Copy link

Description:

This PR updates tf_func and tf_func2 by replacing all Python print statements with tf.print. Since these functions are decorated with @relaxed_tf_function (a wrapper for TensorFlow’s tf.function), using standard print statements can lead to unexpected behavior due to TensorFlow’s tracing mechanism. According to TensorFlow’s documentation:

Side effects, like printing, […] can behave unexpectedly inside a tf.function, sometimes executing twice or not at all. […] TensorFlow APIs like tf.print […] are the best way to ensure your code will be executed by the TensorFlow runtime with each call. (Source)

Changes Made:

• Replaced all print statements with tf.print.

This ensures that debug outputs execute consistently and aligns with TensorFlow’s best practices for side-effect management within tf.function.

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.

1 participant