Everyone is welcome to contribute, and we value everybody’s contribution. Code is thus not the only way to help the community. Answering questions, helping others, reaching out and improving the documentations are immensely valuable to the community.
It also helps us if you spread the word: reference the library from blog posts on the awesome projects it made possible, shout out on Twitter every time it has helped you, or simply star the repo to say “thank you”.
Whichever way you choose to contribute, please be mindful to respect our code of conduct.
There are 4 ways you can contribute to transformers:
In particular there is a special Good First
Issue listing. It will give you a list of
open Issues that are open to anybody to work on. Just comment in the issue that you’d like to work
on it. In that same listing you will also find some Issues with Good Second Issue label. These are
typically slightly more complicated than the Issues with just Good First Issue label. But if you
feel you know what you’re doing, go for it.
All are equally valuable to the community.
Do your best to follow these guidelines when submitting an issue or a feature request. It will make it easier for us to come back to you quickly and with good feedback.
The 🤗 Transformers library is robust and reliable thanks to the users who notify us of the problems they encounter. So thank you for reporting an issue.
First, we would really appreciate it if you could make sure the bug was not already reported (use the search bar on Github under Issues).
Did not find it? :( So we can act quickly on it, please follow these steps:
To get the OS and software versions automatically, you can run the following command:
transformers-cli envor from the root of the repository the following command:
python src/transformers/commands/transformers_cli.py envAwesome! Please provide the following information:
If you are willing to contribute the model yourself, let us know so we can best guide you.
We have added a detailed guide and templates to guide you in the process of adding a new model. You can find them
in the templates(https://github.com/huggingface/transformers/tree/master/templates) folder.
A world-class feature request addresses the following points:
If your issue is well written we’re already 80% of the way there by the time you post it.
We have added templates to guide you in the process of adding a new example script for training or testing the
models in the library. You can find them in the templates(https://github.com/huggingface/transformers/tree/master/templates)
folder.
Before writing code, we strongly advise you to search through the existing PRs or issues to make sure that nobody is already working on the same thing. If you are unsure, it is always a good idea to open an issue to get some feedback.
You will need basic git proficiency to be able to contribute to
transformers. git is not the easiest tool to use but it has the greatest
manual. Type git --help in a shell and enjoy. If you prefer books, Pro
Git is a very good reference.
Follow these steps to start contributing:
Fork the repository by clicking on the ‘Fork’ button on the repository’s page. This creates a copy of the code under your GitHub user account.
Clone your fork to your local disk, and add the base repository as a remote:
$ git clone git@github.com:<your Github handle>/transformers.git
$ cd transformers
$ git remote add upstream https://github.com/huggingface/transformers.gitCreate a new branch to hold your development changes:
$ git checkout -b a-descriptive-name-for-my-changes
Do not work on the master branch.
Set up a development environment by running the following command in a virtual environment:
$ pip install -e ".[dev]"(If transformers was already installed in the virtual environment, remove
it with pip uninstall transformers before reinstalling it in editable
mode with the -e flag.)
To run the full test suite, you might need the additional dependency on datasets which requires a separate source
install:
$ git clone https://github.com/huggingface/datasets
$ cd datasets
$ pip install -e .If you have already cloned that repo, you might need to git pull to get the most recent changes in the datasets
library.
Develop the features on your branch.
As you work on the features, you should make sure that the test suite passes:
$ make testNote, that this command uses -n auto pytest flag, therefore, it will start as many parallel pytest processes as the number of your computer’s CPU-cores, and if you have lots of those and a few GPUs and not a great amount of RAM, it’s likely to overload your computer. Therefore, to run the test suite, you may want to consider using this command instead:
$ python -m pytest -n 3 --dist=loadfile -s -v ./tests/
Adjust the value of -n to fit the load your hardware can support.
transformers relies on black and isort to format its source code
consistently. After you make changes, format them with:
$ make style
transformers also uses flake8 and a few custom scripts to check for coding mistakes. Quality
control runs in CI, however you can also run the same checks with:
$ make quality
You can do the automatic style corrections and code verifications that can’t be automated in one go:
$ make fixup
This target is also optimized to only work with files modified by the PR you’re working on.
If you’re modifying documents under docs/source, make sure to validate that
they can still be built. This check also runs in CI. To run a local check
make sure you have installed the documentation builder requirements, by
running pip install .[tf,torch,docs] once from the root of this repository
and then run:
$ make docs
Once you’re happy with your changes, add changed files using git add and
make a commit with git commit to record your changes locally:
$ git add modified_file.py $ git commit
Please write good commit messages.
It is a good idea to sync your copy of the code with the original repository regularly. This way you can quickly account for changes:
$ git fetch upstream $ git rebase upstream/master
Push the changes to your account using:
$ git push -u origin a-descriptive-name-for-my-changes
Once you are satisfied (and the checklist below is happy too), go to the webpage of your fork on GitHub. Click on ‘Pull request’ to send your changes to the project maintainers for review.
It’s ok if maintainers ask you for changes. It happens to core contributors too! So everyone can see the changes in the Pull request, work in your local branch and push the changes to your fork. They will automatically appear in the pull request.
[WIP]. These
are useful to avoid duplicated work, and to differentiate it from PRs ready
to be merged;ModelTester.all_model_classes = (MyModel, MyModelWithLMHead,...), which triggers the common tests.@slow tests, make sure they pass using
RUN_SLOW=1 python -m pytest tests/test_my_new_model.py.RUN_SLOW=1 python -m pytest tests/test_tokenization_{your_model_name}.py passes.
CircleCI does not run the slow tests, but github actions does every night!modeling_bert.py for an
example.dataset like
the ones hosted on hf-internal-testing(https://huggingface.co/hf-internal-testing) in which to place these files and reference
them by URL.See more about the checks run on a pull request in our PR guide
An extensive test suite is included to test the library behavior and several examples. Library tests can be found in the tests folder and examples tests in the examples folder.
We like pytest and pytest-xdist because it’s faster. From the root of the
repository, here’s how to run tests with pytest for the library:
$ python -m pytest -n auto --dist=loadfile -s -v ./tests/
and for the examples:
$ pip install -r examples/xxx/requirements.txt # only needed the first time
$ python -m pytest -n auto --dist=loadfile -s -v ./examples/In fact, that’s how make test and make test-examples are implemented (sans the pip install line)!
You can specify a smaller set of tests in order to test only the feature you’re working on.
By default, slow tests are skipped. Set the RUN_SLOW environment variable to
yes to run them. This will download many gigabytes of models — make sure you
have enough disk space and a good Internet connection, or a lot of patience!
$ RUN_SLOW=yes python -m pytest -n auto --dist=loadfile -s -v ./tests/
$ RUN_SLOW=yes python -m pytest -n auto --dist=loadfile -s -v ./examples/Likewise, set the RUN_CUSTOM_TOKENIZERS environment variable to yes to run
tests for custom tokenizers, which don’t run by default either.
🤗 Transformers uses pytest as a test runner only. It doesn’t use any
pytest-specific features in the test suite itself.
This means unittest is fully supported. Here’s how to run tests with
unittest:
$ python -m unittest discover -s tests -t . -v $ python -m unittest discover -s examples -t examples -v
For documentation strings, transformers follows the google style.
Check our documentation writing guide
for more information.
On windows, you need to configure git to transform Windows CRLF line endings to Linux LF line endings:
git config core.autocrlf input
One way one can run the make command on Window is to pass by MSYS2:
pacman -Syu and install make with pacman -S makeC:\msys64\usr\bin to your PATH environment variable.You can now use make from any terminal (Powershell, cmd.exe, etc) 🎉
To avoid pinging the upstream repository which adds reference notes to each upstream PR and sends unnessary notifications to the developers involved in these PRs, when syncing the master branch of a forked repository, please, follow these steps:
$ git checkout -b your-branch-for-syncing
$ git pull --squash --no-commit upstream master
$ git commit -m '<your message without GitHub references>'
$ git push --set-upstream origin your-branch-for-syncing