Skip to content

Commit

Permalink
chore!: make mlflow as an optional dependency (#47)
Browse files Browse the repository at this point in the history
Signed-off-by: Avik Basu <[email protected]>
  • Loading branch information
ab93 committed Oct 18, 2022
1 parent 9cc97cb commit 22f8e5d
Show file tree
Hide file tree
Showing 11 changed files with 1,237 additions and 346 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install dependencies
run: |
poetry env use ${{ matrix.python-version }}
poetry install --no-root
poetry install --all-extras
- name: Test with pytest
run: make test
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install dependencies
run: |
poetry env use ${{ matrix.python-version }}
poetry install --no-root
poetry install --all-extras
- name: Run Coverage
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install dependencies
run: |
poetry env use ${{ matrix.python-version }}
poetry install --no-root
poetry install
- name: Black format check
run: poetry run black --check .
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install dependencies
run: |
poetry env use ${{ matrix.python-version }}
poetry install --no-root
poetry install --all-extras
- name: Build dist
run: poetry build
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lint: format

# install all dependencies
setup:
poetry install -v
poetry install --all-extras

# test your application (tests in the tests/ directory)
test:
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ the result further or drop it after a trigger request.

## Installation

numalogic can be installed using pip.
```shell
pip install numalogic
```

If using mlflow for model registry, install using:
```shell
pip install numalogic[mlflow]
```

### Build locally

1. Install [Poetry](https://python-poetry.org/docs/):
Expand All @@ -53,13 +59,17 @@ pip install numalogic
```
poetry install
```
If extra dependencies are needed:
```
poetry install --all-extras
```
4. To run unit tests:
```
make test
```
5. To format code style using black:
```
make format
make lint
```

## Usage
Expand Down Expand Up @@ -133,7 +143,7 @@ Now that the model is trained, let's save it. Numalogic has built in support
for Mlflow's tracking and logging system.

Let's first start the [mlflow server on localhost](https://www.mlflow.org/docs/latest/tracking.html#scenario-1-mlflow-on-localhost),
which has already been installed via `poetry` dependency:
which has already been installed optionally via `poetry` dependency:
```shell
mlflow server \
--default-artifact-root {directory}/mlruns --serve-artifacts \
Expand Down
9 changes: 6 additions & 3 deletions numalogic/registry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from numalogic.registry.artifact import ArtifactManager
from numalogic.registry.mlflow_registry import MLflowRegistrar


__all__ = ["ArtifactManager", "MLflowRegistrar"]
try:
from numalogic.registry.mlflow_registry import MLflowRegistrar
except ImportError:
__all__ = ["ArtifactManager"]
else:
__all__ = ["ArtifactManager", "MLflowRegistrar"]
2 changes: 2 additions & 0 deletions numalogic/tests/registry/_mlflow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def mock_log_model_pytorch(*_, **__):
signature_dict=None,
utc_time_created="2022-05-23 22:35:59.557372",
mlflow_version="1.26.0",
signature=None,
)


Expand All @@ -133,6 +134,7 @@ def mock_log_model_sklearn(*_, **__):
signature_dict=None,
utc_time_created="2022-05-23 22:35:59.557372",
mlflow_version="1.26.0",
signature=None,
)


Expand Down
5 changes: 1 addition & 4 deletions numalogic/tools/types.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from typing import Union, Dict, NewType, TypeVar, Sequence, Optional

from mlflow.entities.model_registry import ModelVersion
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.pipeline import Pipeline
from torch import nn

Artifact = NewType("Artifact", Union[nn.Module, BaseEstimator, TransformerMixin, Pipeline])
ArtifactDict = NewType(
"ArtifactDict",
Optional[
Dict[str, Union[Sequence[Artifact], Dict[str, Artifact], Artifact, None, ModelVersion]]
],
Optional[Dict[str, Union[Sequence[Artifact], Dict[str, Artifact], Artifact, None]]],
)
AutoencoderModel = TypeVar("AutoencoderModel", bound="TorchAE")
Loading

0 comments on commit 22f8e5d

Please sign in to comment.