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 / 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.
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):
@sayakpaul
sayakpaul / benchmark_sd_trt.py
Last active November 30, 2023 11:10
Benchmarking script for Stable Diffusion on TensorRT
import argparse
import torch
import torch_tensorrt
import torch.utils.benchmark as benchmark
from diffusers import DiffusionPipeline
CKPT = "CompVis/stable-diffusion-v1-4"
PROMPT = "a majestic castle in the clouds"
import xformers.ops
import torch.nn.functional as F
import torch
# xformers: 1, 4096, 16, 72
# SDPA: 1, 16, 4096, 72
q = torch.randn(1, 4096, 16, 72, generator=torch.manual_seed(0)).cuda()
k = torch.randn(1, 4096, 16, 72, generator=torch.manual_seed(1)).cuda()
v = torch.randn(1, 4096, 16, 72, generator=torch.manual_seed(2)).cuda()
import argparse
import time
import torch
from diffusers import AutoencoderKL, StableDiffusionXLPipeline
from diffusers.utils import load_image
PIPELINE_ID = "stabilityai/stable-diffusion-xl-base-1.0"
VAE_PATH = "madebyollin/sdxl-vae-fp16-fix"
"""
Examples:
(1) python benchmark_controlnet_sdxl.py --controlnet_id diffusers/controlnet-depth-sdxl-1.0
(2) python benchmark_controlnet_sdxl.py --controlnet_id diffusers/controlnet-depth-sdxl-1.0-small
(3) python benchmark_controlnet_sdxl.py --controlnet_id diffusers/controlnet-depth-sdxl-1.0-mid
"""
import argparse
import time
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.