Views
No views yet
NitroFusion: High-Fidelity Single-Step Diffusion through Dynamic Adversarial TrainingDar-Yen Chen, Hmrishav Bandyopadhyay, Kai Zou, Yi-Zhe Song

nitrosd-realism_comfyui.safetensors and nitrosd-vibrant_comfyui.safetensors, as well as a workflow are now released.nitrosd-realism_unet.safetensors: Produces photorealistic images with fine details.nitrosd-vibrant_unet.safetensors: Offers vibrant, saturated color characteristics.1from diffusers import LCMScheduler
2class TimestepShiftLCMScheduler(LCMScheduler):
3 def __init__(self, *args, shifted_timestep=250, **kwargs):
4 super().__init__(*args, **kwargs)
5 self.register_to_config(shifted_timestep=shifted_timestep)
6 def set_timesteps(self, *args, **kwargs):
7 super().set_timesteps(*args, **kwargs)
8 self.origin_timesteps = self.timesteps.clone()
9 self.shifted_timesteps = (self.timesteps * self.config.shifted_timestep / self.config.num_train_timesteps).long()
10 self.timesteps = self.shifted_timesteps
11 def step(self, model_output, timestep, sample, generator=None, return_dict=True):
12 if self.step_index is None:
13 self._init_step_index(timestep)
14 self.timesteps = self.origin_timesteps
15 output = super().step(model_output, timestep, sample, generator, return_dict)
16 self.timesteps = self.shifted_timesteps
17 return output1import torch
2from diffusers import DiffusionPipeline, UNet2DConditionModel
3from huggingface_hub import hf_hub_download
4from safetensors.torch import load_file
5# Load model.
6base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
7repo = "ChenDY/NitroFusion"
8# NitroSD-Realism
9ckpt = "nitrosd-realism_unet.safetensors"
10unet = UNet2DConditionModel.from_config(base_model_id, subfolder="unet").to("cuda", torch.float16)
11unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
12scheduler = TimestepShiftLCMScheduler.from_pretrained(base_model_id, subfolder="scheduler", shifted_timestep=250)
13scheduler.config.original_inference_steps = 4
14# # NitroSD-Vibrant
15# ckpt = "nitrosd-vibrant_unet.safetensors"
16# unet = UNet2DConditionModel.from_config(base_model_id, subfolder="unet").to("cuda", torch.float16)
17# unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
18# scheduler = TimestepShiftLCMScheduler.from_pretrained(base_model_id, subfolder="scheduler", shifted_timestep=500)
19# scheduler.config.original_inference_steps = 4
20pipe = DiffusionPipeline.from_pretrained(
21 base_model_id,
22 unet=unet,
23 scheduler=scheduler,
24 torch_dtype=torch.float16,
25 variant="fp16",
26).to("cuda")
27prompt = "a photo of a cat"
28image = pipe(
29 prompt=prompt,
30 num_inference_steps=1, # NotroSD-Realism and -Vibrant both support 1 - 4 inference steps.
31 guidance_scale=0,
32).images[0]nitrosd-realism_comfyui.safetensors and nitrosd-vibrant_comfyui.safetensors, and place them in the ComfyUI/models/checkpoints.ComfyUI/custom_nodes.