Skip to content

Commit adc18c9

Browse files
authored
🧑‍💻 Fix issues with Cache processing on GitHub (#962)
- Fix issues with Cache processing on GitHub
1 parent 9d0c40c commit adc18c9

File tree

4 files changed

+23
-43
lines changed

4 files changed

+23
-43
lines changed

.github/workflows/python-package.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
python-version: ["3.10", "3.11", "3.12", "3.13"]
2121

2222
steps:
23-
- uses: actions/checkout@v3
23+
- uses: actions/checkout@v4
2424
- name: Set up Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v3
25+
uses: actions/setup-python@v4
2626
with:
2727
python-version: ${{ matrix.python-version }}
2828
- name: Install dependencies
@@ -33,7 +33,7 @@ jobs:
3333
python -m pip install ruff==0.13.3 pytest pytest-cov pytest-runner
3434
pip install -r requirements/requirements.txt
3535
- name: Cache tiatoolbox static assets
36-
uses: actions/cache@v3
36+
uses: actions/cache@v4
3737
with:
3838
key: tiatoolbox-home-static
3939
path: ~/.tiatoolbox
@@ -76,6 +76,17 @@ jobs:
7676
coverage-file: coverage.xml
7777
dsn: ${{ secrets.DEEPSOURCE_DSN }}
7878
fail-ci-on-error: false
79+
- name: List tiatoolbox contents
80+
run: ls -lahR ~/.tiatoolbox
81+
- name: Delete Hugging Face cache for large models
82+
run: |
83+
find ~/.tiatoolbox/models -type f -size +250M -exec bash -c '
84+
for model_path; do
85+
model_name=$(basename "$model_path")
86+
cache_dir="$HOME/.tiatoolbox/models/.cache/huggingface/download"
87+
rm -vf "$cache_dir/${model_name}.lock" "$cache_dir/${model_name}.metadata"
88+
done
89+
' bash {} +
7990
8091
release:
8192
runs-on: ubuntu-24.04
@@ -84,10 +95,10 @@ jobs:
8495
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/pre-release' || startsWith(github.ref, 'refs/tags/v')
8596

8697
steps:
87-
- uses: actions/checkout@v3
98+
- uses: actions/checkout@v4
8899

89100
- name: Set up Python 3.10
90-
uses: actions/setup-python@v3
101+
uses: actions/setup-python@v4
91102
with:
92103
python-version: '3.10'
93104
cache: 'pip'

tests/models/test_arch_mapde.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Unit test package for SCCNN."""
22

33
from collections.abc import Callable
4+
from pathlib import Path
45

56
import numpy as np
67
import torch
@@ -14,15 +15,15 @@
1415
ON_GPU = toolbox_env.has_gpu()
1516

1617

17-
def _load_mapde(name: str) -> MapDe:
18+
def _load_mapde(name: str) -> tuple[MapDe, str]:
1819
"""Loads MapDe model with specified weights."""
1920
model = MapDe()
2021
weights_path = fetch_pretrained_weights(name)
2122
map_location = select_device(on_gpu=ON_GPU)
2223
pretrained = torch.load(weights_path, map_location=map_location)
2324
model.load_state_dict(pretrained)
2425
model.to(map_location)
25-
return model
26+
return model, weights_path
2627

2728

2829
def test_functionality(remote_sample: Callable) -> None:
@@ -42,12 +43,13 @@ def test_functionality(remote_sample: Callable) -> None:
4243
coord_space="resolution",
4344
)
4445

45-
model = _load_mapde(name="mapde-conic")
46+
model, weights_path = _load_mapde(name="mapde-conic")
4647
patch = model.preproc(patch)
4748
batch = torch.from_numpy(patch)[None]
4849
output = model.infer_batch(model, batch, device=select_device(on_gpu=ON_GPU))
4950
output = model.postproc(output[0])
5051
assert np.all(output[0:2] == [[19, 171], [53, 89]])
52+
Path(weights_path).unlink()
5153

5254

5355
def test_multiclass_output() -> None:

tests/models/test_arch_micronet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_functionality(
4242
output = model.infer_batch(model, batch, device=map_location)
4343
output, _ = model.postproc(output[0])
4444
assert np.max(np.unique(output)) == 46
45+
Path(weights_path).unlink()
4546

4647

4748
def test_value_error() -> None:

tests/models/test_hovernet.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,6 @@ def test_functionality(remote_sample: Callable) -> None:
4040
output = model.postproc(output)
4141
assert len(output[1]) > 0, "Must have some nuclei."
4242

43-
# * test fast mode (architecture used for MoNuSAC data)
44-
patch = reader.read_bounds(
45-
(0, 0, 256, 256),
46-
resolution=0.25,
47-
units="mpp",
48-
coord_space="resolution",
49-
)
50-
batch = torch.from_numpy(patch)[None]
51-
model = HoVerNet(num_types=5, mode="fast")
52-
weights_path = fetch_pretrained_weights("hovernet_fast-monusac")
53-
pretrained = torch.load(weights_path)
54-
model.load_state_dict(pretrained)
55-
output = model.infer_batch(model, batch, device=select_device(on_gpu=False))
56-
output = [v[0] for v in output]
57-
output = model.postproc(output)
58-
assert len(output[1]) > 0, "Must have some nuclei."
59-
6043
# * test original mode on CoNSeP dataset (architecture used in HoVerNet paper)
6144
patch = reader.read_bounds(
6245
(0, 0, 270, 270),
@@ -74,26 +57,9 @@ def test_functionality(remote_sample: Callable) -> None:
7457
output = model.postproc(output)
7558
assert len(output[1]) > 0, "Must have some nuclei."
7659

77-
# * test original mode on Kumar dataset (architecture used in HoVerNet paper)
78-
patch = reader.read_bounds(
79-
(0, 0, 270, 270),
80-
resolution=0.25,
81-
units="mpp",
82-
coord_space="resolution",
83-
)
84-
batch = torch.from_numpy(patch)[None]
85-
model = HoVerNet(num_types=None, mode="original")
86-
weights_path = fetch_pretrained_weights("hovernet_original-kumar")
87-
pretrained = torch.load(weights_path)
88-
model.load_state_dict(pretrained)
89-
output = model.infer_batch(model, batch, device=select_device(on_gpu=False))
90-
output = [v[0] for v in output]
91-
output = model.postproc(output)
92-
assert len(output[1]) > 0, "Must have some nuclei."
93-
9460
# test crash when providing exotic mode
9561
with pytest.raises(ValueError, match=r".*Invalid mode.*"):
96-
model = HoVerNet(num_types=None, mode="super")
62+
_ = HoVerNet(num_types=None, mode="super")
9763

9864

9965
def test_unit_blocks() -> None:

0 commit comments

Comments
 (0)