[sd3] make sure height and size are divisible by 16 by yiyixuxu · Pull Request #9573 · huggingface/diffusers (original) (raw)

for 1920 X 1080 should get an input error and ask user to resize to 1920 x 1072 (on current main will get an error on scheduler step)

import torch import argparse from diffusers import StableDiffusion3Pipeline

def main(height, width): device = torch.device("cuda:1")

pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", torch_dtype=torch.float16)
pipe = pipe.to(device)
generator = torch.Generator(device=device).manual_seed(0)

image = pipe(
    "A cat holding a sign that says hello world",
    negative_prompt="",
    num_inference_steps=28,
    height=height,
    width=width,
    guidance_scale=7.0,
    generator=generator,
).images[0]

print(f"{height}x{width} -> image: {image.size}")
image.save(f"yiyi_test_1_out_{height}_{width}.png")

if name == "main": parser = argparse.ArgumentParser(description="Generate an image with Stable Diffusion 3") parser.add_argument("--height", type=int, default=1920, help="Height of the output image") parser.add_argument("--width", type=int, default=1080, help="Width of the output image")

args = parser.parse_args()

main(args.height, args.width)