192 points · by avocado2 · 4y ago · 143 comments
It looks like the committer made their changes in the top commit, then merged the updated CompViz StableDiffusion change set on top of it for some reason. That's where the license change, rick astley image, etc come from.
And yes, StableDiffusion from the original repo will rick roll you if you try to generate something that triggers its NSFW filter.
Here's the code that does it:
https://github.com/CompVis/stable-diffusion/blob/main/script...
And here's what it looks like:
It goes without saying that the authors of a piece of software have the right to make the software do whatever they want, but that shouldn't stop us from recognizing that AI engineers are starting to act like megalomaniac overseers who consider it part of their mission to steer humanity onto the "right" path.
Who exactly do these people think they are?
Imagine this behavior from a web browser. "The URL of the file you were trying to download triggered my NSFW classifier, so I'm going to replace the file with this funny image."
This isn't funny, it's creepy.
As someone that manages nsfw open source projects, this move seems fine to me.
And actually kinda hilarious.
As currently implemented (and the implementation took more work than a confirmation prompt would have!), it's an obvious attempt to control, rather than protect, users. They try their best to dress it up like a joke, but it clearly isn't.
Also, if the author wanted to block NSFW contents at all, I'm pretty sure one can actually make the filter inseparable from the main network. This isn't the case here AFAIK.
Don't let people who are clearly motivated by a moralistic desire to control others hide behind BS pseudo-legal excuses.
These people wrote a bunch of Python code that pipes images and text through a GPU, and they're acting as if they had created a secret weapon that somehow humanity must be protected from. If that's not megalomania, I don't know what is.
Yes, for malware. As in, software created by criminals to damage your computer and/or steal your personal information.
That's not even remotely comparable to what StableDiffusion does here. What they do is refuse to generate content you requested, based on opaque criteria that no doubt are ultimately influenced by quasi-religious sentiments retained from the Bronze Age.
Software engineers who took the time to think about the ways that their work could be used.
How many times have we seen on HN people pleading with developers to think about the ethical dimensions of their work?
Why is that a problem, exactly?
> That can cause all sorts of lasting psychological harm and other societal negative consequences.
Like what? To me this sounds like a problem with how some people want to have absolute control over what others do and want everyone else to play along. That's what I find really creepy.
Someone wants to generate porn of me fucking a donkey? Let them. They already could do that with ms-paint and I don't get magically harmed if they do.
This reminds me of the old saying: "Sticks and stones may break my bones, but AI-generated/photoshopped/glued-together pictures of me fucking a donkey will never hurt me" :)
I would argue the authors went out of their way to actually make it very easy to “decensor” their model in a way that lets them wash their hands of things. So regardless of the outrage over their Puritanism, they actually have made it easier to make pornography than ever before. I don’t think applying the tiny speedbump of their model being censored by default is unreasonable in the interests of conservativism.
In the long run these men will go down in the history of pornography.
(What is silly is that DALLE2 won't let you edit a picture with a face in it, so you can't outpaint one of its own generations. But actually you can, if you crop it carefully.)
Just replace in scripts/txt2img.py:
- x_checked_image, has_nsfw_concept = check_safety(x_samples_ddim)
+ x_checked_image = x_samples_ddim
And be done with it.
It has an effect, but nothing like what's claimed in the submission title. On a 1070Ti (8GB), I managed to go up from 512576 to 576640.
- Communicate ahead of time; don't surprise maintainers with sweeping architectural changes or huge features no one wants or would like to review;
- Try to break up changes into logical units that can be understood and reviewed independently;
- Write useful and detailed commit messages (some bad examples: "Update attention.py", "various clean-ups, code now beautified");
- Don't sneak in anything unrelated to the PR; don't sneak anything unrelated into a commit;
- Absolutely don't use a code formatter to format the entire code base if the repo wasn't already using one. You can suggest that separately. And changes like that are best done by a trusted member.
Personally I blame juniors that insist on using the git CLI instead of a million visual GUIs to git. They get told just do a git commit, have no idea what they changed so can't produce a meaningful commit message, and because it's the command line good luck getting a visual representation of what you're committing.
and this: https://www.aleksandrhovhannisyan.com/blog/atomic-git-commit...
That way your "large change" becomes a collection of small, easy to reason about and well explained changes.
We Have Neon, who is making a PR.
We have Upstream, SD source.
We have basu, repo maintainer.
Neon pulled in upstream changes, and are trying to merge those into basu's repo AND then on top of that, apply neon edits to the code.
Ways to make this cleaner:
- Basu pulls in upstream changes, Neon just puts theirs on top. (Slow, you have to wait for Basu)
- Neon makes two PRs, one to pull in upstream changes, another for his edits on top of those changes. (More work, and coordination, but each PR is "one unit of work")
- Better commit messages: https://github.com/basujindal/stable-diffusion/pull/103#comm... <- notice the repeated and non-descript commit messages? That makes it hard for non-experts to cherry pick out the bits that are really relevant. (Fastest)
Clone the original SD repo, which is what this code was built off of, and follow all the installation instructions:
https://github.com/CompVis/stable-diffusion
In that repo, replace the file ldm/modules/attention.py with this file:
https://raw.githubusercontent.com/neonsecret/stable-diffusio...
Now run a new prompt with a larger image. Note that the original model was trained on 512x512 and may lead to repetition especially if you try to increase both dimensions (this is mentioned in the SD readme) so just run with one dimension increased.
For example try the following example:
python scripts/txt2img.py --prompt "a person gardening, by claude monet" --ddim_steps 50 --seed 12000 --scale 9 --n_iter=1 --n_samples=1 --H=512 --W=1024 --skip_grid
I confirmed that if I run that command with the original attention.py, it fails due to lack of memory. With the new attention.py, it succeeds.
That said, this still uses 13GB of ram on my system.
I suppose you can check out the full repo with the updated code, which seems to have other changes, if you want to give that a try.
https://github.com/neonsecret/stable-diffusion/
I have already been using the original SD repo so I found benefit by just changing attention.py
https://github.com/basujindal/stable-diffusion/commit/47f878...
It's well engineered, maintainable and with decent installation process.
The branch in this PR[2] adds M1 Mac support with a one line patch and it runs faster than the CompVis version (1.5 iterations/sec vs 1.4 for CompVis on a 32 Gb M1 Max,
I highly recommend people switching to that version for the improved flexibility.
The MPS support issue for diffusers is here:
https://github.com/huggingface/diffusers/issues/292
…and it links to the relevant PyTorch issue here:
Copying this change fixed seeds on M1 for me.
Also, that’s only a partial fix that doesn't really work properly. It doesn’t affect img2img and it still gets things wrong on the first render. Since txt2img starts from scratch each time, that means you’re always getting an incorrect render, it just happens to be the same incorrect render each time.
But the situation seems to be the same on the CompVis derived repos, right?
So this is no worse off, but with better engineered and faster code.
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...
[1] https://github.com/basujindal/stable-diffusion/pull/103/file...
> i) The model is being released under a Creative ML OpenRAIL-M license [https://huggingface.co/spaces/CompVis/stable-diffusion-licen...]. This is a permissive license that allows for commercial and non-commercial usage. This license is focused on ethical and legal use of the model as your responsibility and must accompany any distribution of the model. It must also be made available to end users of the model in any service on it.
[0] https://stability.ai/blog/stable-diffusion-public-release
https://m.youtube.com/watch?v=d_CgaHyA_n4&feature=emb_logo
And this is somehow relevant (possibly), as I kept the link open.
[0] https://github.com/CompVis/stable-diffusion#stable-diffusion [1] https://github.com/basujindal/stable-diffusion#txt2img
I use it directly from Python.
I can generate a 512x512 on my 10gb 3080 no problem (or three 384x384 at a time)
It measures memory usage as well.
If I was involved, this PR would be closed and conversation locked, simply because its a ton of formatting changes. The only "memory efficiency" changes are like 6 lines of python where the author uses `del`. Thats it. Everything else is formatting bullshit, and some other merge stuff. Yikes.
Also, some of those PR comments are written by kids or something. Wtf