2023-03-08 16:55:49.501311 [W:onnxruntime:, execution\_frame.cc:835 VerifyOutputSizes]…
- User
2023-03-08 16:55:49.501311 [W:onnxruntime:, execution_frame.cc:835 VerifyOutputSizes] Expected shape from model of {-1} does not match actual shape of {10,3} for output label onnx giving me this error
- Assistant
This error message suggests that there is a mismatch between the expected output shape and the actual output shape of the "label" output from the ONNX model.
The expected shape is specified as {-1}, which means that the size of the first dimension (batch size) can vary. However, the actual shape of the output for the "label" output is {10, 3}, which indicates that the size of the first dimension is fixed to 10, and the size of the second dimension is fixed to 3.
To resolve this issue, you will need to update the ONNX model to ensure that the output shape for the "label" output matches the expected shape. One possible solution is to modify the output shape of the model to be {batch_size, -1}, where "batch_size" is the size of the first dimension of the input data. This will allow the output shape to vary based on the size of the input batch.
- User
this is the model: student_model.eval() with torch.no_grad(): inputs = { "lstm_token_ids": torch.ones(1, 512, dtype=torch.int64).to(device), }
symbolic_names = {0: "batch_size", 1: "max_seq_len"}
torch.onnx.export(student_model, (inputs["lstm_token_ids"]), "deepattnbilstm_sentiment_ar.onnx", verbose=False, input_names=["input_ids"], output_names=["label"], export_params=True, dynamic_axes={ "input_ids" : symbolic_names, "label" : {0:"batch_size"} }, opset_version=15, do_constant_folding=True ) - here is the code that use it: def predict_lstm(self, text: Union[List[str], str], custom_preprocessor, ):
TEXT PREPROCESSING
preprocessed_text = [] for index in range(len(text)): preprocessed_text.append(custom_preprocessor.clean_text( text[index] ))
TEXT TOKENIZATION
lstm_token_ids = self.lstm_preprocessing(preprocessed_text,1,512) lstm_onnx_input = {"input_ids": lstm_token_ids,}
print(lstm_onnx_input) lstm_output = self.han_session_dict[self.task].run(None, lstm_onnx_input)[0] print(lstm_output) - the model is supposed to be dynamic, i dont get the issue
- Assistant
Based on the code you provided, it seems that you are exporting the ONNX model with a fixed output shape for the "label" output. Specifically, you are specifying the output shape for the "label" output as ["label"] with a fixed batch size of 1:
cssoutput_names=["label"], dynamic_axes={ "input_ids" : symbolic_names, "label" : {0:"batch_size"} }This means that the ONNX model will always output a tensor of shape [1, -1] for the "label" output, where the size of the second dimension can vary depending on the input.
However, when you run the model using
lstm_onnx_input, the size of the first dimension in the "label" output is not 1, but rather the size of the input batch. This causes the size mismatch error you are seeing.To fix this issue, you can modify the ONNX model export code to use a dynamic batch size for the "label" output, as follows:
cssoutput_names=["label"], dynamic_axes={ "input_ids" : symbolic_names, "label" : {0:"batch_size", 1:"-1"} }This will ensure that the "label" output has a dynamic shape with a varying batch size and a variable size for the second dimension. Once you have made this change, you should re-export the ONNX model and try running it again.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.