Intel® Extension for TensorFlow* is compatible with stock TensorFlow*. This example shows Stable Diffusion Inference for Text2Image.
Install the Intel® Extension for TensorFlow* in legacy running environment, Tensorflow will execute the Inference on Intel GPU.
Verified Hardware Platforms:
- Intel® Data Center GPU Max Series
- Intel® Data Center GPU Flex Series 170
We optimized official keras-cv Stable Diffusion, for example, concatenate two forward passes, combine computation in loops to reduce op number, and add fp16 mode for model. However, this optimization hasn't been up streamed. To get better performance, instead of installing official keras-cv, you may want to clone keras-cv, apply patch, then install it as shown here:
git clone https://github.com/keras-team/keras-cv.git
cd keras-cv
git reset --hard 53d8aad680ce56bb37f7245dd5e2782f2ca37034
git apply patch
pip install .
Refer to Prepare
- Setup for GPU
./pip_set_env.sh
Enable oneAPI running environment (only for GPU) and virtual running environment.
- For GPU, refer to Running
python stable_diffusion_inference.py --precision fp32
python stable_diffusion_inference.py --precision fp16
Note: At present, we evaluate accuracy by calculating the Fréchet inception distance (FID) between FP16 outcomes of 7 images on XPU and FP16 outcomes on NVIDIA A100. This may change with subsequent releases.
python stable_diffusion_accuracy.py --precision fp16 \
--load_ref_result --ref_result_dir "./nv_results/img_arrays_for_acc.txt"
With successful execution, it will print out the following results:
latency 81.1146879196167 ms, throughput 12.328223477737884 it/s
- If you get the following error log, refer to Enable Running Environment to Enable oneAPI running environment.
tensorflow.python.framework.errors_impl.NotFoundError: libmkl_sycl.so.2: cannot open shared object file: No such file or directory