Skip to content

Commit ed22b4f

Browse files
authored
Revive make quality (open-mmlab#203)
* Revive Make utils * Add datasets for training too
1 parent f9522d8 commit ed22b4f

File tree

16 files changed

+27
-140
lines changed

16 files changed

+27
-140
lines changed

Makefile

-5
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ test:
7979
test-examples:
8080
python -m pytest -n auto --dist=loadfile -s -v ./examples/pytorch/
8181

82-
# Run tests for SageMaker DLC release
83-
84-
test-sagemaker: # install sagemaker dependencies in advance with pip install .[sagemaker]
85-
TEST_SAGEMAKER=True python -m pytest -n auto -s -v ./tests/sagemaker
86-
8782

8883
# Release stuff
8984

setup.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,22 @@
7777
# 2. once modified, run: `make deps_table_update` to update src/diffusers/dependency_versions_table.py
7878
_deps = [
7979
"Pillow",
80+
"accelerate>=0.11.0",
8081
"black~=22.0,>=22.3",
82+
"datasets",
8183
"filelock",
8284
"flake8>=3.8.3",
85+
"hf-doc-builder>=0.3.0",
8386
"huggingface-hub",
8487
"importlib_metadata",
8588
"isort>=5.5.4",
89+
"modelcards==0.1.4",
8690
"numpy",
8791
"pytest",
8892
"regex!=2019.12.17",
8993
"requests",
90-
"torch>=1.4",
9194
"tensorboard",
92-
"modelcards==0.1.4"
95+
"torch>=1.4",
9396
]
9497

9598
# this is a lookup table with items like:
@@ -161,12 +164,10 @@ def run(self):
161164

162165
extras = {}
163166
extras["quality"] = ["black ~= 22.0", "isort >= 5.5.4", "flake8 >= 3.8.3"]
164-
extras["docs"] = []
165-
extras["training"] = ["tensorboard", "modelcards"]
166-
extras["test"] = [
167-
"pytest",
168-
]
169-
extras["dev"] = extras["quality"] + extras["test"] + extras["training"]
167+
extras["docs"] = ["hf-doc-builder"]
168+
extras["training"] = ["accelerate", "datasets", "tensorboard", "modelcards"]
169+
extras["test"] = ["pytest"]
170+
extras["dev"] = extras["quality"] + extras["test"] + extras["training"] + extras["docs"]
170171

171172
install_requires = [
172173
deps["importlib_metadata"],

src/diffusers/dependency_versions_table.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
# 2. run `make deps_table_update``
44
deps = {
55
"Pillow": "Pillow",
6+
"accelerate": "accelerate>=0.11.0",
67
"black": "black~=22.0,>=22.3",
78
"filelock": "filelock",
89
"flake8": "flake8>=3.8.3",
10+
"hf-doc-builder": "hf-doc-builder>=0.3.0",
911
"huggingface-hub": "huggingface-hub",
1012
"importlib_metadata": "importlib_metadata",
1113
"isort": "isort>=5.5.4",
14+
"modelcards": "modelcards==0.1.4",
1215
"numpy": "numpy",
1316
"pytest": "pytest",
1417
"regex": "regex!=2019.12.17",
1518
"requests": "requests",
1619
"torch": "torch>=1.4",
1720
"tensorboard": "tensorboard",
18-
"modelcards": "modelcards==0.1.4",
1921
}

src/diffusers/optimization.py

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from enum import Enum
1919
from typing import Optional, Union
2020

21-
import torch
2221
from torch.optim import Optimizer
2322
from torch.optim.lr_scheduler import LambdaLR
2423

src/diffusers/pipelines/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from ..utils import is_inflect_available, is_transformers_available, is_unidecode_available
1+
# flake8: noqa
2+
# There's no way to ignore "F401 '...' imported but unused" warnings in this
3+
# module, but to preserve other warnings. So, don't check this module at all.
4+
5+
from ..utils import is_transformers_available
26
from .ddim import DDIMPipeline
37
from .ddpm import DDPMPipeline
48
from .latent_diffusion_uncond import LDMPipeline
+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# flake8: noqa
12
from .pipeline_ddim import DDIMPipeline
+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# flake8: noqa
12
from .pipeline_ddpm import DDPMPipeline

src/diffusers/pipelines/latent_diffusion/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# flake8: noqa
12
from ...utils import is_transformers_available
23

34

Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# flake8: noqa
12
from .pipeline_latent_diffusion_uncond import LDMPipeline
+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# flake8: noqa
12
from .pipeline_pndm import PNDMPipeline
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# flake8: noqa
12
from .pipeline_score_sde_ve import ScoreSdeVePipeline

src/diffusers/pipelines/stable_diffusion/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# flake8: noqa
12
from ...utils import is_transformers_available
23

34

Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# flake8: noqa
12
from .pipeline_stochastic_karras_ve import KarrasVePipeline

src/diffusers/schedulers/scheduling_lms_discrete.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import List, Union
15+
from typing import Union
1616

1717
import numpy as np
1818
import torch

src/diffusers/utils/dummy_scipy_objects.py

-14
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,3 @@ class LMSDiscreteScheduler(metaclass=DummyObject):
88

99
def __init__(self, *args, **kwargs):
1010
requires_backends(self, ["scipy"])
11-
12-
13-
class LDMTextToImagePipeline(metaclass=DummyObject):
14-
_backends = ["scipy"]
15-
16-
def __init__(self, *args, **kwargs):
17-
requires_backends(self, ["scipy"])
18-
19-
20-
class StableDiffusionPipeline(metaclass=DummyObject):
21-
_backends = ["scipy"]
22-
23-
def __init__(self, *args, **kwargs):
24-
requires_backends(self, ["scipy"])

tests/test_layers_utils.py

+1-109
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414
# limitations under the License.
1515

1616

17-
import inspect
18-
import tempfile
1917
import unittest
2018

2119
import numpy as np
2220
import torch
2321

2422
from diffusers.models.embeddings import get_timestep_embedding
25-
from diffusers.models.resnet import Downsample1D, Downsample2D, Upsample1D, Upsample2D
26-
from diffusers.testing_utils import floats_tensor, slow, torch_device
23+
from diffusers.models.resnet import Downsample2D, Upsample2D
2724

2825

2926
torch.backends.cuda.matmul.allow_tf32 = False
@@ -219,108 +216,3 @@ def test_downsample_with_conv_out_dim(self):
219216
output_slice = downsampled[0, -1, -3:, -3:]
220217
expected_slice = torch.tensor([-0.6586, 0.5985, 0.0721, 0.1256, -0.1492, 0.4436, -0.2544, 0.5021, 1.1522])
221218
assert torch.allclose(output_slice.flatten(), expected_slice, atol=1e-3)
222-
223-
224-
class Upsample1DBlockTests(unittest.TestCase):
225-
def test_upsample_default(self):
226-
torch.manual_seed(0)
227-
sample = torch.randn(1, 32, 32)
228-
upsample = Upsample1D(channels=32, use_conv=False)
229-
with torch.no_grad():
230-
upsampled = upsample(sample)
231-
232-
assert upsampled.shape == (1, 32, 64)
233-
output_slice = upsampled[0, -1, -8:]
234-
expected_slice = torch.tensor([-1.6340, -1.6340, 0.5374, 0.5374, 1.0826, 1.0826, -1.7105, -1.7105])
235-
assert torch.allclose(output_slice.flatten(), expected_slice, atol=1e-3)
236-
237-
def test_upsample_with_conv(self):
238-
torch.manual_seed(0)
239-
sample = torch.randn(1, 32, 32)
240-
upsample = Upsample1D(channels=32, use_conv=True)
241-
with torch.no_grad():
242-
upsampled = upsample(sample)
243-
244-
assert upsampled.shape == (1, 32, 64)
245-
output_slice = upsampled[0, -1, -8:]
246-
expected_slice = torch.tensor([-0.4546, -0.5010, -0.2996, 0.2844, 0.4040, -0.7772, -0.6862, 0.3612])
247-
assert torch.allclose(output_slice.flatten(), expected_slice, atol=1e-3)
248-
249-
def test_upsample_with_conv_out_dim(self):
250-
torch.manual_seed(0)
251-
sample = torch.randn(1, 32, 32)
252-
upsample = Upsample1D(channels=32, use_conv=True, out_channels=64)
253-
with torch.no_grad():
254-
upsampled = upsample(sample)
255-
256-
assert upsampled.shape == (1, 64, 64)
257-
output_slice = upsampled[0, -1, -8:]
258-
expected_slice = torch.tensor([-0.0516, -0.0972, 0.9740, 1.1883, 0.4539, -0.5285, -0.5851, 0.1152])
259-
assert torch.allclose(output_slice.flatten(), expected_slice, atol=1e-3)
260-
261-
def test_upsample_with_transpose(self):
262-
torch.manual_seed(0)
263-
sample = torch.randn(1, 32, 32)
264-
upsample = Upsample1D(channels=32, use_conv=False, use_conv_transpose=True)
265-
with torch.no_grad():
266-
upsampled = upsample(sample)
267-
268-
assert upsampled.shape == (1, 32, 64)
269-
output_slice = upsampled[0, -1, -8:]
270-
expected_slice = torch.tensor([-0.2238, -0.5842, -0.7165, 0.6699, 0.1033, -0.4269, -0.8974, -0.3716])
271-
assert torch.allclose(output_slice.flatten(), expected_slice, atol=1e-3)
272-
273-
274-
class Downsample1DBlockTests(unittest.TestCase):
275-
def test_downsample_default(self):
276-
torch.manual_seed(0)
277-
sample = torch.randn(1, 32, 64)
278-
downsample = Downsample1D(channels=32, use_conv=False)
279-
with torch.no_grad():
280-
downsampled = downsample(sample)
281-
282-
assert downsampled.shape == (1, 32, 32)
283-
output_slice = downsampled[0, -1, -8:]
284-
expected_slice = torch.tensor([-0.8796, 1.0945, -0.3434, 0.2910, 0.3391, -0.4488, -0.9568, -0.2909])
285-
max_diff = (output_slice.flatten() - expected_slice).abs().sum().item()
286-
assert max_diff <= 1e-3
287-
# assert torch.allclose(output_slice.flatten(), expected_slice, atol=1e-1)
288-
289-
def test_downsample_with_conv(self):
290-
torch.manual_seed(0)
291-
sample = torch.randn(1, 32, 64)
292-
downsample = Downsample1D(channels=32, use_conv=True)
293-
with torch.no_grad():
294-
downsampled = downsample(sample)
295-
296-
assert downsampled.shape == (1, 32, 32)
297-
output_slice = downsampled[0, -1, -8:]
298-
299-
expected_slice = torch.tensor(
300-
[0.1723, 0.0811, -0.6205, -0.3045, 0.0666, -0.2381, -0.0238, 0.2834],
301-
)
302-
assert torch.allclose(output_slice.flatten(), expected_slice, atol=1e-3)
303-
304-
def test_downsample_with_conv_pad1(self):
305-
torch.manual_seed(0)
306-
sample = torch.randn(1, 32, 64)
307-
downsample = Downsample1D(channels=32, use_conv=True, padding=1)
308-
with torch.no_grad():
309-
downsampled = downsample(sample)
310-
311-
assert downsampled.shape == (1, 32, 32)
312-
output_slice = downsampled[0, -1, -8:]
313-
expected_slice = torch.tensor([0.1723, 0.0811, -0.6205, -0.3045, 0.0666, -0.2381, -0.0238, 0.2834])
314-
assert torch.allclose(output_slice.flatten(), expected_slice, atol=1e-3)
315-
316-
def test_downsample_with_conv_out_dim(self):
317-
torch.manual_seed(0)
318-
sample = torch.randn(1, 32, 64)
319-
downsample = Downsample1D(channels=32, use_conv=True, out_channels=16)
320-
with torch.no_grad():
321-
downsampled = downsample(sample)
322-
323-
assert downsampled.shape == (1, 16, 32)
324-
output_slice = downsampled[0, -1, -8:]
325-
expected_slice = torch.tensor([1.1067, -0.5255, -0.4451, 0.0487, -0.3664, -0.7945, -0.4495, -0.3129])
326-
assert torch.allclose(output_slice.flatten(), expected_slice, atol=1e-3)

0 commit comments

Comments
 (0)