Skip to content
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

Move safety detection to model call in Flax safety checker #1023

Merged

Conversation

jonatanklosko
Copy link
Contributor

Currently a part of the safety checker is outside the model forward pass and is run separately without jitting. This PR merges it into the model call by vectorizing the relevant loops.

See #558 (comment).

I tested that the concept scores before and after this change are the same, and that 2 unsafe among 4 total images are still properly detected.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 27, 2022

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

@patrickvonplaten
Copy link
Contributor

This looks good to me - ok to merge! What do you think @pcuenca ?

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 great and works fine! Thanks a lot for working on this :)

@pcuenca
Copy link
Member

pcuenca commented Oct 30, 2022

After these changes, I believe it should now be possible to further simplify the code and make it more jax-like by:

  • Making __call__ end-to-end pmappable.
  • Removing _p_generate and _p_get_has_nsfw_concepts.
  • Removing the jit argument from __call__.

Therefore, it'd be up to the user whether to pmap the function invocation.

We can address those changes in an upcoming PR :)

@pcuenca pcuenca merged commit 8e4fd68 into huggingface:main Oct 30, 2022
@jonatanklosko jonatanklosko deleted the jk-flax-sd-safety-checker-jit-all branch October 31, 2022 10:27
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
…ce#1023)

* Move safety detection to model call in Flax safety checker

* Update src/diffusers/pipelines/stable_diffusion/safety_checker_flax.py
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