-
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.
Merge pull request #12 from NillionNetwork/feature/major-refactor
Modularize tech design
- Loading branch information
Showing
20 changed files
with
423 additions
and
391 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .model_client import ModelClient | ||
from .clients import * |
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,4 @@ | ||
from .sklearn import SklearnClient | ||
from .torch import TorchClient | ||
|
||
__all__ = ["SklearnClient", "TorchClient"] |
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,29 @@ | ||
"""Scikit-learn client implementation""" | ||
|
||
import sklearn | ||
from nada_ai.client.model_client import ModelClient | ||
from nada_ai.typing import LinearModel | ||
|
||
__all__ = ["SklearnClient"] | ||
|
||
|
||
class SklearnClient(ModelClient): | ||
"""ModelClient for Scikit-learn models""" | ||
|
||
def __init__(self, model: sklearn.base.BaseEstimator) -> None: | ||
""" | ||
Client initialization. | ||
Args: | ||
model (sklearn.base.BaseEstimator): Sklearn model object to wrap around. | ||
""" | ||
if isinstance(model, LinearModel): | ||
state_dict = {"coef": model.coef_} | ||
if model.fit_intercept is True: | ||
state_dict.update({"intercept": model.intercept_}) | ||
else: | ||
raise NotImplementedError( | ||
f"Instantiating ModelClient from Sklearn model type `{type(model).__name__}` is not yet implemented." | ||
) | ||
|
||
self.state_dict = state_dict |
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 @@ | ||
"""PyTorch client implementation""" | ||
|
||
from torch import nn | ||
from nada_ai.client.model_client import ModelClient | ||
|
||
__all__ = ["TorchClient"] | ||
|
||
|
||
class TorchClient(ModelClient): | ||
"""ModelClient for PyTorch models""" | ||
|
||
def __init__(self, model: nn.Module) -> None: | ||
""" | ||
Client initialization. | ||
Args: | ||
model (nn.Module): PyTorch model object to wrap around. | ||
""" | ||
self.state_dict = model.state_dict() |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from .module import Module | ||
from .parameter import Parameter | ||
from .layers import * | ||
from .activations import * | ||
from .modules import * |
Oops, something went wrong.