from diffusers import StableDiffusion3Pipeline, SD3Transformer2DModel
import gguf
from gguf.quants import dequantize
from safetensors.torch import load_file
from transformers import T5Config, T5EncoderModel
import torch
defload_transformer_from_gguf(filepath):
sd = {}
reader = gguf.GGUFReader(filepath)
for item in reader.tensors:
xs = dequantize(item.data, item.tensor_type)
tensor = torch.tensor(xs)
sd[item.name] = tensor.to(dtype=torch.float16)
config = SD3Transformer2DModel.load_config('./transformer')
transformer = SD3Transformer2DModel.from_config(config).to(dtype=torch.float16)
transformer.load_state_dict(sd)
transformer.eval()
return transformer
transformer = load_transformer_from_gguf('sd3_medium.Q8.gguf')
# Load T5 encoder in F8_E4M3 format.# t5_config = T5Config.from_pretrained('text_encoder_3')# t5 = T5EncoderModel(t5_config).to(dtype=torch.float16)# t5_sd = load_file('t5xxl_fp8_e4m3fn.safetensors')# t5.load_state_dict(t5_sd)# t5.eval()
pipe = StableDiffusion3Pipeline.from_pretrained('stabilityai/stable-diffusion-3-medium-diffusers',
transformer=transformer,
# Either disable the T5 encoder.
text_encoder_3=None,
tokenizer_3=None,
# Or enable it.# text_encoder_3=t5,
torch_dtype=torch.float16)
pipe.enable_model_cpu_offload()
image = pipe('cat playing piano', num_inference_steps=20).images[0]
image.save('cat.png')
Disclaimer
Use of this code and the copy of documentation requires citation and attribution to the author via a link to their Hugging Face profile in all resulting work.
Runs of twodgirl stable-diffusion-3-medium-gguf on huggingface.co
34
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About stable-diffusion-3-medium-gguf huggingface.co Model
More stable-diffusion-3-medium-gguf license Visit here:
stable-diffusion-3-medium-gguf huggingface.co is an AI model on huggingface.co that provides stable-diffusion-3-medium-gguf's model effect (), which can be used instantly with this twodgirl stable-diffusion-3-medium-gguf model. huggingface.co supports a free trial of the stable-diffusion-3-medium-gguf model, and also provides paid use of the stable-diffusion-3-medium-gguf. Support call stable-diffusion-3-medium-gguf model through api, including Node.js, Python, http.
stable-diffusion-3-medium-gguf huggingface.co is an online trial and call api platform, which integrates stable-diffusion-3-medium-gguf's modeling effects, including api services, and provides a free online trial of stable-diffusion-3-medium-gguf, you can try stable-diffusion-3-medium-gguf online for free by clicking the link below.
twodgirl stable-diffusion-3-medium-gguf online free url in huggingface.co:
stable-diffusion-3-medium-gguf is an open source model from GitHub that offers a free installation service, and any user can find stable-diffusion-3-medium-gguf on GitHub to install. At the same time, huggingface.co provides the effect of stable-diffusion-3-medium-gguf install, users can directly use stable-diffusion-3-medium-gguf installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
stable-diffusion-3-medium-gguf install url in huggingface.co: