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

Fixed OwlViTModel inplace operations #24529

Merged
merged 2 commits into from
Jun 29, 2023

Conversation

pasqualedem
Copy link
Contributor

What does this PR do?

This PR replaces the "/=" operator in OwlViTModel which causes an error in the backward pass with the non-inplace version.

Fixes #24525

#24525

Who can review?

@ydshieh

Copy link
Collaborator

@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.

Thank you for opening the PR to fix it.
LGTM, but ping a core maintainer @sgugger to have a look too.

@@ -1293,8 +1293,8 @@ def forward(
return (pred_logits, image_class_embeds)

# Normalize image and text features
image_class_embeds /= torch.linalg.norm(image_class_embeds, dim=-1, keepdim=True) + 1e-6
query_embeds /= torch.linalg.norm(query_embeds, dim=-1, keepdim=True) + 1e-6
image_class_embeds = image_class_embeds / torch.linalg.norm(image_class_embeds, dim=-1, keepdim=True) + 1e-6
Copy link
Collaborator

Choose a reason for hiding this comment

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

wait. I think we should do

(torch.linalg.norm(image_class_embeds, dim=-1, keepdim=True) + 1e-6) instead

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
image_class_embeds = image_class_embeds / torch.linalg.norm(image_class_embeds, dim=-1, keepdim=True) + 1e-6
image_class_embeds = image_class_embeds / (torch.linalg.norm(image_class_embeds, dim=-1, keepdim=True) + 1e-6)

@@ -1293,8 +1293,8 @@ def forward(
return (pred_logits, image_class_embeds)

# Normalize image and text features
image_class_embeds /= torch.linalg.norm(image_class_embeds, dim=-1, keepdim=True) + 1e-6
query_embeds /= torch.linalg.norm(query_embeds, dim=-1, keepdim=True) + 1e-6
image_class_embeds = image_class_embeds / torch.linalg.norm(image_class_embeds, dim=-1, keepdim=True) + 1e-6
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
image_class_embeds = image_class_embeds / torch.linalg.norm(image_class_embeds, dim=-1, keepdim=True) + 1e-6
image_class_embeds = image_class_embeds / (torch.linalg.norm(image_class_embeds, dim=-1, keepdim=True) + 1e-6)

src/transformers/models/owlvit/modeling_owlvit.py Outdated Show resolved Hide resolved
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.

LGTM with @ydshieh suggestions, thanks!

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 27, 2023

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

@ydshieh
Copy link
Collaborator

ydshieh commented Jun 29, 2023

@pasqualedem Could you apply the commit suggestions, then we can merge 🙏 Thanks.

Copy link
Collaborator

@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.

Thanks again!

@ydshieh ydshieh merged commit 10c2ac7 into huggingface:main Jun 29, 2023
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

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.

Backward pass error during OWL-ViT finetuning
4 participants