Skip to content

Commit f597d2d

Browse files
committed
[API Compat] Add aliases for apis in paddle.optimizer.lr
1 parent fce4808 commit f597d2d

3 files changed

Lines changed: 111 additions & 1 deletion

File tree

python/paddle/optim/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from . import lr_scheduler
1516
from .adadelta import Adadelta
1617
from .adagrad import Adagrad
1718
from .adam import Adam
@@ -42,4 +43,5 @@
4243
"RMSProp",
4344
"Rprop",
4445
"SGD",
46+
"lr_scheduler",
4547
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from paddle.optimizer.lr import (
16+
CosineAnnealingDecay as CosineAnnealingLR, # noqa: F401
17+
CosineAnnealingWarmRestarts as CosineAnnealingWarmRestarts,
18+
CyclicLR as CyclicLR,
19+
ExponentialDecay as ExponentialLR, # noqa: F401
20+
LambdaDecay as LambdaLR, # noqa: F401
21+
LinearLR as LinearLR,
22+
LRScheduler as LRScheduler,
23+
MultiplicativeDecay as MultiplicativeLR, # noqa: F401
24+
MultiStepDecay as MultiStepLR, # noqa: F401
25+
OneCycleLR as OneCycleLR,
26+
PiecewiseDecay as ConstantLR, # noqa: F401
27+
ReduceOnPlateau as ReduceLROnPlateau, # noqa: F401
28+
StepDecay as StepLR, # noqa: F401
29+
)

test/legacy_test/test_api_alias.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,91 @@ def setUp(self):
187187
paddle.optim.sgd.SGD,
188188
None,
189189
),
190+
(
191+
paddle.optimizer.lr.PiecewiseDecay,
192+
paddle.optim.lr_scheduler.ConstantLR,
193+
None,
194+
None,
195+
),
196+
(
197+
paddle.optimizer.lr.CosineAnnealingDecay,
198+
paddle.optim.lr_scheduler.CosineAnnealingLR,
199+
None,
200+
None,
201+
),
202+
(
203+
paddle.optimizer.lr.CosineAnnealingWarmRestarts,
204+
paddle.optim.lr_scheduler.CosineAnnealingWarmRestarts,
205+
None,
206+
None,
207+
),
208+
(
209+
paddle.optimizer.lr.CyclicLR,
210+
paddle.optim.lr_scheduler.CyclicLR,
211+
None,
212+
None,
213+
),
214+
(
215+
paddle.optimizer.lr.ExponentialDecay,
216+
paddle.optim.lr_scheduler.ExponentialLR,
217+
None,
218+
None,
219+
),
220+
(
221+
paddle.optimizer.lr.LRScheduler,
222+
paddle.optim.lr_scheduler.LRScheduler,
223+
None,
224+
None,
225+
),
226+
(
227+
paddle.optimizer.lr.LambdaDecay,
228+
paddle.optim.lr_scheduler.LambdaLR,
229+
None,
230+
None,
231+
),
232+
(
233+
paddle.optimizer.lr.LinearLR,
234+
paddle.optim.lr_scheduler.LinearLR,
235+
None,
236+
None,
237+
),
238+
(
239+
paddle.optimizer.lr.MultiStepDecay,
240+
paddle.optim.lr_scheduler.MultiStepLR,
241+
None,
242+
None,
243+
),
244+
(
245+
paddle.optimizer.lr.MultiplicativeDecay,
246+
paddle.optim.lr_scheduler.MultiplicativeLR,
247+
None,
248+
None,
249+
),
250+
(
251+
paddle.optimizer.lr.OneCycleLR,
252+
paddle.optim.lr_scheduler.OneCycleLR,
253+
None,
254+
None,
255+
),
256+
(
257+
paddle.optimizer.lr.ReduceOnPlateau,
258+
paddle.optim.lr_scheduler.ReduceLROnPlateau,
259+
None,
260+
None,
261+
),
262+
(
263+
paddle.optimizer.lr.StepDecay,
264+
paddle.optim.lr_scheduler.StepLR,
265+
None,
266+
None,
267+
),
190268
]
191269

192270
def test_compatibility(self):
193271
for pairs in self.api_map:
194272
self.assertTrue(pairs[0], pairs[1])
195-
self.assertTrue(pairs[0], pairs[2])
273+
if pairs[2] is not None:
274+
self.assertTrue(pairs[0], pairs[2])
196275
if pairs[3] is not None:
197276
self.assertTrue(pairs[0], pairs[3])
198277

0 commit comments

Comments
 (0)