-
Notifications
You must be signed in to change notification settings - Fork 7
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
add stable diffusion from huggingface #254
Merged
Merged
Changes from 34 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
73931f1
first commit
MarcelWilnicki 4f5dd6e
wip
MarcelWilnicki 22fab55
wip
MarcelWilnicki ee2779a
wip
MarcelWilnicki 516be16
wip
MarcelWilnicki d4d63f1
wip
MarcelWilnicki a448e6e
wip
MarcelWilnicki 0f5e469
wip
MarcelWilnicki 35944e6
wip
MarcelWilnicki b4dcce5
wip
MarcelWilnicki c67203e
wip
MarcelWilnicki 32fe752
wip
MarcelWilnicki 83197c2
wip
MarcelWilnicki 60bdb2d
add sapphire rapid version
MarcelWilnicki bc1d48f
wip
MarcelWilnicki c24959f
wip
MarcelWilnicki cf2e2ce
wip
MarcelWilnicki d6953cf
wip
MarcelWilnicki 731c565
wip
MarcelWilnicki d261f4b
wip
MarcelWilnicki 62ae9ba
wip
MarcelWilnicki 46cad0c
wip
MarcelWilnicki a7403da
wip
MarcelWilnicki 625d2f4
wip
MarcelWilnicki de4edef
wip
MarcelWilnicki 778594a
wip
MarcelWilnicki 45e6f85
wip
MarcelWilnicki ee86fa2
rename files
MarcelWilnicki 2bab8a7
wipC
MarcelWilnicki 273b7dc
wip
MarcelWilnicki 9038ce6
wip
MarcelWilnicki 061dcf5
wip
MarcelWilnicki 02b1167
wip
MarcelWilnicki 629a088
wip
MarcelWilnicki 135f6d9
wip
MarcelWilnicki 382c1c5
wip
MarcelWilnicki 2d49f62
wip
MarcelWilnicki 4ec2c31
Merge branch 'main' into marcel/stable-diffusionxlbase
MarcelWilnicki 95ef5dd
wip
MarcelWilnicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright (c) 2024, Ampere Computing LLC | ||
try: | ||
from utils import misc # noqa | ||
except ModuleNotFoundError: | ||
import os | ||
import sys | ||
filename = "set_env_variables.sh" | ||
directory = os.path.realpath(__file__).split("/")[:-1] | ||
for idx in range(1, len(directory) - 1): | ||
subdir = "/".join(directory[:-idx]) | ||
if filename in os.listdir(subdir): | ||
print(f"\nPlease run \033[91m'source {os.path.join(subdir, filename)}'\033[0m first.") | ||
break | ||
else: | ||
print(f"\n\033[91mFAIL: Couldn't find {filename}, are you running this script as part of Ampere Model Library?" | ||
f"\033[0m") | ||
sys.exit(1) | ||
|
||
|
||
def run_pytorch_fp32(model_name, steps, batch_size, num_runs, timeout, **kwargs): | ||
import os | ||
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 | ||
|
||
if os.environ.get("ENABLE_BF16_X86") == "1": | ||
model = DiffusionPipeline.from_pretrained(model_name, | ||
use_safetensors=True, | ||
torch_dtype=torch.bfloat16).to("cpu") | ||
else: | ||
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) | ||
stablediffusion = StableDiffusion() | ||
return run_model(single_pass_pytorch, runner, stablediffusion, batch_size, num_runs, timeout) | ||
|
||
|
||
if __name__ == "__main__": | ||
from utils.helpers import DefaultArgParser | ||
|
||
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") | ||
|
||
run_pytorch_fp32(**vars(parser.parse())) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright (c) 2024, Ampere Computing LLC | ||
from random import randint, seed | ||
from random import randint | ||
from utils.helpers import Dataset | ||
|
||
|
||
|
@@ -14,7 +14,6 @@ def get_input(self): | |
adjectives = ["big", "small", "thin", "wide", "blonde", "pale"] | ||
nouns = ["dog", "cat", "horse", "astronaut", "human", "robot"] | ||
actions = ["sings", "rides a triceratop", "rides a horse", "eats a burger", "washes clothes", "looks at hands"] | ||
seed(42) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove seed? It's good to have deterministic behavior and repeatable results. |
||
|
||
a = adjectives[randint(0, len(adjectives) - 1)] + " " | ||
b = nouns[randint(0, len(nouns) - 1)] + " " + actions[randint(0, len(actions) - 1)] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ENABLE_BF16_X86 is currently used to enable implicit bf16 in AML. Here you are explicitly loading model in bfloat16 - create run_pytorch_bf16 function instead.