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

Generate: TF contrastive search with XLA support #20050

Merged
merged 11 commits into from
Nov 7, 2022

Conversation

gante
Copy link
Member

@gante gante commented Nov 3, 2022

What does this PR do?

Adds contrastive search to TF, with XLA support.

In essence, TF's contrastive search is very similar to PT's, adapted to the structure that is present in other TF XLA generation functions (i.e. has a dedicated function to loop over, a separate function to update model_kwargs when in XLA mode, ...). The most notable difference is how the best candidate token (and associated model variables) are gathered -- PT relies on slicing, which TF doesn't support, so a tf.gather alternative is used.

The exact same integration tests (with the same input, model, and outputs) were added whenever possible. Three integration tests were not added, which will be addressed in a follow-up PR:

  1. GPT-J -- PT's test runs at half precision, for which we don't have the same TF facilities
  2. OPT -- OPT is not XLA compatible atm (it runs, but the position embeddings are wrong with padded structures, so we get different outputs)
  3. T5 -- the model used for this test do not have TF weights

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Nov 3, 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.

Very clean, thanks for doing all the ground work in the PyTorch method in previous PRs!

@gante
Copy link
Member Author

gante commented Nov 7, 2022

(@Rocketknight1 is off, so I'm merging this to not slow down the corresponding blog post, which will contain TF examples thanks to this PR :D In any case, have a quick look when you're back, to ensure we kill any bad pattern before v4.25 gets released!)

@gante gante merged commit a0f8674 into huggingface:main Nov 7, 2022
@gante gante deleted the tf_contrastive branch November 7, 2022 10:54
mpierrau pushed a commit to mpierrau/transformers that referenced this pull request Dec 15, 2022
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.

3 participants