4 ms·
Yeah, but with the CompVis derived repos, it’s pretty easy to go in and change all the calls to PyTorch random number generators. Having said that, the last co
by JimDabell 4y ago
Yeah, but with the CompVis derived repos, it’s pretty easy to go in and change all the calls to PyTorch random number generators.
Having said that, the last comment [0] on the PyTorch issue gave me the idea of monkey patching the random functions. The supplied code assumes you’re always passing in a generator, which is not true in this case, but if you monkey patch the three rand/randn/randn_like functions to do nothing but swap out the device parameter for 'cpu' and then call to('ops') on the return value, it’s enough to get stable seed functionality for the CompVis derived repos without modifying their code, so I’m guessing it will probably work for diffusers as well.
Also, it’s probably a bug in the CompVis code, but even after you fix the random number generator, the very first run in a session uses an incorrect seed. The workaround is to generate an image once to throw away whenever you start a new session.
[0] https://github.com/pytorch/pytorch/issues/84288#issuecomment-1236247109 https://github.com/pytorch/pytorch/issues/84288#issuecomment...
- nl 4y agoThis branch seems to fix these issues: https://github.com/huggingface/diffusers/tree/mps https://github.com/huggingface/diffusers/tree/mps (Annoyingly I just went and made similar changes and was about to create a PR for them. But they have a fix for a "warm-up" issue I wasn't aware of too)
- JimDabell 4y agoYes, the warm-up issue is what I meant by “the very first run in a session uses an incorrect seed”. It looks like they’ve backed away from that now and expect developers to warm up themselves. Not a big deal, you can just use a single step to do that.