File tree Expand file tree Collapse file tree 2 files changed +15
-15
lines changed
keras/optimizers/optimizer_experimental Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -101,18 +101,25 @@ def _create_iteration_variable(self):
101
101
def _process_kwargs (self , kwargs ):
102
102
# Remove the `is_legacy_optimizer` arg, which is for serialization only.
103
103
kwargs .pop ("is_legacy_optimizer" , None )
104
+ lr = kwargs .pop ("lr" , None )
105
+ if lr :
106
+ logging .warning (
107
+ "`lr` is deprecated, please use "
108
+ "`learning_rate` instead, or use the legacy optimizer, e.g.,"
109
+ f"tf.keras.optimizers.legacy.{ self .__class__ .__name__ } ."
110
+ )
104
111
legacy_kwargs = {
105
- "lr" ,
106
112
"decay" ,
107
- "gradient_transformers" ,
108
113
"gradient_aggregator" ,
114
+ "gradient_transformers" ,
109
115
}
110
116
for k in kwargs :
111
117
if k in legacy_kwargs :
112
- logging .warning (
113
- "%s is deprecated in `optimizer_experimental.Optimizer`"
114
- ", please check the docstring for valid arguments." ,
115
- k ,
118
+ raise ValueError (
119
+ f"{ k } is deprecated in the new Keras optimizer, please"
120
+ "check the docstring for valid arguments, or use the "
121
+ "legacy optimizer, e.g., "
122
+ f"tf.keras.optimizers.legacy.{ self .__class__ .__name__ } ."
116
123
)
117
124
else :
118
125
raise TypeError (
Original file line number Diff line number Diff line change 4
4
"""
5
5
6
6
import os
7
- import re
8
7
9
8
import numpy as np
10
9
import tensorflow .compat .v2 as tf
11
- from absl import logging
12
10
from absl .testing import parameterized
13
11
14
12
import keras
@@ -209,14 +207,9 @@ def testClipGlobalNorm(self):
209
207
clipped_grad = optimizer ._clip_gradients (grad )
210
208
self .assertAllClose (clipped_grad [0 ], [0.5 , 0.5 ])
211
209
212
- def testPassingLegacyArgsRaiseWarning (self ):
213
- with self .assertLogs (level = "WARNING" ) as log_output :
214
- logging .set_verbosity (logging .WARNING )
210
+ def testPassingLegacyArgsRaiseError (self ):
211
+ with self .assertRaisesRegex (ValueError , "decay is deprecated*" ):
215
212
_ = adam_new .Adam (clipnorm = 1 , decay = 0.5 )
216
- expected_log = "decay is deprecated in"
217
- output = log_output [0 ][0 ].message
218
-
219
- self .assertTrue (re .search (expected_log , output ))
220
213
221
214
def testPassingLegacyClipnorm (self ):
222
215
optimizer = adam_new .Adam (clipnorm = 1 )
You can’t perform that action at this time.
0 commit comments