1import torch
2from diffusers import DiffusionPipeline
3
4model_id = 'bghira/sd35m-sfwbooru'
5pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) # loading directly in bf16
6
7prompt = "A photo-realistic image of a cat"
8negative_prompt = 'blurry, cropped, ugly'
9
10pipeline.to('cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu') # the pipeline is already in its target precision level
11model_output = pipeline(
12 prompt=prompt,
13 negative_prompt=negative_prompt,
14 num_inference_steps=30,
15 generator=torch.Generator(device='cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu').manual_seed(42),
16 width=1024,
17 height=1024,
18 guidance_scale=3.2,
19 skip_guidance_layers=[7, 8, 9],
20).images[0]
21
22model_output.save("output.png", format="PNG")
23
SimpleTuner generates a safetensors variant of the EMA weights and a pt file.
The safetensors file is intended to be used for inference, and the pt file is for continuing finetuning.
The EMA model may provide a more well-rounded result, but typically will feel undertrained compared to the full model as it is a running decayed average of the model weights.