Skip to content

Commit 1c41255

Browse files
anton-lpcuenca
authored andcommitted
[CI] Add slow MPS tests (huggingface#1104)
* [CI] Add slow MPS tests * fix yml * temporarily resolve caching * Tests: fix mps crashes. * Skip test_load_pipeline_from_git on mps. Not compatible with float16. * Increase tolerance, use CPU generator, alt. slices. * Move to nightly * style Co-authored-by: Pedro Cuenca <[email protected]>
1 parent 359a0e3 commit 1c41255

File tree

5 files changed

+89
-15
lines changed

5 files changed

+89
-15
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Nightly integration tests
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *" # every day at midnight
6+
7+
env:
8+
DIFFUSERS_IS_CI: yes
9+
HF_HOME: /mnt/cache
10+
OMP_NUM_THREADS: 8
11+
MKL_NUM_THREADS: 8
12+
PYTEST_TIMEOUT: 1000
13+
RUN_SLOW: yes
14+
15+
jobs:
16+
run_slow_tests_apple_m1:
17+
name: Slow PyTorch MPS tests on MacOS
18+
runs-on: [ self-hosted, apple-m1 ]
19+
20+
steps:
21+
- name: Checkout diffusers
22+
uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 2
25+
26+
- name: Clean checkout
27+
shell: arch -arch arm64 bash {0}
28+
run: |
29+
git clean -fxd
30+
31+
- name: Setup miniconda
32+
uses: ./.github/actions/setup-miniconda
33+
with:
34+
python-version: 3.9
35+
36+
- name: Install dependencies
37+
shell: arch -arch arm64 bash {0}
38+
run: |
39+
${CONDA_RUN} python -m pip install --upgrade pip
40+
${CONDA_RUN} python -m pip install -e .[quality,test]
41+
${CONDA_RUN} python -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
42+
${CONDA_RUN} python -m pip install git+https://github.com/huggingface/accelerate
43+
44+
- name: Environment
45+
shell: arch -arch arm64 bash {0}
46+
run: |
47+
${CONDA_RUN} python utils/print_env.py
48+
49+
- name: Run slow PyTorch tests on M1 (MPS)
50+
shell: arch -arch arm64 bash {0}
51+
env:
52+
HF_HOME: /System/Volumes/Data/mnt/cache
53+
HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN }}
54+
run: |
55+
${CONDA_RUN} python -m pytest -n 1 -s -v --make-reports=tests_torch_mps tests/
56+
57+
- name: Failure short reports
58+
if: ${{ failure() }}
59+
run: cat reports/tests_torch_mps_failures_short.txt
60+
61+
- name: Test suite reports artifacts
62+
if: ${{ always() }}
63+
uses: actions/upload-artifact@v2
64+
with:
65+
name: torch_mps_test_reports
66+
path: reports

.github/workflows/pr_tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ env:
1414
OMP_NUM_THREADS: 4
1515
MKL_NUM_THREADS: 4
1616
PYTEST_TIMEOUT: 60
17-
MPS_TORCH_VERSION: 1.13.0
1817

1918
jobs:
2019
run_fast_tests:
@@ -126,7 +125,7 @@ jobs:
126125
run: |
127126
${CONDA_RUN} python -m pip install --upgrade pip
128127
${CONDA_RUN} python -m pip install -e .[quality,test]
129-
${CONDA_RUN} python -m pip install --pre torch==${MPS_TORCH_VERSION} --extra-index-url https://download.pytorch.org/whl/test/cpu
128+
${CONDA_RUN} python -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
130129
${CONDA_RUN} python -m pip install git+https://github.com/huggingface/accelerate
131130
${CONDA_RUN} python -m pip install -U git+https://github.com/huggingface/transformers
132131
@@ -137,6 +136,9 @@ jobs:
137136
138137
- name: Run fast PyTorch tests on M1 (MPS)
139138
shell: arch -arch arm64 bash {0}
139+
env:
140+
HF_HOME: /System/Volumes/Data/mnt/cache
141+
HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN }}
140142
run: |
141143
${CONDA_RUN} python -m pytest -n 0 -s -v --make-reports=tests_torch_mps tests/
142144

.github/workflows/push_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,4 @@ jobs:
153153
uses: actions/upload-artifact@v2
154154
with:
155155
name: examples_test_reports
156-
path: reports
156+
path: reports

tests/models/test_models_vae.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,19 @@ def get_sd_vae_model(self, model_id="CompVis/stable-diffusion-v1-4", fp16=False)
165165
return model
166166

167167
def get_generator(self, seed=0):
168+
if torch_device == "mps":
169+
return torch.Generator().manual_seed(seed)
168170
return torch.Generator(device=torch_device).manual_seed(seed)
169171

170172
@parameterized.expand(
171173
[
172174
# fmt: off
173-
[33, [-0.1603, 0.9878, -0.0495, -0.0790, -0.2709, 0.8375, -0.2060, -0.0824]],
174-
[47, [-0.2376, 0.1168, 0.1332, -0.4840, -0.2508, -0.0791, -0.0493, -0.4089]],
175+
[33, [-0.1603, 0.9878, -0.0495, -0.0790, -0.2709, 0.8375, -0.2060, -0.0824], [-0.2395, 0.0098, 0.0102, -0.0709, -0.2840, -0.0274, -0.0718, -0.1824]],
176+
[47, [-0.2376, 0.1168, 0.1332, -0.4840, -0.2508, -0.0791, -0.0493, -0.4089], [0.0350, 0.0847, 0.0467, 0.0344, -0.0842, -0.0547, -0.0633, -0.1131]],
175177
# fmt: on
176178
]
177179
)
178-
def test_stable_diffusion(self, seed, expected_slice):
180+
def test_stable_diffusion(self, seed, expected_slice, expected_slice_mps):
179181
model = self.get_sd_vae_model()
180182
image = self.get_sd_image(seed)
181183
generator = self.get_generator(seed)
@@ -186,7 +188,7 @@ def test_stable_diffusion(self, seed, expected_slice):
186188
assert sample.shape == image.shape
187189

188190
output_slice = sample[-1, -2:, -2:, :2].flatten().float().cpu()
189-
expected_output_slice = torch.tensor(expected_slice)
191+
expected_output_slice = torch.tensor(expected_slice_mps if torch_device == "mps" else expected_slice)
190192

191193
assert torch_all_close(output_slice, expected_output_slice, atol=1e-3)
192194

@@ -217,12 +219,12 @@ def test_stable_diffusion_fp16(self, seed, expected_slice):
217219
@parameterized.expand(
218220
[
219221
# fmt: off
220-
[33, [-0.1609, 0.9866, -0.0487, -0.0777, -0.2716, 0.8368, -0.2055, -0.0814]],
221-
[47, [-0.2377, 0.1147, 0.1333, -0.4841, -0.2506, -0.0805, -0.0491, -0.4085]],
222+
[33, [-0.1609, 0.9866, -0.0487, -0.0777, -0.2716, 0.8368, -0.2055, -0.0814], [-0.2395, 0.0098, 0.0102, -0.0709, -0.2840, -0.0274, -0.0718, -0.1824]],
223+
[47, [-0.2377, 0.1147, 0.1333, -0.4841, -0.2506, -0.0805, -0.0491, -0.4085], [0.0350, 0.0847, 0.0467, 0.0344, -0.0842, -0.0547, -0.0633, -0.1131]],
222224
# fmt: on
223225
]
224226
)
225-
def test_stable_diffusion_mode(self, seed, expected_slice):
227+
def test_stable_diffusion_mode(self, seed, expected_slice, expected_slice_mps):
226228
model = self.get_sd_vae_model()
227229
image = self.get_sd_image(seed)
228230

@@ -232,7 +234,7 @@ def test_stable_diffusion_mode(self, seed, expected_slice):
232234
assert sample.shape == image.shape
233235

234236
output_slice = sample[-1, -2:, -2:, :2].flatten().float().cpu()
235-
expected_output_slice = torch.tensor(expected_slice)
237+
expected_output_slice = torch.tensor(expected_slice_mps if torch_device == "mps" else expected_slice)
236238

237239
assert torch_all_close(output_slice, expected_output_slice, atol=1e-3)
238240

@@ -267,6 +269,7 @@ def test_stable_diffusion_decode(self, seed, expected_slice):
267269
# fmt: on
268270
]
269271
)
272+
@require_torch_gpu
270273
def test_stable_diffusion_decode_fp16(self, seed, expected_slice):
271274
model = self.get_sd_vae_model(fp16=True)
272275
encoding = self.get_sd_image(seed, shape=(3, 4, 64, 64), fp16=True)
@@ -303,4 +306,5 @@ def test_stable_diffusion_encode_sample(self, seed, expected_slice):
303306
output_slice = sample[0, -1, -3:, -3:].flatten().cpu()
304307
expected_output_slice = torch.tensor(expected_slice)
305308

306-
assert torch_all_close(output_slice, expected_output_slice, atol=1e-3)
309+
tolerance = 1e-3 if torch_device != "mps" else 1e-2
310+
assert torch_all_close(output_slice, expected_output_slice, atol=tolerance)

tests/pipelines/latent_diffusion/test_latent_diffusion_uncond.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ def test_inference_uncond(self):
9797

9898
assert image.shape == (1, 64, 64, 3)
9999
expected_slice = np.array([0.8512, 0.818, 0.6411, 0.6808, 0.4465, 0.5618, 0.46, 0.6231, 0.5172])
100-
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
101-
assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2
100+
tolerance = 1e-2 if torch_device != "mps" else 3e-2
101+
assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance
102+
assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < tolerance
102103

103104

104105
@slow
@@ -116,4 +117,5 @@ def test_inference_uncond(self):
116117

117118
assert image.shape == (1, 256, 256, 3)
118119
expected_slice = np.array([0.4399, 0.44975, 0.46825, 0.474, 0.4359, 0.4581, 0.45095, 0.4341, 0.4447])
119-
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
120+
tolerance = 1e-2 if torch_device != "mps" else 3e-2
121+
assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance

0 commit comments

Comments
 (0)