Skip to content

Instantly share code, notes, and snippets.

View sayakpaul's full-sized avatar
:octocat:
Learn, unlearn and relearn.

Sayak Paul sayakpaul

:octocat:
Learn, unlearn and relearn.
View GitHub Profile
@sayakpaul
sayakpaul / benchmark_pixart-900m-1024-ft.py
Created July 2, 2024 08:59
Benchmarks the "ptx0/pixart-900m-1024-ft" model with `torch.compile()`.
import torch
torch.set_float32_matmul_precision("high")
from diffusers import DiffusionPipeline
import time
pipeline_id = "ptx0/pixart-900m-1024-ft"
pipeline = DiffusionPipeline.from_pretrained(
pipeline_id,
@sayakpaul
sayakpaul / run_sd3_compile.py
Last active June 17, 2024 07:47
The script shows how to run SD3 with `torch.compile()`
import torch
torch.set_float32_matmul_precision("high")
from diffusers import StableDiffusion3Pipeline
import time
id = "stabilityai/stable-diffusion-3-medium-diffusers"
pipeline = StableDiffusion3Pipeline.from_pretrained(
id,
@sayakpaul
sayakpaul / run_sd3_8bit.py
Last active June 21, 2024 07:20
The code snippet shows how to run Stable Diffusion 3 with a 8bit T5-xxl, drastically reducing the memory requirements.
from diffusers import StableDiffusion3Pipeline
from transformers import T5EncoderModel
import torch
import time
import gc
def flush():
gc.collect()
torch.cuda.empty_cache()
@sayakpaul
sayakpaul / run_hunyuan_dit_compile.py
Created June 5, 2024 05:56
Benchmarking script for running Hunyuan DiT with `torch.compile()`.
import torch
torch.set_float32_matmul_precision("high")
from diffusers import HunyuanDiTPipeline
import argparse
import time
def load_pipeline(args):
@sayakpaul
sayakpaul / run_hunyuan_dit_less_memory.py
Created June 5, 2024 03:55
Run `HunyuanDiTPipeline` from Diffusers under 6GBs of GPU VRAM.
"""
Make sure you have `diffusers`, `accelerate`, `transformers`, and `bitsandbytes` installed.
You also set up PyTorch and CUDA.
Once the dependencies are installed, you can run `python run_hunyuan_dit_less_memory.py`.
"""
from diffusers import HunyuanDiTPipeline
from transformers import T5EncoderModel
@sayakpaul
sayakpaul / custom_pipelines_with_custom_transformers.ipynb
Created March 13, 2024 12:03
This notebook shows how to use a custom `transformers` model within a Stable Diffusion pipeline.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sayakpaul
sayakpaul / instructions.md
Last active February 15, 2024 18:23
Utilities for formatting Python projects. Inspired from what's done in `diffusers`.
@sayakpaul
sayakpaul / coco_30k_hf_datasets.py
Created January 31, 2024 10:34
Samples 30k samples randomly from the COCO 2014 validation set.
from datasets import Dataset, Features
from datasets import Image as ImageFeature
from datasets import Value
import pandas as pd
import os
# CSV comes from the notebook above.
df = pd.read_csv("coco_30k_randomly_sampled_2014_val.csv")
root_path = "val2014"
@sayakpaul
sayakpaul / get_params_diffusers_diffusers.py
Last active January 22, 2024 04:24
PoCs a utility to get the totsl parameters count of a diffusers pipeline without hefty downloads.
from huggingface_hub import (
hf_hub_download,
list_files_info,
parse_safetensors_file_metadata,
)
import json
import argparse
def get_files_info(args):
# SDXL: 0.613, 0.5566, 0.54, 0.4162, 0.4042, 0.4596, 0.5374, 0.5286, 0.5038
# SD: 0.5396, 0.5707, 0.477, 0.4665, 0.5419, 0.4594, 0.4857, 0.4741, 0.4804
from diffusers import DiffusionPipeline
from peft import LoraConfig
import argparse
import torch
def load_pipeline(pipeline_id):