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

Support for OFT (and problem with bundle format) #135

Closed
cyber-meow opened this issue Dec 14, 2023 · 3 comments
Closed

Support for OFT (and problem with bundle format) #135

cyber-meow opened this issue Dec 14, 2023 · 3 comments

Comments

@cyber-meow
Copy link

cyber-meow commented Dec 14, 2023

OFT from Controlling Text-to-Image Diffusion by Orthogonal Finetuning is now working in webui after Kohaku fixes inference: AUTOMATIC1111/stable-diffusion-webui#14300

To make it work with OFT, I initially tried adding "NetworkModuleOFT": "oft_blocks" to LORAANDSOON. This runs but does not give the good results because OFT performs multiplication instead of addition.
What really fixes the problem is to add this in line 981

if ltype == "NetworkModuleOFT":
    oft_parameters = torch.nn.Parameter(getattr(lora.modules[key],LORAANDSOON[ltype]))
    I = torch.eye(oft_parameters.size()[1]).to(oft_parameters.device)
    oft_parameters = oft_parameters * ratio + I * (1-ratio)
    setattr(lora.modules[key], "oft_blocks", oft_parameters)
    set = True

Illustration:
xyz_grid-0018-954588431

This is from this OFT bundle: https://civitai.com/models/173081


By the way, the same issue for bundle format (i.e. an additional network with built-in embeddings) that I mentioned earlier for regional prompter hako-mikan/sd-webui-regional-prompter#258 applies to LBW as well. This is not so critical but may worth some investigation if you have some time.

Thank you for the great plugins in any case.

@cyber-meow cyber-meow changed the title Support for oft (and problem with bundle format) Support for OFT (and problem with bundle format) Dec 14, 2023
@KohakuBlueleaf
Copy link

I recommend to modify scale instead of oft_blocks since kohya/lycoris have different implementation and have different math form for oft_blocks

hako-mikan added a commit that referenced this issue Dec 17, 2023
@hako-mikan
Copy link
Owner

Fixed.
Thanks @KohakuBlueleaf for advice.

@cyber-meow
Copy link
Author

Indeed. Both issues are solved now. Thanks.

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

No branches or pull requests

3 participants