From b600eeedf5ad2cf01b1a0fcb8498516e3ab188a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20P=C3=A9rez-Garc=C3=ADa?= Date: Wed, 25 Jan 2023 19:24:24 +0000 Subject: [PATCH 1/7] Unpin dependencies and refactor packaging --- .github/workflows/multimodal-pr.yml | 2 +- hi-ml-multimodal/.mypy.ini | 2 +- hi-ml-multimodal/MANIFEST.in | 1 - hi-ml-multimodal/Makefile | 14 ++--- hi-ml-multimodal/README.md | 2 +- hi-ml-multimodal/environment.yml | 14 ----- hi-ml-multimodal/pyproject.toml | 5 ++ hi-ml-multimodal/requirements_build.txt | 9 --- hi-ml-multimodal/requirements_run.txt | 8 --- hi-ml-multimodal/requirements_test.txt | 13 ----- hi-ml-multimodal/setup.cfg | 73 +++++++++++++++++++++++++ hi-ml-multimodal/setup.py | 38 ------------- 12 files changed, 85 insertions(+), 96 deletions(-) delete mode 100644 hi-ml-multimodal/environment.yml create mode 100644 hi-ml-multimodal/pyproject.toml delete mode 100644 hi-ml-multimodal/requirements_build.txt delete mode 100644 hi-ml-multimodal/requirements_run.txt delete mode 100644 hi-ml-multimodal/requirements_test.txt create mode 100644 hi-ml-multimodal/setup.cfg delete mode 100644 hi-ml-multimodal/setup.py diff --git a/.github/workflows/multimodal-pr.yml b/.github/workflows/multimodal-pr.yml index eb793f3be..07161457e 100644 --- a/.github/workflows/multimodal-pr.yml +++ b/.github/workflows/multimodal-pr.yml @@ -11,7 +11,7 @@ on: - ".github/workflows/multimodal-*.yml" env: - pythonVersion: 3.7 + pythonVersion: 3.10 folder: hi-ml-multimodal HIML_TENANT_ID: ${{ secrets.HIML_TENANT_ID }} HIML_RESOURCE_GROUP: ${{ secrets.HIML_RESOURCE_GROUP }} diff --git a/hi-ml-multimodal/.mypy.ini b/hi-ml-multimodal/.mypy.ini index b3cf78687..aa664619d 100644 --- a/hi-ml-multimodal/.mypy.ini +++ b/hi-ml-multimodal/.mypy.ini @@ -1,5 +1,5 @@ [mypy] -python_version=3.7 +python_version=3.10 scripts_are_modules=True namespace_packages=True show_traceback=True diff --git a/hi-ml-multimodal/MANIFEST.in b/hi-ml-multimodal/MANIFEST.in index 035be0b8e..c1a7121c1 100644 --- a/hi-ml-multimodal/MANIFEST.in +++ b/hi-ml-multimodal/MANIFEST.in @@ -1,3 +1,2 @@ include LICENSE -include requirements_run.txt include README.md diff --git a/hi-ml-multimodal/Makefile b/hi-ml-multimodal/Makefile index 82e63ef61..56e26008d 100644 --- a/hi-ml-multimodal/Makefile +++ b/hi-ml-multimodal/Makefile @@ -1,29 +1,24 @@ ## Package management -# Create a Conda environment for this folder only -env: - conda env create --file environment.yml - pip install -r requirements_test.txt - pip install -r requirements_build.txt - # pip upgrade pip_upgrade: python -m pip install --upgrade pip # pip upgrade and install build requirements pip_build: pip_upgrade - pip install -r requirements_build.txt + pip install .[build] # pip upgrade and install test requirements pip_test: pip_upgrade - pip install -r requirements_test.txt + pip install .[test] # pip install local package in editable mode for development and testing pip_local: pip install -e . # pip install everything for local development and testing -pip: pip_build pip_test pip_local +pip: + pip install -e .[dev] ## Actions @@ -45,7 +40,6 @@ flake8: # run mypy, assuming test requirements already installed mypy: - mypy --install-types --show-error-codes --non-interactive setup.py mypy --install-types --show-error-codes --non-interactive src mypy --install-types --show-error-codes --non-interactive test_multimodal diff --git a/hi-ml-multimodal/README.md b/hi-ml-multimodal/README.md index 14a163a12..a7081cbe4 100644 --- a/hi-ml-multimodal/README.md +++ b/hi-ml-multimodal/README.md @@ -6,7 +6,7 @@ The code is available on [GitHub][1] and [Hugging Face 🤗][6]. ## Getting started The best way to get started is by running the [phrase grounding notebook][2]. -All the dependencies will be installed upon execution, so Python 3.7 and [Jupyter][3] are the only requirements to get started. +All the dependencies will be installed upon execution, so [Jupyter][3] is the only requirements to get started. The notebook can also be run on [Binder][4], without the need to download any code or install any libraries: diff --git a/hi-ml-multimodal/environment.yml b/hi-ml-multimodal/environment.yml deleted file mode 100644 index 1750632d0..000000000 --- a/hi-ml-multimodal/environment.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: multimodal -channels: - - defaults - - conda-forge - - pytorch -dependencies: - - pip=20.1.1 - - python=3.7.3 - - cudatoolkit=11.1 - - pytorch=1.9.0 - - torchvision=0.10.0 - - pip: - - -r requirements_run.txt - - -r requirements_test.txt diff --git a/hi-ml-multimodal/pyproject.toml b/hi-ml-multimodal/pyproject.toml new file mode 100644 index 000000000..31f14ba9b --- /dev/null +++ b/hi-ml-multimodal/pyproject.toml @@ -0,0 +1,5 @@ +[build-system] +requires = [ + "setuptools>=42", +] +build-backend = "setuptools.build_meta" diff --git a/hi-ml-multimodal/requirements_build.txt b/hi-ml-multimodal/requirements_build.txt deleted file mode 100644 index bdf1f1aa6..000000000 --- a/hi-ml-multimodal/requirements_build.txt +++ /dev/null @@ -1,9 +0,0 @@ -docutils==0.16 -myst-parser==0.15.2 -setuptools==65.5.1 -sphinx==4.1.2 -sphinx-autodoc-typehints==1.12.0 -sphinx-automodapi==0.13 -sphinx-rtd-theme==1.0.0 -twine==3.3.0 -wheel==0.38.1 diff --git a/hi-ml-multimodal/requirements_run.txt b/hi-ml-multimodal/requirements_run.txt deleted file mode 100644 index 87030a342..000000000 --- a/hi-ml-multimodal/requirements_run.txt +++ /dev/null @@ -1,8 +0,0 @@ -huggingface-hub==0.6.0 -pillow==9.3.0 -pydicom==2.2.2 -scikit-image==0.18.1 -SimpleITK==2.1.1 -torch==1.9.0 -torchvision>0.9,<=0.10.0 -transformers==4.17.0 diff --git a/hi-ml-multimodal/requirements_test.txt b/hi-ml-multimodal/requirements_test.txt deleted file mode 100644 index 7b29988d0..000000000 --- a/hi-ml-multimodal/requirements_test.txt +++ /dev/null @@ -1,13 +0,0 @@ -bump2version==1.0.1 -coverage==6.3.2 -flake8==5.0.2 -ipykernel==6.15.0 -ipython==7.34.0 -mypy==0.931 -papermill==2.3.4 -pycobertura==2.0.1 -pytest==6.2.2 -pytest-cov==2.11.1 -pytest-rerunfailures==10.2 -pytest-timeout==2.0.1 -setuptools==65.5.1 diff --git a/hi-ml-multimodal/setup.cfg b/hi-ml-multimodal/setup.cfg new file mode 100644 index 000000000..02d6642a3 --- /dev/null +++ b/hi-ml-multimodal/setup.cfg @@ -0,0 +1,73 @@ +[metadata] +name = hi-ml-multimodal +version = 0.1.2 +author = Biomedical Imaging Team @ Microsoft Health Futures +author_email = innereyedev@microsoft.com +url = https://github.com/microsoft/hi-ml +description = Microsoft Health Futures package to work with multi-modal health data +long_description = file: README.md +long_description_content_type = text/markdown +license_file = MIT License +platforms = OS Independent +classifiers = + Intended Audience :: Science/Research + Natural Language :: English + Operating System :: OS Independent + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.10 + Topic :: Scientific/Engineering + Topic :: Scientific/Engineering :: Artificial Intelligence + Topic :: Scientific/Engineering :: Image Processing + Topic :: Scientific/Engineering :: Medical Science Apps. + Typing :: Typed + Development Status :: 3 - Alpha + License :: OSI Approved :: MIT License + +[options] +install_requires = + huggingface-hub + pillow + pydicom + scikit-image + SimpleITK + torch + torchvision + transformers +python_requires = >=3.10,<3.11 +include_package_data = True +zip_safe = False + +[options.packages.find] +where = src + +[options.extras_require] +dev = + %(quality)s + %(test)s + bump2version + pre-commit +build = + docutils + myst-parser + sphinx + sphinx-autodoc-typehints + sphinx-automodapi + sphinx-rtd-theme + twine +test = + coverage + flake8 + ipykernel + ipython + mypy + papermill + pycobertura + pytest + pytest-cov + pytest-rerunfailures + pytest-timeout + +[bdist_wheel] +universal = 1 diff --git a/hi-ml-multimodal/setup.py b/hi-ml-multimodal/setup.py deleted file mode 100644 index 30dce0bfd..000000000 --- a/hi-ml-multimodal/setup.py +++ /dev/null @@ -1,38 +0,0 @@ -# ------------------------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. -# ------------------------------------------------------------------------------------------ - -from pathlib import Path -from setuptools import find_namespace_packages, setup # type: ignore - - -long_description = Path("README.md").read_text(encoding="utf-8") -version = "0.1.2" -package_name = "hi-ml-multimodal" -install_requires = Path("requirements_run.txt").read_text().splitlines() - -description = "Microsoft Health Futures package to work with multi-modal health data" - -setup( - name=package_name, - version=version, - description=description, - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/microsoft/hi-ml", - author="Biomedical Imaging Team @ Microsoft Health Futures", - author_email="innereyedev@microsoft.com", - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Science/Research", - "Topic :: Scientific/Engineering :: Medical Science Apps.", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.7" - ], - license="MIT License", - packages=find_namespace_packages(where="src"), - package_dir={"": "src"}, - include_package_data=True, - install_requires=install_requires, -) From bc416882ce9d7daf310aeb65727bec1d945242f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20P=C3=A9rez-Garc=C3=ADa?= Date: Wed, 25 Jan 2023 19:29:05 +0000 Subject: [PATCH 2/7] Fix Python version on CI --- .github/workflows/multimodal-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/multimodal-pr.yml b/.github/workflows/multimodal-pr.yml index 07161457e..48f9264de 100644 --- a/.github/workflows/multimodal-pr.yml +++ b/.github/workflows/multimodal-pr.yml @@ -11,7 +11,7 @@ on: - ".github/workflows/multimodal-*.yml" env: - pythonVersion: 3.10 + pythonVersion: "3.10" folder: hi-ml-multimodal HIML_TENANT_ID: ${{ secrets.HIML_TENANT_ID }} HIML_RESOURCE_GROUP: ${{ secrets.HIML_RESOURCE_GROUP }} From e5b600143f1bc38a65e4c0a295e81a67b2a29759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20P=C3=A9rez-Garc=C3=ADa?= Date: Wed, 25 Jan 2023 19:32:13 +0000 Subject: [PATCH 3/7] Fix extra dependencies --- hi-ml-multimodal/setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hi-ml-multimodal/setup.cfg b/hi-ml-multimodal/setup.cfg index 02d6642a3..61d0bab75 100644 --- a/hi-ml-multimodal/setup.cfg +++ b/hi-ml-multimodal/setup.cfg @@ -44,7 +44,7 @@ where = src [options.extras_require] dev = - %(quality)s + %(build)s %(test)s bump2version pre-commit From 3b2c4a1e028bdef6babac520d4616cabcf926fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20P=C3=A9rez-Garc=C3=ADa?= Date: Wed, 25 Jan 2023 19:38:44 +0000 Subject: [PATCH 4/7] Fix RTD requirements --- readthedocs_requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readthedocs_requirements.txt b/readthedocs_requirements.txt index cdf27b6c8..0890ded92 100644 --- a/readthedocs_requirements.txt +++ b/readthedocs_requirements.txt @@ -1,4 +1,4 @@ -r build_requirements.txt -r hi-ml/run_requirements.txt -r hi-ml-azure/run_requirements.txt --r hi-ml-multimodal/requirements_run.txt +./hi-ml-multimodal From f65910feed2573dbcc7f9e5aa341bbe93552d0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20P=C3=A9rez-Garc=C3=ADa?= Date: Wed, 25 Jan 2023 19:41:16 +0000 Subject: [PATCH 5/7] Add matplotlib to dependencies --- hi-ml-multimodal/setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/hi-ml-multimodal/setup.cfg b/hi-ml-multimodal/setup.cfg index 61d0bab75..9b69b2374 100644 --- a/hi-ml-multimodal/setup.cfg +++ b/hi-ml-multimodal/setup.cfg @@ -28,6 +28,7 @@ classifiers = [options] install_requires = huggingface-hub + matplotlib pillow pydicom scikit-image From 29d626d2abd3bb4c4f6f72603e819320fa9c620d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20P=C3=A9rez-Garc=C3=ADa?= Date: Wed, 25 Jan 2023 19:50:03 +0000 Subject: [PATCH 6/7] Fix mypy error --- .../test_multimodal/vlp/test_zero_shot_classification.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hi-ml-multimodal/test_multimodal/vlp/test_zero_shot_classification.py b/hi-ml-multimodal/test_multimodal/vlp/test_zero_shot_classification.py index a5dd54d1e..25dc33ee1 100644 --- a/hi-ml-multimodal/test_multimodal/vlp/test_zero_shot_classification.py +++ b/hi-ml-multimodal/test_multimodal/vlp/test_zero_shot_classification.py @@ -1,7 +1,7 @@ import tempfile from enum import Enum, unique from pathlib import Path -from typing import List, Tuple, Union +from typing import List, Optional, Tuple, Union import requests from torchvision.datasets.utils import check_integrity @@ -46,7 +46,7 @@ def _get_default_text_prompts_for_pneumonia() -> Tuple[List, List]: return pos_query, neg_query -def save_img_from_url(image_url: str, local_path: Union[str, Path], md5: str = None) -> None: +def save_img_from_url(image_url: str, local_path: Union[str, Path], md5: Optional[str] = None) -> None: """ Pull an image from a URL and save it to a local path """ From 03156e11dcc658011650b0827739428e9608b401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20P=C3=A9rez-Garc=C3=ADa?= Date: Wed, 25 Jan 2023 19:51:01 +0000 Subject: [PATCH 7/7] Fix flake8 config error --- hi-ml-multimodal/.flake8 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hi-ml-multimodal/.flake8 b/hi-ml-multimodal/.flake8 index 95b69fb65..217f74fba 100644 --- a/hi-ml-multimodal/.flake8 +++ b/hi-ml-multimodal/.flake8 @@ -2,5 +2,5 @@ max-line-length = 120 max-complexity = 25 ignore = - E731, # Do not assign a lambda expression, use a def - W503 # Line break before binary operator + E731 + W503