From 37b941ddd1b15fe8e02500995a8b928ee2d386ed Mon Sep 17 00:00:00 2001 From: annahedstroem Date: Tue, 15 Jul 2025 16:47:05 +0200 Subject: [PATCH 01/10] added new release version --- quantus/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantus/__init__.py b/quantus/__init__.py index 407f5c73..2f6ecd0d 100644 --- a/quantus/__init__.py +++ b/quantus/__init__.py @@ -5,7 +5,7 @@ # Quantus project URL: . # Set the correct version. -__version__ = "0.5.3" +__version__ = "0.6.0" # Expose quantus.evaluate to the user. from quantus.evaluation import evaluate From c14d54e279f49a0e8c8f0f9b9139e5b6d43f0246 Mon Sep 17 00:00:00 2001 From: annahedstroem Date: Tue, 15 Jul 2025 16:54:25 +0200 Subject: [PATCH 02/10] small changes to tf tests --- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2e829fa1..1f3cd112 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,8 @@ tensorflow = [ # 2.16 is shipped without keras "tensorflow<2.16.0", # keras V3 broke everything - "keras<3" + "keras<3", + "numpy<2" ] captum = [ "quantus[torch]", @@ -91,6 +92,7 @@ tests = [ "pytest-lazy-fixture>=0.6.3", "pytest-mock==3.10.0", "pytest_xdist", + "numpy<2", "quantus[full]" ] From 60d88499b857f8b237617cc8bda50e5f1ebec6ba Mon Sep 17 00:00:00 2001 From: annahedstroem Date: Tue, 15 Jul 2025 17:34:59 +0200 Subject: [PATCH 03/10] small update to tox file --- .github/workflows/python-package.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 2d905ec5..40bd04f6 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -32,6 +32,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install tox-gh run: pip install tox-gh + - name: Install quantus with test dependencies + run: pip install .[tests] - name: Setup test environment run: tox run --notest - name: Test with PyTest From 5aa881defec7a1b91c514664403eb0c3bb680d22 Mon Sep 17 00:00:00 2001 From: annahedstroem Date: Tue, 15 Jul 2025 17:38:13 +0200 Subject: [PATCH 04/10] small update to tox file coverage --- .github/workflows/codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 53b18ab6..dd8a4486 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -20,7 +20,7 @@ jobs: uses: actions/setup-python@v4 with: cache: 'pip' - python-version: "3.9" + python-version: "3.10" - name: Install tox-gh run: pip install tox-gh From 461993c68ce5a31e3fd112962a25c637bba24221 Mon Sep 17 00:00:00 2001 From: annahedstroem Date: Tue, 15 Jul 2025 17:44:29 +0200 Subject: [PATCH 05/10] updated nympy syntax for stacking --- quantus/metrics/faithfulness/selectivity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantus/metrics/faithfulness/selectivity.py b/quantus/metrics/faithfulness/selectivity.py index d9197cbd..544d926f 100644 --- a/quantus/metrics/faithfulness/selectivity.py +++ b/quantus/metrics/faithfulness/selectivity.py @@ -375,6 +375,6 @@ def evaluate_batch( y_pred_perturb = model.predict(x_input)[np.arange(batch_size), y_batch] results.append(y_pred_perturb) - results = np.stack(results, 1, dtype=np.float64) + results = np.stack(results, 1).astype(np.float64) return results From fcfa58bc0cb825b6dbb5e40284df43e3e9dd65d1 Mon Sep 17 00:00:00 2001 From: annahedstroem Date: Tue, 15 Jul 2025 17:49:19 +0200 Subject: [PATCH 06/10] fixes transfomers tests --- "tests/assets/Icon\r" | 0 tests/functions/test_pytorch_model.py | 6 ++++++ 2 files changed, 6 insertions(+) delete mode 100644 "tests/assets/Icon\r" diff --git "a/tests/assets/Icon\r" "b/tests/assets/Icon\r" deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/functions/test_pytorch_model.py b/tests/functions/test_pytorch_model.py index caa64f50..59081760 100644 --- a/tests/functions/test_pytorch_model.py +++ b/tests/functions/test_pytorch_model.py @@ -11,6 +11,12 @@ from scipy.special import softmax from quantus.helpers.model.pytorch_model import PyTorchModel +def torch_available(): + try: + import torch + return True + except ImportError: + return False @pytest.fixture def mock_input_torch_array(): From 65ef20bbeff14e81e7b2f22a14ac65d26465668d Mon Sep 17 00:00:00 2001 From: annahedstroem Date: Tue, 15 Jul 2025 17:51:29 +0200 Subject: [PATCH 07/10] added explicit torch installation --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1f3cd112..011d316e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,10 +79,10 @@ zennit = [ ] transformers = [ "quantus[torch]", - "transformers>=4.38.2", + "transformers>=4.38.2", #"transformers<4.38.0" ] full = [ - "quantus[captum,tf-explain,zennit,transformers]" + "quantus[captum,tf-explain,zennit,transformers,torch]" ] tests = [ "coverage>=7.2.3", From 08ec7fb6afabed2306c678ad17ba5aacf96e60b2 Mon Sep 17 00:00:00 2001 From: annahedstroem Date: Mon, 21 Jul 2025 11:19:53 +0200 Subject: [PATCH 08/10] updated tox.init for 3.8 build --- tox.ini | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tox.ini b/tox.ini index aa678a73..0a583aa0 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,8 @@ commands = [testenv:coverage] description = Run the tests with coverage -base_python = py310 +base_python = + deps = {[testenv]deps} coverage @@ -27,14 +28,14 @@ commands = [testenv:build] description = Build environment -base_python = py310 deps = - . build twine commands = - python3 -m build . - python3 -m twine check ./dist/* --strict + python -c "import shutil; shutil.rmtree('dist', ignore_errors=True)" + python -m build . + python -m twine check ./dist/* --strict + [testenv:lint] description = Check the code style From 61eaeb47a713f6c64e6c0b4e166c9aa4bb3d9d18 Mon Sep 17 00:00:00 2001 From: annahedstroem Date: Mon, 21 Jul 2025 11:55:55 +0200 Subject: [PATCH 09/10] fixing for tox and pyproject --- pyproject.toml | 9 +++++++-- tox.ini | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 011d316e..8d25ec57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,10 +51,15 @@ dynamic = ["version"] # [project.optional-dependencies] torch = [ + # Mac/Windows or unknown platform fallback "torch>=1.13.1; sys_platform != 'linux'", "torchvision>=0.15.1; sys_platform != 'linux'", - "torch>=1.13.1, <2.0.0; sys_platform == 'linux' and python_version <= '3.10'", - "torchvision>=0.14.0, <0.15.1; sys_platform == 'linux' and python_version <= '3.10'", + + # Linux + Python 3.8–3.10 → use torch 1.x + "torch>=1.13.1, <2.0.0; sys_platform == 'linux' and python_version < '3.11'", + "torchvision>=0.14.0, <0.15.1; sys_platform == 'linux' and python_version < '3.11'", + + # Linux + Python 3.11+ → use torch 2.x "torch>=2.0.0; sys_platform == 'linux' and python_version >= '3.11'", "torchvision>=0.15.1; sys_platform == 'linux' and python_version >= '3.11'", ] diff --git a/tox.ini b/tox.ini index 0a583aa0..341a2100 100644 --- a/tox.ini +++ b/tox.ini @@ -12,9 +12,13 @@ deps = .[tests] pass_env = TF_XLA_FLAGS +commands_pre = + python -c "import sys, platform; print(f'Python: {sys.version_info.major}.{sys.version_info.minor}, Platform: {platform.system()}')" + python -c "import sys; import subprocess; v=sys.version_info; linux=sys.platform=='linux'; needs=torch_install=(linux and (v.major==3 and v.minor in (9,10))); subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'torch<2.0.0']) if needs else None" commands = pytest -s -v {posargs} + [testenv:coverage] description = Run the tests with coverage base_python = From b03d0c37609d18a5f9133441952dba8062240821 Mon Sep 17 00:00:00 2001 From: annahedstroem Date: Mon, 21 Jul 2025 12:06:53 +0200 Subject: [PATCH 10/10] updated hf model conftests functions --- tests/conftest.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index bde949ac..11b7362f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -239,23 +239,36 @@ def load_mnist_model_softmax(): @pytest.fixture(scope="session", autouse=False) def load_hf_distilbert_sequence_classifier(): - """ - TODO - """ - DISTILBERT_BASE = "distilbert-base-uncased" - model = AutoModelForSequenceClassification.from_pretrained(DISTILBERT_BASE, cache_dir="/tmp/") - return model + try: + import torch + except ImportError: + pytest.skip("Skipping because torch is not available.") + + try: + from transformers import AutoModelForSequenceClassification + DISTILBERT_BASE = "distilbert-base-uncased" + return AutoModelForSequenceClassification.from_pretrained(DISTILBERT_BASE, cache_dir="/tmp/") + except Exception as e: + pytest.skip(f"Skipping because model loading failed: {e}") + @pytest.fixture(scope="session", autouse=False) def dummy_hf_tokenizer(): - """ - TODO - """ - DISTILBERT_BASE = "distilbert-base-uncased" - REFERENCE_TEXT = "The quick brown fox jumps over the lazy dog" - tokenizer = AutoTokenizer.from_pretrained(DISTILBERT_BASE, cache_dir="/tmp/", clean_up_tokenization_spaces=True) - return tokenizer(REFERENCE_TEXT, return_tensors="pt") + try: + import torch + except ImportError: + pytest.skip("Skipping because torch is not available.") + + try: + from transformers import AutoTokenizer + DISTILBERT_BASE = "distilbert-base-uncased" + REFERENCE_TEXT = "The quick brown fox jumps over the lazy dog" + tokenizer = AutoTokenizer.from_pretrained(DISTILBERT_BASE, cache_dir="/tmp/", clean_up_tokenization_spaces=True) + return tokenizer(REFERENCE_TEXT, return_tensors="pt") + except Exception as e: + pytest.skip(f"Skipping because tokenizer loading failed: {e}") + @pytest.fixture(scope="session", autouse=True)