Artificial Intelligence (AI)
Discuss current events in AI and technological innovations with Intel® employees
691 Discussions

Try Out Text-to-Image GenAI with a Stable Diffusion Workshop on the Intel® Tiber™ Developer Cloud

Sonya_Wach
Employee
0 6 5,977

What is Intel Tiber Developer Cloud?

The Intel® Tiber™ Developer Cloud is a cloud-based platform that empowers developers, AI/ML researchers, ecosystem partners, AI startups, and enterprise customers by providing access to cutting-edge Intel hardware and software solutions so that AI and High-Performance Computing applications can be built, tested, run, and optimized at a low cost and overhead. The Intel Tiber Developer Cloud provides developers an easy path to innovate with small or large workloads on Intel CPUs, GPUs, and the AI PC, including access to AI-optimized software such as oneAPI.

For developers and enterprise customers looking to test the capabilities of the platform and hardware and learn what Intel enables them to do, an option to use complimentary shared environments and Jupyter notebooks exists.

This post will walk you through a workshop that provides hands-on experience with the Stable Diffusion model to create images based on a text prompt. You will learn how to leverage PyTorch* with Intel® Gaudi® AI Accelerators to run inference with the stable-diffusion text-to-image generation model and understand how the Intel Tiber Developer Cloud can help you develop and deploy generative AI workloads.

Generative AI and Stable Diffusion

Generative AI (GenAI) is rapidly becoming ubiquitous across industries, transforming how content is created and providing new ways to solve problems and push the boundaries of creativity. Text-to-image generation is a popular GenAI application that creates images based on text prompts by interpreting the meaning and context of a user-provided description. The model is trained on large datasets of images paired with corresponding textual descriptions to learn associations between words and visual features.

Stable Diffusion is a popular deep learning GenAI model that generates images through text-to-image synthesis. With diffusion models, images are created by gradually refining random noise into a meaningful visual output. Stable Diffusion is open-source, efficient, and scalable, making it popular in various creative applications.

This training utilizes the Intel Gaudi AI Accelerator with PyTorch to run the Stable Diffusion model. For GPU support and better performance, you can also utilize the Intel® Extension for PyTorch, which optimizes deep learning training and inference performance on Intel processors for various applications, including large language models (LLMs) and Generative AI (GenAI).

Inference with Stable Diffusion Workshop

To get started with this workshop, head to cloud.intel.com and Sign Up with an email, or Sign In if you already have an account.

Once on the platform, use the Menu icon on the top left to navigate to the Training page.

console.cloud.intel.com_training (1).png

 

The Training page showcases several JupyterLab workshops you can try on the Intel Tiber Developer Cloud, including trainings in AI, AI with Intel Gaudi 2 Accelerators, C++ SYCL, Gen AI, and the Rendering Toolkit.

In this tutorial, we will navigate to the AI with Intel Gaudi 2 Accelerator training and examine the Inference with Stable Diffusion v2.1 workshop. Click Learn More or Launch to access the Jupyter notebook.

console.cloud.intel.com_training (2).png

 

Once your Jupyter notebook training has launched, ensure the Kernel in the top right is set to Python 3 (ipykernel). Run the cells and follow the steps in the notebook to see an example of inference using stable diffusion and generating an image from your prompt. Below is a further explanation of the steps outlined in the training notebook. Note: the cells outlined in this document are just for reference and are missing key lines needed to run effectively; consult the Jupyter notebook for the full code.

jupyter-batch-us-region-1.cloud.intel.com_user_u599fa6b2b3723ab67ca28bfb27d0915_lab.png

 

Step 1: Setting up the Environment

We will first clone the Habana Model-References repository branch to this docker and install all the Python package dependencies. We will also download the model checkpoint from Hugging Face.

%cd ~/Gaudi-tutorials/PyTorch/Single_card_tutorials
!git clone -b 1.15.1 https://github.com/habanaai/Model-References
%cd Model-References/PyTorch/generative_models/stable-diffusion-v-2-1
!pip install -q -r requirements.txt
!wget https://huggingface.co/stabilityai/stable-diffusion-2-1-base/resolve/main/
v2-1_512-ema-pruned.ckpt

After downloading all the requirements and models, we are now ready for the image generation

 

Step 2: Running the Inference

prompt = input("Enter a prompt for image generation: ")

 The line of code above creates a prompt field from which the model generates the image. You can input any text to create an image; for example, we will use the prompt “cat wearing a hat” in this tutorial.

After entering your text prompt, the following code with defined parameters will run to generate the image.

cmd = f'python3 scripts/txt2img.py --prompt "{prompt}" 1
--ckpt v2-1_512-ema-pruned.ckpt \
--config configs/stable-diffusion/v2-inference.yaml \
--H 512 --W 512 \
--n_samples 1 \
--n_iter 2 --steps 35 \
--k_sampler dpmpp_2m \
--use_hpu_graph'

print(cmd)
import os
os.system(cmd)

 

Step 3: Viewing the Results

Our image will be created using Stable Diffusion, and we can check the result. You can run the cells in the notebook, or you can use the File Browser on the left-hand panel to navigate to the output folder to view the generated image:

/Gaudi-tutorials/PyTorch/Single_card_tutorials/Model-References
/PyTorch/generative_models/stable-diffusion-v-2-1/outputs/txt2img-samples/

You can view your generated image once you locate the outputs folder and find your image, grid-0000.png. Here is the image generated from this tutorial’s prompt:

cathat.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

After running through the steps in the notebook, you will have successfully been exposed to the capabilities of GenAI and Stable Diffusion on Intel Gaudi AI Accelerators, including PyTorch, model inference, and prompt engineering.

Check out Intel Tiber Developer Cloud to access the latest silicon hardware and optimized software to help develop and power your next innovative AI projects! We encourage you to check out Intel’s AI Tools and Framework optimizations and learn about the unified, open, standards-based oneAPI programming model that forms the foundation of Intel’s AI Software Portfolio. Also, discover how our other collaborations with industry-leading independent software vendors (ISV), system integrators (SI), original equipment manufacturers (OEM), and enterprise users accelerate AI adoption.

Additional Resources
About the Author
AI/ML Technical Software Product Marketing Manager at Intel. MBA, Engineer, and previous two-time startup founder with a passion for all things AI and new tech.
6 Comments
debonairblackfish

Screenshot 2024-09-18 at 11.28.38 AM.png

 

Sonya_Wach
Employee

@debonairblackfish Please reach out to itdc_training_requests@intel.com to request access to the training if you are seeing this error. 

debonairblackfish

I made sure that the Kernel in the top right is set to Python 3 (ipykernel). I clicked "Run" in the menu bar, then clicked "Run All Cells" and nothing happened. Now, when I click "Run All Cells" I get the following error message: Screen Shot 2024-09-18 at 8.06.43 PM.png

Unfortunately, I don't know what to do next or what pending input I must submit.

Sonya_Wach
Employee

@debonairblackfish The pending input is likely cell #5 - the prompt for the image generation. You need to input your prompt for the notebook and model to continue to run and finish. You can input this prompt or try restarting the kernel and running the cells again.

debonairblackfish

Would it be possible for you to create a new workshop where we can use FLUX.1 schnell?

Sonya_Wach
Employee

@debonairblackfish We'll keep an eye on it! You can also create a new notebook on Intel Tiber Developer Cloud and try out the FLUX.1 [schnell] model on Hugging Face through the diffusers python library, but it may not work out-of-the-box.