Giter Site home page Giter Site logo

FreeU support about stable-diffusion.cpp HOT 8 OPEN

lpn256 avatar lpn256 commented on May 29, 2024 1
FreeU support

from stable-diffusion.cpp.

Comments (8)

bssrdf avatar bssrdf commented on May 29, 2024 5

I gave a try but I am not sure if implemented correctly. Here are the comparison without and with FreeU.

FreeU OFF FreeU ON
freeu-off_5 freeu-on_5
freeu-off_4 freeu-on_4
freeu-off_3 freeu-on_3
freeu-off_2 freeu-on_2
freeu-off_6 freeu-on_6

Above ones are all using artiusV21_v21.safetensors file. Below comparison switched to v2-1_768-nonema-pruned.safetensors.

FreeU OFF FreeU ON
freeu-off_7 freeu-on_7

FreeU definitely won here 😸 .

from stable-diffusion.cpp.

FSSRepo avatar FSSRepo commented on May 29, 2024 3

Interesting, I'll see if I can give it some time to at least try if it works.

Bad new:

To implement this, it would be necessary to create the operation for the fourier transform and its inverse in ggml, and that is very difficult.

from stable-diffusion.cpp.

bssrdf avatar bssrdf commented on May 29, 2024 3

@FSSRepo, @leejet, thanks. There is still quite some work before I can make a PR.

  • The changes to sd.cpp are relatively trivial but they do require some interface mods (I think it is better to make a switch for FreeU on or off).
  • The ggml mods are more substantial, but still manageable. The problem is the two operators (FFT_FILTER and FREEU_BACKBONE) I added for FreeU are too specific and may not get accepted. I see there are some ggml extensions in sd.cpp but I don't see how cuda backends can be added. I am seeking your advice.
  • The two additional operators are only implemented for GPU backend and I have to work on their CPU counterparts.

@FSSRepo, I can verify that the two operators are functioning correctly as I have test cases for both. But I don't think I can replicate results with sd-webui or with the implementation from the original author's repository.

from stable-diffusion.cpp.

bssrdf avatar bssrdf commented on May 29, 2024 1

I gave a try but I am not sure if implemented correctly.

@bssrdf Do you mean in sd.cpp? I checked your fork, and I don't see anything related.

Yes. Please check out add-freeu-support branch of my sd.cpp fork as well as add-freeu-support branch of my ggml fork. Most of the work is done in ggml. Sorry, code is a bit messy now and I will do a clean up before the PR.

from stable-diffusion.cpp.

leejet avatar leejet commented on May 29, 2024 1

I gave a try but I am not sure if implemented correctly.

@bssrdf Do you mean in sd.cpp? I checked your fork, and I don't see anything related.

Yes. Please check out add-freeu-support branch of my sd.cpp fork as well as add-freeu-support branch of my ggml fork. Most of the work is done in ggml. Sorry, code is a bit messy now and I will do a clean up before the PR.

Great job! Can you create a PR for both ggml and sd.cpp?

from stable-diffusion.cpp.

lpn256 avatar lpn256 commented on May 29, 2024

FreeU_v2 seems to be a paper update: https://twitter.com/scy994/status/1714499568573039102

from stable-diffusion.cpp.

FSSRepo avatar FSSRepo commented on May 29, 2024

I gave a try but I am not sure if implemented correctly.

@bssrdf Do you mean in sd.cpp? I checked your fork, and I don't see anything related.

from stable-diffusion.cpp.

FSSRepo avatar FSSRepo commented on May 29, 2024

@bssrdf Great job, to implement that functionality in sd.cpp for obvious reasons, it must also be compatible with the CPU backend. I don't know much about how to implement the FFT optimally, so I can't help you with that. I'm also interested to see if you could replicate those results with sd-webui or with the implementation from the repository to check if they match or are similar. Additionally, it would be helpful to determine if certain values passed to the Fourier_filter function are the same as those you receive with your implementation.

def Fourier_filter(x, threshold, scale):
    # FFT
    x_freq = fft.fftn(x, dim=(-2, -1))
    x_freq = fft.fftshift(x_freq, dim=(-2, -1))
    
    B, C, H, W = x_freq.shape
    mask = torch.ones((B, C, H, W)).cuda() 

    crow, ccol = H // 2, W //2
    mask[..., crow - threshold:crow + threshold, ccol - threshold:ccol + threshold] = scale
    x_freq = x_freq * mask

    # IFFT
    x_freq = fft.ifftshift(x_freq, dim=(-2, -1))
    x_filtered = fft.ifftn(x_freq, dim=(-2, -1)).real

from stable-diffusion.cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.