-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fabrice Normandin <[email protected]>
- Loading branch information
Showing
15 changed files
with
113 additions
and
130 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
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 |
---|---|---|
@@ -1,26 +1,10 @@ | ||
from hydra_zen import builds, store | ||
|
||
from project.algorithms.jax_example import JaxExample | ||
from project.algorithms.no_op import NoOp | ||
|
||
from .example import ExampleAlgorithm | ||
|
||
# NOTE: This works the same way as creating config files for each algorithm under | ||
# `configs/algorithm`. From the command-line, you can select both configs that are yaml files as | ||
# well as structured config (dataclasses). | ||
|
||
# If you add a configuration file under `configs/algorithm`, it will also be available as an option | ||
# from the command-line, and be validated against the schema. | ||
# todo: It might be nicer if we did this this `configs/algorithms` instead of here, no? | ||
algorithm_store = store(group="algorithm") | ||
algorithm_store(ExampleAlgorithm.HParams(), name="example_algo") | ||
algorithm_store(builds(NoOp, populate_full_signature=False), name="no_op") | ||
algorithm_store(JaxExample.HParams(), name="jax_example") | ||
|
||
algorithm_store.add_to_hydra_store() | ||
|
||
__all__ = [ | ||
"ExampleAlgorithm", | ||
"ManualGradientsExample", | ||
"JaxExample", | ||
"NoOp", | ||
] |
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
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
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,24 @@ | ||
from hydra_zen import make_custom_builds_fn, store | ||
from hydra_zen.third_party.pydantic import pydantic_parser | ||
|
||
builds_fn = make_custom_builds_fn( | ||
zen_partial=True, populate_full_signature=True, zen_wrappers=pydantic_parser | ||
) | ||
|
||
|
||
# NOTE: This works the same way as creating config files for each algorithm under | ||
# `configs/algorithm`. From the command-line, you can select both configs that are yaml files as | ||
# well as structured config (dataclasses). | ||
|
||
# If you add a configuration file under `configs/algorithm`, it will also be available as an option | ||
# from the command-line, and can use these configs in their default list. | ||
algorithm_store = store(group="algorithm") | ||
|
||
|
||
def populate_algorithm_store(): | ||
# Note: import here to avoid circular imports. | ||
from project.algorithms import ExampleAlgorithm, JaxExample, NoOp | ||
|
||
algorithm_store(builds_fn(ExampleAlgorithm), name="example_algo") | ||
algorithm_store(builds_fn(NoOp), name="no_op") | ||
algorithm_store(builds_fn(JaxExample), name="jax_example") |
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,7 @@ | ||
defaults: | ||
- optimizer/[email protected] | ||
- lr_scheduler/[email protected]_scheduler | ||
_target_: project.algorithms.example.ExampleAlgorithm | ||
_partial_: true | ||
hp: | ||
_target_: project.algorithms.example.ExampleAlgorithm.HParams |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
import torch | ||
import torch.optim.lr_scheduler | ||
from hydra_zen import make_custom_builds_fn, store | ||
from hydra_zen.third_party.pydantic import pydantic_parser | ||
|
||
builds_fn = make_custom_builds_fn( | ||
zen_partial=True, populate_full_signature=True, zen_wrappers=pydantic_parser | ||
) | ||
|
||
CosineAnnealingLRConfig = builds_fn(torch.optim.lr_scheduler.CosineAnnealingLR, T_max=85) | ||
StepLRConfig = builds_fn(torch.optim.lr_scheduler.CosineAnnealingLR) | ||
lr_scheduler_store = store(group="algorithm/lr_scheduler") | ||
lr_scheduler_store(StepLRConfig, name="step_lr") | ||
lr_scheduler_store(CosineAnnealingLRConfig, name="cosine_annealing_lr") | ||
|
||
|
||
# IDEA: Could be interesting to generate configs for any member of the torch.optimizer.lr_scheduler | ||
# package dynamically (and store it)? | ||
# def __getattr__(self, name: str): | ||
# """""" |
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,14 @@ | ||
import torch | ||
import torch.optim | ||
from hydra_zen import make_custom_builds_fn, store | ||
from hydra_zen.third_party.pydantic import pydantic_parser | ||
|
||
builds_fn = make_custom_builds_fn( | ||
zen_partial=True, populate_full_signature=True, zen_wrappers=pydantic_parser | ||
) | ||
|
||
optimizer_store = store(group="algorithm/optimizer") | ||
AdamConfig = builds_fn(torch.optim.Adam) | ||
SGDConfig = builds_fn(torch.optim.SGD) | ||
optimizer_store(AdamConfig, name="adam") | ||
optimizer_store(SGDConfig, name="sgd") |
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