opensi·si

We are happy to accept contributions to PEFT. If you plan to contribute, please read this to make the process as smooth as possible.

Contribute to PEFT

We are happy to accept contributions to PEFT. If you plan to contribute, please read this to make the process as smooth as possible.

Discuss and obtain approval before opening a PR

Before opening a pull request (including a draft), open or find an issue in huggingface/peft and discuss your proposed contribution. If there is an existing issue and someone is already working on it, has declared their intent to work on it, or has an open PR, you should not submit a separate PR. Wait for a PEFT maintainer or Hugging Face member to explicitly approve the proposal. If you open an issue, keep the length and complexity of the description in proportion with the complexity of the issue. Often, a short description with a reproducer is more valuable than a long description.

An approval comment contains the message /peft-triage approved. It may additionally state the assigned contributor's name, for example /peft-triage approved username or /peft-triage approved @username. Opening a PR for an issue you're not assigned to will lead to closure of said PR.

Link the approved, open issue in your PR description using #123, huggingface/peft#123, or ``. As an exception, maintainers may designate specific long-running discussions that can be referenced by their full GitHub URL without a separate approval comment. If you reference several issues or discussions, one valid reference is sufficient.

An automated workflow checks PRs for approved open issues or discussions. PRs without a valid reference are automatically closed with an explanation. You can obtain issue approval, update the PR description, and reopen the same PR; please do not create a replacement. If you believe your PR was closed incorrectly, ping the maintainers on the PR.

The independent stale bot can still close inactive items, even if labeled as triaged. If you feel like the maintainers have overlooked your contribution, you may ping them, but not earlier than before two weeks of inactivity.

Installation

Follow these steps to start contributing:

  1. 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.

  2. Clone your fork to your local disk, and add the base repository as a remote. The following command assumes you have your public SSH key uploaded to GitHub. See the following guide for more information.

    git clone git@github.com:<your Github handle>/peft.git
    cd peft
    git remote add upstream https://github.com/huggingface/peft.git
  3. Create a new branch to hold your development changes, and do this for every new PR you work on.

    Start by synchronizing your main branch with the upstream/main branch (more details in the GitHub Docs):

    git checkout main
    git fetch upstream
    git merge upstream/main

    Once your main branch is synchronized, create a new branch from it:

    git checkout -b a-descriptive-name-for-my-changes

    Do not work on the main branch.

  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:

    pip install -e ".[test]"

    (If PEFT was already installed in the virtual environment, remove it with pip uninstall peft before reinstalling it.)

If you are new to creating a pull request, follow the Creating a pull request guide by GitHub.

Tests and code quality checks

Regardless of the contribution type (unless it’s only about the docs), you should run tests and code quality checks before creating a PR to ensure your contribution doesn’t break anything and follows the project standards.

Running test and checks

We provide a Makefile to execute the necessary tests. Run the code below for the unit test:

make test

Run one of the following to either only check or check and fix code quality and style:

make quality  # just check
make style  # check and fix

Running make quality will also check if all methods/classes from PEFT's public API (i.e. everything that's mentioned in peft.__all__) are mentioned in the docs. These errors cannot be fixed by make style, you need to make sure to document new items in the public API in the docs to fix this error.

You can also set up pre-commit to run these fixes automatically as Git commit hooks.

$ pip install pre-commit
$ pre-commit install

Running all the tests can take a while, so during development it can be more efficient to only run tests specific to your change, e.g. via:

pytest tests/<test-file-name> -k <name-of-test>

This should finish much quicker and allow for faster iteration.

Adding tests

For a general guide on adding new tests, check tests/README.md.

If your change is specific to a hardware setting (e.g., it requires CUDA), take a look at tests/test_gpu_examples.py and tests/test_common_gpu.py to see if it makes sense to add tests there. If your change could have an effect on saving and loading models, please run the tests with the --regression flag to trigger regression tests.

Stale PRs

It can happen that while you’re working on your PR, the underlying code base changes due to other changes being merged. If that happens – especially when there is a merge conflict – please update your branch with the latest changes. This can be a merge or a rebase, and we'll squash and merge the PR once it’s ready. Avoid force pushes to make reviews easier.

PR description

When opening a PR, please provide a nice description of the change you're proposing and reference the approved issue as described above. If it relates to other issues or PRs, please reference them as well. Providing a good description not only helps the reviewers review your code better and faster, it can also be used later (as a basis) for the commit message which helps with long term maintenance of the project.

Keep the length and complexity of the PR description in line with the change. We don't need ten paragraphs of explanation for a trivial one-line change. Don't restate what is obvious from looking at the diff (e.g. "Fixed the typo in 'foobaar').

If your code makes some non-trivial changes, it may also be a good idea to add comments to the code to explain those changes. For example, if you had to iterate on your implementation multiple times because the most obvious way didn’t work, it’s a good indication that a code comment is needed.

If relevant, indicate how you tested the change, e.g. by showing the pytest test command or reproducer code.

Reviewer feedback

After submitting your PR, a maintainer will typically give feedback within a couple of days. If you don't get any feedback within two weeks, your PR might have slipped their notice; feel free to ping the maintainers then, but no earlier.

If the reviewer provides in-line comments, don't mark them as resolved if you addressed them. Leave these comments open, as they are helping the reviewer to resume their work.

After working through reviewer feedback, ping the reviewer so that they know the PR is ready to review.

Bugfixes

Please give a description of the circumstances that led to the bug. If there is an existing issue, please link to it (e.g., “Resolves #12345”).

Ideally when a bugfix is provided, it should be accompanied by a test for the bug. The test should fail with the current code and pass with the bugfix. Add a comment to the test that references the issue or PR. Without a test, it is more difficult to prevent regressions in the future.