-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Add Safe Stable Diffusion Pipeline #1244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Safe Stable Diffusion Pipeline #1244
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
Ran make fix-copies after adding new pipline
|
@patrickvonplaten I'd appreciate some pointers on the check that is currently failing. I'm not really sure how this is something I can fix. Error message: Bad request for commit endpoint:
[37](https://github.com/huggingface/diffusers/actions/runs/3438139061/jobs/5733811656#step:11:38)
KeyError: 'endpoint'
[38](https://github.com/huggingface/diffusers/actions/runs/3438139061/jobs/5733811656#step:11:39)
[39](https://github.com/huggingface/diffusers/actions/runs/3438139061/jobs/5733811656#step:11:40)
Traceback (most recent call last):
[40](https://github.com/huggingface/diffusers/actions/runs/3438139061/jobs/5733811656#step:11:41)
File "/usr/local/lib/python3.8/site-packages/huggingface_hub/utils/_errors.py", line 213, in hf_raise_for_status
[41](https://github.com/huggingface/diffusers/actions/runs/3438139061/jobs/5733811656#step:11:42)
response.raise_for_status()
[42](https://github.com/huggingface/diffusers/actions/runs/3438139061/jobs/5733811656#step:11:43)
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 1021, in raise_for_status
[43](https://github.com/huggingface/diffusers/actions/runs/3438139061/jobs/5733811656#step:11:44)
raise HTTPError(http_error_msg, response=self)
[44](https://github.com/huggingface/diffusers/actions/runs/3438139061/jobs/5733811656#step:11:45)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://huggingface.co/api/datasets/hf-doc-build/doc-build-dev/commit/main
[45](https://github.com/huggingface/diffusers/actions/runs/3438139061/jobs/5733811656#step:11:46) |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. |
|
Alright as it appears the issue from before was not related to the PR itself. |
src/diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py
Show resolved
Hide resolved
|
Hey @manuelbrack, Sorry for replying so late here. The PR looks to be in a great shape :-) Also should we maybe upload a stable diffusion checkpoint under your repo on the Hub clearly advertising it as a "safety stable diffusion" model and also so that Finally, it could be nice to add your model to the docs with a nice doc page linking to your original repo and your paper. Maybe you can have a look at this PR: #1299 to see what things you could all add to the doc (pipeline table, pipeline page, ...) Let me know if something is not clear! Also very happy to dive into the PR next week if you're stuck somewhere :-) Very exciting - the first really safety driven model in |
|
Thanks for the feedback, we are already working on the refactoring, docs and test. Adding a checkpoint to the our labs huggingface page sounds like a great idea. Should we get that going, or is this something that we should leave up to you guys? |
|
TODOs
|
| ```python | ||
| >>> from diffusers import StableDiffusionPipelineSafe | ||
|
|
||
| >>> pipeline = StableDiffusionPipelineSafe.from_pretrained("AIML-TUDA/stable-diffusion-safe") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool examples!
| image = self.decode_latents(latents) | ||
|
|
||
| # 9. Run safety checker | ||
| image, has_nsfw_concept = self.run_safety_checker(image, device, text_embeddings.dtype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering whether we really need the safety checker here - given that the model is already guided towards safe images before does this final CLIP check help?
The advantage of removing it would be that we would save 1GB on RAM and potentially have much fewer false positives (e.g. cases where the images is incorrectly classified as nfsw).
But also happy to leave it in if you think it adds another important layer of "safety"
…safe-latent-diffusion
src/diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py
Show resolved
Hide resolved
|
Hey @manuelbrack, Great work! The tests and doc examples are on point and it's also very nice that you additionally hold the checkpoint here: https://huggingface.co/AIML-TUDA/stable-diffusion-safe Just two two final things before merging:
Once I can update the tests after 1. , we can merge this one :-) Wasn't able to find your email address online - could you maybe write me an email at patrick[at]huggingface.co so that we could maybe connect with our ethics / safety group at Hugging Face and think about how to best promote this model together? :-) |
|
regarding the safety checker we discussed the issue and opted to have it enabled by default. |
|
Cool merging this PR then :-) |
|
@manuelbrack let me know if you'd like to get in touch with our diffusers team to promote your work here. We could think about writing a blog post about how this model mitigates known problems of stable diffusion here: https://huggingface.co/blog or create a nice space. Feel free to send me an email :-) |
* Add pipeline_stable_diffusion_safe.py to pipelines * Fix repository consistency Ran make fix-copies after adding new pipline * Add Paper/Equation reference for parameters to doc string * Ensure code style and quality * Perform code refactoring * Fix copies inherited from merge with huggingface/main * Add docs * Fix code style * Fix errors in documentation * Fix refactoring error * remove debugging print statement * added Safe Latent Diffusion tests * Fix style * Fix style * Add pre-defined safety configurations * Fix line-break * fix some tests * finish * Change safety checker * Add missing safety_checker.py file * Remove unused imports Co-authored-by: PatrickSchrML <[email protected]> Co-authored-by: Patrick von Platen <[email protected]>
As discussed in isuse #1242 this PR adds a new Pipeline implementing the paper on Safe Latent Diffusion.
SLD mitigates the well known issue that models like Stable Diffusion that are trained on unfiltered, web-crawled datasets tend to suffer from inappropriate degeneration. For instance SD may unexpectedly generate nudity, violence, images depicting self-harm, or otherwise offensive content.