Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
931182f
[Repro] Correct reproducability
patrickvonplaten Jan 3, 2023
57b6694
up
patrickvonplaten Jan 3, 2023
70a7afd
up
patrickvonplaten Jan 3, 2023
5e5035c
uP
patrickvonplaten Jan 3, 2023
ebfb3b7
up
patrickvonplaten Jan 3, 2023
2d826b4
need better image
patrickvonplaten Jan 3, 2023
3275375
allow conversion from no state dict checkpoints
patrickvonplaten Jan 3, 2023
880a5ef
up
patrickvonplaten Jan 4, 2023
6988144
up
patrickvonplaten Jan 4, 2023
0417a36
up
patrickvonplaten Jan 4, 2023
2ff5f0b
up
patrickvonplaten Jan 4, 2023
e5ae3e6
check tensors
patrickvonplaten Jan 4, 2023
34eec6d
check tensors
patrickvonplaten Jan 4, 2023
c1273c2
check tensors
patrickvonplaten Jan 4, 2023
1d3aa46
check tensors
patrickvonplaten Jan 4, 2023
0e7ce64
next try
patrickvonplaten Jan 4, 2023
e314d2e
up
patrickvonplaten Jan 4, 2023
5da5aab
up
patrickvonplaten Jan 4, 2023
604a93c
better name
patrickvonplaten Jan 4, 2023
188ed46
up
patrickvonplaten Jan 4, 2023
1cfa031
up
patrickvonplaten Jan 4, 2023
c673e4f
Apply suggestions from code review
patrickvonplaten Jan 4, 2023
05ad68c
correct more
patrickvonplaten Jan 4, 2023
f2b00b2
Merge branch 'main' of https://github.com/huggingface/diffusers into …
patrickvonplaten Jan 4, 2023
bce82e5
up
patrickvonplaten Jan 4, 2023
5021981
replace all torch randn
patrickvonplaten Jan 4, 2023
abfbecd
fix
patrickvonplaten Jan 4, 2023
2334802
correct
patrickvonplaten Jan 4, 2023
50654a9
correct
patrickvonplaten Jan 4, 2023
25096d3
finish
patrickvonplaten Jan 4, 2023
5f02e58
fix more
patrickvonplaten Jan 4, 2023
e6c1847
up
patrickvonplaten Jan 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/push_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches:
- main
pull_request: # TODO: only for debugging, remove before merging!
branches:
- main

env:
DIFFUSERS_IS_CI: yes
Expand Down
4 changes: 2 additions & 2 deletions src/diffusers/pipelines/unclip/pipeline_unclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from ...models import PriorTransformer, UNet2DConditionModel, UNet2DModel
from ...pipelines import DiffusionPipeline, ImagePipelineOutput
from ...schedulers import UnCLIPScheduler
from ...utils import is_accelerate_available, logging, torch_randn
from ...utils import is_accelerate_available, logging, rand_tensorn
from .text_proj import UnCLIPTextProjModel


Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(

def prepare_latents(self, shape, dtype, device, generator, latents, scheduler):
if latents is None:
latents = torch_randn(shape, generator=generator, device=device, dtype=dtype)
latents = rand_tensorn(shape, generator=generator, device=device, dtype=dtype)
else:
if latents.shape != shape:
raise ValueError(f"Unexpected latents shape, got {latents.shape}, expected {shape}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from ...models import UNet2DConditionModel, UNet2DModel
from ...pipelines import DiffusionPipeline, ImagePipelineOutput
from ...schedulers import UnCLIPScheduler
from ...utils import is_accelerate_available, logging, torch_randn
from ...utils import is_accelerate_available, logging, rand_tensorn
from .text_proj import UnCLIPTextProjModel


Expand Down Expand Up @@ -113,7 +113,7 @@ def __init__(
# Copied from diffusers.pipelines.unclip.pipeline_unclip.UnCLIPPipeline.prepare_latents
def prepare_latents(self, shape, dtype, device, generator, latents, scheduler):
if latents is None:
latents = torch_randn(shape, generator=generator, device=device, dtype=dtype)
latents = rand_tensorn(shape, generator=generator, device=device, dtype=dtype)
else:
if latents.shape != shape:
raise ValueError(f"Unexpected latents shape, got {latents.shape}, expected {shape}")
Expand Down
6 changes: 3 additions & 3 deletions src/diffusers/schedulers/scheduling_unclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import torch

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, torch_randn
from ..utils import BaseOutput, rand_tensorn
from .scheduling_utils import SchedulerMixin


Expand Down Expand Up @@ -273,7 +273,7 @@ def step(
# 6. Add noise
variance = 0
if t > 0:
variance_noise = torch_randn(
variance_noise = rand_tensorn(
model_output.shape, dtype=model_output.dtype, generator=generator, device=model_output.device
)

Expand All @@ -293,7 +293,7 @@ def step(
" for the UnCLIPScheduler."
)

variance = variance * variance_noise
# variance = variance * variance_noise

pred_prev_sample = pred_prev_sample + variance

Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
from .logging import get_logger
from .outputs import BaseOutput
from .pil_utils import PIL_INTERPOLATION
from .torch_utils import torch_randn
from .torch_utils import rand_tensorn


if is_torch_available():
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
logger = logging.get_logger(__name__) # pylint: disable=invalid-name


def torch_randn(
def rand_tensorn(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there is simply no way to make things fully deterministic even if we generate all tensors on CPU.

shape: Union[Tuple, List],
generator: Optional[Union[List["torch.Generator"], "torch.Generator"]] = None,
device: Optional["torch.device"] = None,
Expand Down
6 changes: 5 additions & 1 deletion tests/pipelines/unclip/test_unclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@


torch.backends.cuda.matmul.allow_tf32 = False
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False


class UnCLIPPipelineFastTests(unittest.TestCase):
Expand Down Expand Up @@ -375,7 +377,7 @@ def tearDown(self):
def test_unclip_karlo(self):
expected_image = load_numpy(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
"/unclip/karlo_v1_alpha_horse_fp16.npy"
"/unclip/karlo_v1_alpha_horse.npy"
)

pipeline = UnCLIPPipeline.from_pretrained("kakaobrain/karlo-v1-alpha", torch_dtype=torch.float16)
Expand All @@ -392,6 +394,8 @@ def test_unclip_karlo(self):

image = output.images[0]

np.save("/home/patrick_huggingface_co/diffusers-images/unclip/karlo_v1_alpha_horse.npy", image)

assert image.shape == (256, 256, 3)
assert np.abs(expected_image - image).max() < 1e-2

Expand Down