forked from fedbiomed/fedbiomed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first commit: partial implementation with design proposal
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from abc import abstractmethod | ||
from typing import Callable | ||
|
||
from fedbiomed.common import models | ||
from fedbiomed.common.exceptions import FedbiomedOptimizerError | ||
from fedbiomed.common.optimizers.optimizer import Optimizer | ||
|
||
import declearn | ||
|
||
|
||
class GenericOptimizer: | ||
model: models | ||
optimizer: Optimizer | ||
_step_method: Callable = NotImplemented | ||
def __init__(self, model, optimizer): | ||
self.model = model | ||
self.optimizer = optimizer | ||
|
||
if isinstance(optimizer, declearn.optimizer.Optimizer): | ||
self._step_method = optimizer.step_modules | ||
else: | ||
self._step_method = optimizer.step_native | ||
|
||
def step(self, weights, gradients): | ||
if self._step_method is NotImplemented: | ||
raise FedbiomedOptimizerError("Error, method used for step not implemeted yet") | ||
return self._step_method(weights, gradients) | ||
|
||
def step_modules(self): | ||
pass | ||
|
||
def set_state(self): | ||
pass | ||
def get_state(self): | ||
pass | ||
@abstractmethod | ||
def step_native(self): | ||
pass | ||
|
||
class TorchOptimizer(GenericOptimizer): | ||
def setp_native(self): | ||
pass | ||
|
||
|
||
class SkLearnOptimizer(GenericOptimizer): | ||
def step_native(self): | ||
pass | ||
|
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