Skip to content

Commit

Permalink
Made some of dependencies optional
Browse files Browse the repository at this point in the history
Made some of dependencies optional
  • Loading branch information
AlekseySh authored Dec 7, 2023
1 parent 0cb0a1b commit f1d6e8e
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r ci/requirements_tests.txt
python3 -m pip install -r ci/requirements_optional.txt
python3 -m pip install -e .
- name: Running all tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ run_all_tests: download_mock_dataset wandb_login

.PHONY: run_short_tests
run_short_tests: download_mock_dataset
export PYTORCH_ENABLE_MPS_FALLBACK=1; pytest --disable-warnings -sv -m "not long" tests
export PYTORCH_ENABLE_MPS_FALLBACK=1; pytest --disable-warnings -sv -m "not long and not needs_optional_dependency" tests
pytest --disable-warnings --doctest-modules --doctest-continue-on-failure -sv oml

.PHONY: test_converters
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ features_queries = inference_on_images(extractor, paths=queries, transform=trans
features_galleries = inference_on_images(extractor, paths=galleries, transform=transform, **args)

# Now we can explicitly build pairwise matrix of distances or save you RAM via using kNN
use_knn = True
use_knn = False
top_k = 3

if use_knn:
Expand Down
2 changes: 2 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ RUN pip install Cython==0.29.28
### Python libs
COPY ci/requirements.txt requirements.txt
COPY ci/requirements_tests.txt requirements_tests.txt
COPY ci/requirements_optional.txt requirements_optional.txt
RUN pip install --no-cache-dir -r requirements.txt ${EXTRA_INDEX}
RUN pip install --no-cache-dir -r requirements_optional.txt
RUN pip install --no-cache-dir -r requirements_tests.txt

WORKDIR /oml-lib
Expand Down
6 changes: 0 additions & 6 deletions ci/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,4 @@ hydra-core==1.3.0
python-dotenv>=0.17.0
validators>=0.18.0
gdown>=4.0

# todo: make it optional
grad-cam>=1.4.6
jupyter>=1.0.0
tensorboard
neptune-client>=0.14.2, <1.0.0
wandb>=0.15.4
4 changes: 4 additions & 0 deletions ci/requirements_optional.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
grad-cam>=1.4.6
jupyter>=1.0.0
neptune-client>=0.14.2, <1.0.0
wandb>=0.15.4
2 changes: 1 addition & 1 deletion docs/readme/examples_source/extractor/retrieval_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ features_queries = inference_on_images(extractor, paths=queries, transform=trans
features_galleries = inference_on_images(extractor, paths=galleries, transform=transform, **args)

# Now we can explicitly build pairwise matrix of distances or save you RAM via using kNN
use_knn = True
use_knn = False
top_k = 3

if use_knn:
Expand Down
3 changes: 2 additions & 1 deletion oml/lightning/callbacks/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import matplotlib.pyplot as plt
import numpy as np
import pytorch_lightning as pl
from neptune.new.types import File
from pytorch_lightning import Callback
from pytorch_lightning.loggers import NeptuneLogger, TensorBoardLogger, WandbLogger
from pytorch_lightning.utilities.types import STEP_OUTPUT
Expand Down Expand Up @@ -106,6 +105,8 @@ def _log_images(self, pl_module: pl.LightningModule) -> None:
for fig, metric_log_str in zip(*self.metric.visualize()):
log_str = f"{LOG_IMAGE_FOLDER}/{metric_log_str}"
if isinstance(pl_module.logger, NeptuneLogger):
from neptune.new.types import File # this is the optional dependency

pl_module.logger.experiment[log_str].log(File.as_image(fig))
elif isinstance(pl_module.logger, WandbLogger):
fig_img = figure_to_nparray(fig)
Expand Down
4 changes: 3 additions & 1 deletion oml/lightning/pipelines/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any, Dict, Optional

import torch
import wandb
from pytorch_lightning.callbacks import ModelCheckpoint
from pytorch_lightning.loggers import NeptuneLogger, TensorBoardLogger, WandbLogger
from pytorch_lightning.loggers.logger import Logger
Expand Down Expand Up @@ -114,6 +113,9 @@ def upload_files_to_neptune_cloud(logger: NeptuneLogger, cfg: TCfg) -> None:


def upload_files_to_wandb_cloud(logger: WandbLogger, cfg: TCfg) -> None:
# this is the optional dependency
import wandb

assert isinstance(logger, WandbLogger)

# log transforms as files
Expand Down
2 changes: 1 addition & 1 deletion tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from oml.const import PROJECT_ROOT

LIBS_TO_IGNORE = ["torch_xla"]
LIBS_TO_IGNORE = ["torch_xla", "pytorch_grad_cam", "wandb", "neptune", "IPython"]

NEED_TO_TEST_NOTEBOOKS = True

Expand Down
4 changes: 2 additions & 2 deletions tests/test_oml/test_models/test_visualisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_numpy_image() -> np.ndarray:
return np.random.randint(0, 256, size=IMAGE_SIZE, dtype=np.uint8)


@pytest.mark.long
@pytest.mark.needs_optional_dependency
@pytest.mark.parametrize(
"draw_function",
[
Expand All @@ -44,7 +44,7 @@ def test_visualisation(draw_function: Any, image: Union[np.ndarray, Image.Image]
assert image_modified.shape == IMAGE_SIZE


@pytest.mark.long
@pytest.mark.needs_optional_dependency
@pytest.mark.parametrize(
"draw_function",
[
Expand Down
4 changes: 1 addition & 3 deletions tests/test_oml/test_registry/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def get_opt() -> Optimizer:
("transforms", TRANSFORMS_REGISTRY, get_transforms, None),
("pairwise_model", PAIRWISE_MODELS_REGISTRY, get_pairwise_model, None),
("postprocessor", POSTPROCESSORS_REGISTRY, get_postprocessor, None),
# We marked these secret required tests as "long" to skip them on push requests from public
# forks to OML. Nevertheless, the tests will be executed if PR is merged with all the needed credentials.
pytest.param("logger", LOGGERS_REGISTRY, get_logger, None, marks=pytest.mark.long),
pytest.param("logger", LOGGERS_REGISTRY, get_logger, None, marks=pytest.mark.needs_optional_dependency),
],
)
def test_registry(folder_name, registry, factory_fun, runtime_args) -> None:
Expand Down

0 comments on commit f1d6e8e

Please sign in to comment.