Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
Signed-off-by: Mengni Wang <[email protected]>
  • Loading branch information
mengniwang95 committed Aug 12, 2024
1 parent 2e45599 commit 206bf96
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
# under the License.
# pylint:disable=redefined-outer-name,logging-format-interpolation
import argparse
import inspect
import logging
import os
import time
import inspect
from typing import List

import numpy as np
import onnx
import onnxruntime as ort
import torch
from typing import List
from diffusers import OnnxRuntimeModel, OnnxStableDiffusionPipeline

from onnx_neural_compressor import data_reader
from onnx_neural_compressor.quantization import config, quantize, QuantType
from diffusers import OnnxStableDiffusionPipeline, OnnxRuntimeModel
from onnx_neural_compressor.quantization import QuantType, config, quantize

logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.WARN
Expand Down Expand Up @@ -70,17 +72,13 @@
"tensor(double)": np.float64,
}


def benchmark(model):
generator = None if args.seed is None else np.random.RandomState(args.seed)

pipe = OnnxStableDiffusionPipeline.from_pretrained(
args.model_path,
provider=args.provider
)
pipe = OnnxStableDiffusionPipeline.from_pretrained(args.model_path, provider=args.provider)
if args.quantized_unet_path is not None:
unet = OnnxRuntimeModel(
model=ort.InferenceSession(args.quantized_unet_path, providers=[args.provider])
)
unet = OnnxRuntimeModel(model=ort.InferenceSession(args.quantized_unet_path, providers=[args.provider]))
pipe.unet = unet

image = None
Expand Down Expand Up @@ -249,15 +247,15 @@ def rewind(self):
data_reader,
weight_type=QuantType.QInt8,
activation_type=QuantType.QUInt8,
op_types_to_quantize=["MatMul","Gemm"],
op_types_to_quantize=["MatMul", "Gemm"],
per_channel=True,
extra_options={
"SmoothQuant": True,
"SmoothQuantAlpha": args.alpha,
"WeightSymmetric": True,
"ActivationSymmetric": False,
"OpTypesToExcludeOutputQuantization": ["MatMul", "Gemm"],
}
)
},
)
input_path = os.path.join(args.model_path, "unet/model.onnx")
quantize(input_path, args.output_model, cfg, optimization_level=ort.GraphOptimizationLevel.ORT_ENABLE_EXTENDED)
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ function init_params {
do
case $var in
--input_model=*)
input_model=$(echo $var |cut -f2 -d=)
input_model=$(echo "$var" |cut -f2 -d=)
;;
--quantized_unet_path=*)
quantized_unet_path=$(echo $var |cut -f2 -d=)
quantized_unet_path=$(echo "$var" |cut -f2 -d=)
;;
--batch_size=*)
batch_size=$(echo $var |cut -f2 -d=)
batch_size=$(echo "$var" |cut -f2 -d=)
;;
--prompt=*)
prompt=$(echo $var |cut -f2 -d=)
prompt=$(echo "$var" |cut -f2 -d=)
;;
--image_path=*)
image_path=$(echo $var |cut -f2 -d=)
image_path=$(echo "$var" |cut -f2 -d=)
;;
esac
done
Expand All @@ -44,21 +44,21 @@ function run_benchmark {

extra_cmd=""

if [ ! -z $quantized_unet_path ]; then
extra_cmd=$extra_cmd"--quantized_unet_path ${quantized_unet_path} "
if [ "$quantized_unet_path" ]; then
extra_cmd=$extra_cmd"--quantized_unet_path=${quantized_unet_path} "
fi

if [ ! -z $prompt ]; then
extra_cmd=$extra_cmd"--prompt ${prompt} "
if [ "$prompt" ]; then
extra_cmd=$extra_cmd"--prompt=${prompt} "
fi

if [ ! -z $image_path ]; then
extra_cmd=$extra_cmd"--image_path ${image_path} "
if [ "$image_path" ]; then
extra_cmd=$extra_cmd"--image_path=${image_path} "
fi

python main.py \
--model_path ${input_model} \
--batch_size=${batch_size-1} \
--model_path="${input_model}" \
--batch_size="${batch_size-1}" \
--benchmark \
${extra_cmd}

Check warning on line 63 in examples/nlp/huggingface_model/text_to_image/stable_diffusion_v1_5/quantization/ptq_static/run_benchmark.sh

View workflow job for this annotation

GitHub Actions / Optional Lint

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./examples/nlp/huggingface_model/text_to_image/stable_diffusion_v1_5/quantization/ptq_static/run_benchmark.sh:63:6: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ function init_params {
do
case $var in
--input_model=*)
input_model=$(echo $var |cut -f2 -d=)
input_model=$(echo "$var" |cut -f2 -d=)
;;
--output_model=*)
output_model=$(echo $var |cut -f2 -d=)
output_model=$(echo "$var" |cut -f2 -d=)
;;
--alpha=*)
alpha=$(echo $var |cut -f2 -d=)
alpha=$(echo "$var" |cut -f2 -d=)
;;
esac
done
Expand All @@ -42,9 +42,9 @@ function run_tuning {
fi

python main.py \
--model_path ${input_model} \
--output_model ${output_model} \
--alpha ${alpha-0.7} \
--model_path "${input_model}" \
--output_model "${output_model}" \
--alpha "${alpha-0.7}" \
--tune
}

Expand Down
4 changes: 3 additions & 1 deletion onnx_neural_compressor/algorithms/smoother/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ def mul(node, scale): # pragma: no cover
# Mul operator has broadcast mechanism
self.model.remove_initializer(tensor)
self.model.add_initializer(
onnx.helper.make_tensor(inp, tensor.data_type, list(new_tensor.shape), new_tensor.flatten().tolist())
onnx.helper.make_tensor(
inp, tensor.data_type, list(new_tensor.shape), new_tensor.flatten().tolist()
)
)
self.tensor_scales_info[key] = (
1.0 / scale
Expand Down

0 comments on commit 206bf96

Please sign in to comment.