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

Fix OwlViT torchscript tests #18347

Merged
merged 3 commits into from
Jul 29, 2022

Conversation

ydshieh
Copy link
Collaborator

@ydshieh ydshieh commented Jul 28, 2022

What does this PR do?

Fix OwlViTForObjectDetection torchscript tests. The main problem comes from the fact that we provide

traced_model = torch.jit.trace(model, (input_ids, pixel_values))

but OwlViTForObjectDetection has different order of arguments.

I could simply change the order in the test method, but probably it is better to have OwlViTForObjectDetection and OwlViTModel have the same argument order .

current failed job run

Copy link
Collaborator Author

@ydshieh ydshieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments.

@@ -1153,7 +1153,6 @@ def forward(

class OwlViTForObjectDetection(OwlViTPreTrainedModel):
config_class = OwlViTConfig
main_input_name = "pixel_values"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to remove this since the arguments are swapped.

@@ -1383,6 +1382,8 @@ def forward(
text_model_last_hidden_states,
vision_model_last_hidden_states,
)
output = tuple(x for x in output if x is not None)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to remove the None elements from the outputs if return_dict=False.
This is what we do for all models.
And it is also necessary for jit.trace

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, ran the tests and everything looks good!

@ydshieh ydshieh requested review from alaradirik and sgugger July 28, 2022 17:56
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jul 28, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's double check with @alaradirik but LGTM!

@ydshieh ydshieh merged commit a64bcb5 into huggingface:main Jul 29, 2022
@ydshieh ydshieh deleted the fix_owlvit_torchscript_test branch July 29, 2022 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants