Unverified Commit 6ba2231d authored by Patrick von Platen's avatar Patrick von Platen Committed by GitHub
Browse files

Reproducibility 3/3 (#1924)



* make tests deterministic

* run slow tests

* prepare for testing

* finish

* refactor

* add print statements

* finish more

* correct some test failures

* more fixes

* set up to correct tests

* more corrections

* up

* fix more

* more prints

* add

* up

* up

* up

* uP

* uP

* more fixes

* uP

* up

* up

* up

* up

* fix more

* up

* up

* clean tests

* up

* up

* up

* more fixes

* Apply suggestions from code review
Co-authored-by: default avatarSuraj Patil <surajp815@gmail.com>

* make

* correct

* finish

* finish
Co-authored-by: default avatarSuraj Patil <surajp815@gmail.com>
parent 008c22d3
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
title: Text-Guided Depth-to-Image title: Text-Guided Depth-to-Image
- local: using-diffusers/reusing_seeds - local: using-diffusers/reusing_seeds
title: Reusing seeds for deterministic generation title: Reusing seeds for deterministic generation
- local: using-diffusers/reproducibility
title: Reproducibility
- local: using-diffusers/custom_pipeline_examples - local: using-diffusers/custom_pipeline_examples
title: Community Pipelines title: Community Pipelines
- local: using-diffusers/contribute_pipeline - local: using-diffusers/contribute_pipeline
......
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->
# Reproducibility
Before reading about reproducibility for Diffusers, it is strongly recommended to take a look at
[PyTorch's statement about reproducibility](https://pytorch.org/docs/stable/notes/randomness.html).
PyTorch states that
> *completely reproducible results are not guaranteed across PyTorch releases, individual commits, or different platforms.*
While one can never expect the same results across platforms, one can expect results to be reproducible
across releases, platforms, etc... within a certain tolerance. However, this tolerance strongly varies
depending on the diffusion pipeline and checkpoint.
In the following, we show how to best control sources of randomness for diffusion models.
## Inference
During inference, diffusion pipelines heavily rely on random sampling operations, such as the creating the
gaussian noise tensors to be denoised and adding noise to the scheduling step.
Let's have a look at an example. We run the [DDIM pipeline](./api/pipelines/ddim.mdx)
for just two inference steps and return a numpy tensor to look into the numerical values of the output.
```python
from diffusers import DDIMPipeline
import numpy as np
model_id = "google/ddpm-cifar10-32"
# load model and scheduler
ddim = DDIMPipeline.from_pretrained(model_id)
# run pipeline for just two steps and return numpy tensor
image = ddim(num_inference_steps=2, output_type="np").images
print(np.abs(image).sum())
```
Running the above prints a value of 1464.2076, but running it again prints a different
value of 1495.1768. What is going on here? Every time the pipeline is run, gaussian noise
is created and step-wise denoised. To create the gaussian noise with [`torch.randn`](https://pytorch.org/docs/stable/generated/torch.randn.html), a different random seed is taken every time, thus leading to a different result.
This is a desired property of diffusion pipelines, as it means that the pipeline can create a different random image every time it is run. In many cases, one would like to generate the exact same image of a certain
run, for which case an instance of a [PyTorch generator](https://pytorch.org/docs/stable/generated/torch.randn.html) has to be passed:
```python
import torch
from diffusers import DDIMPipeline
import numpy as np
model_id = "google/ddpm-cifar10-32"
# load model and scheduler
ddim = DDIMPipeline.from_pretrained(model_id)
# create a generator for reproducibility
generator = torch.Generator(device="cpu").manual_seed(0)
# run pipeline for just two steps and return numpy tensor
image = ddim(num_inference_steps=2, output_type="np", generator=generator).images
print(np.abs(image).sum())
```
Running the above always prints a value of 1491.1711 - also upon running it again because we
define the generator object to be passed to all random functions of the pipeline.
If you run this code snippet on your specific hardware and version, you should get a similar, if not the same, result.
<Tip>
It might be a bit unintuitive at first to pass `generator` objects to the pipelines instead of
just integer values representing the seed, but this is the recommended design when dealing with
probabilistic models in PyTorch as generators are *random states* that are advanced and can thus be
passed to multiple pipelines in a sequence.
</Tip>
Great! Now, we know how to write reproducible pipelines, but it gets a bit trickier since the above example only runs on the CPU. How do we also achieve reproducibility on GPU?
In short, one should not expect full reproducibility across different hardware when running pipelines on GPU
as matrix multiplications are less deterministic on GPU than on CPU and diffusion pipelines tend to require
a lot of matrix multiplications. Let's see what we can do to keep the randomness within limits across
different GPU hardware.
To achieve maximum speed performance, it is recommended to create the generator directly on GPU when running
the pipeline on GPU:
```python
import torch
from diffusers import DDIMPipeline
import numpy as np
model_id = "google/ddpm-cifar10-32"
# load model and scheduler
ddim = DDIMPipeline.from_pretrained(model_id)
ddim.to("cuda")
# create a generator for reproducibility
generator = torch.Generator(device="cuda").manual_seed(0)
# run pipeline for just two steps and return numpy tensor
image = ddim(num_inference_steps=2, output_type="np", generator=generator).images
print(np.abs(image).sum())
```
Running the above now prints a value of 1389.8634 - even though we're using the exact same seed!
This is unfortunate as it means we cannot reproduce the results we achieved on GPU, also on CPU.
Nevertheless, it should be expected since the GPU uses a different random number generator than the CPU.
To circumvent this problem, we created a [`randn_tensor`](#diffusers.utils.randn_tensor) function, which can create random noise
on the CPU and then move the tensor to GPU if necessary. The function is used everywhere inside the pipelines allowing the user to **always** pass a CPU generator even if the pipeline is run on GPU:
```python
import torch
from diffusers import DDIMPipeline
import numpy as np
model_id = "google/ddpm-cifar10-32"
# load model and scheduler
ddim = DDIMPipeline.from_pretrained(model_id)
ddim.to("cuda")
# create a generator for reproducibility
generator = torch.manual_seed(0)
# run pipeline for just two steps and return numpy tensor
image = ddim(num_inference_steps=2, output_type="np", generator=generator).images
print(np.abs(image).sum())
```
Running the above now prints a value of 1491.1713, much closer to the value of 1491.1711 when
the pipeline is fully run on the CPU.
<Tip>
As a consequence, we recommend always passing a CPU generator if Reproducibility is important.
The loss of performance is often neglectable, but one can be sure to generate much more similar
values than if the pipeline would have been run on CPU.
</Tip>
Finally, we noticed that more complex pipelines, such as [`UnCLIPPipeline`] are often extremely
susceptible to precision error propagation and thus one cannot expect even similar results across
different GPU hardware or PyTorch versions. In such cases, one has to make sure to run
exactly the same hardware and PyTorch version for full Reproducibility.
## Randomness utilities
### randn_tensor
[[autodoc]] diffusers.utils.randn_tensor
...@@ -17,7 +17,7 @@ from typing import List, Optional, Tuple, Union ...@@ -17,7 +17,7 @@ from typing import List, Optional, Tuple, Union
import torch import torch
from ...schedulers import DDIMScheduler from ...schedulers import DDIMScheduler
from ...utils import deprecate, randn_tensor from ...utils import randn_tensor
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
...@@ -78,24 +78,6 @@ class DDIMPipeline(DiffusionPipeline): ...@@ -78,24 +78,6 @@ class DDIMPipeline(DiffusionPipeline):
True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images. True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images.
""" """
if (
generator is not None
and isinstance(generator, torch.Generator)
and generator.device.type != self.device.type
and self.device.type != "mps"
):
message = (
f"The `generator` device is `{generator.device}` and does not match the pipeline "
f"device `{self.device}`, so the `generator` will be ignored. "
f'Please use `generator=torch.Generator(device="{self.device}")` instead.'
)
deprecate(
"generator.device == 'cpu'",
"0.13.0",
message,
)
generator = None
# Sample gaussian noise to begin loop # Sample gaussian noise to begin loop
if isinstance(self.unet.sample_size, int): if isinstance(self.unet.sample_size, int):
image_shape = (batch_size, self.unet.in_channels, self.unet.sample_size, self.unet.sample_size) image_shape = (batch_size, self.unet.in_channels, self.unet.sample_size, self.unet.sample_size)
......
...@@ -76,6 +76,7 @@ if is_torch_available(): ...@@ -76,6 +76,7 @@ if is_torch_available():
load_numpy, load_numpy,
nightly, nightly,
parse_flag_from_env, parse_flag_from_env,
print_tensor_test,
require_torch_gpu, require_torch_gpu,
slow, slow,
torch_all_close, torch_all_close,
......
...@@ -8,7 +8,7 @@ import urllib.parse ...@@ -8,7 +8,7 @@ import urllib.parse
from distutils.util import strtobool from distutils.util import strtobool
from io import BytesIO, StringIO from io import BytesIO, StringIO
from pathlib import Path from pathlib import Path
from typing import Union from typing import Optional, Union
import numpy as np import numpy as np
...@@ -45,6 +45,21 @@ def torch_all_close(a, b, *args, **kwargs): ...@@ -45,6 +45,21 @@ def torch_all_close(a, b, *args, **kwargs):
return True return True
def print_tensor_test(tensor, filename="test_corrections.txt", expected_tensor_name="expected_slice"):
test_name = os.environ.get("PYTEST_CURRENT_TEST")
if not torch.is_tensor(tensor):
tensor = torch.from_numpy(tensor)
tensor_str = str(tensor.detach().cpu().flatten().to(torch.float32)).replace("\n", "")
# format is usually:
# expected_slice = np.array([-0.5713, -0.3018, -0.9814, 0.04663, -0.879, 0.76, -1.734, 0.1044, 1.161])
output_str = tensor_str.replace("tensor", f"{expected_tensor_name} = np.array")
test_file, test_class, test_fn = test_name.split("::")
test_fn = test_fn.split()[0]
with open(filename, "a") as f:
print(";".join([test_file, test_class, test_fn, output_str]), file=f)
def get_tests_dir(append_path=None): def get_tests_dir(append_path=None):
""" """
Args: Args:
...@@ -150,9 +165,13 @@ def require_onnxruntime(test_case): ...@@ -150,9 +165,13 @@ def require_onnxruntime(test_case):
return unittest.skipUnless(is_onnx_available(), "test requires onnxruntime")(test_case) return unittest.skipUnless(is_onnx_available(), "test requires onnxruntime")(test_case)
def load_numpy(arry: Union[str, np.ndarray]) -> np.ndarray: def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -> np.ndarray:
if isinstance(arry, str): if isinstance(arry, str):
if arry.startswith("http://") or arry.startswith("https://"): # local_path = "/home/patrick_huggingface_co/"
if local_path is not None:
# local_path can be passed to correct images of tests
return os.path.join(local_path, "/".join([arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]]))
elif arry.startswith("http://") or arry.startswith("https://"):
response = requests.get(arry) response = requests.get(arry)
response.raise_for_status() response.raise_for_status()
arry = np.load(BytesIO(response.content)) arry = np.load(BytesIO(response.content))
......
...@@ -166,7 +166,7 @@ class AutoencoderKLIntegrationTests(unittest.TestCase): ...@@ -166,7 +166,7 @@ class AutoencoderKLIntegrationTests(unittest.TestCase):
def get_generator(self, seed=0): def get_generator(self, seed=0):
if torch_device == "mps": if torch_device == "mps":
return torch.Generator().manual_seed(seed) return torch.manual_seed(seed)
return torch.Generator(device=torch_device).manual_seed(seed) return torch.Generator(device=torch_device).manual_seed(seed)
@parameterized.expand( @parameterized.expand(
......
...@@ -188,6 +188,7 @@ class AltDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -188,6 +188,7 @@ class AltDiffusionPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.51605093, 0.5707241, 0.47365507, 0.50578886, 0.5633877, 0.4642503, 0.5182081, 0.48763484, 0.49084237] [0.51605093, 0.5707241, 0.47365507, 0.50578886, 0.5633877, 0.4642503, 0.5182081, 0.48763484, 0.49084237]
) )
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
...@@ -207,20 +208,16 @@ class AltDiffusionPipelineIntegrationTests(unittest.TestCase): ...@@ -207,20 +208,16 @@ class AltDiffusionPipelineIntegrationTests(unittest.TestCase):
alt_pipe.set_progress_bar_config(disable=None) alt_pipe.set_progress_bar_config(disable=None)
prompt = "A painting of a squirrel eating a burger" prompt = "A painting of a squirrel eating a burger"
generator = torch.Generator(device=torch_device).manual_seed(0) generator = torch.manual_seed(0)
with torch.autocast("cuda"): output = alt_pipe([prompt], generator=generator, guidance_scale=6.0, num_inference_steps=20, output_type="np")
output = alt_pipe(
[prompt], generator=generator, guidance_scale=6.0, num_inference_steps=20, output_type="np"
)
image = output.images image = output.images
image_slice = image[0, -3:, -3:, -1] image_slice = image[0, -3:, -3:, -1]
assert image.shape == (1, 512, 512, 3) assert image.shape == (1, 512, 512, 3)
expected_slice = np.array( expected_slice = np.array([0.1010, 0.0800, 0.0794, 0.0885, 0.0843, 0.0762, 0.0769, 0.0729, 0.0586])
[0.8720703, 0.87109375, 0.87402344, 0.87109375, 0.8779297, 0.8925781, 0.8823242, 0.8808594, 0.8613281]
)
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
def test_alt_diffusion_fast_ddim(self): def test_alt_diffusion_fast_ddim(self):
...@@ -231,44 +228,14 @@ class AltDiffusionPipelineIntegrationTests(unittest.TestCase): ...@@ -231,44 +228,14 @@ class AltDiffusionPipelineIntegrationTests(unittest.TestCase):
alt_pipe.set_progress_bar_config(disable=None) alt_pipe.set_progress_bar_config(disable=None)
prompt = "A painting of a squirrel eating a burger" prompt = "A painting of a squirrel eating a burger"
generator = torch.Generator(device=torch_device).manual_seed(0) generator = torch.manual_seed(0)
with torch.autocast("cuda"): output = alt_pipe([prompt], generator=generator, num_inference_steps=2, output_type="numpy")
output = alt_pipe([prompt], generator=generator, num_inference_steps=2, output_type="numpy")
image = output.images image = output.images
image_slice = image[0, -3:, -3:, -1] image_slice = image[0, -3:, -3:, -1]
assert image.shape == (1, 512, 512, 3) assert image.shape == (1, 512, 512, 3)
expected_slice = np.array( expected_slice = np.array([0.4019, 0.4052, 0.3810, 0.4119, 0.3916, 0.3982, 0.4651, 0.4195, 0.5323])
[0.9267578, 0.9301758, 0.9013672, 0.9345703, 0.92578125, 0.94433594, 0.9423828, 0.9423828, 0.9160156]
)
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
def test_alt_diffusion_text2img_pipeline_fp16(self):
torch.cuda.reset_peak_memory_stats()
model_id = "BAAI/AltDiffusion"
pipe = AltDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, safety_checker=None)
pipe = pipe.to(torch_device)
pipe.set_progress_bar_config(disable=None)
prompt = "a photograph of an astronaut riding a horse"
generator = torch.Generator(device=torch_device).manual_seed(0) assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
output_chunked = pipe(
[prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy"
)
image_chunked = output_chunked.images
generator = torch.Generator(device=torch_device).manual_seed(0)
with torch.autocast(torch_device):
output = pipe(
[prompt], generator=generator, guidance_scale=7.5, num_inference_steps=10, output_type="numpy"
)
image = output.images
# Make sure results are close enough
diff = np.abs(image_chunked.flatten() - image.flatten())
# They ARE different since ops are not run always at the same precision
# however, they should be extremely close.
assert diff.mean() < 2e-2
...@@ -162,6 +162,7 @@ class AltDiffusionImg2ImgPipelineFastTests(unittest.TestCase): ...@@ -162,6 +162,7 @@ class AltDiffusionImg2ImgPipelineFastTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.41293705, 0.38656747, 0.40876025, 0.4782187, 0.4656803, 0.41394007, 0.4142093, 0.47150758, 0.4570448] [0.41293705, 0.38656747, 0.40876025, 0.4782187, 0.4656803, 0.41394007, 0.4142093, 0.47150758, 0.4570448]
) )
assert np.abs(image_slice.flatten() - expected_slice).max() < 1.5e-3 assert np.abs(image_slice.flatten() - expected_slice).max() < 1.5e-3
assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1.5e-3 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1.5e-3
...@@ -196,7 +197,7 @@ class AltDiffusionImg2ImgPipelineFastTests(unittest.TestCase): ...@@ -196,7 +197,7 @@ class AltDiffusionImg2ImgPipelineFastTests(unittest.TestCase):
alt_pipe.set_progress_bar_config(disable=None) alt_pipe.set_progress_bar_config(disable=None)
prompt = "A painting of a squirrel eating a burger" prompt = "A painting of a squirrel eating a burger"
generator = torch.Generator(device=torch_device).manual_seed(0) generator = torch.manual_seed(0)
image = alt_pipe( image = alt_pipe(
[prompt], [prompt],
generator=generator, generator=generator,
...@@ -227,7 +228,7 @@ class AltDiffusionImg2ImgPipelineFastTests(unittest.TestCase): ...@@ -227,7 +228,7 @@ class AltDiffusionImg2ImgPipelineFastTests(unittest.TestCase):
prompt = "A fantasy landscape, trending on artstation" prompt = "A fantasy landscape, trending on artstation"
generator = torch.Generator(device=torch_device).manual_seed(0) generator = torch.manual_seed(0)
output = pipe( output = pipe(
prompt=prompt, prompt=prompt,
image=init_image, image=init_image,
...@@ -241,7 +242,8 @@ class AltDiffusionImg2ImgPipelineFastTests(unittest.TestCase): ...@@ -241,7 +242,8 @@ class AltDiffusionImg2ImgPipelineFastTests(unittest.TestCase):
image_slice = image[255:258, 383:386, -1] image_slice = image[255:258, 383:386, -1]
assert image.shape == (504, 760, 3) assert image.shape == (504, 760, 3)
expected_slice = np.array([0.3252, 0.3340, 0.3418, 0.3263, 0.3346, 0.3300, 0.3163, 0.3470, 0.3427]) expected_slice = np.array([0.9358, 0.9397, 0.9599, 0.9901, 1.0000, 1.0000, 0.9882, 1.0000, 1.0000])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3
...@@ -275,7 +277,7 @@ class AltDiffusionImg2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -275,7 +277,7 @@ class AltDiffusionImg2ImgPipelineIntegrationTests(unittest.TestCase):
prompt = "A fantasy landscape, trending on artstation" prompt = "A fantasy landscape, trending on artstation"
generator = torch.Generator(device=torch_device).manual_seed(0) generator = torch.manual_seed(0)
output = pipe( output = pipe(
prompt=prompt, prompt=prompt,
image=init_image, image=init_image,
......
...@@ -119,6 +119,7 @@ class PipelineFastTests(unittest.TestCase): ...@@ -119,6 +119,7 @@ class PipelineFastTests(unittest.TestCase):
image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10]
image_from_tuple_slice = np.frombuffer(image_from_tuple.tobytes(), dtype="uint8")[:10] image_from_tuple_slice = np.frombuffer(image_from_tuple.tobytes(), dtype="uint8")[:10]
expected_slice = np.array([255, 255, 255, 0, 181, 0, 124, 0, 15, 255]) expected_slice = np.array([255, 255, 255, 0, 181, 0, 124, 0, 15, 255])
assert np.abs(image_slice.flatten() - expected_slice).max() == 0 assert np.abs(image_slice.flatten() - expected_slice).max() == 0
assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() == 0 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() == 0
...@@ -142,6 +143,7 @@ class PipelineFastTests(unittest.TestCase): ...@@ -142,6 +143,7 @@ class PipelineFastTests(unittest.TestCase):
) )
image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10]
expected_slice = np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121]) expected_slice = np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121])
assert np.abs(image_slice.flatten() - expected_slice).max() == 0 assert np.abs(image_slice.flatten() - expected_slice).max() == 0
dummy_unet_condition = self.dummy_unet_condition dummy_unet_condition = self.dummy_unet_condition
...@@ -155,6 +157,7 @@ class PipelineFastTests(unittest.TestCase): ...@@ -155,6 +157,7 @@ class PipelineFastTests(unittest.TestCase):
image = output.images[0] image = output.images[0]
image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10]
expected_slice = np.array([120, 139, 147, 123, 124, 96, 115, 121, 126, 144]) expected_slice = np.array([120, 139, 147, 123, 124, 96, 115, 121, 126, 144])
assert np.abs(image_slice.flatten() - expected_slice).max() == 0 assert np.abs(image_slice.flatten() - expected_slice).max() == 0
...@@ -183,4 +186,5 @@ class PipelineIntegrationTests(unittest.TestCase): ...@@ -183,4 +186,5 @@ class PipelineIntegrationTests(unittest.TestCase):
assert image.height == pipe.unet.sample_size[0] and image.width == pipe.unet.sample_size[1] assert image.height == pipe.unet.sample_size[0] and image.width == pipe.unet.sample_size[1]
image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10] image_slice = np.frombuffer(image.tobytes(), dtype="uint8")[:10]
expected_slice = np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26]) expected_slice = np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26])
assert np.abs(image_slice.flatten() - expected_slice).max() == 0 assert np.abs(image_slice.flatten() - expected_slice).max() == 0
...@@ -104,14 +104,15 @@ class PipelineIntegrationTests(unittest.TestCase): ...@@ -104,14 +104,15 @@ class PipelineIntegrationTests(unittest.TestCase):
pipe = pipe.to(device) pipe = pipe.to(device)
pipe.set_progress_bar_config(disable=None) pipe.set_progress_bar_config(disable=None)
generator = torch.Generator(device=device).manual_seed(0) generator = torch.manual_seed(0)
output = pipe(generator=generator, num_inference_steps=100, audio_length_in_s=4.096) output = pipe(generator=generator, num_inference_steps=100, audio_length_in_s=4.096)
audio = output.audios audio = output.audios
audio_slice = audio[0, -3:, -3:] audio_slice = audio[0, -3:, -3:]
assert audio.shape == (1, 2, pipe.unet.sample_size) assert audio.shape == (1, 2, pipe.unet.sample_size)
expected_slice = np.array([-0.1576, -0.1526, -0.127, -0.2699, -0.2762, -0.2487]) expected_slice = np.array([-0.0192, -0.0231, -0.0318, -0.0059, 0.0002, -0.0020])
assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2
def test_dance_diffusion_fp16(self): def test_dance_diffusion_fp16(self):
...@@ -121,12 +122,13 @@ class PipelineIntegrationTests(unittest.TestCase): ...@@ -121,12 +122,13 @@ class PipelineIntegrationTests(unittest.TestCase):
pipe = pipe.to(device) pipe = pipe.to(device)
pipe.set_progress_bar_config(disable=None) pipe.set_progress_bar_config(disable=None)
generator = torch.Generator(device=device).manual_seed(0) generator = torch.manual_seed(0)
output = pipe(generator=generator, num_inference_steps=100, audio_length_in_s=4.096) output = pipe(generator=generator, num_inference_steps=100, audio_length_in_s=4.096)
audio = output.audios audio = output.audios
audio_slice = audio[0, -3:, -3:] audio_slice = audio[0, -3:, -3:]
assert audio.shape == (1, 2, pipe.unet.sample_size) assert audio.shape == (1, 2, pipe.unet.sample_size)
expected_slice = np.array([-0.1693, -0.1698, -0.1447, -0.3044, -0.3203, -0.2937]) expected_slice = np.array([-0.0367, -0.0488, -0.0771, -0.0525, -0.0444, -0.0341])
assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(audio_slice.flatten() - expected_slice).max() < 1e-2
...@@ -82,40 +82,42 @@ class DDIMPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -82,40 +82,42 @@ class DDIMPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
@slow @slow
@require_torch_gpu @require_torch_gpu
class DDIMPipelineIntegrationTests(unittest.TestCase): class DDIMPipelineIntegrationTests(unittest.TestCase):
def test_inference_ema_bedroom(self): def test_inference_cifar10(self):
model_id = "google/ddpm-ema-bedroom-256" model_id = "google/ddpm-cifar10-32"
unet = UNet2DModel.from_pretrained(model_id) unet = UNet2DModel.from_pretrained(model_id)
scheduler = DDIMScheduler.from_pretrained(model_id) scheduler = DDIMScheduler()
ddpm = DDIMPipeline(unet=unet, scheduler=scheduler) ddim = DDIMPipeline(unet=unet, scheduler=scheduler)
ddpm.to(torch_device) ddim.to(torch_device)
ddpm.set_progress_bar_config(disable=None) ddim.set_progress_bar_config(disable=None)
generator = torch.Generator(device=torch_device).manual_seed(0) generator = torch.manual_seed(0)
image = ddpm(generator=generator, output_type="numpy").images image = ddim(generator=generator, eta=0.0, output_type="numpy").images
image_slice = image[0, -3:, -3:, -1] image_slice = image[0, -3:, -3:, -1]
assert image.shape == (1, 256, 256, 3) assert image.shape == (1, 32, 32, 3)
expected_slice = np.array([0.1546, 0.1561, 0.1595, 0.1564, 0.1569, 0.1585, 0.1554, 0.1550, 0.1575]) expected_slice = np.array([0.1723, 0.1617, 0.1600, 0.1626, 0.1497, 0.1513, 0.1505, 0.1442, 0.1453])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
def test_inference_cifar10(self): def test_inference_ema_bedroom(self):
model_id = "google/ddpm-cifar10-32" model_id = "google/ddpm-ema-bedroom-256"
unet = UNet2DModel.from_pretrained(model_id) unet = UNet2DModel.from_pretrained(model_id)
scheduler = DDIMScheduler() scheduler = DDIMScheduler.from_pretrained(model_id)
ddim = DDIMPipeline(unet=unet, scheduler=scheduler) ddpm = DDIMPipeline(unet=unet, scheduler=scheduler)
ddim.to(torch_device) ddpm.to(torch_device)
ddim.set_progress_bar_config(disable=None) ddpm.set_progress_bar_config(disable=None)
generator = torch.Generator(device=torch_device).manual_seed(0) generator = torch.manual_seed(0)
image = ddim(generator=generator, eta=0.0, output_type="numpy").images image = ddpm(generator=generator, output_type="numpy").images
image_slice = image[0, -3:, -3:, -1] image_slice = image[0, -3:, -3:, -1]
assert image.shape == (1, 32, 32, 3) assert image.shape == (1, 256, 256, 3)
expected_slice = np.array([0.2060, 0.2042, 0.2022, 0.2193, 0.2146, 0.2110, 0.2471, 0.2446, 0.2388]) expected_slice = np.array([0.0060, 0.0201, 0.0344, 0.0024, 0.0018, 0.0002, 0.0022, 0.0000, 0.0069])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
...@@ -63,6 +63,7 @@ class DDPMPipelineFastTests(unittest.TestCase): ...@@ -63,6 +63,7 @@ class DDPMPipelineFastTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[5.589e-01, 7.089e-01, 2.632e-01, 6.841e-01, 1.000e-04, 9.999e-01, 1.973e-01, 1.000e-04, 8.010e-02] [5.589e-01, 7.089e-01, 2.632e-01, 6.841e-01, 1.000e-04, 9.999e-01, 1.973e-01, 1.000e-04, 8.010e-02]
) )
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2
...@@ -79,14 +80,10 @@ class DDPMPipelineFastTests(unittest.TestCase): ...@@ -79,14 +80,10 @@ class DDPMPipelineFastTests(unittest.TestCase):
if torch_device == "mps": if torch_device == "mps":
_ = ddpm(num_inference_steps=1) _ = ddpm(num_inference_steps=1)
if torch_device == "mps": generator = torch.manual_seed(0)
# device type MPS is not supported for torch.Generator() api.
generator = torch.manual_seed(0)
else:
generator = torch.Generator(device=torch_device).manual_seed(0)
image = ddpm(generator=generator, num_inference_steps=2, output_type="numpy").images image = ddpm(generator=generator, num_inference_steps=2, output_type="numpy").images
generator = generator.manual_seed(0) generator = torch.manual_seed(0)
image_eps = ddpm(generator=generator, num_inference_steps=2, output_type="numpy", predict_epsilon=False)[0] image_eps = ddpm(generator=generator, num_inference_steps=2, output_type="numpy", predict_epsilon=False)[0]
image_slice = image[0, -3:, -3:, -1] image_slice = image[0, -3:, -3:, -1]
...@@ -108,14 +105,10 @@ class DDPMPipelineFastTests(unittest.TestCase): ...@@ -108,14 +105,10 @@ class DDPMPipelineFastTests(unittest.TestCase):
if torch_device == "mps": if torch_device == "mps":
_ = ddpm(num_inference_steps=1) _ = ddpm(num_inference_steps=1)
if torch_device == "mps": generator = torch.manual_seed(0)
# device type MPS is not supported for torch.Generator() api.
generator = torch.manual_seed(0)
else:
generator = torch.Generator(device=torch_device).manual_seed(0)
image = ddpm(generator=generator, num_inference_steps=2, output_type="numpy").images image = ddpm(generator=generator, num_inference_steps=2, output_type="numpy").images
generator = generator.manual_seed(0) generator = torch.manual_seed(0)
image_eps = ddpm(generator=generator, num_inference_steps=2, output_type="numpy")[0] image_eps = ddpm(generator=generator, num_inference_steps=2, output_type="numpy")[0]
image_slice = image[0, -3:, -3:, -1] image_slice = image[0, -3:, -3:, -1]
...@@ -139,11 +132,12 @@ class DDPMPipelineIntegrationTests(unittest.TestCase): ...@@ -139,11 +132,12 @@ class DDPMPipelineIntegrationTests(unittest.TestCase):
ddpm.to(torch_device) ddpm.to(torch_device)
ddpm.set_progress_bar_config(disable=None) ddpm.set_progress_bar_config(disable=None)
generator = torch.Generator(device=torch_device).manual_seed(0) generator = torch.manual_seed(0)
image = ddpm(generator=generator, output_type="numpy").images image = ddpm(generator=generator, output_type="numpy").images
image_slice = image[0, -3:, -3:, -1] image_slice = image[0, -3:, -3:, -1]
assert image.shape == (1, 32, 32, 3) assert image.shape == (1, 32, 32, 3)
expected_slice = np.array([0.4454, 0.2025, 0.0315, 0.3023, 0.2575, 0.1031, 0.0953, 0.1604, 0.2020]) expected_slice = np.array([0.4454, 0.2025, 0.0315, 0.3023, 0.2575, 0.1031, 0.0953, 0.1604, 0.2020])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
...@@ -114,15 +114,14 @@ class DiTPipelineIntegrationTests(unittest.TestCase): ...@@ -114,15 +114,14 @@ class DiTPipelineIntegrationTests(unittest.TestCase):
assert np.abs((expected_image - image).max()) < 1e-3 assert np.abs((expected_image - image).max()) < 1e-3
def test_dit_512_fp16(self): def test_dit_512_fp16(self):
generator = torch.manual_seed(0)
pipe = DiTPipeline.from_pretrained("facebook/DiT-XL-2-512", torch_dtype=torch.float16) pipe = DiTPipeline.from_pretrained("facebook/DiT-XL-2-512", torch_dtype=torch.float16)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe.to("cuda") pipe.to("cuda")
words = ["vase", "umbrella", "white shark", "white wolf"] words = ["vase", "umbrella"]
ids = pipe.get_label_ids(words) ids = pipe.get_label_ids(words)
generator = torch.manual_seed(0)
images = pipe(ids, generator=generator, num_inference_steps=25, output_type="np").images images = pipe(ids, generator=generator, num_inference_steps=25, output_type="np").images
for word, image in zip(words, images): for word, image in zip(words, images):
...@@ -130,4 +129,5 @@ class DiTPipelineIntegrationTests(unittest.TestCase): ...@@ -130,4 +129,5 @@ class DiTPipelineIntegrationTests(unittest.TestCase):
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
f"/dit/{word}_fp16.npy" f"/dit/{word}_fp16.npy"
) )
assert np.abs((expected_image - image).max()) < 1e-2
assert np.abs((expected_image - image).max()) < 7.5e-1
...@@ -59,6 +59,7 @@ class KarrasVePipelineFastTests(unittest.TestCase): ...@@ -59,6 +59,7 @@ class KarrasVePipelineFastTests(unittest.TestCase):
assert image.shape == (1, 32, 32, 3) assert image.shape == (1, 32, 32, 3)
expected_slice = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) expected_slice = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2
...@@ -81,4 +82,5 @@ class KarrasVePipelineIntegrationTests(unittest.TestCase): ...@@ -81,4 +82,5 @@ class KarrasVePipelineIntegrationTests(unittest.TestCase):
image_slice = image[0, -3:, -3:, -1] image_slice = image[0, -3:, -3:, -1]
assert image.shape == (1, 256, 256, 3) assert image.shape == (1, 256, 256, 3)
expected_slice = np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]) expected_slice = np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
...@@ -126,7 +126,7 @@ class LDMTextToImagePipelineSlowTests(unittest.TestCase): ...@@ -126,7 +126,7 @@ class LDMTextToImagePipelineSlowTests(unittest.TestCase):
torch.cuda.empty_cache() torch.cuda.empty_cache()
def get_inputs(self, device, dtype=torch.float32, seed=0): def get_inputs(self, device, dtype=torch.float32, seed=0):
generator = torch.Generator(device=device).manual_seed(seed) generator = torch.manual_seed(seed)
latents = np.random.RandomState(seed).standard_normal((1, 4, 32, 32)) latents = np.random.RandomState(seed).standard_normal((1, 4, 32, 32))
latents = torch.from_numpy(latents).to(device=device, dtype=dtype) latents = torch.from_numpy(latents).to(device=device, dtype=dtype)
inputs = { inputs = {
...@@ -162,7 +162,7 @@ class LDMTextToImagePipelineNightlyTests(unittest.TestCase): ...@@ -162,7 +162,7 @@ class LDMTextToImagePipelineNightlyTests(unittest.TestCase):
torch.cuda.empty_cache() torch.cuda.empty_cache()
def get_inputs(self, device, dtype=torch.float32, seed=0): def get_inputs(self, device, dtype=torch.float32, seed=0):
generator = torch.Generator(device=device).manual_seed(seed) generator = torch.manual_seed(seed)
latents = np.random.RandomState(seed).standard_normal((1, 4, 32, 32)) latents = np.random.RandomState(seed).standard_normal((1, 4, 32, 32))
latents = torch.from_numpy(latents).to(device=device, dtype=dtype) latents = torch.from_numpy(latents).to(device=device, dtype=dtype)
inputs = { inputs = {
......
...@@ -83,6 +83,7 @@ class LDMSuperResolutionPipelineFastTests(unittest.TestCase): ...@@ -83,6 +83,7 @@ class LDMSuperResolutionPipelineFastTests(unittest.TestCase):
assert image.shape == (1, 64, 64, 3) assert image.shape == (1, 64, 64, 3)
expected_slice = np.array([0.8678, 0.8245, 0.6381, 0.6830, 0.4385, 0.5599, 0.4641, 0.6201, 0.5150]) expected_slice = np.array([0.8678, 0.8245, 0.6381, 0.6830, 0.4385, 0.5599, 0.4641, 0.6201, 0.5150])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
@unittest.skipIf(torch_device != "cuda", "This test requires a GPU") @unittest.skipIf(torch_device != "cuda", "This test requires a GPU")
...@@ -101,8 +102,7 @@ class LDMSuperResolutionPipelineFastTests(unittest.TestCase): ...@@ -101,8 +102,7 @@ class LDMSuperResolutionPipelineFastTests(unittest.TestCase):
init_image = self.dummy_image.to(torch_device) init_image = self.dummy_image.to(torch_device)
generator = torch.Generator(device=torch_device).manual_seed(0) image = ldm(init_image, num_inference_steps=2, output_type="numpy").images
image = ldm(init_image, generator=generator, num_inference_steps=2, output_type="numpy").images
assert image.shape == (1, 64, 64, 3) assert image.shape == (1, 64, 64, 3)
...@@ -121,11 +121,12 @@ class LDMSuperResolutionPipelineIntegrationTests(unittest.TestCase): ...@@ -121,11 +121,12 @@ class LDMSuperResolutionPipelineIntegrationTests(unittest.TestCase):
ldm.to(torch_device) ldm.to(torch_device)
ldm.set_progress_bar_config(disable=None) ldm.set_progress_bar_config(disable=None)
generator = torch.Generator(device=torch_device).manual_seed(0) generator = torch.manual_seed(0)
image = ldm(image=init_image, generator=generator, num_inference_steps=20, output_type="numpy").images image = ldm(image=init_image, generator=generator, num_inference_steps=20, output_type="numpy").images
image_slice = image[0, -3:, -3:, -1] image_slice = image[0, -3:, -3:, -1]
assert image.shape == (1, 256, 256, 3) assert image.shape == (1, 256, 256, 3)
expected_slice = np.array([0.7418, 0.7472, 0.7424, 0.7422, 0.7463, 0.726, 0.7382, 0.7248, 0.6828]) expected_slice = np.array([0.7644, 0.7679, 0.7642, 0.7633, 0.7666, 0.7560, 0.7425, 0.7257, 0.6907])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
...@@ -96,6 +96,7 @@ class LDMPipelineFastTests(unittest.TestCase): ...@@ -96,6 +96,7 @@ class LDMPipelineFastTests(unittest.TestCase):
assert image.shape == (1, 64, 64, 3) assert image.shape == (1, 64, 64, 3)
expected_slice = np.array([0.8512, 0.818, 0.6411, 0.6808, 0.4465, 0.5618, 0.46, 0.6231, 0.5172]) expected_slice = np.array([0.8512, 0.818, 0.6411, 0.6808, 0.4465, 0.5618, 0.46, 0.6231, 0.5172])
tolerance = 1e-2 if torch_device != "mps" else 3e-2 tolerance = 1e-2 if torch_device != "mps" else 3e-2
assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance
assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < tolerance assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < tolerance
...@@ -116,4 +117,5 @@ class LDMPipelineIntegrationTests(unittest.TestCase): ...@@ -116,4 +117,5 @@ class LDMPipelineIntegrationTests(unittest.TestCase):
assert image.shape == (1, 256, 256, 3) assert image.shape == (1, 256, 256, 3)
expected_slice = np.array([0.4399, 0.44975, 0.46825, 0.474, 0.4359, 0.4581, 0.45095, 0.4341, 0.4447]) expected_slice = np.array([0.4399, 0.44975, 0.46825, 0.474, 0.4359, 0.4581, 0.45095, 0.4341, 0.4447])
tolerance = 1e-2 if torch_device != "mps" else 3e-2 tolerance = 1e-2 if torch_device != "mps" else 3e-2
assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance assert np.abs(image_slice.flatten() - expected_slice).max() < tolerance
...@@ -205,7 +205,7 @@ class PaintByExamplePipelineIntegrationTests(unittest.TestCase): ...@@ -205,7 +205,7 @@ class PaintByExamplePipelineIntegrationTests(unittest.TestCase):
pipe = pipe.to(torch_device) pipe = pipe.to(torch_device)
pipe.set_progress_bar_config(disable=None) pipe.set_progress_bar_config(disable=None)
generator = torch.Generator(device=torch_device).manual_seed(321) generator = torch.manual_seed(321)
output = pipe( output = pipe(
image=init_image, image=init_image,
mask_image=mask_image, mask_image=mask_image,
...@@ -221,7 +221,6 @@ class PaintByExamplePipelineIntegrationTests(unittest.TestCase): ...@@ -221,7 +221,6 @@ class PaintByExamplePipelineIntegrationTests(unittest.TestCase):
image_slice = image[0, -3:, -3:, -1] image_slice = image[0, -3:, -3:, -1]
assert image.shape == (1, 512, 512, 3) assert image.shape == (1, 512, 512, 3)
expected_slice = np.array( expected_slice = np.array([0.4834, 0.4811, 0.4874, 0.5122, 0.5081, 0.5144, 0.5291, 0.5290, 0.5374])
[0.47455794, 0.47086594, 0.47683704, 0.51024145, 0.5064255, 0.5123164, 0.532502, 0.5328063, 0.5428694]
)
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
...@@ -59,6 +59,7 @@ class PNDMPipelineFastTests(unittest.TestCase): ...@@ -59,6 +59,7 @@ class PNDMPipelineFastTests(unittest.TestCase):
assert image.shape == (1, 32, 32, 3) assert image.shape == (1, 32, 32, 3)
expected_slice = np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]) expected_slice = np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2
...@@ -82,4 +83,5 @@ class PNDMPipelineIntegrationTests(unittest.TestCase): ...@@ -82,4 +83,5 @@ class PNDMPipelineIntegrationTests(unittest.TestCase):
assert image.shape == (1, 32, 32, 3) assert image.shape == (1, 32, 32, 3)
expected_slice = np.array([0.1564, 0.14645, 0.1406, 0.14715, 0.12425, 0.14045, 0.13115, 0.12175, 0.125]) expected_slice = np.array([0.1564, 0.14645, 0.1406, 0.14715, 0.12425, 0.14045, 0.13115, 0.12175, 0.125])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
...@@ -81,6 +81,7 @@ class RepaintPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -81,6 +81,7 @@ class RepaintPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
assert image.shape == (1, 32, 32, 3) assert image.shape == (1, 32, 32, 3)
expected_slice = np.array([1.0000, 0.5426, 0.5497, 0.2200, 1.0000, 1.0000, 0.5623, 1.0000, 0.6274]) expected_slice = np.array([1.0000, 0.5426, 0.5497, 0.2200, 1.0000, 1.0000, 0.5623, 1.0000, 0.6274])
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3
...@@ -113,7 +114,7 @@ class RepaintPipelineNightlyTests(unittest.TestCase): ...@@ -113,7 +114,7 @@ class RepaintPipelineNightlyTests(unittest.TestCase):
repaint.set_progress_bar_config(disable=None) repaint.set_progress_bar_config(disable=None)
repaint.enable_attention_slicing() repaint.enable_attention_slicing()
generator = torch.Generator(device=torch_device).manual_seed(0) generator = torch.manual_seed(0)
output = repaint( output = repaint(
original_image, original_image,
mask_image, mask_image,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment