| 1 |
<!--- |
| 2 |
Copyright 2022 The HuggingFace Team. All rights reserved. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
--> |
| 16 |
|
| 17 |
# How to contribute to 🤗 Accelerate? |
| 18 |
|
| 19 |
Everyone is welcome to contribute, and we value everybody's contribution. Code |
| 20 |
is thus not the only way to help the community. Answering questions, helping |
| 21 |
others, reaching out and improving the documentations are immensely valuable to |
| 22 |
the community. |
| 23 |
|
| 24 |
It also helps us if you spread the word: reference the library from blog posts |
| 25 |
on the awesome projects it made possible, shout out on Twitter every time it has |
| 26 |
helped you, or simply star the repo to say "thank you". |
| 27 |
|
| 28 |
Whichever way you choose to contribute, please be mindful to respect our |
| 29 |
[code of conduct](https://github.com/huggingface/accelerate/blob/main/CODE_OF_CONDUCT.md). |
| 30 |
|
| 31 |
## You can contribute in so many ways! |
| 32 |
|
| 33 |
Some of the ways you can contribute to Accelerate: |
| 34 |
* Fixing outstanding issues with the existing code; |
| 35 |
* Contributing to the examples or to the documentation; |
| 36 |
* Submitting issues related to bugs or desired new features. |
| 37 |
|
| 38 |
## Submitting a new issue or feature request |
| 39 |
|
| 40 |
Do your best to follow these guidelines when submitting an issue or a feature |
| 41 |
request. It will make it easier for us to come back to you quickly and with good |
| 42 |
feedback. |
| 43 |
|
| 44 |
### Did you find a bug? |
| 45 |
|
| 46 |
The 🤗 Accelerate library is robust and reliable thanks to the users who notify us of |
| 47 |
the problems they encounter. So thank you for reporting an issue. |
| 48 |
|
| 49 |
First, we would really appreciate it if you could **make sure the bug was not |
| 50 |
already reported** (use the search bar on Github under Issues). |
| 51 |
|
| 52 |
Did not find it? :( So we can act quickly on it, please follow these steps: |
| 53 |
|
| 54 |
* Include your **OS type and version**, the versions of **Python** and **PyTorch**. |
| 55 |
* A short, self-contained, code snippet that allows us to reproduce the bug in |
| 56 |
less than 30s; |
| 57 |
* Provide the with your Accelerate configuration (located by default in `~/.cache/huggingface/accelerate/default_config.yaml`) |
| 58 |
|
| 59 |
### Do you want a new feature? |
| 60 |
|
| 61 |
A good feature request addresses the following points: |
| 62 |
|
| 63 |
1. Motivation first: |
| 64 |
* Is it related to a problem/frustration with the library? If so, please explain |
| 65 |
why. Providing a code snippet that demonstrates the problem is best. |
| 66 |
* Is it related to something you would need for a project? We'd love to hear |
| 67 |
about it! |
| 68 |
* Is it something you worked on and think could benefit the community? |
| 69 |
Awesome! Tell us what problem it solved for you. |
| 70 |
2. Write a *full paragraph* describing the feature; |
| 71 |
3. Provide a **code snippet** that demonstrates its future use; |
| 72 |
4. In case this is related to a paper, please attach a link; |
| 73 |
5. Attach any additional information (drawings, screenshots, etc.) you think may help. |
| 74 |
|
| 75 |
If your issue is well written we're already 80% of the way there by the time you |
| 76 |
post it. |
| 77 |
|
| 78 |
## Submitting a pull request (PR) |
| 79 |
|
| 80 |
Before writing code, we strongly advise you to search through the existing PRs or |
| 81 |
issues to make sure that nobody is already working on the same thing. If you are |
| 82 |
unsure, it is always a good idea to open an issue to get some feedback. |
| 83 |
|
| 84 |
You will need basic `git` proficiency to be able to contribute to |
| 85 |
🤗 Accelerate. `git` is not the easiest tool to use but it has the greatest |
| 86 |
manual. Type `git --help` in a shell and enjoy. If you prefer books, [Pro |
| 87 |
Git](https://git-scm.com/book/en/v2) is a very good reference. |
| 88 |
|
| 89 |
Follow these steps to start contributing: |
| 90 |
|
| 91 |
1. Fork the [repository](https://github.com/huggingface/accelerate) by |
| 92 |
clicking on the 'Fork' button on the repository's page. This creates a copy of the code |
| 93 |
under your GitHub user account. |
| 94 |
|
| 95 |
2. Clone your fork to your local disk, and add the base repository as a remote. The following command |
| 96 |
assumes you have your public SSH key uploaded to GitHub. See the following guide for more |
| 97 |
[information](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository). |
| 98 |
|
| 99 |
```bash |
| 100 |
$ git clone [email protected]:<your Github handle>/accelerate.git |
| 101 |
$ cd accelerate |
| 102 |
$ git remote add upstream https://github.com/huggingface/accelerate.git |
| 103 |
``` |
| 104 |
|
| 105 |
3. Create a new branch to hold your development changes, and do this for every new PR you work on. |
| 106 |
|
| 107 |
Start by synchronizing your `main` branch with the `upstream/main` branch (ore details in the [GitHub Docs](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork)): |
| 108 |
|
| 109 |
```bash |
| 110 |
$ git checkout main |
| 111 |
$ git fetch upstream |
| 112 |
$ git merge upstream/main |
| 113 |
``` |
| 114 |
|
| 115 |
Once your `main` branch is synchronized, create a new branch from it: |
| 116 |
|
| 117 |
```bash |
| 118 |
$ git checkout -b a-descriptive-name-for-my-changes |
| 119 |
``` |
| 120 |
|
| 121 |
**Do not** work on the `main` branch. |
| 122 |
|
| 123 |
4. Set up a development environment by running the following command in a conda or a virtual environment you've created for working on this library: |
| 124 |
|
| 125 |
```bash |
| 126 |
$ pip install -e ".[dev]" |
| 127 |
``` |
| 128 |
|
| 129 |
This will install all testing and linting/code quality dependencies for the library (see `quality`, `test_dev`, |
| 130 |
`test_prod` targets in [`setup.py`](./setup.py)). |
| 131 |
|
| 132 |
(If accelerate was already installed in the virtual environment, remove |
| 133 |
it with `pip uninstall accelerate` before reinstalling it in editable |
| 134 |
mode with the `-e` flag). |
| 135 |
|
| 136 |
Alternatively, if you are using [Visual Studio Code](https://code.visualstudio.com/Download), the fastest way to get set up is by using |
| 137 |
the provided Dev Container. Documentation on how to get started with dev containers is available [here](https://code.visualstudio.com/docs/remote/containers). |
| 138 |
|
| 139 |
5. Develop the features on your branch. |
| 140 |
|
| 141 |
As you work on the features, you should make sure that the test suite |
| 142 |
passes. You should run the tests impacted by your changes like this (see |
| 143 |
below an explanation regarding the environment variable): |
| 144 |
|
| 145 |
```bash |
| 146 |
$ pytest tests/<TEST_TO_RUN>.py |
| 147 |
``` |
| 148 |
|
| 149 |
> For the following commands leveraging the `make` utility, we recommend using the WSL system when running on |
| 150 |
> Windows. More information [here](https://docs.microsoft.com/en-us/windows/wsl/about). |
| 151 |
|
| 152 |
You can also run the full suite with the following command. |
| 153 |
|
| 154 |
```bash |
| 155 |
$ make test |
| 156 |
``` |
| 157 |
|
| 158 |
`accelerate` relies on `ruff` to format its source code |
| 159 |
consistently. After you make changes, apply automatic style corrections and code verifications |
| 160 |
that can't be automated in one go with: |
| 161 |
|
| 162 |
This target is also optimized to only work with files modified by the PR you're working on. |
| 163 |
|
| 164 |
If you prefer to run the checks one after the other, the following command apply the |
| 165 |
style corrections: |
| 166 |
|
| 167 |
```bash |
| 168 |
$ make style |
| 169 |
``` |
| 170 |
|
| 171 |
`accelerate` also uses a few custom scripts to check for coding mistakes. Quality |
| 172 |
control runs in CI, however you can also run the same checks with: |
| 173 |
|
| 174 |
```bash |
| 175 |
$ make quality |
| 176 |
``` |
| 177 |
|
| 178 |
You can also set up [`pre-commit`](https://pre-commit.com/) to run these checks |
| 179 |
automatically as Git commit hooks. |
| 180 |
|
| 181 |
```bash |
| 182 |
$ pip install pre-commit |
| 183 |
$ pre-commit install |
| 184 |
``` |
| 185 |
|
| 186 |
Once you're happy with your changes, add changed files using `git add` and |
| 187 |
make a commit with `git commit` to record your changes locally: |
| 188 |
|
| 189 |
```bash |
| 190 |
$ git add modified_file.py |
| 191 |
$ git commit |
| 192 |
``` |
| 193 |
|
| 194 |
Please write [good commit messages](https://chris.beams.io/posts/git-commit/). |
| 195 |
|
| 196 |
It is a good idea to sync your copy of the code with the original |
| 197 |
repository regularly. This way you can quickly account for changes: |
| 198 |
|
| 199 |
```bash |
| 200 |
$ git fetch upstream |
| 201 |
$ git rebase upstream/main |
| 202 |
``` |
| 203 |
|
| 204 |
Push the changes to your account using: |
| 205 |
|
| 206 |
```bash |
| 207 |
$ git push -u origin a-descriptive-name-for-my-changes |
| 208 |
``` |
| 209 |
|
| 210 |
6. Once you are satisfied (**and the checklist below is happy too**), go to the |
| 211 |
webpage of your fork on GitHub. Click on 'Pull request' to send your changes |
| 212 |
to the project maintainers for review. |
| 213 |
|
| 214 |
7. It's ok if maintainers ask you for changes. It happens to core contributors |
| 215 |
too! So everyone can see the changes in the Pull request, work in your local |
| 216 |
branch and push the changes to your fork. They will automatically appear in |
| 217 |
the pull request. |
| 218 |
|
| 219 |
|
| 220 |
### Checklist |
| 221 |
|
| 222 |
1. The title of your pull request should be a summary of its contribution; |
| 223 |
2. If your pull request addresses an issue, please mention the issue number in |
| 224 |
the pull request description to make sure they are linked (and people |
| 225 |
consulting the issue know you are working on it); |
| 226 |
3. To indicate a work in progress please prefix the title with `[WIP]`, or mark |
| 227 |
the PR as a draft PR. These are useful to avoid duplicated work, and to differentiate |
| 228 |
it from PRs ready to be merged; |
| 229 |
4. Make sure existing tests pass; |
| 230 |
5. Add high-coverage tests. No quality testing = no merge. |
| 231 |
|
| 232 |
See an example of a good PR here: https://github.com/huggingface/accelerate/pull/255 |
| 233 |
|
| 234 |
### Tests |
| 235 |
|
| 236 |
An extensive test suite is included to test the library behavior and several examples. Library tests can be found in |
| 237 |
the [tests folder](https://github.com/huggingface/accelerate/tree/main/tests). |
| 238 |
|
| 239 |
We use `pytest` in order to run the tests. From the root of the |
| 240 |
repository, here's how to run tests with `pytest` for the library: |
| 241 |
|
| 242 |
```bash |
| 243 |
$ python -m pytest -sv ./tests |
| 244 |
``` |
| 245 |
|
| 246 |
In fact, that's how `make test` is implemented (sans the `pip install` line)! |
| 247 |
|
| 248 |
You can specify a smaller set of tests in order to test only the feature |
| 249 |
you're working on. |