Skip to content

Commit

Permalink
added the call and updated docs
Browse files Browse the repository at this point in the history
scap3yvt authored Nov 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 64e15cf commit 48f9e0b
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions GANDLF/optimizers/README.md
Original file line number Diff line number Diff line change
@@ -3,10 +3,12 @@
## Adding a new algorithm

- For an optimizer defined in PyTorch [[ref](https://pytorch.org/docs/stable/optim.html#algorithms)], update the `GANDLF.optimizers.wrap_torch.py` submodule.
- For a custom optimizer, create a new submodule called `GANDLF.optimizers.${awesome_optimizer}.py`. Ensure that it inherits from PyTorch's base optimizer class [[ref](https://pytorch.org/docs/stable/optim.html#base-class)]
- For a custom optimizer, create a new submodule called `GANDLF.optimizers.${awesome_optimizer}.py`.
- For a third-party optimizer (where the code is available from an external repository), add the relevant code under the `GANDLF.optimizers.thirdparty` submodule.
- If a new dependency needs to be used, update GaNDLF's [`setup.py`](https://github.com/mlcommons/GaNDLF/blob/master/setup.py) with the new requirement.
- Define a new submodule under `GANDLF.optimizers` as `GANDLF.optimizers.wrap_${package_name}.py`.
- Ensure that the new algorithm is wrapped in a function which returns an object with the PyTorch optimizer type. Use any of the optimizers in `GANDLF.optimizers.wrap_torch.py` as an example.
- Add the algorithm's identifier to `GANDLF.optimizers.__init__.global_optimizer_dict` with an appropriate key.
- Call the new algorithm from the config using the `optimizer` key.
- [Update the tests!](https://mlcommons.github.io/GaNDLF/extending/#update-tests)https://mlcommons.github.io/GaNDLF/extending/#update-tests
- [If appropriate, please update the tests!](https://mlcommons.github.io/GaNDLF/extending/#update-tests)https://mlcommons.github.io/GaNDLF/extending/#update-tests
- All wrappers should return the type `from torch.optim.optimizer.Optimizer`.
3 changes: 2 additions & 1 deletion GANDLF/optimizers/__init__.py
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@

from .wrap_monai import novograd_wrapper

from .thirdparty import ademamix_wrapper, lion_wrapper
from .thirdparty import ademamix_wrapper, lion_wrapper, adopt_wrapper

global_optimizer_dict = {
"sgd": sgd,
@@ -33,6 +33,7 @@
"nadam": nadam,
"ademamix": ademamix_wrapper,
"lion": lion_wrapper,
"adopt": adopt_wrapper,
}


0 comments on commit 48f9e0b

Please sign in to comment.