Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stable Diffusion XL #1882

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions torchbenchmark/canary_models/stable_diffusion_xl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Stable Diffusion XL model
It requires users to specify "HUGGINGFACE_AUTH_TOKEN" in environment variable
to authorize login and agree HuggingFace terms and conditions.
"""
from torchbenchmark.tasks import COMPUTER_VISION
from torchbenchmark.util.model import BenchmarkModel
from torchbenchmark.util.framework.huggingface.model_factory import HuggingFaceAuthMixin

import torch
from diffusers import DiffusionPipeline


class Model(BenchmarkModel, HuggingFaceAuthMixin):
task = COMPUTER_VISION.GENERATION

DEFAULT_TRAIN_BSIZE = 1
DEFAULT_EVAL_BSIZE = 1
ALLOW_CUSTOMIZE_BSIZE = False
# Default eval precision on CUDA device is fp16
DEFAULT_EVAL_CUDA_PRECISION = "fp16"

def __init__(self, test, device, batch_size=None, extra_args=[]):
HuggingFaceAuthMixin.__init__(self)
super().__init__(test=test, device=device,
batch_size=batch_size, extra_args=extra_args)
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
self.pipe = DiffusionPipeline.from_pretrained(model_id).to(device)
random_input = torch.randn(1, 4, 256, 256).to(device)
timestep = torch.tensor([1.0]).to(device)
encoder_hidden_states = torch.randn(1, 1, 2048).to(device)
added_cond_kwargs = {
"text_embeds": torch.randn(1, 2560).to(device), # Example tensor, adjust shape as needed
"time_ids": torch.tensor([1]).to(device) # Replace 'some_value' with the appropriate value or tensor shape for time_ids
}

self.args_tuple = (random_input, timestep, encoder_hidden_states, added_cond_kwargs)

def enable_fp16_half(self):
pass

def get_module(self):
self.pipe.unet, self.args_tuple

def train(self):
raise NotImplementedError("Train is not implemented for the stable diffusion XL model.")

def eval(self):
image = self.pipe.unet(*self.args_tuple)
return (image, )
17 changes: 17 additions & 0 deletions torchbenchmark/canary_models/stable_diffusion_xl/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from torchbenchmark.util.framework.diffusers import install_diffusers
from torchbenchmark.util.framework.huggingface.model_factory import HuggingFaceAuthMixin
import torch
import os
import warnings
MODEL_NAME = "stabilityai/stable-diffusion-2"

def load_model_checkpoint():
from diffusers import StableDiffusionPipeline
StableDiffusionPipeline.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, safety_checker=None)

if __name__ == "__main__":
if not 'HUGGING_FACE_HUB_TOKEN' in os.environ:
warnings.warn("Make sure to set `HUGGINGFACE_HUB_TOKEN` so you can download weights")
else:
install_diffusers()
load_model_checkpoint()
10 changes: 10 additions & 0 deletions torchbenchmark/canary_models/stable_diffusion_xl/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
devices:
NVIDIA A100-SXM4-40GB:
eval_batch_size: 32
eval_benchmark: false
eval_deterministic: false
eval_nograd: true
train_benchmark: false
train_deterministic: false
not_implemented:
- device: cpu
2 changes: 1 addition & 1 deletion torchbenchmark/util/framework/diffusers/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
git+https://github.com/huggingface/diffusers.git@56958e1
diffusers==0.20.2