Skip to content

Conversation

@patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Jan 3, 2023

2nd PR of the series after #1902.

This PR allows one to pass CPU generators even when the model is run on GPU to improve the reproducability of models since this way the latents are not dependent on the CUDA / GPU hardware (see: pytorch/pytorch#87992).

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jan 3, 2023

The documentation is not available anymore as the PR was closed or merged.

@patrickvonplaten patrickvonplaten changed the title [Repro] Correct reproducability [WIP, Repro] Correct reproducability Jan 3, 2023


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.


causal_attention_mask = torch.full(
[num_embeddings + additional_embeddings, num_embeddings + additional_embeddings], float("-inf")
[num_embeddings + additional_embeddings, num_embeddings + additional_embeddings], -10000.0
Copy link
Contributor Author

@patrickvonplaten patrickvonplaten Jan 4, 2023

Choose a reason for hiding this comment

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

For consistency, doesn't change the outputs here. Actually surprised that PyTorch seems to be able to handle + float("-inf") in newer versions, but think in older versions it wasn't the case.

images[0].save("/home/patrick_huggingface_co/diffusers-images/unclip/karlo_v1_alpha_horse_image.png")

assert image.shape == (256, 256, 3)
assert np.abs(expected_image - image).max() < 1e-1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even on CPU I cannot get a higher precision

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@anton-l I'd say we make this a nightly ? It takes 5 min on CPU

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it should be ok to move the tests for less frequently updated pipelines completely to nightly IMO

# Here we just check that the image doesn't deviate more than 10 pixels from the reference image on average
avg_diff = np.abs(image - expected_image).mean()

assert avg_diff < 10, f"Error image deviates {avg_diff} pixels on average"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty high avg difference, but it doesn't seem like we can get closer than this.

@patrickvonplaten patrickvonplaten changed the title [WIP, Repro] Correct reproducability Improve reproduceability 2/3 Jan 4, 2023
@patrickvonplaten
Copy link
Contributor Author

All slow tests passing -> Good enough for merge. Will complete the PR series tomorrow 🥳

@patrickvonplaten patrickvonplaten merged commit 9b63854 into main Jan 4, 2023
@patrickvonplaten patrickvonplaten deleted the improve_reproduce branch January 4, 2023 22:54
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* [Repro] Correct reproducability

* up

* up

* uP

* up

* need better image

* allow conversion from no state dict checkpoints

* up

* up

* up

* up

* check tensors

* check tensors

* check tensors

* check tensors

* next try

* up

* up

* better name

* up

* up

* Apply suggestions from code review

* correct more

* up

* replace all torch randn

* fix

* correct

* correct

* finish

* fix more

* up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants