Could you share guide how to use model locally ?
#4
by zgltyq - opened
I'm new here and I can't run the model using the default guide for safetensors.
I'm new here and I can't run the model using the default guide for safetensors.
hi do you use stable-diffusion-webui(AUTOMATIC1111) on your PC?
or use Google colab + diffusers online? or something else?
I'm new here and I can't run the model using the default guide for safetensors.
This thread is old, I know. But I'm registering here the answer because I also started yesterday too. And I had a lot of troubles and I needed to read, to code and test a lot before do something.
import os
import torch
from diffusers import DiffusionPipeline
from datetime import datetime
# Set memory optimization
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
# Free up GPU memory
torch.cuda.empty_cache()
# Define maximum memory for devices (adjust based on your hardware)
max_memory = {0: "6GiB", "cpu": "40GiB"} # Very low GPU memory to force CPU offloading
# Initialize the pipeline without moving to a device
model_name="digiplay/DucHaiten-Real3D-NSFW-V1"
pipeline = DiffusionPipeline.from_pretrained(
model_name,
torch_dtype=torch.float16,
max_memory=max_memory
)
# Se ainda assim estiver sem memória, use pipeline.enable_sequential_cpu_offload() ao invés de pipeline.enable_vae_slicing
pipeline.enable_vae_slicing()
pipeline.enable_model_cpu_offload()
pipeline.enable_attention_slicing()
NOW = datetime.now().strftime("%Y-%m-%d_%H%M%S")
Prompt="Magazine ad, iconic, 1943, Cartoon, sharp focus, comic, 2k art on canvas by kyoani and ROSSDRAWS, princess"
Prompt2="cartoon, colored manga"
Negative_prompt="extra limbs, double torso, extra arms, extra hands, mangled fingers, missing lips, extra legs"
# Se alterar de 600x800 para 720x1280 dobra o tempo de computação, mas ainda cabe na GPU
height=688
width=896
num_images_per_prompt=5
output_image_file=model_name.replace('/', '_').replace('\\', '_')
last_image_file_saved=""
for index, image in enumerate(pipeline(
Prompt,
prompt2=Prompt2,
negative_prompt=Negative_prompt,
height=height,
width=width,
num_images_per_prompt=num_images_per_prompt,
add_watermarker=False,
num_inference_steps=35).images):
last_image_file_saved=f"{output_image_file}_{NOW}_{index}.png"
image.save(last_image_file_saved)
print("last_image_file_saved: ", last_image_file_saved)

