Last active
August 4, 2024 20:41
-
-
Save al-swaiti/476e0737b7d09cfd8bd74c820eb58847 to your computer and use it in GitHub Desktop.
quantization of "pixart sigma"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://huggingface.co/PixArt-alpha/PixArt-Sigma-XL-2-1024-MS/tree/main/transformer | |
# https://huggingface.co/blog/quanto-diffusers | |
#python -m venv quanta or conda whatever | |
#source ./quanta/bin/activate >>> default (bash shell) | |
# pip install --force git+https://github.com/huggingface/diffusers.git | |
# pip install torch optimum.quanto | |
#run first part to create model | |
#run second part to test model | |
####################firstpart##################### | |
# from diffusers import PixArtTransformer2DModel | |
# from optimum.quanto import QuantizedPixArtTransformer2DModel, qfloat8 | |
# model = PixArtTransformer2DModel.from_pretrained("PixArt-alpha/PixArt-Sigma-XL-2-1024-MS", subfolder="transformer") | |
# qmodel = QuantizedPixArtTransformer2DModel.quantize(model, weights=qfloat8) | |
# qmodel.save_pretrained("pixart-sigma-fp8") | |
####################secondpart##################### | |
from optimum.quanto import QuantizedPixArtTransformer2DModel | |
import torch | |
transformer = QuantizedPixArtTransformer2DModel.from_pretrained("pixart-sigma-fp8") | |
transformer.to(device="cuda", dtype=torch.float16) | |
from diffusers import DiffusionPipeline | |
import torch | |
pipe = DiffusionPipeline.from_pretrained( | |
"PixArt-alpha/PixArt-Sigma-XL-2-1024-MS", | |
transformer=None, | |
torch_dtype=torch.float16, | |
) | |
pipe.enable_sequential_cpu_offload() | |
pipe.transformer = transformer | |
prompt = "A small rose with a happy face in the Sahara desert., master piece, award wining " | |
image = pipe(prompt).images[0] | |
image.save("sd3_hello_world-8bit-T5.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment