How to run juggernaut model in local

140 Views Asked by At

I want to run fine-tuned stable diffusion models in my local pc using python. For example juggernaut: https://huggingface.co/RunDiffusion/Juggernaut-XL-v9

This is my code (it works with stable-diffusion-xl-base-1.0):

import random
from diffusers import DiffusionPipeline, StableDiffusionXLImg2ImgPipeline
import torch
import gc
import time

# for cleaning memory
gc.collect()
torch.cuda.empty_cache()

start_time = time.time()

model = "RunDiffusion/Juggernaut-XL-v9"
pipe = DiffusionPipeline.from_pretrained(
    model,
    torch_dtype=torch.float16,
)

pipe.to("cuda")

prompt = ("a portrait of male as a knight in middle ages, masculine looking, battle in the background, sharp focus, highly detailed, movie-style lighting, shadows")
seed = random.randint(0, 2**32 - 1)

generator = torch.Generator("cuda").manual_seed(seed)
image = pipe(prompt=prompt, generator=generator, num_inference_steps=1)
image = image.images[0]
image.save(f"output_images/{seed}.png")

end_time = time.time()

total_time = end_time - start_time
minutes = int(total_time // 60) 
seconds = int(total_time % 60) 

print(f"Took: {minutes} min {seconds} sec")
print(f"Saved to output_images/{seed}.png")

But I am getting:

OSError: Error no file named pytorch_model.bin, tf_model.h5, model.ckpt.index or flax_model.msgpack found in directory

Maybe because of python, cuda versions. I'm dropping down my libraries versions:

Python 3.9.0

PyTorch: 2.2.0+cu118

CUDA : 11.8

Diffusers: 0.26.3

Transformers: 4.38.1

1

There are 1 best solutions below

1
zoo joo On

pipe = DiffusionPipeline.from_pretrained( model, torch_dtype=torch.float16, variant='fp16',use_safetensors=True, )