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

🚨 [Idefics2] Update ignore index #30898

Merged

Conversation

NielsRogge
Copy link
Contributor

What does this PR do?

This PR proposes to set the ignore index of the loss function of Idefics2 like the value of any other LLM/multimodal in the Transformers library, which is -100 (the default ignore index of PyTorch's cross-entropy loss).

It's up to users to create the labels and set whatever they don't want to be included in the loss calculation to -100. In the case of Idefics2, this could look like so:

labels = batch["input_ids"].clone()
labels[labels == processor.tokenizer.pad_token_id] = -100
labels[labels == processor.image_processor.image_token_id] = -100

which means, it's up to the user to make sure padding and image tokens are ignored.

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

@amyeroberts amyeroberts 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 adding!

Two things to update before merging:

  • Docstring info to match this logic
  • Add an example in on modeling pad on how to mask, as users will likely not know to mask the images

Copy link
Member

@VictorSanh VictorSanh left a comment

Choose a reason for hiding this comment

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

thanks!

@amyeroberts amyeroberts changed the title [Idefics2] Update ignore index 🚨 [Idefics2] Update ignore index May 21, 2024
Copy link
Collaborator

@amyeroberts amyeroberts 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 updating and providing an example!

Added a 🚨 to flag that this is a breaking change

@NielsRogge NielsRogge merged commit 60bb571 into huggingface:main May 21, 2024
22 checks passed
@NielsRogge
Copy link
Contributor Author

Thanks, btw @VictorSanh could you update the DocVQA notebook to account for this change?

Vaibhavs10 pushed a commit to Vaibhavs10/transformers that referenced this pull request May 22, 2024
* Update ignore index

* Update docs

* Update docs
@VictorSanh
Copy link
Member

Thanks, btw @VictorSanh could you update the DocVQA notebook to account for this change?

good point! done!

itazap pushed a commit that referenced this pull request May 24, 2024
* Update ignore index

* Update docs

* Update docs
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.

None yet

4 participants