Skip to content

SD-XL update #260

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

Merged
merged 8 commits into from
Sep 4, 2024
Merged
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
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ invisible-watermark
torchmetrics<1.0.0
kornia
open-clip-torch<2.26.1
diffusers
accelerate
41 changes: 38 additions & 3 deletions text_to_image/stable_diffusion/run_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,52 @@ def single_pass_pytorch(_runner, _stablediffusion):
_stablediffusion.submit_count(batch_size, x_samples)

runner = PyTorchRunnerV2(model)
stablediffusion = StableDiffusion()
return run_model(single_pass_pytorch, runner, stablediffusion, batch_size, num_runs, timeout)
stable_diffusion_dataset = StableDiffusion()
return run_model(single_pass_pytorch, runner, stable_diffusion_dataset, batch_size, num_runs, timeout)


def run_pytorch_fp32(model_name, steps, batch_size, num_runs, timeout, **kwargs):
import torch._dynamo
from diffusers import DiffusionPipeline
torch._dynamo.config.suppress_errors = True

from utils.benchmark import run_model
from utils.pytorch import apply_compile
from utils.pytorch import PyTorchRunnerV2
from utils.text_to_image.stable_diffusion import StableDiffusion

model = DiffusionPipeline.from_pretrained(model_name,
use_safetensors=True).to("cpu")

model.unet = apply_compile(model.unet)

def single_pass_pytorch(_runner, _stablediffusion):
prompts = [_stablediffusion.get_input() for _ in range(batch_size)]
x_samples = _runner.run(batch_size * steps, prompt=prompts, num_inference_steps=steps)
_stablediffusion.submit_count(batch_size, x_samples)

runner = PyTorchRunnerV2(model)
stable_diffusion_dataset = StableDiffusion()
return run_model(single_pass_pytorch, runner, stable_diffusion_dataset, batch_size, num_runs, timeout)


if __name__ == "__main__":
from utils.helpers import DefaultArgParser
from utils.misc import print_goodbye_message_and_die

stablediffusion_variants = ["stabilityai/stable-diffusion-xl-base-1.0"]
parser = DefaultArgParser(["pytorch"])
parser.require_model_name(stablediffusion_variants)
parser.ask_for_batch_size()
parser.add_argument("--steps", type=int, default=25, help="steps through which the model processes the input")
parser.add_argument("-p", "--precision", type=str, choices=["fp32", "bf16"], required=True,
help="precision in which to run the model")

run_pytorch_bf16(**vars(parser.parse()))
args = parser.parse()
if args.precision == "fp32":
run_pytorch_fp32(**vars(parser.parse()))
elif args.precision == "bf16":
run_pytorch_bf16(**vars(parser.parse()))
else:
print_goodbye_message_and_die(
"this model seems to be unsupported in a specified precision: " + args.precision)