Skip to content

Commit f45f606

Browse files
PhilJdfacaiy
authored andcommitted
Decoupled weight decay (#164)
* Add decoupled weight decay optimizers and helper class for optimizer tests. * Adapt README.md. Fix broken link to keras_utils. * Remove TF private API calls. * Add imports to __init__.py * Fix indentation of comments, remove call to tf.test.main from optimizer_test_base. * Move optimizer_test_base into weight_decay_test for now. In the optimizer tests, optimizer params are now keywords instead of a dict. Fix code in comments to support tf-2.0, naming errors, line length. * Delete optimizer_test_base.py Remove keras object registration in the factory function. * Fix code formatting via patch file.
1 parent 4118a11 commit f45f606

File tree

5 files changed

+724
-2
lines changed

5 files changed

+724
-2
lines changed

tensorflow_addons/optimizers/BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ py_library(
88
"__init__.py",
99
"lazy_adam.py",
1010
"moving_average.py",
11+
"weight_decay_optimizers.py",
1112
],
1213
srcs_version = "PY2AND3",
1314
deps = [
@@ -40,3 +41,16 @@ py_test(
4041
":optimizers",
4142
],
4243
)
44+
45+
py_test(
46+
name = "weight_decay_optimizers_test",
47+
size = "small",
48+
srcs = [
49+
"weight_decay_optimizers_test.py",
50+
],
51+
main = "weight_decay_optimizers_test.py",
52+
srcs_version = "PY2AND3",
53+
deps = [
54+
":optimizers",
55+
],
56+
)

tensorflow_addons/optimizers/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55
|:---------- |:------------- |:--------------|
66
| lazy_adam | SIG-Addons | addons@tensorflow.org |
77
| moving_average | Dheeraj R. Reddy | dheeraj98reddy@gmail.com |
8+
| weight_decay_optimizers | Phil Jund | ijund.phil@googlemail.com |
9+
810

911
## Components
1012
| Submodule | Optimizer | Reference |
11-
|:----------------------- |:---------------------- |:---------|
13+
|:--------- |:---------- |:---------|
1214
| lazy_adam | LazyAdam | https://arxiv.org/abs/1412.6980 |
1315
| moving_average | MovingAverage | |
16+
| weight_decay_optimizers | SGDW, AdamW, extend_with_decoupled_weight_decay | https://arxiv.org/pdf/1711.05101.pdf |
1417

1518

1619
## Contribution Guidelines
1720
#### Standard API
1821
In order to conform with the current API standard, all optimizers
1922
must:
2023
* Inherit from either `keras.optimizer_v2.OptimizerV2` or its subclasses.
21-
* [Register as a keras global object](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/utils/python/keras_utils.py)
24+
* [Register as a keras global object](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/utils/keras_utils.py)
2225
so it can be serialized properly.
2326
* Add the addon to the `py_library` in this sub-package's BUILD file.
2427

tensorflow_addons/optimizers/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@
1919
from __future__ import print_function
2020

2121
from tensorflow_addons.optimizers.lazy_adam import LazyAdam
22+
from tensorflow_addons.optimizers.weight_decay_optimizers import AdamW
23+
from tensorflow_addons.optimizers.weight_decay_optimizers import SGDW
24+
from tensorflow_addons.optimizers.weight_decay_optimizers import (
25+
extend_with_decoupled_weight_decay)
2226
from tensorflow_addons.optimizers.moving_average import MovingAverage

0 commit comments

Comments
 (0)