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 pix2struct #34374

Merged
merged 5 commits into from
Oct 28, 2024
Merged

Fix pix2struct #34374

merged 5 commits into from
Oct 28, 2024

Conversation

IlyasMoutawwakil
Copy link
Member

What does this PR do?

In #34089 some stuff might have not being copied correctly from T5. In pix2struct case past_key_value was being overridden by the first attention block, resulting in failure in cross attention.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@echarlaix
Copy link
Collaborator

echarlaix commented Oct 24, 2024

In transformers v4.46 generation for Pix2Struct fail when setting use_cache=True

Code to reproduce this issue : https://huggingface.co/docs/transformers/v4.46.0/en/model_doc/pix2struct#transformers.Pix2StructForConditionalGeneration.forward.example with use_cache=True

from PIL import Image
import requests
from transformers import AutoProcessor, Pix2StructForConditionalGeneration
model_id = "google/pix2struct-textcaps-base"

processor = AutoProcessor.from_pretrained(model_id)
model = Pix2StructForConditionalGeneration.from_pretrained(model_id)
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(images=image, return_tensors="pt")
generated_ids = model.generate(**inputs, max_new_tokens=50, use_cache=True)

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

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

Thanks for fixing! Very bad that we don't have generation test mixin in Pix2Struct 😢 , will add tests in the next batch with some left-over VLMs

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Thanks! can you add the snippet as a test? 🤗

@IlyasMoutawwakil
Copy link
Member Author

@ArthurZucker I added a small quick test

@IlyasMoutawwakil
Copy link
Member Author

there's one thing I don't understand, running the same test with T5 passes even without eval mode, but it was necessary to get it passing for pix2struct.

@IlyasMoutawwakil IlyasMoutawwakil merged commit fddbd3c into main Oct 28, 2024
18 checks passed
@IlyasMoutawwakil IlyasMoutawwakil deleted the fix-pix2struct branch October 28, 2024 10:24
Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Thanks, did not have the chance to approve but LGTM 🤗

ArthurZucker pushed a commit that referenced this pull request Oct 29, 2024
* fix

* fix and test use_cache test

* style

* remove atol
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.

5 participants