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

fix api name, english doc, unittest, and remove useless alias of 2.0 lr_scheduler #27686

Merged
merged 11 commits into from
Oct 13, 2020
Merged
7 changes: 0 additions & 7 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,6 @@
from .framework import load #DEFINE_ALIAS
from .framework import DataParallel #DEFINE_ALIAS

from .framework import NoamDecay #DEFINE_ALIAS
from .framework import PiecewiseDecay #DEFINE_ALIAS
from .framework import NaturalExpDecay #DEFINE_ALIAS
from .framework import ExponentialDecay #DEFINE_ALIAS
from .framework import InverseTimeDecay #DEFINE_ALIAS
from .framework import PolynomialDecay #DEFINE_ALIAS
from .framework import CosineDecay #DEFINE_ALIAS
from .framework import set_default_dtype #DEFINE_ALIAS
from .framework import get_default_dtype #DEFINE_ALIAS

Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/dygraph/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def load_dygraph(model_path, **configs):
state_dict = emb.state_dict()
fluid.save_dygraph(state_dict, "paddle_dy")

scheduler = paddle.optimizer.lr_scheduler.NoamLR(
scheduler = paddle.optimizer.lr.NoamDecay(
d_model=0.01, warmup_steps=100, verbose=True)
adam = paddle.optimizer.Adam(
learning_rate=scheduler,
Expand Down
8 changes: 4 additions & 4 deletions python/paddle/fluid/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def close(self):

def _run_parallel(self, program, scope, feed, fetch_list, fetch_var_name,
return_numpy, return_merged):
from paddle.optimizer.lr_scheduler import _LRScheduler
from paddle.optimizer.lr import LRScheduler
exe = program._executor
# TODO(zhenghuihuang): quantization uses Graph in CompiledProgram
# instead of program. We will add support for checking Vars in Graph
Expand Down Expand Up @@ -901,7 +901,7 @@ def _run_parallel(self, program, scope, feed, fetch_list, fetch_var_name,

if hasattr(program._program, 'lr_sheduler'):
lr_sheduler = program._program.lr_sheduler
assert isinstance(lr_sheduler, _LRScheduler), "must be _LRScheduler"
assert isinstance(lr_sheduler, LRScheduler), "must be LRScheduler"
lr_value = lr_sheduler()
lr_var = program._program.global_block().vars[lr_sheduler._var_name]
lr_tensor = _as_lodtensor(lr_value, core.CPUPlace(), lr_var.dtype)
Expand Down Expand Up @@ -1238,7 +1238,7 @@ def _run_impl(self, program, feed, fetch_list, feed_var_name,

def _run_program(self, program, feed, fetch_list, feed_var_name,
fetch_var_name, scope, return_numpy, use_program_cache):
from paddle.optimizer.lr_scheduler import _LRScheduler
from paddle.optimizer.lr import LRScheduler
if feed is None:
feed = {}
elif isinstance(feed, (list, tuple)):
Expand Down Expand Up @@ -1296,7 +1296,7 @@ def _run_program(self, program, feed, fetch_list, feed_var_name,
self._feed_data(program, feed, feed_var_name, scope)
if hasattr(program, 'lr_sheduler'):
assert isinstance(program.lr_sheduler,
_LRScheduler), "must be _LRScheduler"
LRScheduler), "must be LRScheduler"
lr_sheduler = program.lr_sheduler
lr_value = lr_sheduler()
lr_var = program.global_block().vars[lr_sheduler._var_name]
Expand Down
24 changes: 12 additions & 12 deletions python/paddle/fluid/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def __init__(self,
grad_clip=None,
name=None):
# Because of the loop import, so place it in the function body
from paddle.optimizer.lr_scheduler import _LRScheduler
from paddle.optimizer.lr import LRScheduler
self._parameter_list = list(
parameter_list) if parameter_list is not None else None
self._name = name
if framework.in_dygraph_mode():
if not isinstance(learning_rate,
(float, LearningRateDecay, _LRScheduler)):
(float, LearningRateDecay, LRScheduler)):
raise TypeError(
"learning rate should be float or _LRScheduler, got %s here"
"learning rate should be float or LRScheduler, got %s here"
% type(learning_rate))
if self._parameter_list is None:
raise AttributeError(
Expand All @@ -94,9 +94,9 @@ def __init__(self,
break
else:
if not isinstance(learning_rate,
(float, framework.Variable, _LRScheduler)):
(float, framework.Variable, LRScheduler)):
raise TypeError(
"learning rate should be float or _LRScheduler, got %s here"
"learning rate should be float or LRScheduler, got %s here"
% type(learning_rate))

if grad_clip is not None:
Expand Down Expand Up @@ -147,13 +147,13 @@ def state_dict(self):
state_dict = adam.state_dict()

'''
from paddle.optimizer.lr_scheduler import _LRScheduler
from paddle.optimizer.lr import LRScheduler
state_dict = {}
for k, v in self._accumulators.items():
for para_name, var_tmp in v.items():
state_dict[var_tmp.name] = var_tmp
# global step if use lr decay
if isinstance(self._learning_rate, _LRScheduler):
if isinstance(self._learning_rate, LRScheduler):
state_dict["LR_Scheduler"] = self._learning_rate.state_dict()
return state_dict
if isinstance(self._learning_rate, LearningRateDecay):
Expand Down Expand Up @@ -193,7 +193,7 @@ def set_state_dict(self, state_dict):
state_dict = emb.state_dict()
fluid.save_dygraph(state_dict, "paddle_dy")

scheduler = paddle.optimizer.lr_scheduler.NoamLR(
scheduler = paddle.optimizer.lr.NoamDecay(
d_model=0.01, warmup_steps=100, verbose=True)
adam = paddle.optimizer.Adam(
learning_rate=scheduler,
Expand All @@ -203,8 +203,8 @@ def set_state_dict(self, state_dict):

para_state_dict, opti_state_dict = fluid.load_dygraph("paddle_dy")
'''
from paddle.optimizer.lr_scheduler import _LRScheduler
if isinstance(self._learning_rate, _LRScheduler):
from paddle.optimizer.lr import LRScheduler
if isinstance(self._learning_rate, LRScheduler):
self._learning_rate.set_dict(state_dict["LR_Scheduler"])

if isinstance(self._learning_rate, LearningRateDecay):
Expand Down Expand Up @@ -269,8 +269,8 @@ def get_opti_var_name_list(self):
return self._opti_name_list

def _create_global_learning_rate(self):
from paddle.optimizer.lr_scheduler import _LRScheduler
if isinstance(self._learning_rate, _LRScheduler):
from paddle.optimizer.lr import LRScheduler
if isinstance(self._learning_rate, LRScheduler):
lr_var = self._global_learning_rate()
# only create global lr_var once
if not isinstance(lr_var, framework.Variable):
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_adam_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ def test_adam_op_with_state_dict(self):
state_dict = adam.state_dict()
adam.set_state_dict(state_dict)

#learning_rate is _LRScheduler
learning_rate = paddle.optimizer.CosineAnnealingLR(
#learning_rate is LRScheduler
learning_rate = paddle.optimizer.lr.CosineAnnealingDecay(
learning_rate=0.1, T_max=10)
adam = paddle.optimizer.Adam(
learning_rate=learning_rate,
Expand Down
24 changes: 16 additions & 8 deletions python/paddle/fluid/tests/unittests/test_directory_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,22 @@ def test_new_directory(self):
'paddle.distributed.prepare_context', 'paddle.DataParallel',
'paddle.jit', 'paddle.jit.TracedLayer', 'paddle.jit.to_static',
'paddle.jit.ProgramTranslator', 'paddle.jit.TranslatedLayer',
'paddle.jit.save', 'paddle.jit.load', 'paddle.NoamDecay',
'paddle.PiecewiseDecay', 'paddle.NaturalExpDecay',
'paddle.ExponentialDecay', 'paddle.InverseTimeDecay',
'paddle.PolynomialDecay', 'paddle.CosineDecay',
'paddle.static.Executor', 'paddle.static.global_scope',
'paddle.static.scope_guard', 'paddle.static.append_backward',
'paddle.static.gradients', 'paddle.static.BuildStrategy',
'paddle.static.CompiledProgram', 'paddle.static.ExecutionStrategy',
'paddle.jit.save', 'paddle.jit.load',
'paddle.optimizer.lr.LRScheduler', 'paddle.optimizer.lr.NoamDecay',
'paddle.optimizer.lr.PiecewiseDecay',
'paddle.optimizer.lr.NaturalExpDecay',
'paddle.optimizer.lr.ExponentialDecay',
'paddle.optimizer.lr.InverseTimeDecay',
'paddle.optimizer.lr.PolynomialDecay',
'paddle.optimizer.lr.CosineAnnealingDecay',
'paddle.optimizer.lr.MultiStepDecay',
'paddle.optimizer.lr.StepDecay', 'paddle.optimizer.lr.LambdaDecay',
'paddle.optimizer.lr.ReduceOnPlateau',
'paddle.optimizer.lr.LinearWarmup', 'paddle.static.Executor',
'paddle.static.global_scope', 'paddle.static.scope_guard',
'paddle.static.append_backward', 'paddle.static.gradients',
'paddle.static.BuildStrategy', 'paddle.static.CompiledProgram',
'paddle.static.ExecutionStrategy',
'paddle.static.default_main_program',
'paddle.static.default_startup_program', 'paddle.static.Program',
'paddle.static.name_scope', 'paddle.static.program_guard',
Expand Down
Loading