Skip to content

Implement attention splicing for textual inversion #757

Closed

Description

@allo-

Is your feature request related to a problem? Please describe.
Textual inversion requires a lot of (V)RAM and could possibly benefit from attention splicing.

Describe the solution you'd like
Implement attention splicing for textual inversion

Describe alternatives you've considered
I tried to use unet.set_attention_slice(unet.config.attention_head_dim // 2), but it didn't seem to do much. I am not sure if I need to enable it at more places or if it just is not efficient for the training pipeline.

Activity

  1. patil-suraj commented on Oct 7, 2022

    @patil-suraj
    Contributor

    Hi @allo- ! the attention slicing is mostly meant to be used for inference, it won't help much for training.
    Also the textual inversion training fits on 16GB GPU and we are working on couple of other things to reduce it a bit further.
    cf #687

  2. allo- commented on Oct 7, 2022

    @allo-
    ContributorAuthor

    With batch size 1 it fits into 12 GB for me, but when the GPU is used for other things as well, it becomes complicated. A workaround is to learn smaller sizes. 480 leaves more room in GPU RAM and still yields acceptable results. But every optimization is welcome!

    Next thing I wanted to try is, if fp16 trained embeddings work on fp32 models. I guess it works (better than the other way round) as the fp16 embeddings can be represented in larger floating point types as well and one may only miss a better minimum when training with less precision?

  3. patil-suraj commented on Oct 7, 2022

    @patil-suraj
    Contributor

    fp16 embeddings should work fine with f32 model.

  4. allo- commented on Oct 7, 2022

    @allo-
    ContributorAuthor

    After disabling it again, it seems it made at least some difference to enable attention slicing on unet.
    At least when I commented the line I got a OOM crash on the next run. It could of course be coincidence but the last runs before it was fine (while still being near the limit of my VRAM). When it saves some memory, it could be useful to (optionally) enable it.

  5. patil-suraj commented on Oct 10, 2022

    @patil-suraj
    Contributor

    Once #687 is merged it should help save a lot of VRAM, we can revisit this if that saving is not enough and then optionally enable this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions