-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kabir Khan
committed
Jun 30, 2023
1 parent
a822d3c
commit 59f3f55
Showing
3 changed files
with
94 additions
and
25 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import dataclasses | ||
from typing import Union, Iterable | ||
import catalogue | ||
from confection import registry, Config | ||
from pydantic import BaseModel | ||
|
||
# Create a new registry. | ||
registry.optimizers = catalogue.create("confection", "optimizers", entry_points=False) | ||
|
||
|
||
# Define a dummy optimizer class. | ||
|
||
@dataclasses.dataclass | ||
class MyCoolOptimizer: | ||
learn_rate: float | ||
gamma: float | ||
|
||
|
||
@registry.optimizers.register("my_cool_optimizer.v1") | ||
def make_my_optimizer(learn_rate: Union[float, Iterable[float]], gamma: float): | ||
return MyCoolOptimizer(learn_rate=learn_rate, gamma=gamma) | ||
|
||
|
||
if __name__ == "__main__": | ||
# Load the config file from disk, resolve it and fetch the instantiated optimizer object. | ||
cfg_str = """ | ||
[optimizer] | ||
@optimizers = "my_cool_optimizer.v1" | ||
learn_rate = 0.001 | ||
gamma = 1e-8 | ||
""" | ||
config = Config().from_str(cfg_str) | ||
resolved = registry.resolve(config) | ||
optimizer = resolved["optimizer"] # MyCoolOptimizer(learn_rate=0.001, gamma=1e-08) | ||
|
||
print(config, resolved, optimizer) |
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