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

Allow script tracing DINOv2 #27537

Closed
Danil328 opened this issue Nov 16, 2023 · 4 comments · Fixed by #27561
Closed

Allow script tracing DINOv2 #27537

Danil328 opened this issue Nov 16, 2023 · 4 comments · Fixed by #27561

Comments

@Danil328
Copy link

I found PR to dinov2 "Pass scale factor as a tuple of floats to F.interpolate() to allow tracing."
facebookresearch/dinov2#247

https://github.com/huggingface/transformers/blob/85fde09c97213bf7e8625f83096bb2a9e183f987/src/transformers/models/dinov2/modeling_dinov2.py#L104C19-L104C19

@Danil328
Copy link
Author

Danil328 commented Nov 16, 2023

I have exception now:
image

@amyeroberts
Copy link
Collaborator

Hi @Danil328, thanks for raising this issue!

Could you make sure to follow the issue template and include details of your running environment and a minimal reproducible snippet?

From the error it looks like the scale_factor values being passed to interpolate is a NoneType.

@Danil328
Copy link
Author

Danil328 commented Nov 16, 2023

Same problem in facebookresearch - facebookresearch/dinov2#102

Reproduction

import torch
from transformers import AutoImageProcessor, AutoModel
from PIL import Image
import requests

url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)

processor = AutoImageProcessor.from_pretrained('facebook/dinov2-base')
model = AutoModel.from_pretrained('facebook/dinov2-base')

inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
last_hidden_states = outputs.last_hidden_state

with torch.no_grad():
    example_input = torch.rand(1, 3, 224, 224, dtype=torch.float32, device="cuda")
    traced_model = torch.jit.trace(model.cuda(), example_input) # fails here

Error

image

Expected behavior

Success

Enviroment

bash python=3.8 torch==2.0.1 transformers==4.35.0

@amyeroberts amyeroberts mentioned this issue Nov 17, 2023
5 tasks
@amyeroberts
Copy link
Collaborator

@Danil328 - thanks for providing the snippet! I've opened a PR which should resolve the issue

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 a pull request may close this issue.

2 participants