Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up tests #293

Merged
merged 26 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ff7404b
add folder for user installation test
jarlsondre Jan 16, 2025
2b918c7
update tests to run in parallel
jarlsondre Jan 16, 2025
640268b
Merge branch 'main' into test-user-installation
jarlsondre Jan 16, 2025
958ef21
fix linting errors in dummy script
jarlsondre Jan 16, 2025
5dfe88e
add normal test to compare
jarlsondre Jan 16, 2025
8466a1f
empty dummy script for now
jarlsondre Jan 16, 2025
8f30f15
try to only run loggers
jarlsondre Jan 17, 2025
00e47ef
separate tests into multiple workflows
jarlsondre Jan 17, 2025
a49e3e9
remove horovod setup for all to test which needs it
jarlsondre Jan 17, 2025
6aa38c5
remove old pytest
jarlsondre Jan 17, 2025
d0c570a
remove old directory
jarlsondre Jan 17, 2025
5dd6de1
update tests to hopefully work in parallel
jarlsondre Jan 20, 2025
280d7b2
remove split tests
jarlsondre Jan 20, 2025
6d8cb6a
Merge branch 'main' into test-user-installation
jarlsondre Jan 20, 2025
dcddffc
remove tensorflow building for tests
jarlsondre Jan 20, 2025
3bb0a74
fix linting errors
jarlsondre Jan 20, 2025
dfef658
add missing marker and add uv to generic torch
jarlsondre Jan 20, 2025
f069d90
change version in pytest
jarlsondre Jan 20, 2025
b4f190e
update generic torch with check for NO_CUDA flag
jarlsondre Jan 20, 2025
788bed4
merge
jarlsondre Jan 20, 2025
79a461b
add other fixtures and add comment with how to build tf
jarlsondre Jan 20, 2025
73a0258
fix linting errors
jarlsondre Jan 20, 2025
9dea219
add comment about env variables
jarlsondre Jan 20, 2025
aebd695
fix grammar
jarlsondre Jan 21, 2025
fd3b153
add no cache dir to pip install
jarlsondre Jan 21, 2025
aab9a0e
small bugfix in generic_torch
jarlsondre Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
---
name: Unit and integration tests
name: Testing with pytest

on:
pull_request:
branches: [main, dev]

jobs:
test-itwinai:
name: Test itwinai with pytest
test-torch:
name: Testing with pytest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install compilers for Horovod
run: |
sudo apt-get update &&
sudo apt-get install -y gcc-11 g++-11 &&
sudo apt-get install -y cmake &&
sudo apt-get install openmpi-bin openmpi-common openmpi-doc libopenmpi-dev &&
gcc --version &&
cmake --version &&
mpirun --version

- name: Set up Python 3.11.9
uses: actions/setup-python@v4
with:
python-version: 3.11.9

- name: Make PyTorch virtualenv
shell: bash -l {0}
run: make torch-env-cpu

- name: Make Tensorflow virtualenv
shell: bash -l {0}
run: make tensorflow-env-cpu

# NOTE, to change the name in which tests are run, set custom TORCH_ENV and TF_ENV env variables.
# Default environment names are ".venv-pytorch" and ".venv-tf"
# Comment this back in to also build tensorflow env
jarlsondre marked this conversation as resolved.
Show resolved Hide resolved
# - name: Make Tensorflow virtualenv
# shell: bash -l {0}
# run: make tensorflow-env-cpu

- name: Run pytest for workflows
shell: bash -l {0}
run: .venv-pytorch/bin/pytest -v ./tests/ -m "not hpc"


run: .venv-pytorch/bin/pytest -v -n logical ./tests/ -m "not hpc and not tensorflow"
15 changes: 12 additions & 3 deletions env-files/torch/generic_torch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,23 @@ fi

# Activate the venv and then install itwinai as editable
source $ENV_NAME/bin/activate
pip install -e ".[torch,tf,dev]" \
pip install uv

if [ -z "$NO_CUDA" ]; then
# Install with CUDA support
uv pip install -e ".[torch,dev]" \
--no-cache-dir \
--extra-index-url https://download.pytorch.org/whl/cu121
else
# Install without CUDA support
uv pip install -e ".[torch,dev]"
fi


# Install Prov4ML
if [[ "$(uname)" == "Darwin" ]]; then
pip install --no-cache-dir "prov4ml[apple]@git+https://github.com/matbun/ProvML@new-main"
uv pip install --no-cache-dir "prov4ml[apple]@git+https://github.com/matbun/ProvML@new-main"
else
# Assuming Nvidia GPUs are available
pip install --no-cache-dir "prov4ml[nvidia]@git+https://github.com/matbun/ProvML@new-main"
uv pip install --no-cache-dir "prov4ml[nvidia]@git+https://github.com/matbun/ProvML@new-main"
fi
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ dev = [
"ipykernel>=6.29.5",
"ipython>=8.30.0",
"ruff>=0.8.3",
"psutil>=6.1.0",
"pytest-xdist>=3.6.1",
]
docs = [
"sphinx-rtd-theme>=2.0.0",
Expand Down
36 changes: 20 additions & 16 deletions tests/loggers/conftest.py
jarlsondre marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
# - Anna Lappe <[email protected]> - CERN
# -------------------------------------------------------------------------------------

import shutil
import tempfile
from pathlib import Path
from unittest.mock import MagicMock

import pytest
Expand All @@ -27,37 +28,40 @@

@pytest.fixture(scope="module")
def console_logger():
yield ConsoleLogger(savedir="/tmp/console/test_mllogs", log_freq=1)
shutil.rmtree("/tmp/console/test_mllogs", ignore_errors=True)
with tempfile.TemporaryDirectory() as temp_dir:
save_dir = Path(temp_dir) / "console/test_mllogs"
yield ConsoleLogger(savedir=save_dir, log_freq=1)


@pytest.fixture(scope="module")
def mlflow_logger():
yield MLFlowLogger(
savedir="/tmp/mlflow/test_mllogs",
experiment_name="test_experiment",
tracking_uri="file:///tmp/mlruns",
)
shutil.rmtree("/tmp/mlflow/test_mllogs", ignore_errors=True)
shutil.rmtree("/tmp/mlruns", ignore_errors=True)
with tempfile.TemporaryDirectory() as temp_dir:
save_dir = Path(temp_dir) / "mlflow/test_mllogs"
yield MLFlowLogger(
savedir=save_dir,
experiment_name="test_experiment",
)


@pytest.fixture(scope="module")
def wandb_logger():
yield WandBLogger(savedir="/tmp/wandb/test_mllogs", project_name="test_project")
shutil.rmtree("/tmp/wandb/test_mllogs", ignore_errors=True)
with tempfile.TemporaryDirectory() as temp_dir:
save_dir = Path(temp_dir) / "wandb/test_mllogs"
yield WandBLogger(savedir=save_dir, project_name="test_project")


@pytest.fixture(scope="module")
def tensorboard_logger_tf():
yield TensorBoardLogger(savedir="/tmp/tf_tb/test_mllogs", framework="tensorflow")
shutil.rmtree("/tmp/tf_tb/test_mllogs", ignore_errors=True)
with tempfile.TemporaryDirectory() as temp_dir:
save_dir = Path(temp_dir) / "tf_tb/test_mllogs"
yield TensorBoardLogger(savedir=save_dir, framework="tensorflow")


@pytest.fixture(scope="module")
def tensorboard_logger_torch():
yield TensorBoardLogger(savedir="/tmp/torch_tb/test_mllogs", framework="pytorch")
shutil.rmtree("/tmp/torch_tb/test_mllogs", ignore_errors=True)
with tempfile.TemporaryDirectory() as temp_dir:
save_dir = Path(temp_dir) / "torch_tb/test_mllogs"
yield TensorBoardLogger(savedir=save_dir, framework="pytorch")


@pytest.fixture(scope="module")
Expand Down
1 change: 1 addition & 0 deletions tests/use-cases/test_mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_mnist_train_torch_lightning(torch_env, install_requirements):
subprocess.run(cmd.split(), check=True, cwd=temp_dir)


@pytest.mark.tensorflow
@pytest.mark.functional
def test_mnist_train_tf(tf_env, install_requirements):
"""
Expand Down
5 changes: 2 additions & 3 deletions use-cases/mnist/torch/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
self.save_path = save_path

@monitor_exec
def execute(self) -> Tuple[Dataset, Dataset]:
def execute(self) -> Tuple[Dataset, Dataset, None]:
train_dataset = datasets.MNIST(
self.save_path,
train=True,
Expand Down Expand Up @@ -95,8 +95,7 @@ def __getitem__(self, index: int) -> Tuple[Any, Any]:

@staticmethod
def generate_jpg_sample(root: str, max_items: int = 100):
"""Generate a sample dataset of JPG images starting from
LeCun's test dataset.
"""Generate a sample dataset of JPG images starting from LeCun's test dataset.

Args:
root (str): sample path on disk
Expand Down
Loading
Loading