devilismyfriend / StableTuner

Finetuning SD in style.
GNU Affero General Public License v3.0
666 stars 51 forks source link

Support long prompts in the model playground, coincidentally add support for weighted prompts. #91

Closed allenbenz closed 1 year ago

allenbenz commented 1 year ago

We can use the diffusers community pipeline "Long Prompt Weighting Stable Diffusion" to enable prompts longer than 75 tokens long in the model playground.

With this change the new limit is 3 * 75 tokens. It's adjustable by passing in max_embeddings_multiples, The default is 3.

This pipeline also adds support for weighted tokens, if that's an issue it can be turned off via skip_parsing=True, It does change the behavior of parenthesis and square brackets if its enabled, see documentation below.

    Parses a string with attention tokens and returns a list of pairs: text and its associated weight.
    Accepted tokens are:
      (abc) - increases attention to abc by a multiplier of 1.1
      (abc:3.12) - increases attention to abc by a multiplier of 3.12
      [abc] - decreases attention to abc by a multiplier of 1.1
      \( - literal character '('
      \[ - literal character '['
      \) - literal character ')'
      \] - literal character ']'
      \\ - literal character '\'
      anything else - just text
Nerogar commented 1 year ago

Will this work with models other than the base model? eg. inpainting and depth2image models. Even if it works, you did not change the following lines that set self.play_model_variant to a specific value based on the pipeline class. This will break the model playground for inpainting and depth2image models

allenbenz commented 1 year ago

As written it doesn't work with non-base models, I'll play around a bit to see what can be done.

allenbenz commented 1 year ago

Ugh, I hadn't looked very deep into anything. I didn't realize the pipelines weren't composable.

So I could stick self.pipe = DiffusionPipeline.from_pretrained(model, custom_pipeline="lpw_stable_diffusion", **self.pipe.component) under if isinstance(self.pipe, StableDiffusionPipeline) but that's going to confuse people when the prompts work sometimes and don't later.

So for StableTuner's usecase the Long Prompt Weighting Stable Diffusion pipeline is only useful as a reference.

I'm going to close the PR as it shouldn't be merged and isn't the start of the appropriate implementation.