Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/.config/model_params_pytorch_3x.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@
"main_script": "main.py",
"batch_size": 1
},
"sd21_static_int8":{
"model_src_dir": "diffusion_model/diffusers/stable_diffusion/static_quant",
"dataset_location": "/tf_dataset2/datasets/coco2017/coco/",
"input_model": "",
"main_script": "main.py",
"batch_size": 1,
"iters": 10
},
"lcm_static_int8":{
"model_src_dir": "diffusion_model/diffusers/stable_diffusion/static_quant",
"dataset_location": "/tf_dataset2/datasets/coco2017/coco/",
"input_model": "",
"main_script": "main.py",
"batch_size": 1,
"iters": 10
},
"resnet18_mixed_precision": {
"model_src_dir": "cv/mixed_precision",
"dataset_location": "/tf_dataset/pytorch/ImageNet/raw",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Stable Diffusion

Stable Diffusion quantization and inference best known configurations with static quant.

## Model Information

| **Framework** | **Model Repo** |
|:-------------:|:-------------------------------------------------------------------:|
| PyTorch | https://huggingface.co/stabilityai/stable-diffusion-2-1 |
| PyTorch | https://huggingface.co/SimianLuo/LCM_Dreamshaper_v7 |

# Pre-Requisite

### Datasets

Download the 2017 [COCO dataset](https://cocodataset.org) using the `download_dataset.sh` script.
Export the `DATASET_DIR` environment variable to specify the directory where the dataset will be downloaded. This environment variable will be used again when running training scripts.
```
export DATASET_DIR=<directory where the dataset will be saved>
bash download_dataset.sh
```

# Quantization and Inference
quantization
```shell
python main.py \
--model_name_or_path stabilityai/stable-diffusion-2-1 \
--dataset_path=${DATASET_DIR} \
--quantized_model_path=${INT8_MODEL} \
--compile_inductor \
--precision=int8-bf16 \
--calibration
```
inference
```shell
python main.py \
--model_name_or_path stabilityai/stable-diffusion-2-1 \
--dataset_path=${DATASET_DIR} \
--precision=int8-bf16 \
--benchmark \
-w 1 \
-i 10 \
--quantized_model_path=${INT8_MODEL} \
--compile_inductor
```
## FID evaluation
We have also evaluated FID scores on COCO2017 validation dataset for BF16 model, mixture of BF16 and INT8 model. FID results are listed below.

| Model | BF16 | INT8+BF16 |
|----------------------|-------|-----------|
| stable-diffusion-2-1 | 27.8630 | 27.8618 |
| SimianLuo/LCM_Dreamshaper_v7|42.1710| 42.3138|

To evaluated FID score on COCO2017 validation dataset for mixture of BF16 and INT8 model, you can use below command.

```bash
python main.py \
--dataset_path=${DATASET_DIR} \
--precision=int8-bf16 \
--accuracy \
--quantized_model_path=${INT8_MODEL} \
--compile_inductor
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# Copyright (c) 2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

DATASET_DIR=${DATASET_DIR-$PWD}

dir=$(pwd)
mkdir ${DATASET_DIR}; cd ${DATASET_DIR}
curl -O http://images.cocodataset.org/zips/val2017.zip; unzip val2017.zip
curl -O http://images.cocodataset.org/annotations/annotations_trainval2017.zip; unzip annotations_trainval2017.zip
cd $dir
Loading