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

Mixed precision tutorial does not work for custom training loop #20894

Open
CaptainDario opened this issue Feb 12, 2025 · 0 comments
Open

Mixed precision tutorial does not work for custom training loop #20894

CaptainDario opened this issue Feb 12, 2025 · 0 comments
Assignees

Comments

@CaptainDario
Copy link

CaptainDario commented Feb 12, 2025

I am trying to follow the mixed precision tutorial when using a custom training loop, specifically

@tf.function
def train_step(x, y):
  with tf.GradientTape() as tape:
    predictions = model(x)
    loss = loss_object(y, predictions)
    scaled_loss = optimizer.get_scaled_loss(loss)
  scaled_gradients = tape.gradient(scaled_loss, model.trainable_variables)
  gradients = optimizer.get_unscaled_gradients(scaled_gradients)
  optimizer.apply_gradients(zip(gradients, model.trainable_variables))
  return loss

When trying to invoke, get_scaled_loss and get_unscaled_gradients an exception is thrown that those methods are undefined.

Maybe this is related to #19244

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

No branches or pull requests

2 participants