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

Alternative implementation in Refiners #4

Open
limiteinductive opened this issue Oct 12, 2023 · 0 comments
Open

Alternative implementation in Refiners #4

limiteinductive opened this issue Oct 12, 2023 · 0 comments

Comments

@limiteinductive
Copy link

Hi @Newbeeer !

Thank you for you amazing work and paper.

I've implemented the Restart method for the DDIM Scheduler in the library called Refiners. We are building Refiners, an open source (MIT), PyTorch-based framework made to easily train and run adapters on top of foundational models.

Demo:

Follow these install steps
Run the code snippet below:

import torch

from refiners.foundationals.latent_diffusion import StableDiffusion_1
from refiners.fluxion.utils import manual_seed


device = "cuda"

sd15 = StableDiffusion_1(device="cuda", dtype=torch.float16)
sd15.clip_text_encoder.load_from_safetensors("clip_text.safetensors")
sd15.lda.load_from_safetensors("lda.safetensors")
sd15.unet.load_from_safetensors("unet.safetensors")

with torch.no_grad():
    prompt = "a cute cat, detailed high-quality professional image"
    negative_prompt = "lowres, bad anatomy, bad hands, cropped, worst quality"

    clip_text_embedding = sd15.compute_clip_text_embedding(text=prompt, negative_text=negative_prompt)

    manual_seed(2)
    x = torch.randn(1, 4, 64, 64, device=device, dtype=torch.float16)
    
    restart = Restart(
        ldm=sd15,
        num_steps=10,
        num_iterations=2,
        start_time=0.1,
        end_time=2
    )
    

    for step in sd15.steps:
        x = sd15(
            x,
            step=step,
            clip_text_embedding=clip_text_embedding,
            condition_scale=7.5,
        )
        
        if step == restart.start_step:
            x = restart(
                x,
                clip_text_embedding=clip_text_embedding,
                condition_scale=8,
            )

    predicted_image = sd15.lda.decode_latents(x)

predicted_image.save("output.png")
print("done: see output.png")

With Restart:
image

Without Restart:
image

It would be great to have you feedback, since there is currently not many implementation of Restart. It would be great if you had some insights on how to support the DPM Scheduler.

Thank you!

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

1 participant