Skip to content

Conversation

@patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Mar 8, 2022

What does this PR do?

This PR is the first step to make generate a 1st class citizen in the docs. It improves the generate API for PyTorch and Flax generate, improves the examples for PyTorch and adds PyTorch to the example doc tests.

Once the TF generate refactor is complete - it's API can also be improved with better examples.

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.

@patrickvonplaten
Copy link
Contributor Author

No doc-builder triggered here? 😢

@LysandreJik
Copy link
Member

Docs live here: https://moon-ci-docs.huggingface.co/docs/transformers/pr_15988/en/index

@patrickvonplaten
Copy link
Contributor Author

Docs live here: https://moon-ci-docs.huggingface.co/docs/transformers/pr_15988/en/index

The docs are not updated on the link if the PR is changed (or it takes too long). Will build the docs locally now, but I think it makes it quite difficult for the community to add/change docs.

@LysandreJik
Copy link
Member

LysandreJik commented Mar 9, 2022

The job updates the docs. Are they not up to date here? https://moon-ci-docs.huggingface.co/docs/transformers/pr_15988/en/main_classes/text_generation

@patrickvonplaten
Copy link
Contributor Author

The job updates the docs. Are they not up to date here? https://moon-ci-docs.huggingface.co/docs/transformers/pr_15988/en/main_classes/text_generation

Nope

@patrickvonplaten patrickvonplaten changed the title [Docs] Move generate docs [Docs] Improve PyTorch generate API Mar 9, 2022
@patrickvonplaten patrickvonplaten changed the title [Docs] Improve PyTorch generate API [Docs] Improve PyTorch, Flax generate API Mar 9, 2022
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.

Thanks for expanding the doc!

@patrickvonplaten patrickvonplaten merged commit 6ce11c2 into huggingface:master Mar 10, 2022
@patrickvonplaten patrickvonplaten deleted the move_generate_to_its_own_page branch March 10, 2022 10:54

# Generation

The methods for auto-regressive text generation, namely [`~generation_utils.GenerationMixin.generate`] (for the PyTorch models), [`~generation_tf_utils.TFGenerationMixin.generate`] (for the TensorFlow models) and [`~generation_flax_utils.FlaxGenerationMixin.generate`] (for the Flax/JAX models), are implemented in [`~generation_utils.GenerationMixin`], [`~generation_tf_utils.TFGenerationMixin`] and [`~generation_flax_utils.FlaxGenerationMixin`] respectively.
Copy link
Member

Choose a reason for hiding this comment

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

I think replacing the first paragraph with the suggestion below makes it easier for the user to map each generate to its GenerationMixin class :)

Each framework has a generate method for auto-regressive text generation implemented in their respective GenerationMixin class:

  • PyTorch [~generation_utils.GenerationMixin.generate] is implemented in [~generation_utils.GenerationMixin].
  • TensorFlow [~generation_tf_utils.TFGenerationMixin.generate] is implemented in [~generation_tf_utils.TFGenerationMixin].
  • Flax/JAX [~generation_flax_utils.FlaxGenerationMixin.generate] is implemented in [~generation_flax_utils.FlaxGenerationMixin].

The `GenerationMixin` classes are inherited by the corresponding base model classes, *e.g.* [`PreTrainedModel`], [`TFPreTrainedModel`], and [`FlaxPreTrainedModel`] respectively, therefore exposing all
methods for auto-regressive text generation to every model class.

## GenerationMixn
Copy link
Member

Choose a reason for hiding this comment

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

Small typo for each of the GenerationMixin classes: GenerationMixin, TFGenerationMixin, FlaxGenerationMixin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correcting it here: #16133 (comment) . Thanks!

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.

4 participants