-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: reorganize submodules to follow PEP8 naming convention
- Loading branch information
Showing
14 changed files
with
423 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2022 MetaOPT Team. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
from torchopt._src.optimizer.base import Optimizer | ||
from torchopt._src.optimizer.adam import Adam | ||
from torchopt._src.optimizer.rmsprop import RMSProp | ||
from torchopt._src.optimizer.sgd import SGD | ||
|
||
from torchopt._src.optimizer import meta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2022 MetaOPT Team. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
from torchopt._src.alias import adam | ||
from torchopt._src.optimizer.base import Optimizer | ||
from torchopt._src.typing import ScalarOrSchedule | ||
|
||
|
||
class Adam(Optimizer): | ||
"""A canonical Stochastic Gradient Descent optimizer.""" | ||
|
||
def __init__( | ||
self, | ||
params, | ||
lr: ScalarOrSchedule, | ||
b1: float = 0.9, | ||
b2: float = 0.999, | ||
eps: float = 1e-8, | ||
eps_root: float = 0.0, | ||
use_accelerated_op: bool = False | ||
): | ||
"""The `init` function. | ||
Args: | ||
params (iterable): | ||
An iterable of `torch.Tensor`s. Specifies what Tensors should be | ||
optimized. | ||
args: | ||
Other arguments see `alias.sgd`. | ||
""" | ||
|
||
super().__init__( | ||
params, | ||
adam( | ||
lr=lr, | ||
b1=b1, | ||
b2=b2, | ||
eps=eps, | ||
eps_root=eps_root, | ||
moment_requires_grad=False, | ||
use_accelerated_op=use_accelerated_op | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2022 MetaOPT Team. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
from torchopt._src.optimizer.meta.base import MetaOptimizer | ||
from torchopt._src.optimizer.meta.adam import MetaAdam | ||
from torchopt._src.optimizer.meta.rmsprop import MetaRMSProp | ||
from torchopt._src.optimizer.meta.sgd import MetaSGD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2022 MetaOPT Team. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
from torchopt._src.alias import adam | ||
from torchopt._src.optimizer.meta.base import MetaOptimizer | ||
from torchopt._src.typing import ScalarOrSchedule | ||
|
||
|
||
class MetaAdam(MetaOptimizer): | ||
"""The classic Adam optimizer.""" | ||
|
||
def __init__( | ||
self, | ||
net, | ||
lr: ScalarOrSchedule, | ||
b1: float = 0.9, | ||
b2: float = 0.999, | ||
eps: float = 1e-8, | ||
eps_root: float = 0.0, | ||
moment_requires_grad: bool = True, | ||
use_accelerated_op: bool = False | ||
): | ||
"""The `init` function. | ||
Args: | ||
net (nn.Module): | ||
A network whose parameters should be optimized. | ||
args: | ||
Other arguments see `alias.adam`, here we set `moment_requires_grad=True` | ||
to make tensors like momentum be differentiable. | ||
""" | ||
|
||
super().__init__( | ||
net, | ||
adam( | ||
lr=lr, | ||
b1=b1, | ||
b2=b2, | ||
eps=eps, | ||
eps_root=eps_root, | ||
moment_requires_grad=moment_requires_grad, | ||
use_accelerated_op=use_accelerated_op | ||
) | ||
) |
Oops, something went wrong.