We â¤ď¸ contributions from the open-source community! Everyone is welcome, and all types of participation ânot just codeâ are valued and appreciated. Answering questions, helping others, reaching out and improving the documentation are all immensely valuable to the community, so donât be afraid and get involved if youâre up for it!
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â.
We encourage everyone to start by saying đ in our public Discord channel. We discuss the hottest trends about diffusion models, ask questions, show-off personal projects, help each other with contributions, or just hang out â.
Whichever way you choose to contribute, we strive to be part of an open, welcoming and kind community. Please, read our code of conduct and be mindful to respect it during your interactions.
You can contribute in so many ways! Just to name a few:
All are equally valuable to the community.
If you need inspiration, you can look out for issues youâd like to tackle to contribute to the library. There are a few filters that can be helpful:
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 𧨠Diffusers 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).
Awesome! Please provide the following information:
If you are willing to contribute the model yourself, let us know so we can best guide you.
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.
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
𧨠Diffusers. 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 (supported Python versions):
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>/diffusers.git
$ cd diffusers
$ git remote add upstream https://github.com/huggingface/diffusers.git
Create a new branch to hold your development changes:
$ git checkout -b a-descriptive-name-for-my-changes
Do not work on the main
branch.
Set up a development environment by running the following command in a virtual environment:
$ pip install -e ".[dev]"
(If Diffusers was already installed in the virtual environment, remove
it with pip uninstall diffusers
before reinstalling it in editable
mode with the -e
flag.)
To run the full test suite, you might need the additional dependency on transformers
and datasets
which requires a separate source
install:
$ git clone https://github.com/huggingface/transformers
$ cd transformers
$ pip install -e .
$ 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. You should run the tests impacted by your changes like this:
$ pytest tests/<TEST_TO_RUN>.py
You can also run the full suite with the following command, but it takes a beefy machine to produce a result in a decent amount of time now that Diffusers has grown a lot. Here is the command for it:
$ make test
For more information about tests, check out the dedicated documentation
𧨠Diffusers relies on black
and isort
to format its source code
consistently. After you make changes, apply automatic style corrections and code verifications
that canât be automated in one go with:
$ make style
𧨠Diffusers also uses ruff
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
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
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/main
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;@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
for an example.dataset
like
the ones hosted on hf-internal-testing
in which to place these files and reference or huggingface/documentation-images.
If an external contribution, feel free to add the images to your PR and ask a Hugging Face member to migrate your images
to this dataset.An extensive test suite is included to test the library behavior and several examples. Library tests can be found in the tests 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/
In fact, thatâs how make test
is implemented!
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/
unittest
is fully supported, hereâs how to run tests with it:
$ python -m unittest discover -s tests -t . -v $ python -m unittest discover -s examples -t examples -v
To avoid pinging the upstream repository which adds reference notes to each upstream PR and sends unnecessary notifications to the developers involved in these PRs, when syncing the main branch of a forked repository, please, follow these steps:
$ git checkout -b your-branch-for-syncing
$ git pull --squash --no-commit upstream main
$ git commit -m '<your message without GitHub references>'
$ git push --set-upstream origin your-branch-for-syncing
For documentation strings, 𧨠Diffusers follows the google style.
This guide was heavily inspired by the awesome scikit-learn guide to contributing.