Skip to content

Commit

Permalink
relocate python/paddle/fluid/regularizer.py (#53106)
Browse files Browse the repository at this point in the history
* relocate regularizer.py

* fix bug

* fix bug

* fix bug

* relocate the import

* replace _regularization_coeff with coeff

* remove the L1DecayRegularizer and L2DecayRegularizer
  • Loading branch information
longranger2 authored May 15, 2023
1 parent 8105607 commit 00e415d
Show file tree
Hide file tree
Showing 38 changed files with 198 additions and 416 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from paddle.fluid.optimizer import Momentum, Optimizer
from paddle.framework import core, in_dygraph_mode
from paddle.nn.clip import ClipGradByNorm, append_gradient_clip_ops
from paddle.regularizer import L1Decay, L2Decay
from paddle.static import create_global_var


Expand Down Expand Up @@ -99,8 +100,7 @@ def _get_regularization_param(self, regularization):
regular_coeff = 0.0

if regularization is not None:
regular_coeff = regularization._regularization_coeff
from paddle.fluid.regularizer import L1Decay, L2Decay
regular_coeff = regularization._coeff

if isinstance(regularization, L1Decay):
regular_type = 1
Expand Down
2 changes: 0 additions & 2 deletions python/paddle/fluid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
from . import optimizer
from . import backward
from .backward import gradients
from . import regularizer
from . import incubate
from .param_attr import ParamAttr, WeightNormParamAttr
from .data_feeder import DataFeeder
Expand Down Expand Up @@ -116,7 +115,6 @@
'nets',
'optimizer',
'backward',
'regularizer',
'LoDTensor',
'LoDTensorArray',
'CPUPlace',
Expand Down
10 changes: 5 additions & 5 deletions python/paddle/fluid/contrib/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.fluid.optimizer import Optimizer
from paddle.fluid.regularizer import L1DecayRegularizer
from paddle.fluid.regularizer import L2DecayRegularizer
from paddle.regularizer import L1Decay
from paddle.regularizer import L2Decay
from paddle.fluid import core
from paddle.fluid import framework
from paddle.fluid.framework import program_guard
Expand Down Expand Up @@ -117,7 +117,7 @@ def __init__(
):
assert learning_rate is not None
assert momentum is not None
predicate = lambda regular: isinstance(regular, L2DecayRegularizer)
predicate = lambda regular: isinstance(regular, L2Decay)
py_regular = None if predicate(regularization) else regularization
super().__init__(
learning_rate=learning_rate,
Expand All @@ -131,9 +131,9 @@ def __init__(
self._use_nesterov = bool(use_nesterov)
self._regularization_method = ""
self._regularization_coeff = 0
if isinstance(regularization, L2DecayRegularizer):
if isinstance(regularization, L2Decay):
self._regularization_method = "l2_decay"
self._regularization_coeff = regularization._regularization_coeff
self._regularization_coeff = regularization._coeff
self._multi_precision = multi_precision
self._rescale_grad = rescale_grad
self._master_weights = {}
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/layers/learning_rate_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def piecewise_decay(boundaries, values):
optimizer = fluid.optimizer.Momentum(
momentum=0.9,
learning_rate=fluid.layers.piecewise_decay(boundaries=boundaries, values=values),
regularization=fluid.regularizer.L2Decay(1e-4))
regularization=paddle.regularizer.L2Decay(1e-4))
"""
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/param_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import paddle
from .regularizer import WeightDecayRegularizer
from paddle.regularizer import WeightDecayRegularizer
from paddle.fluid.data_feeder import check_type

__all__ = [
Expand Down
300 changes: 0 additions & 300 deletions python/paddle/fluid/regularizer.py

This file was deleted.

Loading

0 comments on commit 00e415d

Please sign in to comment.