Open mllopartbsc opened 1 year ago
Looks like tensor in the model with name "/duration_predictor/flows.4/Reshape_27_output_0" has size 0. I think it may be because you are using random generated calibration data. For quantization, you need to use carefully selected real data set to get good accuracy.
And could you please share the augmented model?
Hi @yufenglee,
Thank you for the prompt response. The Coqui VITS ONNX is a text to speech model. Therefore, since the input data needed are English sentences, that is precisely what I'm generating inside the sentences list. I don't see any problem with that. What do you mean by carefully selected real datasets? And what would be the difference with what I'm inputting?
On the other hand, when I run my script, no "augmented_model.onnx" is created. Because of that, I can't share it with you. However, at some point there was an augmented_model.onnx created, but I deleted it because it was from the bert static quantization example I believe. Isn't it supposedly created after every instance?
Here's the script used to convert the VITS model to ONNX. It may give you some insights on the workings of the dummy inputs and the expected input.
Kind Regards
In regards to the last comment, I commented out the following section of my script:
# Generate 50 random sentences
subjects = ["I", "You", "Bob", "Alice", "The cat", "The robot"]
verbs = ["like", "hate", "see", "touch", "admire", "love"]
objects = ["apples", "the moon", "the rain", "a beautiful painting", "the idea of existence", "the sound of the ocean"]
sentences = []
for i in range(50):
subject = random.choice(subjects)
verb = random.choice(verbs)
object = random.choice(objects)
sentence = f"{subject} {verb} {object}."
sentences.append(sentence)
And changed for this hand-made list of 50 English sentences:
sentences = [
"The sky is blue.",
"I love apples.",
"She is reading a book.",
"I have a pet dog.",
"I like to play soccer.",
"Python is a powerful language.",
"The sun sets in the west.",
"The food here is delicious.",
"I am going to the park.",
"The cake is in the oven.",
"He is playing the guitar.",
"It is raining outside.",
"I am baking cookies.",
"I enjoy reading novels.",
"She likes to play tennis.",
"We are going on a trip.",
"I am learning Spanish.",
"He is practicing the piano.",
"She loves to dance.",
"The dog is sleeping.",
"I am eating a sandwich.",
"They are watching a movie.",
"She has a red bicycle.",
"I am visiting my grandparents.",
"I lost my keys.",
"The birds are singing.",
"I am drinking coffee.",
"He is studying for the exam.",
"I went to the beach.",
"I am learning to cook.",
"The cat is playing with a ball.",
"She is brushing her hair.",
"He has a blue car.",
"I am painting a picture.",
"She is feeding the birds.",
"The pizza is delicious.",
"I saw a beautiful sunset.",
"I am playing video games.",
"She is knitting a scarf.",
"They are planting flowers.",
"The moon is full tonight.",
"I am writing a letter.",
"The ice cream is melting.",
"She is washing the dishes.",
"I am going for a run.",
"He is fixing the computer.",
"I am listening to music.",
"The coffee is hot.",
"I am cleaning the house.",
"He is driving a truck."
]
So that they're not randomly generated.
Without modifying the path of the augmented model in the calibrate.py script, this is the error that emerges:
WARNING:root:Please consider to run pre-processing before quantization. Refer to example: https://github.com/microsoft/onnxruntime-inference-examples/blob/main/quantization/image_classification/cpu/ReadMe.md
2023-07-17 16:41:31.575414164 [W:onnxruntime:, execution_frame.cc:651 AllocateMLValueTensorPreAllocateBuffer] Shape mismatch attempting to re-use buffer. {1} != {0}. Validate usage of dim_value (values should be > 0) and dim_param (all values with the same string should equate to the same size) in shapes in the model.
2023-07-17 16:41:31.575516224 [E:onnxruntime:, sequential_executor.cc:514 ExecuteKernel] Non-zero status code returned while running Reshape node. Name:'/duration_predictor/flows.2/Reshape_27_output_0_ReduceMax_Reshape' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:40 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, onnxruntime::TensorShapeVector&, bool) gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{0}, requested shape:{1}
Traceback (most recent call last):
File "/home/mllopart/PycharmProjects/ttsAPI/tts-api/server/static_quantization.py", line 196, in <module>
quantize_static(model_name, quantize_name, calibration_data_reader=DataReader(x, x_lengths, scales), quant_format=QuantFormat.QDQ)
File "/home/mllopart/PycharmProjects/ttsAPI/venv/lib/python3.10/site-packages/onnxruntime/quantization/quantize.py", line 369, in quantize_static
calibrator.collect_data(calibration_data_reader)
File "/home/mllopart/PycharmProjects/ttsAPI/venv/lib/python3.10/site-packages/onnxruntime/quantization/calibrate.py", line 243, in collect_data
self.intermediate_outputs.append(self.infer_session.run(None, inputs))
File "/home/mllopart/PycharmProjects/ttsAPI/venv/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 217, in run
return self._sess.run(output_names, input_feed, run_options)
onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node. Name:'/duration_predictor/flows.2/Reshape_27_output_0_ReduceMax_Reshape' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:40 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, onnxruntime::TensorShapeVector&, bool) gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{0}, requested shape:{1}
If I modify the path of the session to the VITS model, then this error emerges from the quantize.py script:
WARNING:root:failed to infer the type of tensor: . Skip to quantize it. Please check if it is expected.
WARNING:root:failed to infer the type of tensor: . Skip to quantize it. Please check if it is expected.
.
.
.
WARNING:root:failed to infer the type of tensor: . Skip to quantize it. Please check if it is expected.
Traceback (most recent call last):
File "/home/mllopart/PycharmProjects/ttsAPI/tts-api/server/static_quantization.py", line 201, in <module>
quantize_static(model_name, quantize_name, calibration_data_reader=DataReader(x, x_lengths, scales), quant_format=QuantFormat.QDQ)
File "/home/mllopart/PycharmProjects/ttsAPI/venv/lib/python3.10/site-packages/onnxruntime/quantization/quantize.py", line 406, in quantize_static
quantizer.quantize_model()
File "/home/mllopart/PycharmProjects/ttsAPI/venv/lib/python3.10/site-packages/onnxruntime/quantization/qdq_quantizer.py", line 217, in quantize_model
self._quantize_normal_tensors()
File "/home/mllopart/PycharmProjects/ttsAPI/venv/lib/python3.10/site-packages/onnxruntime/quantization/qdq_quantizer.py", line 385, in _quantize_normal_tensors
raise ValueError(
ValueError: Quantization parameters are not specified for param /text_encoder/Constant_output_0. In static mode quantization params for inputs and outputs of nodes to be quantized are required.
Therefore, I get the same errors if I don't generate the input data randomly.
Again, thank you for the quick answer.
I am running into this as well–has it been resolved?
I am running into this as well–has it been resolved?
No, it hasn't.
Describe the issue
Hi, I was trying to statically quantize this Coqui VITS model that I had previously exported to ONNX. When doing so, I encountered this error:
onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node. Name:'/duration_predictor/flows.4/Reshape_27_output_0_ReduceMax_Reshape' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:40 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, onnxruntime::TensorShapeVector&, bool) gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{0}, requested shape:{1}
Below is the script that I'm using so that you can reproduce the bug. In order to reproduce it, the only thing you need to change are the paths to import the Coqui VITS model, export the ONNX version and then import it back. You can download the mentioned model and its configuration from this link.
It seems like the reason behind the error is this line from the calibrate.py script. This is the function containing the line:
The error emerges from the self.infer_session.run(None,inputs) part. Here's the definition of the function that creates the session:
As you can see, the onnxruntime.Inference session is created using the augmented_model_path, which is defined in line 54 of the calibrate.py script. Since this model isn't the same as the onnx model used for inference, the error appears because the augmented model requires different inputs. However, in the script I've tested if the input data is correct twice, and it is. And, as you will see with a following test, the error disappears when the inferences session uses the VITS ONNX model instead of the augmented model ONNX. Here, I have three questions:
1- Where does the augmented model come from? Is it created as a blan .onnx file to be filled with the original onnx model?
2- Why does it require different inputs as the original onnx model?
3- How could this input problem be fixed?
However, the problems don't end here. To test out if the problem was only with the inferences session of the augmented model, i changed the inference session to use the coqui VITS onnx model instead. Here's the modificaiton I applied:
I added this between lines 20 and 23 from the calibrate.py script of the onnxruntime library. Then I modified line 243 from this:
self.intermediate_outputs.append(self.infer_session.run(None, inputs))
To this:
self.intermediate_outputs.append(onnx_sess.run(None, inputs))
So that the VITS model was running the inference instead. With that, the calibrate.py was working fine, but a problem arised with the quantize.py script, in line 406. This is the error:
Which seems to be an error about quantization parameters. I am assuming that when converting the VITS model to ONNX these parameters are not present. However, I am not too sure about the cause of this error.
I would appreciate if someone could provide their insights on these errors.
Kind Regards.
To reproduce
1- Install the required libraries (they all appear as imports in the scripts).
2- Download the VITS model and its configuration with the provided link.
3- Change the import and export paths from the script.
4- Run the script.
5- Modify the calibrate.py script from the onnxruntime library to change the inference session to the VITS ONNX model.
6- Run the script again.
Urgency
This problem is very urgent as it is part of a project where inference times are crucial. The sooner it can be fixed the better.
Platform
Linux
OS Version
Ubuntu 22.04.2 LTS
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
ONNX Runtime v1.15.1
ONNX Runtime API
Python
Architecture
X64
Execution Provider
Default CPU
Execution Provider Library Version
No response