diff --git a/README.md b/README.md index 8b0e6f09d1c..b5d8078a128 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ | [Mistral-7B-decode](./models/demos/wormhole/mistral7b) | 33rd | 32 | 10.9 t/s/u - 349 t/s | 13.3 t/s/u - 426 t/s | 21 t/s/u | | [Mamba-2.8B-decode](./models/demos/mamba) | any | 32 | 9.2 t/s/u - 295 t/s | 13.1 t/s/u - 419 t/s | 22 t/s/u | | [BERT-Large](./models/demos/metal_BERT_large_11/) (sen/s) | any | 8 | 270 | 340 | 400 | -| Stable Diffusion 1.4 512x512 | coming soon | 1 | | | | +| Stable Diffusion 1.4 512x512 (seconds for denoise) | | 1 | 114s | 0.2s | | [3] - Generating the i'th token in a sequence while the kv_cache is filled with i-1 rows. diff --git a/models/demos/wormhole/stable_diffusion/README.md b/models/demos/wormhole/stable_diffusion/README.md new file mode 100644 index 00000000000..25f90d513c4 --- /dev/null +++ b/models/demos/wormhole/stable_diffusion/README.md @@ -0,0 +1,32 @@ +# Stable_diffusion Model + +## Introduction +Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input. + +# Details +The entry point to functional_stable_diffusion model is UNet2DConditionModel in `models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_unet_2d_condition_model.py`. The model picks up certain configs and weights from huggingface pretrained model. We have used `CompVis/stable-diffusion-v1-4` version from huggingface as our reference. + +# Inputs +Inputs by default are provided from `input_data.json`. If you wish to change the inputs, provide a different path to test_demo.We do not recommend modifying `input_data.json` file. + +## How to Run + +To run the demo, make sure to build the project, activate the environment, and set the appropriate environment variables. +For more information, refer [installation and build guide](https://github.com/tenstorrent/tt-metal/blob/main/INSTALLING.md). + +Use `pytest --disable-warnings --input-path="models/demos/wormhole/stable_diffusion/demo/input_data.json" models/demos/wormhole/stable_diffusion/demo/demo.py::test_demo` to run the demo. + +If you wish to run the demo with a different input use `pytest --disable-warnings --input-path="" models/demos/wormhole/stable_diffusion/demo/demo.py::test_demo` + +Our second demo is designed to run poloclub/diffusiondb dataset, run this with `pytest --disable-warnings models/demos/wormhole/stable_diffusion/demo/demo.py::test_demo_diffusiondb`. + +If you wish to run for `num_prompts` samples and `num_inference_steps` denoising steps, use `pytest --disable-warnings models/demos/wormhole/stable_diffusion/demo/demo.py::test_demo_diffusiondb[-]` + +Note: ttnn stable diffusion utilizes `PNDMScheduler` and requires `num_inference_steps to be greater than or equal to 4`. [Reference](https://arxiv.org/pdf/2202.09778) + +# Metrics Interpretation +`FID Score (Fréchet Inception Distance)` evaluates the quality of generated images by measuring the similarity between their feature distributions and those of real images. A lower FID score indicates better similarity between generated and real images. +For more information, refer [FID Score](https://lightning.ai/docs/torchmetrics/stable/image/frechet_inception_distance.html). + +`CLIP Score` measures the similarity between the generated images and the input prompts. Higher CLIP scores indicate better alignment between the generated images and the provided text prompts. +For more information, refer [CLIP Score](https://lightning.ai/docs/torchmetrics/stable/multimodal/clip_score.html). diff --git a/models/experimental/functional_stable_diffusion/custom_preprocessing.py b/models/demos/wormhole/stable_diffusion/custom_preprocessing.py similarity index 100% rename from models/experimental/functional_stable_diffusion/custom_preprocessing.py rename to models/demos/wormhole/stable_diffusion/custom_preprocessing.py diff --git a/models/experimental/functional_stable_diffusion/demo/demo.py b/models/demos/wormhole/stable_diffusion/demo/demo.py similarity index 76% rename from models/experimental/functional_stable_diffusion/demo/demo.py rename to models/demos/wormhole/stable_diffusion/demo/demo.py index bad67bd12c1..f904d581e7e 100644 --- a/models/experimental/functional_stable_diffusion/demo/demo.py +++ b/models/demos/wormhole/stable_diffusion/demo/demo.py @@ -11,24 +11,21 @@ from loguru import logger from tqdm.auto import tqdm from datasets import load_dataset -import os from transformers import CLIPTextModel, CLIPTokenizer from diffusers import ( AutoencoderKL, UNet2DConditionModel, ) -from models.utility_functions import ( - skip_for_grayskull, -) +from models.utility_functions import skip_for_grayskull from models.utility_functions import ( enable_persistent_kernel_cache, disable_persistent_kernel_cache, ) from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.sd_pndm_scheduler import TtPNDMScheduler -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_unet_2d_condition_model import ( +from models.demos.wormhole.stable_diffusion.sd_pndm_scheduler import TtPNDMScheduler +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_unet_2d_condition_model import ( UNet2DConditionModel as UNet2D, ) @@ -65,8 +62,6 @@ def tt_guide(noise_pred, guidance_scale): # will return latents noise_pred.shape[3] - 1, ], ) - - # noise_pred_uncond, noise_pred_text = ttnn.split(noise_pred, noise_pred.shape[0] // 2, dim=0) noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond) return noise_pred @@ -108,6 +103,9 @@ def preprocess_images(image_paths): def run_demo_inference(device, reset_seeds, input_path, num_prompts, num_inference_steps, image_size=(256, 256)): disable_persistent_kernel_cache() + assert ( + num_inference_steps >= 4 + ), f"PNDMScheduler only supports num_inference_steps >= 4. Found num_inference_steps={num_inference_steps}" # 1. Load the autoencoder model which will be used to decode the latents into image space. vae = AutoencoderKL.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="vae") @@ -247,93 +245,49 @@ def run_demo_inference_diffusiondb( device, reset_seeds, input_path, num_prompts, num_inference_steps, image_size=(256, 256) ): disable_persistent_kernel_cache() - device.enable_program_cache() + assert ( + num_inference_steps >= 4 + ), f"PNDMScheduler only supports num_inference_steps >= 4. Found num_inference_steps={num_inference_steps}" # 0. Load a sample prompt from the dataset dataset = load_dataset("poloclub/diffusiondb", "2m_random_1k") data_1k = dataset["train"] height, width = image_size - torch_device = "cpu" - # 1. Load the autoencoder model which will be used to decode the latents into image space. - vae = AutoencoderKL.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="vae") - vae.to(torch_device) - vae_scale_factor = 2 ** (len(vae.config.block_out_channels) - 1) - - # 2. Load the tokenizer and text encoder to tokenize and encode the text. - tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14") - text_encoder = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14") - - # 3. The UNet model for generating the latents. - unet = UNet2DConditionModel.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="unet") - - # 4. load the K-LMS scheduler with some fitting parameters. - ttnn_scheduler = TtPNDMScheduler( - beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000, device=device - ) - - text_encoder.to(torch_device) - unet.to(torch_device) - - config = unet.config - parameters = preprocess_model_parameters( - initialize_model=lambda: unet, custom_preprocessor=custom_preprocessor, device=device - ) - input_height = 64 - input_width = 64 - reader_patterns_cache = {} if height == 512 and width == 512 else None - model = UNet2D(device, parameters, 2, input_height, input_width, reader_patterns_cache) - - guidance_scale = 7.5 # Scale for classifier-free guidance - generator = torch.manual_seed(174) # 10233 Seed generator to create the inital latent noise - batch_size = 1 + for i in range(num_prompts): + experiment_name = f"diffusiondb_{i}__{height}x{width}" + input_prompt = [f"{data_1k['prompt'][i]}"] + logger.info(f"input_prompts: {input_prompt}") - # Initial random noise - latents = torch.randn( - (batch_size, unet.config.in_channels, height // vae_scale_factor, width // vae_scale_factor), - generator=generator, - ) - latents = latents.to(torch_device) + image = np.array(data_1k["image"][i]) + ref_images = Image.fromarray(image) + ref_img_path = f"{experiment_name}_ref.png" + ref_images.save(ref_img_path) - ttnn_scheduler.set_timesteps(num_inference_steps) + # 1. Load the autoencoder model which will be used to decode the latents into image space. + vae = AutoencoderKL.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="vae") - latents = latents * ttnn_scheduler.init_noise_sigma - rand_latents = torch.tensor(latents) - rand_latents = ttnn.from_torch(rand_latents, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device) + # 2. Load the tokenizer and text encoder to tokenize and encode the text. + tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14") + text_encoder = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14") - # ttnn_latents = ttnn.from_torch(ttnn_latents, dtype=ttnn.bfloat16, device=device, layout=ttnn.TILE_LAYOUT) - ttnn_latent_model_input = ttnn.concat([rand_latents, rand_latents], dim=0) - _tlist = [] - for t in ttnn_scheduler.timesteps: - _t = constant_prop_time_embeddings(t, ttnn_latent_model_input, unet.time_proj) - _t = _t.unsqueeze(0).unsqueeze(0) - _t = _t.permute(2, 0, 1, 3) # pre-permute temb - _t = ttnn.from_torch(_t, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device) - _tlist.append(_t) + # 3. The UNet model for generating the latents. + unet = UNet2DConditionModel.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="unet") - time_step = ttnn_scheduler.timesteps.tolist() + # 4. load the K-LMS scheduler with some fitting parameters. + ttnn_scheduler = TtPNDMScheduler( + beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000, device=device + ) - interactive = os.environ.get("INTERACTIVE_SD_DEMO", "0") == "1" - i = 0 - while i < num_prompts: - ttnn_scheduler.set_timesteps(num_inference_steps) - if interactive: - print("Enter the input promt, or q to exit:") - input_prompt = [input()] - if input_prompt[0] == "q": - break - else: - input_prompt = [f"{data_1k['prompt'][i]}"] - - image = np.array(data_1k["image"][i]) - ref_images = Image.fromarray(image) - ref_img_path = f"{experiment_name}_ref.png" - ref_images.save(ref_img_path) - i = i + 1 + torch_device = "cpu" + vae.to(torch_device) + text_encoder.to(torch_device) + unet.to(torch_device) - experiment_name = f"diffusiondb_{i}__{height}x{width}" - logger.info(f"input_prompts: {input_prompt}") + guidance_scale = 7.5 # Scale for classifier-free guidance + generator = torch.manual_seed(174) # 10233 Seed generator to create the inital latent noise + batch_size = len(input_prompt) ## First, we get the text_embeddings for the prompt. These embeddings will be used to condition the UNet model. # Tokenizer and Text Encoder @@ -357,10 +311,44 @@ def run_demo_inference_diffusiondb( ttnn_text_embeddings = ttnn.from_torch( ttnn_text_embeddings, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device ) + + vae_scale_factor = 2 ** (len(vae.config.block_out_channels) - 1) + # Initial random noise + latents = torch.randn( + (batch_size, unet.config.in_channels, height // vae_scale_factor, width // vae_scale_factor), + generator=generator, + ) + latents = latents.to(torch_device) + + ttnn_scheduler.set_timesteps(num_inference_steps) + + latents = latents * ttnn_scheduler.init_noise_sigma + ttnn_latents = torch.tensor(latents) + ttnn_latents = ttnn.from_torch(ttnn_latents, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device) + + config = unet.config + parameters = preprocess_model_parameters( + initialize_model=lambda: unet, custom_preprocessor=custom_preprocessor, device=device + ) + input_height = 64 + input_width = 64 + reader_patterns_cache = {} if height == 512 and width == 512 else None + # ttnn_latents = ttnn.from_torch(ttnn_latents, dtype=ttnn.bfloat16, device=device, layout=ttnn.TILE_LAYOUT) + ttnn_latent_model_input = ttnn.concat([ttnn_latents, ttnn_latents], dim=0) + _tlist = [] + for t in ttnn_scheduler.timesteps: + _t = constant_prop_time_embeddings(t, ttnn_latent_model_input, unet.time_proj) + _t = _t.unsqueeze(0).unsqueeze(0) + _t = _t.permute(2, 0, 1, 3) # pre-permute temb + _t = ttnn.from_torch(_t, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device) + _tlist.append(_t) + + time_step = ttnn_scheduler.timesteps.tolist() + + model = UNet2D(device, parameters, 2, input_height, input_width, reader_patterns_cache) iter = 0 - ttnn_latents = rand_latents # # Denoising loop - for index in tqdm(range(len(time_step))): + for index in range(len(time_step)): # expand the latents if we are doing classifier-free guidance to avoid doing two forward passes. ttnn_latent_model_input = ttnn.concat([ttnn_latents, ttnn_latents], dim=0) _t = _tlist[index] @@ -377,12 +365,12 @@ def run_demo_inference_diffusiondb( return_dict=True, config=config, ) + print(f"Sample: {iter}") # perform guidance noise_pred = tt_guide(ttnn_output, guidance_scale) ttnn_latents = ttnn_scheduler.step(noise_pred, t, ttnn_latents).prev_sample - if not interactive: - _save_image_and_latents(ttnn_latents, iter, vae, pre_fix=f"{experiment_name}_tt", pre_fix2="") + _save_image_and_latents(ttnn_latents, iter, vae, pre_fix=f"{experiment_name}_tt", pre_fix2="") iter += 1 enable_persistent_kernel_cache() @@ -401,15 +389,15 @@ def run_demo_inference_diffusiondb( ttnn_output_path = f"{experiment_name}_ttnn.png" pil_images.save(ttnn_output_path) + ref_paths = [ref_img_path, ref_img_path] ttnn_paths = [ttnn_output_path, ttnn_output_path] + + ref_images = preprocess_images(ref_paths) ttnn_images = preprocess_images(ttnn_paths) - if not interactive: - ref_paths = [ref_img_path, ref_img_path] - ref_images = preprocess_images(ref_paths) - # Calculate FID scores - fid_score_ref_ttnn = calculate_fid_score(ref_images, ttnn_images) - logger.info(f"FID Score (Reference vs TTNN): {fid_score_ref_ttnn}") + # Calculate FID scores + fid_score_ref_ttnn = calculate_fid_score(ref_images, ttnn_images) + logger.info(f"FID Score (Reference vs TTNN): {fid_score_ref_ttnn}") # calculate Clip score clip_score = CLIPScore(model_name_or_path="openai/clip-vit-base-patch16") @@ -420,13 +408,14 @@ def run_demo_inference_diffusiondb( @skip_for_grayskull() +@pytest.mark.parametrize("device_l1_small_size", [32768], indirect=True) @pytest.mark.parametrize( "num_prompts", ((1),), ) @pytest.mark.parametrize( "num_inference_steps", - ((2),), + ((4),), ) @pytest.mark.parametrize( "image_size", @@ -444,7 +433,7 @@ def test_demo(device, reset_seeds, input_path, num_prompts, num_inference_steps, ) @pytest.mark.parametrize( "num_inference_steps", - ((30),), + ((4),), ) @pytest.mark.parametrize( "image_size", diff --git a/models/experimental/functional_stable_diffusion/demo/input_data.json b/models/demos/wormhole/stable_diffusion/demo/input_data.json similarity index 100% rename from models/experimental/functional_stable_diffusion/demo/input_data.json rename to models/demos/wormhole/stable_diffusion/demo/input_data.json diff --git a/models/experimental/functional_stable_diffusion/sd_helper_funcs.py b/models/demos/wormhole/stable_diffusion/sd_helper_funcs.py similarity index 100% rename from models/experimental/functional_stable_diffusion/sd_helper_funcs.py rename to models/demos/wormhole/stable_diffusion/sd_helper_funcs.py diff --git a/models/experimental/functional_stable_diffusion/sd_pndm_scheduler.py b/models/demos/wormhole/stable_diffusion/sd_pndm_scheduler.py similarity index 100% rename from models/experimental/functional_stable_diffusion/sd_pndm_scheduler.py rename to models/demos/wormhole/stable_diffusion/sd_pndm_scheduler.py diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_basic_transformer_block.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_basic_transformer_block.py similarity index 94% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_basic_transformer_block.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_basic_transformer_block.py index e7d612dfdb4..027df72fbf3 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_basic_transformer_block.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_basic_transformer_block.py @@ -3,8 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 import ttnn -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_cross_attention import cross_attention -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_feedforward import feedforward +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_cross_attention import cross_attention +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_feedforward import feedforward def basic_transformer_block( diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_cross_attention.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_cross_attention.py similarity index 100% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_cross_attention.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_cross_attention.py diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_cross_attention_down_block_2d.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_cross_attention_down_block_2d.py similarity index 90% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_cross_attention_down_block_2d.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_cross_attention_down_block_2d.py index 7b3d6cee0e4..f4ab72a3130 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_cross_attention_down_block_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_cross_attention_down_block_2d.py @@ -3,9 +3,9 @@ # SPDX-License-Identifier: Apache-2.0 import ttnn -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_transformer_2d import transformer_2d_model -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_downsample_2d import downsample_2d +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_transformer_2d import transformer_2d_model +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_downsample_2d import downsample_2d def cross_attention_down_block_2d( diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_cross_attn_upblock.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_cross_attn_upblock.py similarity index 92% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_cross_attn_upblock.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_cross_attn_upblock.py index 7334014f772..1bacb05a2f9 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_cross_attn_upblock.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_cross_attn_upblock.py @@ -5,9 +5,9 @@ import torch import ttnn from typing import Optional, Dict -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_upsample_2d import upsample2d -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_transformer_2d import transformer_2d_model +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_upsample_2d import upsample2d +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_transformer_2d import transformer_2d_model def torch_to_ttnn(input, device, layout=ttnn.TILE_LAYOUT): diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_downblock_2d.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_downblock_2d.py similarity index 91% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_downblock_2d.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_downblock_2d.py index 49d76f5002b..626a25efd68 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_downblock_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_downblock_2d.py @@ -5,8 +5,8 @@ import ttnn import torch from typing import Optional -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_downsample_2d import downsample_2d +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_downsample_2d import downsample_2d def downblock2d( diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_downsample_2d.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_downsample_2d.py similarity index 98% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_downsample_2d.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_downsample_2d.py index cb3c1037bf1..79f75783ba3 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_downsample_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_downsample_2d.py @@ -9,7 +9,7 @@ import torch.nn as nn from tt_lib.fallback_ops import fallback_ops from models.utility_functions import torch_to_tt_tensor_rm, tt_to_torch_tensor -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_utility_functions import ( run_ttnn_conv_with_pre_and_post_tensor_formatting, ) import math diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_embeddings.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_embeddings.py similarity index 100% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_embeddings.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_embeddings.py diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_feedforward.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_feedforward.py similarity index 80% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_feedforward.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_feedforward.py index b98c8ee19ce..dd7f492d470 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_feedforward.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_feedforward.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import ttnn -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_geglu import geglu +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_geglu import geglu def feedforward(config, hidden_states, parameters, device=None): diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_geglu.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_geglu.py similarity index 100% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_geglu.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_geglu.py diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_resnetblock2d.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_resnetblock2d.py similarity index 99% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_resnetblock2d.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_resnetblock2d.py index 1cd667ab5e4..3bc86323f03 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_resnetblock2d.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_resnetblock2d.py @@ -6,7 +6,7 @@ import torch from typing import Optional, Dict -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_utility_functions import ( run_ttnn_conv_with_pre_and_post_tensor_formatting, pre_process_input, post_process_output, diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_transformer_2d.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_transformer_2d.py similarity index 98% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_transformer_2d.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_transformer_2d.py index b65b066dac6..a33ca84059c 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_transformer_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_transformer_2d.py @@ -8,10 +8,10 @@ from tt_lib.fallback_ops import fallback_ops from models.utility_functions import torch_to_tt_tensor_rm, tt_to_torch_tensor -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_basic_transformer_block import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_basic_transformer_block import ( basic_transformer_block, ) -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_utility_functions import ( run_ttnn_conv_with_pre_and_post_tensor_formatting, post_process_output, ) diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_unet_2d_condition_model.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_unet_2d_condition_model.py similarity index 96% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_unet_2d_condition_model.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_unet_2d_condition_model.py index ecbe8786d05..375b20f474f 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_unet_2d_condition_model.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_unet_2d_condition_model.py @@ -16,19 +16,19 @@ from tt_lib.fallback_ops import fallback_ops from models.utility_functions import is_grayskull -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_embeddings import TtTimestepEmbedding -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_unet_mid_block_2d_cross_attn import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_embeddings import TtTimestepEmbedding +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_unet_mid_block_2d_cross_attn import ( unet_mid_block_2d_cross_attn, ) -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_cross_attention_down_block_2d import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_cross_attention_down_block_2d import ( cross_attention_down_block_2d, ) -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_cross_attn_upblock import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_cross_attn_upblock import ( cross_attention_upblock2d, ) -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_downblock_2d import downblock2d -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_upblock_2d import upblock_2d -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_downblock_2d import downblock2d +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_upblock_2d import upblock_2d +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_utility_functions import ( run_ttnn_conv_with_pre_and_post_tensor_formatting, ) diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_unet_mid_block_2d_cross_attn.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_unet_mid_block_2d_cross_attn.py similarity index 93% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_unet_mid_block_2d_cross_attn.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_unet_mid_block_2d_cross_attn.py index 671e7f36815..fc762f5adbb 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_unet_mid_block_2d_cross_attn.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_unet_mid_block_2d_cross_attn.py @@ -2,8 +2,8 @@ # SPDX-License-Identifier: Apache-2.0 -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_transformer_2d import transformer_2d_model +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_transformer_2d import transformer_2d_model def unet_mid_block_2d_cross_attn( diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_upblock_2d.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_upblock_2d.py similarity index 91% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_upblock_2d.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_upblock_2d.py index ba0ec8e8a98..b32f7184e46 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_upblock_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_upblock_2d.py @@ -5,8 +5,8 @@ import torch import ttnn -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_upsample_2d import upsample2d +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_upsample_2d import upsample2d def upblock_2d( diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_upsample_2d.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_upsample_2d.py similarity index 94% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_upsample_2d.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_upsample_2d.py index 4b3cab44569..20e4a16d3fa 100644 --- a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_upsample_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_upsample_2d.py @@ -10,9 +10,9 @@ tt_to_torch_tensor, ) -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_upsample_nearest_2d import upsample_nearest2d +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_upsample_nearest_2d import upsample_nearest2d from tt_lib.fallback_ops import fallback_ops -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_utility_functions import ( run_ttnn_conv_with_pre_and_post_tensor_formatting, ) diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_upsample_nearest_2d.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_upsample_nearest_2d.py similarity index 100% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_upsample_nearest_2d.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_upsample_nearest_2d.py diff --git a/models/experimental/functional_stable_diffusion/tt/ttnn_functional_utility_functions.py b/models/demos/wormhole/stable_diffusion/tt/ttnn_functional_utility_functions.py similarity index 100% rename from models/experimental/functional_stable_diffusion/tt/ttnn_functional_utility_functions.py rename to models/demos/wormhole/stable_diffusion/tt/ttnn_functional_utility_functions.py diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_basic_transformer_block.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_basic_transformer_block.py similarity index 97% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_basic_transformer_block.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_basic_transformer_block.py index ccb00791766..7182dabff5c 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_basic_transformer_block.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_basic_transformer_block.py @@ -4,8 +4,8 @@ import ttnn import tt_lib as ttl -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_cross_attention import cross_attention -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_feedforward import feedforward +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_cross_attention import cross_attention +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_feedforward import feedforward import torch diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_cross_attention.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_cross_attention.py similarity index 99% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_cross_attention.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_cross_attention.py index 6553ee81949..e5c5a2ca40f 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_cross_attention.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_cross_attention.py @@ -8,7 +8,7 @@ import os import tt_lib as ttl from ttnn.operations.core import squeeze, unsqueeze_to_4D -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( is_tile_dim_alligned, round_up_to_tile_dim, dealloc_input, diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_cross_attention_down_block_2d.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_cross_attention_down_block_2d.py similarity index 92% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_cross_attention_down_block_2d.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_cross_attention_down_block_2d.py index 7a5601c4449..cf38db7cdf5 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_cross_attention_down_block_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_cross_attention_down_block_2d.py @@ -3,9 +3,9 @@ # SPDX-License-Identifier: Apache-2.0 import ttnn -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_transformer_2d import transformer_2d_model -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_downsample_2d import downsample_2d +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_transformer_2d import transformer_2d_model +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_downsample_2d import downsample_2d class cross_attention_down_block_2d: diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_cross_attn_upblock.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_cross_attn_upblock.py similarity index 94% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_cross_attn_upblock.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_cross_attn_upblock.py index 9ed707664a5..47e3c9406a7 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_cross_attn_upblock.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_cross_attn_upblock.py @@ -5,10 +5,10 @@ import torch import ttnn from typing import Optional, Dict -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_upsample_2d import upsample2d -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_transformer_2d import transformer_2d_model -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import dealloc_input +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_upsample_2d import upsample2d +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_transformer_2d import transformer_2d_model +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import dealloc_input def torch_to_ttnn(input, device, layout=ttnn.TILE_LAYOUT): diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_downblock_2d.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_downblock_2d.py similarity index 93% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_downblock_2d.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_downblock_2d.py index 180f9c1171c..57077af2da9 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_downblock_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_downblock_2d.py @@ -5,8 +5,8 @@ import ttnn import torch from typing import Optional -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_downsample_2d import downsample_2d +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_downsample_2d import downsample_2d class downblock2d: diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_downsample_2d.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_downsample_2d.py similarity index 97% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_downsample_2d.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_downsample_2d.py index ebfbd2e424c..cc7fbccc6b0 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_downsample_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_downsample_2d.py @@ -9,7 +9,7 @@ import torch.nn as nn from tt_lib.fallback_ops import fallback_ops from models.utility_functions import torch_to_tt_tensor_rm, tt_to_torch_tensor -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( run_ttnn_conv_with_pre_and_post_tensor_formatting, ) import math diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_embeddings.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_embeddings.py similarity index 100% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_embeddings.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_embeddings.py diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_feedforward.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_feedforward.py similarity index 95% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_feedforward.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_feedforward.py index f9c3fda3174..0d3ae6d714f 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_feedforward.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_feedforward.py @@ -3,8 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 import ttnn -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_geglu import geglu -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_geglu import geglu +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( determine_largest_subblock_size, ) import tt_lib as ttl diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_geglu.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_geglu.py similarity index 98% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_geglu.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_geglu.py index b95bde681d2..6995053123f 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_geglu.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_geglu.py @@ -6,7 +6,7 @@ import torch import math import tt_lib as ttl -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( determine_largest_subblock_size, determine_blocking, ) diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_resnetblock2d.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_resnetblock2d.py similarity index 99% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_resnetblock2d.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_resnetblock2d.py index e06371061f2..f83114d256b 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_resnetblock2d.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_resnetblock2d.py @@ -12,7 +12,7 @@ import os import torch from typing import Optional, Dict -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, post_process_output, permute_conv_parameters, diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_resnetblock2d_new_conv.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_resnetblock2d_new_conv.py similarity index 99% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_resnetblock2d_new_conv.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_resnetblock2d_new_conv.py index 198a69e0bc2..730711fb166 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_resnetblock2d_new_conv.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_resnetblock2d_new_conv.py @@ -12,14 +12,14 @@ import os import torch from typing import Optional, Dict -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, post_process_output, permute_conv_parameters, weight_to_bfp8, ) import time -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import conv_cache +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import conv_cache def torch_to_ttnn(input, device, layout=ttnn.TILE_LAYOUT): diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_transformer_2d.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_transformer_2d.py similarity index 98% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_transformer_2d.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_transformer_2d.py index c2de409cd34..704063da273 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_transformer_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_transformer_2d.py @@ -9,10 +9,10 @@ import os from tt_lib.fallback_ops import fallback_ops from models.utility_functions import torch_to_tt_tensor_rm, tt_to_torch_tensor -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_basic_transformer_block import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_basic_transformer_block import ( basic_transformer_block, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, pad_group_norm_weight, permute_conv_parameters, diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_unet_2d_condition_model.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_unet_2d_condition_model.py similarity index 97% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_unet_2d_condition_model.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_unet_2d_condition_model.py index fef608fa980..3e92c26dc5b 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_unet_2d_condition_model.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_unet_2d_condition_model.py @@ -18,19 +18,19 @@ from tt_lib.fallback_ops import fallback_ops from models.utility_functions import is_grayskull -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_embeddings import TtTimestepEmbedding -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_unet_mid_block_2d_cross_attn import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_embeddings import TtTimestepEmbedding +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_unet_mid_block_2d_cross_attn import ( unet_mid_block_2d_cross_attn, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_cross_attention_down_block_2d import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_cross_attention_down_block_2d import ( cross_attention_down_block_2d, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_cross_attn_upblock import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_cross_attn_upblock import ( cross_attention_upblock2d, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_downblock_2d import downblock2d -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_upblock_2d import upblock_2d -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_downblock_2d import downblock2d +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_upblock_2d import upblock_2d +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pad_group_norm_weight, pre_process_input, ) diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_unet_mid_block_2d_cross_attn.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_unet_mid_block_2d_cross_attn.py similarity index 94% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_unet_mid_block_2d_cross_attn.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_unet_mid_block_2d_cross_attn.py index 5c768ef2b1d..4ffa5038e10 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_unet_mid_block_2d_cross_attn.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_unet_mid_block_2d_cross_attn.py @@ -2,8 +2,8 @@ # SPDX-License-Identifier: Apache-2.0 -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_transformer_2d import transformer_2d_model +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_transformer_2d import transformer_2d_model class unet_mid_block_2d_cross_attn: diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_upblock_2d.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_upblock_2d.py similarity index 95% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_upblock_2d.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_upblock_2d.py index 5c4a168beec..e549828a35e 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_upblock_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_upblock_2d.py @@ -5,8 +5,8 @@ import torch import ttnn -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_upsample_2d import upsample2d +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_upsample_2d import upsample2d class upblock_2d: diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_upsample_2d.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_upsample_2d.py similarity index 92% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_upsample_2d.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_upsample_2d.py index f1dcb473c82..3f0ee9ed738 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_upsample_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_upsample_2d.py @@ -10,12 +10,12 @@ tt_to_torch_tensor, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_upsample_nearest_2d import upsample_nearest2d +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_upsample_nearest_2d import upsample_nearest2d from tt_lib.fallback_ops import fallback_ops -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( run_ttnn_conv_with_pre_and_post_tensor_formatting, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( permute_conv_parameters, ) diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_upsample_nearest_2d.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_upsample_nearest_2d.py similarity index 96% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_upsample_nearest_2d.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_upsample_nearest_2d.py index 11fb8c23ca4..b73f0b97722 100644 --- a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_upsample_nearest_2d.py +++ b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_upsample_nearest_2d.py @@ -7,7 +7,7 @@ import math -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import reshard_to +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import reshard_to class upsample_nearest2d: diff --git a/models/experimental/functional_stable_diffusion/tt2/ttnn_functional_utility_functions.py b/models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_utility_functions.py similarity index 100% rename from models/experimental/functional_stable_diffusion/tt2/ttnn_functional_utility_functions.py rename to models/demos/wormhole/stable_diffusion/tt2/ttnn_functional_utility_functions.py diff --git a/models/experimental/functional_stable_diffusion/tt2_multiple_iteration.py b/models/demos/wormhole/stable_diffusion/tt2_multiple_iteration.py similarity index 97% rename from models/experimental/functional_stable_diffusion/tt2_multiple_iteration.py rename to models/demos/wormhole/stable_diffusion/tt2_multiple_iteration.py index 8482e83e5e1..f4eb958e7a5 100644 --- a/models/experimental/functional_stable_diffusion/tt2_multiple_iteration.py +++ b/models/demos/wormhole/stable_diffusion/tt2_multiple_iteration.py @@ -25,8 +25,8 @@ ) from models.utility_functions import skip_for_wormhole_b0 from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_unet_2d_condition_model import ( +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_unet_2d_condition_model import ( UNet2DConditionModel as UNet2D, ) diff --git a/models/experimental/functional_stable_diffusion/README.md b/models/experimental/functional_stable_diffusion/README.md deleted file mode 100644 index ce76dccf772..00000000000 --- a/models/experimental/functional_stable_diffusion/README.md +++ /dev/null @@ -1,28 +0,0 @@ -## functional_stable_diffusion Demo -## How to Run - -To run the demo, make sure to build the project, activate the environment, and set the appropriate environment variables. -For more information, refer [installation and build guide](https://tenstorrent.github.io/tt-metal/latest/get_started/get_started.html#install-and-build). - -Use `pytest --disable-warnings --input-path="models/experimental/functional_stable_diffusion/demo/input_data.json" models/experimental/functional_stable_diffusion/demo/demo.py::test_demo` to run the demo. - -If you wish to run the demo with a different input use `pytest --disable-warnings --input-path="" models/experimental/functional_stable_diffusion/demo/demo.py::test_demo` - -Our second demo is designed to run poloclub/diffusiondb dataset, run this with `pytest --disable-warnings models/experimental/functional_stable_diffusion/demo/demo.py::test_demo_diffusiondb`. - -If you wish to run for `num_prompts` samples and `num_inference_steps` denoising steps, use `pytest --disable-warnings models/experimental/functional_stable_diffusion/demo/demo.py::test_demo_diffusiondb[-]` - -# Inputs -Inputs by default are provided from `input_data.json`. If you wish you to change the inputs, provide a different path to test_demo. - -We do not recommend modifying `input_data.json` file. - -# Details -The entry point to functional_stable_diffusion model is UNet2DConditionModel in `models/experimental/functional_stable_diffusion/tt/ttnn_functional_unet_2d_condition_model.py`. The model picks up certain configs and weights from huggingface pretrained model. We have used `CompVis/stable-diffusion-v1-4` version from huggingface as our reference. - -# Metrics Interpretation -`FID Score (Fréchet Inception Distance)` evaluates the quality of generated images by measuring the similarity between their feature distributions and those of real images. A lower FID score indicates better similarity between generated and real images. -For more information, refer [FID Score](https://lightning.ai/docs/torchmetrics/stable/image/frechet_inception_distance.html). - -`CLIP Score` measures the similarity between the generated images and the input prompts. Higher CLIP scores indicate better alignment between the generated images and the provided text prompts. -For more information, refer [CLIP Score](https://lightning.ai/docs/torchmetrics/stable/multimodal/clip_score.html). diff --git a/models/experimental/functional_stable_diffusion/tests/test_perf_stable_diffusion.py b/tests/device_perf_tests/stable_diffusion/test_perf_stable_diffusion.py similarity index 82% rename from models/experimental/functional_stable_diffusion/tests/test_perf_stable_diffusion.py rename to tests/device_perf_tests/stable_diffusion/test_perf_stable_diffusion.py index 179908c72d8..52470af49fc 100644 --- a/models/experimental/functional_stable_diffusion/tests/test_perf_stable_diffusion.py +++ b/tests/device_perf_tests/stable_diffusion/test_perf_stable_diffusion.py @@ -30,9 +30,10 @@ ) from ttnn.model_preprocessing import preprocess_model_parameters from ttnn.operations.core import unsqueeze_to_4D -from models.experimental.functional_stable_diffusion.sd_helper_funcs import TtLMSDiscreteScheduler -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_unet_2d_condition_model import ( +from models.demos.wormhole.stable_diffusion.sd_pndm_scheduler import TtPNDMScheduler +from models.demos.wormhole.stable_diffusion.sd_helper_funcs import TtLMSDiscreteScheduler +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_unet_2d_condition_model import ( UNet2DConditionModel as UNet2D, ) @@ -52,9 +53,9 @@ def ttnn_to_torch(input): return input -def constant_prop_time_embeddings(timesteps, batch_size, time_proj): +def constant_prop_time_embeddings(timesteps, sample, time_proj): timesteps = timesteps[None] - timesteps = timesteps.expand(batch_size) + timesteps = timesteps.expand(sample.shape[0]) t_emb = time_proj(timesteps) return t_emb @@ -78,13 +79,16 @@ def unsqueeze_all_params_to_4d(params): @pytest.mark.parametrize( "batch_size, num_inference_steps, expected_compile_time, expected_inference_time", [ - (2, 2, 3600, 0.28), # Issue 7816 Inference time + (2, 4, 3600, 0.28), # Issue 7816 Inference time ], ) def test_stable_diffusion_perf(device, batch_size, num_inference_steps, expected_compile_time, expected_inference_time): device.enable_program_cache() # disable_persistent_kernel_cache() + assert ( + num_inference_steps >= 4 + ), f"PNDMScheduler only supports num_inference_steps >= 4. Found num_inference_steps={num_inference_steps}" # Clear global profiler state before starting measurements profiler.clear() @@ -111,13 +115,10 @@ def test_stable_diffusion_perf(device, batch_size, num_inference_steps, expected config = model.config # setup scheduler - scheduler = LMSDiscreteScheduler( - beta_start=0.00085, - beta_end=0.012, - beta_schedule="scaled_linear", - num_train_timesteps=1000, + ttnn_scheduler = TtPNDMScheduler( + beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000, device=device ) - scheduler.set_timesteps(1) + ttnn_scheduler.set_timesteps(4) parameters = preprocess_model_parameters( model_name=model_name, initialize_model=lambda: model, custom_preprocessor=custom_preprocessor, device=device @@ -135,21 +136,24 @@ def test_stable_diffusion_perf(device, batch_size, num_inference_steps, expected hidden_states_shape = [batch_size, in_channels, input_height, input_width] - input = torch.randn(hidden_states_shape) - timestep = [i for i in tqdm(scheduler.timesteps)][0] - ttnn_timestep = constant_prop_time_embeddings(timestep, batch_size, model.time_proj) - ttnn_timestep = ttnn_timestep.unsqueeze(0).unsqueeze(0) + input_pt = torch.randn(hidden_states_shape) + encoder_hidden_states = torch.randn(encoder_hidden_states_shape) - torch_output = model(input, timestep=timestep, encoder_hidden_states=encoder_hidden_states.squeeze(0)).sample - input = ttnn.from_torch(input, ttnn.bfloat16) + input = ttnn.from_torch(input_pt, ttnn.bfloat16) input = ttnn.to_device(input, device, memory_config=ttnn.L1_MEMORY_CONFIG) input = ttnn.to_layout(input, ttnn.TILE_LAYOUT, dtype=ttnn.bfloat16) - ttnn_timestep = ttnn_timestep.permute(2, 0, 1, 3) # pre-permute temb - ttnn_timestep = ttnn.from_torch(ttnn_timestep, ttnn.bfloat16) - ttnn_timestep = ttnn.to_device(ttnn_timestep, device, memory_config=ttnn.L1_MEMORY_CONFIG) - ttnn_timestep = ttnn.to_layout(ttnn_timestep, ttnn.TILE_LAYOUT, dtype=ttnn.bfloat8_b) + _tlist = [] + for t in ttnn_scheduler.timesteps: + _t = constant_prop_time_embeddings(t, input, model.time_proj) + _t = _t.unsqueeze(0).unsqueeze(0) + _t = _t.permute(2, 0, 1, 3) # pre-permute temb + _t = ttnn.from_torch(_t, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device) + _tlist.append(_t) + + time_step = ttnn_scheduler.timesteps.tolist() + torch_output = model(input_pt, timestep=time_step[0], encoder_hidden_states=encoder_hidden_states.squeeze(0)).sample encoder_hidden_states = torch.nn.functional.pad(encoder_hidden_states, (0, 0, 0, 19)) encoder_hidden_states = ttnn.from_torch( @@ -166,7 +170,7 @@ def test_stable_diffusion_perf(device, batch_size, num_inference_steps, expected profiler.start(f"model_run_for_inference_{i}") ttnn_output = model( input, - timestep=ttnn_timestep, + timestep=_tlist[i], encoder_hidden_states=encoder_hidden_states, class_labels=class_labels, attention_mask=attention_mask, diff --git a/tests/scripts/run_performance.sh b/tests/scripts/run_performance.sh index 084654efd35..23cc2d0d0ba 100755 --- a/tests/scripts/run_performance.sh +++ b/tests/scripts/run_performance.sh @@ -48,7 +48,7 @@ run_perf_models_cnn_javelin() { local test_marker=$2 # Run tests - env WH_ARCH_YAML=wormhole_b0_80_arch_eth_dispatch.yaml pytest models/experimental/functional_stable_diffusion/tests -m $test_marker + env WH_ARCH_YAML=wormhole_b0_80_arch_eth_dispatch.yaml pytest tests/device_perf_tests/stable_diffusion -m $test_marker #env WH_ARCH_YAML=wormhole_b0_80_arch_eth_dispatch.yaml pytest models/experimental/functional_unet/tests -m $test_marker ## Merge all the generated reports @@ -58,7 +58,7 @@ run_perf_models_cnn_javelin() { run_device_perf_models() { local test_marker=$1 - env pytest models/experimental/functional_stable_diffusion/tests -m $test_marker + env pytest tests/device_perf_tests/stable_diffusion -m $test_marker if [ "$tt_arch" == "grayskull" ]; then #TODO(MO): Until #6560 is fixed, GS device profiler test are grouped with diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_basic_transformer_block.py b/tests/ttnn/integration_tests/stable_diffusion/test_basic_transformer_block.py index 29573812dc3..b9469cdd5aa 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_basic_transformer_block.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_basic_transformer_block.py @@ -8,16 +8,16 @@ from diffusers import StableDiffusionPipeline import ttnn import tt_lib as ttl -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_basic_transformer_block import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_basic_transformer_block import ( basic_transformer_block as ttnn_basic_transformer_block, ) -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_basic_transformer_block import ( +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_basic_transformer_block import ( basic_transformer_block as tt2_ttnn_basic_transformer_block, ) from ttnn.model_preprocessing import preprocess_model_parameters from tests.ttnn.utils_for_testing import assert_with_pcc -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, post_process_output, ) diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_cross_attention.py b/tests/ttnn/integration_tests/stable_diffusion/test_cross_attention.py index d5265ddc05d..1e4d7feee97 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_cross_attention.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_cross_attention.py @@ -7,11 +7,11 @@ from diffusers import StableDiffusionPipeline import ttnn -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_cross_attention import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_cross_attention import ( cross_attention as ttnn_cross_attention, ) -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_cross_attention import ( +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_cross_attention import ( cross_attention as tt2_ttnn_cross_attention, ) from ttnn.model_preprocessing import preprocess_model_parameters diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_cross_attn_up_block_2d.py b/tests/ttnn/integration_tests/stable_diffusion/test_cross_attn_up_block_2d.py index 2a43937a933..ea5f7740465 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_cross_attn_up_block_2d.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_cross_attn_up_block_2d.py @@ -11,20 +11,20 @@ from models.utility_functions import tt_to_torch_tensor, torch_random from tests.ttnn.utils_for_testing import assert_with_pcc -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_cross_attn_upblock import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_cross_attn_upblock import ( cross_attention_upblock2d as ttnn_cross_attention_upblock2d, ) from models.utility_functions import ( skip_for_grayskull, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_cross_attn_upblock import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_cross_attn_upblock import ( cross_attention_upblock2d as tt2_ttnn_cross_attention_upblock2d, ) -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, weight_to_bfp8, post_process_output, diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_demo.py b/tests/ttnn/integration_tests/stable_diffusion/test_demo.py new file mode 100644 index 00000000000..4bd7a971ba2 --- /dev/null +++ b/tests/ttnn/integration_tests/stable_diffusion/test_demo.py @@ -0,0 +1,49 @@ +# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. + +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from models.utility_functions import skip_for_grayskull +from models.demos.wormhole.stable_diffusion.demo.demo import test_demo as demo +from models.demos.wormhole.stable_diffusion.demo.demo import test_demo_diffusiondb as demo_db + + +@skip_for_grayskull() +@pytest.mark.parametrize("device_l1_small_size", [32768], indirect=True) +@pytest.mark.parametrize( + "input_path", + (("models/demos/wormhole/stable_diffusion/demo/input_data.json"),), + ids=["default_input"], +) +@pytest.mark.parametrize( + "num_prompts", + ((1),), +) +@pytest.mark.parametrize( + "num_inference_steps", + ((5),), +) +@pytest.mark.parametrize( + "image_size", + ((512, 512),), +) +def test_demo_sd(device, reset_seeds, input_path, num_prompts, num_inference_steps, image_size): + demo(device, reset_seeds, input_path, num_prompts, num_inference_steps, image_size) + + +@skip_for_grayskull() +@pytest.mark.parametrize("device_l1_small_size", [32768], indirect=True) +@pytest.mark.parametrize( + "num_prompts", + ((1),), +) +@pytest.mark.parametrize( + "num_inference_steps", + ((5),), +) +@pytest.mark.parametrize( + "image_size", + ((512, 512),), +) +def test_demo_sd_db(device, reset_seeds, input_path, num_prompts, num_inference_steps, image_size): + demo_db(device, reset_seeds, input_path, num_prompts, num_inference_steps, image_size) diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_down_block_2d.py b/tests/ttnn/integration_tests/stable_diffusion/test_down_block_2d.py index c79b3e44c21..f258bc72e4c 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_down_block_2d.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_down_block_2d.py @@ -12,14 +12,14 @@ from models.utility_functions import ( skip_for_grayskull, ) -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_downblock_2d import ( +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_downblock_2d import ( downblock2d as ttnn_downblock2d, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_downblock_2d import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_downblock_2d import ( downblock2d as tt2_ttnn_downblock2d, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, post_process_output, ) diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_downsample_2d.py b/tests/ttnn/integration_tests/stable_diffusion/test_downsample_2d.py index ccdccfd4b96..56c26a13c43 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_downsample_2d.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_downsample_2d.py @@ -11,17 +11,17 @@ from tests.ttnn.utils_for_testing import assert_with_pcc from ttnn.model_preprocessing import preprocess_model_parameters from models.utility_functions import torch_random -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_downsample_2d import ( +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_downsample_2d import ( downsample_2d as ttnn_downsample_2d, ) from models.utility_functions import ( skip_for_grayskull, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_downsample_2d import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_downsample_2d import ( downsample_2d as tt2_ttnn_downsample_2d, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, post_process_output, ) diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_embedding.py b/tests/ttnn/integration_tests/stable_diffusion/test_embedding.py index 5a5b10df859..05020ebc3ea 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_embedding.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_embedding.py @@ -13,7 +13,7 @@ import ttnn from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_embeddings import TtTimestepEmbedding +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_embeddings import TtTimestepEmbedding import pytest diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_feedforward.py b/tests/ttnn/integration_tests/stable_diffusion/test_feedforward.py index b54f44f53ee..94019851040 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_feedforward.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_feedforward.py @@ -9,11 +9,11 @@ import ttnn from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_feedforward import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_feedforward import ( feedforward as ttnn_feedforward, ) -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_feedforward import ( +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_feedforward import ( feedforward as tt2_ttnn_feedforward, ) from models.utility_functions import torch_random diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_geglu.py b/tests/ttnn/integration_tests/stable_diffusion/test_geglu.py index ee5e354fa4a..b083e4faf64 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_geglu.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_geglu.py @@ -9,10 +9,10 @@ import ttnn from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_geglu import geglu as ttnn_geglu -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_geglu import geglu as tt2_ttnn_geglu +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_geglu import geglu as ttnn_geglu +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_geglu import geglu as tt2_ttnn_geglu from models.utility_functions import torch_random, skip_for_grayskull from tests.ttnn.utils_for_testing import assert_with_pcc diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_resnet_block_2d.py b/tests/ttnn/integration_tests/stable_diffusion/test_resnet_block_2d.py index 0a2d9440543..d25a958b204 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_resnet_block_2d.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_resnet_block_2d.py @@ -13,8 +13,8 @@ import ttnn from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_resnetblock2d import resnetBlock2D +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor def ttnn_to_torch(input): diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_resnet_block_2d_new_conv.py b/tests/ttnn/integration_tests/stable_diffusion/test_resnet_block_2d_new_conv.py index 93f48dc91f1..b86aba9a9a4 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_resnet_block_2d_new_conv.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_resnet_block_2d_new_conv.py @@ -13,9 +13,9 @@ import ttnn from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_resnetblock2d_new_conv import resnetBlock2D -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import conv_cache +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_resnetblock2d_new_conv import resnetBlock2D +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import conv_cache def ttnn_to_torch(input): diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_sharded_attention.py b/tests/ttnn/integration_tests/stable_diffusion/test_sharded_attention.py index 3b201afbc00..4704da79ff5 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_sharded_attention.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_sharded_attention.py @@ -16,7 +16,7 @@ skip_for_wormhole_b0, skip_for_grayskull, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( determine_largest_subblock_size, determine_blocking, ) diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_sharded_matmuls.py b/tests/ttnn/integration_tests/stable_diffusion/test_sharded_matmuls.py index 292356bddc7..dc0388c7bcf 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_sharded_matmuls.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_sharded_matmuls.py @@ -12,7 +12,7 @@ from models.utility_functions import ( skip_for_grayskull, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( determine_largest_subblock_size, round_up_to_tile_dim, ) diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_transformer_2d_model.py b/tests/ttnn/integration_tests/stable_diffusion/test_transformer_2d_model.py index 7a77ca41c49..78a41510ba6 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_transformer_2d_model.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_transformer_2d_model.py @@ -12,12 +12,12 @@ skip_for_grayskull, ) from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_transformer_2d import transformer_2d_model -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_transformer_2d import ( +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_transformer_2d import transformer_2d_model +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_transformer_2d import ( transformer_2d_model as transformer_2d_model_tt2, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, post_process_output, ) diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_ttnn_cross_attention_down_block_2d.py b/tests/ttnn/integration_tests/stable_diffusion/test_ttnn_cross_attention_down_block_2d.py index 94cd58d42bc..df210a8158e 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_ttnn_cross_attention_down_block_2d.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_ttnn_cross_attention_down_block_2d.py @@ -8,7 +8,7 @@ from diffusers import StableDiffusionPipeline import ttnn -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_cross_attention_down_block_2d import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_cross_attention_down_block_2d import ( cross_attention_down_block_2d, ) from ttnn.model_preprocessing import preprocess_model_parameters @@ -16,8 +16,8 @@ from models.utility_functions import ( skip_for_grayskull, ) -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( run_ttnn_conv_with_pre_and_post_tensor_formatting, pre_process_input, post_process_output, diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_unet_2d_condition_model.py b/tests/ttnn/integration_tests/stable_diffusion/test_unet_2d_condition_model.py index 7ee56321f9d..1857f9b6012 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_unet_2d_condition_model.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_unet_2d_condition_model.py @@ -19,15 +19,15 @@ from diffusers import LMSDiscreteScheduler import ttnn from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_unet_2d_condition_model import ( +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_unet_2d_condition_model import ( UNet2DConditionModel, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_unet_2d_condition_model import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_unet_2d_condition_model import ( UNet2DConditionModel as UNet2D, ) import math -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( post_process_output, ) from ttnn.operations.core import unsqueeze_to_4D diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_unet_mid_block_2d_cross_attn.py b/tests/ttnn/integration_tests/stable_diffusion/test_unet_mid_block_2d_cross_attn.py index 7fe3b66aa28..751ab3dbc54 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_unet_mid_block_2d_cross_attn.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_unet_mid_block_2d_cross_attn.py @@ -13,14 +13,14 @@ skip_for_grayskull, ) from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_unet_mid_block_2d_cross_attn import ( +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_unet_mid_block_2d_cross_attn import ( unet_mid_block_2d_cross_attn as ttnn_unet_mid_block_2d_cross_attn, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_unet_mid_block_2d_cross_attn import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_unet_mid_block_2d_cross_attn import ( unet_mid_block_2d_cross_attn as tt2_ttnn_unet_mid_block_2d_cross_attn, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, post_process_output, ) diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_upblock_2d.py b/tests/ttnn/integration_tests/stable_diffusion/test_upblock_2d.py index af783893eb6..e7d2562f05e 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_upblock_2d.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_upblock_2d.py @@ -13,13 +13,13 @@ from models.utility_functions import ( skip_for_grayskull, ) -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_upblock_2d import upblock_2d as ttnn_upblock_2d -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_upblock_2d import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_upblock_2d import upblock_2d as ttnn_upblock_2d +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_upblock_2d import ( upblock_2d as tt2_ttnn_upblock_2d, ) -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor from ttnn.model_preprocessing import preprocess_model_parameters -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, post_process_output, weight_to_bfp8, diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_upsample_2d.py b/tests/ttnn/integration_tests/stable_diffusion/test_upsample_2d.py index 80de7c705f2..acdeaf35a43 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_upsample_2d.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_upsample_2d.py @@ -7,11 +7,11 @@ import pytest import ttnn -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_upsample_2d import upsample2d as ttnn_upsample2d -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_upsample_2d import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_upsample_2d import upsample2d as ttnn_upsample2d +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_upsample_2d import ( upsample2d as tt2_ttnn_upsample2d, ) -from models.experimental.functional_stable_diffusion.custom_preprocessing import custom_preprocessor +from models.demos.wormhole.stable_diffusion.custom_preprocessing import custom_preprocessor from tests.ttnn.utils_for_testing import assert_with_pcc from models.utility_functions import ( skip_for_grayskull, @@ -19,7 +19,7 @@ from ttnn.model_preprocessing import preprocess_model_parameters from models.utility_functions import torch_random -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_utility_functions import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_utility_functions import ( pre_process_input, post_process_output, ) diff --git a/tests/ttnn/integration_tests/stable_diffusion/test_upsample_nearest_2d.py b/tests/ttnn/integration_tests/stable_diffusion/test_upsample_nearest_2d.py index 7cab257f797..c08aa35b345 100644 --- a/tests/ttnn/integration_tests/stable_diffusion/test_upsample_nearest_2d.py +++ b/tests/ttnn/integration_tests/stable_diffusion/test_upsample_nearest_2d.py @@ -6,10 +6,10 @@ import pytest import ttnn -from models.experimental.functional_stable_diffusion.tt.ttnn_functional_upsample_nearest_2d import ( +from models.demos.wormhole.stable_diffusion.tt.ttnn_functional_upsample_nearest_2d import ( upsample_nearest2d as ttnn_upsample_nearest2d, ) -from models.experimental.functional_stable_diffusion.tt2.ttnn_functional_upsample_nearest_2d import ( +from models.demos.wormhole.stable_diffusion.tt2.ttnn_functional_upsample_nearest_2d import ( upsample_nearest2d as tt2_ttnn_upsample_nearest2d, ) from tests.ttnn.utils_for_testing import assert_with_pcc