diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7920e8b44a8..a38b0ad6051 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,8 +4,6 @@ - [Contributing to PyTorch](#contributing-to-pytorch) - [Developing PyTorch](#developing-pytorch) - - [Prerequisites](#prerequisites) - - [Instructions](#instructions) - [Tips and Debugging](#tips-and-debugging) - [Nightly Checkout & Pull](#nightly-checkout--pull) - [Codebase structure](#codebase-structure) @@ -79,73 +77,37 @@ to PyTorch. For more non-technical guidance about how to contribute to PyTorch, see the [Contributing Guide](docs/source/community/contribution_guide.rst). ## Developing PyTorch - -A full set of instructions on installing PyTorch from source is here: -https://github.com/pytorch/pytorch#from-source - -To develop PyTorch on your machine, here are some tips: - -### Prerequisites -* CMake. You can install it via `pip install cmake` -* Python >= 3.7 (3.7.6+ recommended) - -### Instructions -_**Note**: If you get stuck at any step, check out the [tips and debugging](#tips-and-debugging) section below for common solutions_ - -1. Uninstall all existing PyTorch installs. You may need to run `pip -uninstall torch` multiple times. You'll know `torch` is fully -uninstalled when you see `WARNING: Skipping torch as it is not -installed`. (You should only have to `pip uninstall` a few times, but -you can always `uninstall` with `timeout` or in a loop if you're feeling -lazy.) - -```bash -conda uninstall pytorch -y -yes | pip uninstall torch -``` - -2. Clone a copy of PyTorch from source: - -```bash -git clone https://github.com/pytorch/pytorch -cd pytorch -``` - -If you already have PyTorch from source, update it: - -```bash -git pull --rebase -git submodule sync --recursive -git submodule update --init --recursive -``` - -If you want to have no-op incremental rebuilds (which are fast), see [Make no-op build fast](#make-no-op-build-fast) below. - -3. Follow the instructions for [installing PyTorch from source](https://github.com/pytorch/pytorch#from-source), but instead of installing PyTorch via `python setup.py install`, use `python setup.py develop`. - -This mode will symlink the Python files from the current local source -tree into the Python install. This way when you modify a Python file, you -won't need to reinstall PyTorch again and again. This is especially -useful if you are only changing Python files. - -For example: -- Install local PyTorch in `develop` mode -- modify your Python file `torch/__init__.py` (for example) -- test functionality - -You do not need to repeatedly install after modifying Python files (`.py`). However, you would need to reinstall -if you modify Python interface (`.pyi`, `.pyi.in`) or non-Python files (`.cpp`, `.cc`, `.cu`, `.h`, ...). - -In case you want to reinstall, make sure that you uninstall PyTorch -first by running `pip uninstall torch` until you see `WARNING: Skipping -torch as it is not installed`; next run `python setup.py clean`. After -that, you can install in `develop` mode again. +Follow the instructions for [installing PyTorch from source](https://github.com/pytorch/pytorch#from-source). If you get stuck when developing PyTorch on your machine, check out the [tips and debugging](#tips-and-debugging) section below for common solutions. ### Tips and Debugging + +* If you want to have no-op incremental rebuilds (which are fast), see [Make no-op build fast](#make-no-op-build-fast) below. + +* When installing with `python setup.py develop` (in contrast to `python setup.py install`) you will symlink + the Python files from the current local source-tree into the Python install. + This way you do not need to repeatedly install after modifying Python files (`.py`). + However, you would need to reinstall if you modify Python interface (`.pyi`, `.pyi.in`) or + non-Python files (`.cpp`, `.cc`, `.cu`, `.h`, ...). + + To reinstall, first uninstall all existing PyTorch installs. You may need to run `pip + uninstall torch` multiple times. You'll know `torch` is fully + uninstalled when you see `WARNING: Skipping torch as it is not + installed`. (You should only have to `pip uninstall` a few times, but + you can always `uninstall` with `timeout` or in a loop if you're feeling + lazy.) + + ```bash + conda uninstall pytorch -y + yes | pip uninstall torch + ``` + + Next run `python setup.py clean`. After that, you can install in `develop` mode again. + * If a commit is simple and doesn't affect any code (keep in mind that some docstrings contain code that is used in tests), you can add `[skip ci]` (case sensitive) somewhere in your commit message to [skip all build / test steps](https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/). Note that changing the pull request body or title on GitHub itself has no effect. + * If you run into errors when running `python setup.py develop`, here are some debugging steps: 1. Run `printf '#include \nint main() { printf("Hello World");}'|clang -x c -; ./a.out` to make sure your CMake works and can compile this simple Hello World program without errors. @@ -154,18 +116,19 @@ that, you can install in `develop` mode again. `rm -rf build` from the toplevel `pytorch` directory and start over. 3. If you have made edits to the PyTorch repo, commit any change you'd like to keep and clean the repo with the following commands (note that clean _really_ removes all untracked files and changes.): - ```bash - git submodule deinit -f . - git clean -xdf - python setup.py clean - git submodule update --init --recursive # very important to sync the submodules - python setup.py develop # then try running the command again - ``` + ```bash + git submodule deinit -f . + git clean -xdf + python setup.py clean + git submodule update --init --recursive # very important to sync the submodules + python setup.py develop # then try running the command again + ``` 4. The main step within `python setup.py develop` is running `make` from the `build` directory. If you want to - experiment with some environment variables, you can pass them into the command: - ```bash - ENV_KEY1=ENV_VAL1[, ENV_KEY2=ENV_VAL2]* python setup.py develop - ``` + experiment with some environment variables, you can pass them into the command: + ```bash + ENV_KEY1=ENV_VAL1[, ENV_KEY2=ENV_VAL2]* python setup.py develop + ``` + * If you run into issue running `git submodule update --init --recursive`. Please try the following: - If you encounter an error such as ```