Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Error: Unexpected type of example_input #21899

Closed
3 tasks done
kolabearafk opened this issue Dec 28, 2023 · 6 comments
Closed
3 tasks done

[Bug]: Error: Unexpected type of example_input #21899

kolabearafk opened this issue Dec 28, 2023 · 6 comments
Assignees
Labels

Comments

@kolabearafk
Copy link

OpenVINO Version

openvino 2023.2.0

Operating System

Ubuntu 20.04 (LTS)

Device used for inference

CPU

Framework

PyTorch

Model used

StableDiffusion UNet - https://github.com/huggingface/diffusers/blob/645a62bf3bcba47f97bf2a36a8689f40bd6b04fd/src/diffusers/models/unet_2d_condition.py#L843

Issue description

Describe the bug

Can't use dictionary type for example_input when trying to convert pytorch model

Expected behavior

Not giving this - "Error: Unexpected type of example_input" and successfully convert the pytorch model to openvino

Screenshots

Error_OpenVino

Additional context

I'm trying to convert the UNet model from diffusers library's StableDiffusionPipeline but with an additional parameter called "added_cond_kwargs" that is supposed to be Dict[str, torch.Tensor]. But openvino's ov.convert_model(unet, example_input) function is giving the error "Error: Unexpected type of example_input".

It seems openvino's pytorch_frontend_utils.py script raises an error if the type of example_input doesn't match the expected type (see

raise Error("Unexpected type of example_input. Supported types torch.Tensor, np.array or ov.Tensor. "
) but the diffusers library's UNet model requires the added_cond_kwargs parameter to be a Dict (see https://github.com/huggingface/diffusers/blob/645a62bf3bcba47f97bf2a36a8689f40bd6b04fd/src/diffusers/models/unet_2d_condition.py#L843).

Please help! Thank you.

Step-by-step reproduction

No response

Relevant log output

See attached screenshot above.

Issue submission checklist

  • I'm reporting an issue. It's not a question.
  • I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
  • There is reproducer code and related data files such as images, videos, models, etc.
@kolabearafk kolabearafk added bug Something isn't working support_request labels Dec 28, 2023
@mvafin mvafin self-assigned this Dec 28, 2023
@mvafin
Copy link
Contributor

mvafin commented Dec 28, 2023

@kolabearafk What exactly you provide as example_input argument? The dictionary case is supported if you pass dictionary with inputs it should work. It might not work if you pass dictionary in tuple, for example.

@kolabearafk
Copy link
Author

Hi @mvafin,

Thanks for the reply!

I'm trying to put a dictionary inside the example_input dictionary. Please see below for more information:

example_input = {
    "sample": torch.rand((2, 4, 64, 64)), 
    "timestep": torch.tensor(1), 
    "encoder_hidden_states": torch.randn((2, 77, 768)), 
    "added_cond_kwargs": {"image_embeds": torch.rand((2, 1280))}

I was able to get it working after following @eaidova's advice by trying with openvino-nightly instead of openvino 2023.2.0. It was able to convert the unet with openvino-nightly. But I am ran into a different error when compiling the model when it says "CPU Plugin: Input image format dynamic is not supported yet..." Please see attached screenshot for the error message.

Openvino-Nightly-Error

@mvafin
Copy link
Contributor

mvafin commented Dec 29, 2023

@kolabearafk This happens because some of model inputs have unspecified (dynamic) data type. To solve this problem you need to specify data type of the input using something like this:

import openvino as ov

model = ov.convert_model(<...>)  # your ov model
params = model.get_parameters()
params[0].set_element_type(ov.Type.f32)

@kolabearafk
Copy link
Author

import openvino as ov

model = ov.convert_model(<...>) # your ov model
params = model.get_parameters()
params[0].set_element_type(ov.Type.f32)

That doesn't seem to work for some reason and gives the same "CPU Plugin: Input image format dynamic is not supported yet..." error.

@mvafin
Copy link
Contributor

mvafin commented Jan 4, 2024

import openvino as ov
model = ov.convert_model(<...>) # your ov model
params = model.get_parameters()
params[0].set_element_type(ov.Type.f32)

That doesn't seem to work for some reason and gives the same "CPU Plugin: Input image format dynamic is not supported yet..." error.

Could you do print(ov_model) where ov_model is the object you getting from convert_model and paste it here? The model most likely has more then 1 input.

@avitial avitial added category: CPU OpenVINO CPU plugin and removed bug Something isn't working labels Jan 5, 2024
@andrei-kochin
Copy link
Contributor

Closing due to no activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants