Open sunhs opened 1 year ago
I think the core issue is that DummyInputGenerator.random_int_tensor
only outputs int64, this also makes it hard to override for other purposes. (some models should support either int64 or int32, depending on the tokenizers, if onnx itself doesn't support generic int input, the export function should IMO)
Additionally, convert.py, support overriding input from float32 to float16, but not from int64 to int32.
Hi, I am not able to reproduce the error. Could you try two things:
Error caught was: No module named 'triton'
@michaelbenayoun Sorry for the late reply. I've upgraded everything to the latest version, including installing triton
, which I don't think is related to this problem. Now I have
optimum: 1.8.2
diffusers: 0.16.1
transformers: 4.28.1
onnx: 1.14.0
onnxruntime: 1.14.1
triton: 2.0.0.post1
but still the same error.
Did those 2 stacks I suspected conflict do any help?
@sunhs Could you try again with the latest version of Optimum please? You can install it with:
pip install --upgrade optimum
@regisss Hi, I've already upgraded to 1.8.5 with pip install --upgrade 'optimum[onnxruntime]'
but the error still remains. IMO, as far as the two lines of code I mentioned above remain unchanged, this error will not go away (If that's not something onnx/onnxruntime should take care of)
@sunhs I managed to reproduce it. Would you like to submit a PR to fix this with what you're suggesting?
@regisss Sure, I'll take time to try.
Sorry for being so late here. As a reference I need to update the problem description.
After some digging, I found that CLIPTextOnnxConfig.generate_dummy_inputs
indeed calls DummyTextInputGenerator.generate
. But after that, it cast the input to torch.int32
, which makes the difference. I don't know whether this casting is necessary. Maybe @echarlaix could give some clues?
EDIT: Additionally, this error doesn't occur in pytorch 1.13+. This is because pooler_output
of the clip onnx model is
name: "pooler_output"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_param: "batch_size"
}
dim {
dim_value: 768
}
}
}
}
while for pytorch1.12.1 it's
name: "pooler_output"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_param: "batch_size"
}
dim {
dim_param: "Reshapepooler_output_dim_1"
}
}
}
}
where Reshapepooler_output_dim_1
is not an allowed_dynamic_axes
and thus triggers the fix.
Edit: oh, this torch 1.xx specific. I actually can't reproduce on 1.13.1 either. Is this issue about the cast operation introduced, or is there an error raised?
I have no issue running
from optimum.onnxruntime import ORTStableDiffusionPipeline
pipe = ORTStableDiffusionPipeline.from_pretrained("SG161222/Realistic_Vision_V2.0", export=True)
on
onnx 1.14.0
onnxruntime 1.14.1
optimum 1.8.5
transformers 4.28.1
torch 2.0.0
diffusers 0.16.1
I just found it reproduces for pytorch 1.12 but not for either 1.13 or 2.x. I've updated the description (sorry for not having done it earlier).
System Info
Who can help?
@michaelbenayoun
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
EDIT: Note that this error occurs with pytorch 1.12.1, but doesn't occur with pytorch 1.13 or pytorch 2. See comment
Code:
Error:
Expected behavior
Succeed to convert stable diffusion pipeline to onnx.
I looked a bit into the code, and found the following call stacks might conflict:
Stack 1:
We see
dummy_inputs["input_ids"]
istorch.int32
, so is the input node of the exported onnx model.Stack 2:
We see
dummy_inputs["input_ids"]
inOnnxConfig.fix_dynamic_axes
isnp.int64
, which conflicts with the previous one used to export the model.