Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/transformers/optimization_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
import tensorflow as tf


if hasattr(tf.keras, "optimizer") and hasattr(tf.keras.optimizer, "legacy"):
Adam = tf.keras.optimizer.legacy.Adam
else:
Adam = tf.keras.optimizers.Adam


class WarmUp(tf.keras.optimizers.schedules.LearningRateSchedule):
"""
Applies a warmup schedule on a given learning rate decay schedule.
Expand Down Expand Up @@ -163,7 +169,7 @@ def create_optimizer(
return optimizer, lr_schedule


class AdamWeightDecay(tf.keras.optimizers.Adam):
class AdamWeightDecay(Adam):
"""
Adam enables L2 weight decay and clip_by_global_norm on gradients. Just adding the square of the weights to the
loss function is *not* the correct way of using L2 regularization/weight decay with Adam, since that will interact
Expand Down