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

set the lr dtype when create lr var in optimizer #44840

Merged
merged 8 commits into from
Aug 4, 2022
Merged
Changes from 3 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
11 changes: 7 additions & 4 deletions python/paddle/optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ def __init__(self,
else:
self._dtype = self._parameter_list[0].dtype

# learning rate can't be float16, for pure fp16 training, should extra handle the dtype for lr
self._lr_dtype = paddle.get_default_dtype(
) if self._dtype is None else self._dtype
self._lr_dtype = paddle.float32 if self._lr_dtype == paddle.float16 else self._lr_dtype

# each program should have a independent learning rate
# program -> tensor(learning_rate)
self._learning_rate_map = dict()
Expand Down Expand Up @@ -396,8 +401,7 @@ def _create_global_learning_rate(self):
shape=[1],
persistable=True,
stop_gradient=True,
dtype=paddle.get_default_dtype()
if self._dtype is None else self._dtype)
dtype=self._lr_dtype)
main_prog = framework.default_main_program()
main_prog.lr_sheduler = self._learning_rate
main_prog.lr_var = lr_var
Expand All @@ -419,8 +423,7 @@ def _create_global_learning_rate(self):
name=unique_name.generate("learning_rate"),
shape=[1],
value=float(self._learning_rate),
dtype=paddle.get_default_dtype()
if self._dtype is None else self._dtype,
dtype=self._lr_dtype,
persistable=True)

@framework.dygraph_only
Expand Down