Skip to content

Give more customizable options for safety checker #815

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

Merged
merged 9 commits into from
Oct 13, 2022

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Oct 12, 2022

This allows people to disable the safety checker. Note: This is never recommended in the eyes of the diffusers team, but we also don't want people to have to fork the repository in order to disable the safety checker if they deem it necessary in their eyes.
For more information, please have a look at: #254 (comment) .

The safety checker can be disabled by doing:

from diffusers import StableDiffusionPipeline

pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", safety_checker=None)

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 12, 2022

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

Copy link
Member

@anton-l anton-l left a comment

Choose a reason for hiding this comment

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

Good choice with None instead of a disabler method here, this way there's no fuss with extra CLIP weights in memory 👍

Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

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

Looks good! It may be useful to gather more opinions on the warning message :)

" `from_pretrained`. For more information, please have a look at"
" https://github.com/huggingface/diffusers/pull/254"
)

Copy link
Member

Choose a reason for hiding this comment

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

I think referencing another PR dilutes the message. I'd propose something like:

The diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all circumstances. Please, make sure you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public.

I think it's worthwhile to make this as clear as we can, maybe @natolambert, @mmitchellai, @yjernite can provide better wording.

Choose a reason for hiding this comment

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

I would even say:

Ensure that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. Both the diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling it only for use-cases that involve analyzing network behavior or auditing its results.

I mean, I think proposing a use case when removing the safety filter is acceptable kind of justifies why we are proposing this PR to remove it.

@@ -20,11 +20,11 @@ class StableDiffusionPipelineOutput(BaseOutput):
num_channels)`. PIL images or numpy array present the denoised images of the diffusion pipeline.
nsfw_content_detected (`List[bool]`)
List of flags denoting whether the corresponding generated image likely represents "not-safe-for-work"
(nsfw) content.
(nsfw) content. If safety checker is disabled `None` will be returned.

Choose a reason for hiding this comment

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

@patrickvonplaten one question/request -- would it be possible to have a setting that still returns whether or not an image is nsfw, but does not black out that image? This would allow devs who are building on top of this library to do something like show a popup to a user (e.g. 'you are about to view a NSFW image, do you want to proceed')

One possible way to implement this is to pass a flag into the safety checker module that disables the 'return a black image' part of the checker. Another way is to expose the safety checker class so that end users can add the checker in at the end (solely to get the bool[] indicating nsfw-ness)

f"You have disabed the safety checker for {self.__class__} by passing `safety_checker=None`.Please"
" make sure you have very good reasons for this and have considered the consequences of doing so.The"
" `diffusers` team does not recommend disabling the safety under ANY circumstances and strongly"
" suggests to not disable the `safety_checker` by NOT passing `safety_checker=None` to"

Choose a reason for hiding this comment

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

I don't think the second "by NOT passing safety_checker=None to from_pretrained." is necessary

@patrickvonplaten patrickvonplaten merged commit e713346 into main Oct 13, 2022
@patrickvonplaten patrickvonplaten deleted the allow_disabling_safety_checker branch October 13, 2022 13:52
prathikr pushed a commit to prathikr/diffusers that referenced this pull request Oct 26, 2022
* Give more customizable options for safety checker

* Apply suggestions from code review

* Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py

* Finish

* make style

* Apply suggestions from code review

Co-authored-by: Pedro Cuenca <[email protected]>

* up

Co-authored-by: Pedro Cuenca <[email protected]>
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* Give more customizable options for safety checker

* Apply suggestions from code review

* Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py

* Finish

* make style

* Apply suggestions from code review

Co-authored-by: Pedro Cuenca <[email protected]>

* up

Co-authored-by: Pedro Cuenca <[email protected]>
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.

6 participants