|
| 1 | +## Torchvision maintainers guide |
| 2 | + |
| 3 | +This document aims at documenting user-facing policies / principles used when |
| 4 | +developing and maintaining torchvision. Other maintainer info (e.g. release |
| 5 | +process) can be found in the meta-internal wiki. |
| 6 | + |
| 7 | +### What is public and what is private? |
| 8 | + |
| 9 | +For the Python API, torchvision largely follows the [PyTorch |
| 10 | +policy](https://github.com/pytorch/pytorch/wiki/Public-API-definition-and-documentation) |
| 11 | +which is consistent with other major packages |
| 12 | +([numpy](https://numpy.org/neps/nep-0023-backwards-compatibility.html), |
| 13 | +[scikit-learn](https://scikit-learn.org/dev/glossary.html#term-API) etc.). |
| 14 | +We recognize that his policy is somewhat imperfect for some edge cases, and that |
| 15 | +it's difficult to come up with an accurate technical definition. In broad terms, |
| 16 | +which are usually well understood by users, the policy is that: |
| 17 | + |
| 18 | +- modules that can be accessed without leading underscore are public |
| 19 | +- objects in a public file that don't have a leading underscore are public |
| 20 | +- class attributes are public iff they have no leading underscore |
| 21 | +- the rest of the modules / objects / class attributes are considered private |
| 22 | + |
| 23 | +The public API has backward-compatible (BC) guarantees defined in our |
| 24 | +deprecation policy (see below). The private API has not BC guarantees. |
| 25 | + |
| 26 | +For C++, code is private. For Meta employees: if a C++ change breaks fbcode, fix |
| 27 | +fbcode or revert the change. We should be careful about models running in |
| 28 | +production and relying on torchvision ops. |
| 29 | + |
| 30 | +The `test` folder is not importable and is **private.** Even meta-internal |
| 31 | +projects should *not* rely on it (it has happened in the past and is now |
| 32 | +programmatically impossible). |
| 33 | + |
| 34 | +The training references do not have BC guarantees. Breaking changes are |
| 35 | +possible, but we should make sure that the tutorials are still running properly, |
| 36 | +and that their intended narrative is preserved (by e.g. checking outputs, |
| 37 | +etc.). |
| 38 | + |
| 39 | +The rest of the folders (build, android, ios, etc.) are private and have no BC |
| 40 | +guarantees. |
| 41 | + |
| 42 | +### Deprecation policy. |
| 43 | + |
| 44 | +Because they're disruptive, **deprecations should only be used sparingly**. |
| 45 | + |
| 46 | +We largely follow the [PyTorch |
| 47 | +policy](https://github.com/pytorch/pytorch/wiki/PyTorch's-Python-Frontend-Backward-and-Forward-Compatibility-Policy): |
| 48 | +breaking changes require a deprecation period of at least 2 versions. |
| 49 | + |
| 50 | +Deprecations should clearly indicate their deadline in the docs and warning |
| 51 | +messages. Avoid not committing to a deadline, or keeping deprecated APIs for too |
| 52 | +long: it gives no incentive for users to update their code, sends conflicting |
| 53 | +messages ("why was this API removed while this other one is still around?"), and |
| 54 | +accumulates debt in the project. |
| 55 | + |
| 56 | +### Should this attribute be public? Should this function be private? |
| 57 | + |
| 58 | +When designing an API it’s not always obvious what should be exposed as public, |
| 59 | +and what should be kept as a private implementation detail. The following |
| 60 | +guidelines can be useful: |
| 61 | + |
| 62 | +* Functional consistency throughout the library is a top priority, for users and |
| 63 | + developers’ sake. In doubt and unless it’s clearly wrong, expose what other |
| 64 | + similar classes expose. |
| 65 | +* Think really hard about the users and their use-cases, and try to expose what |
| 66 | + they would need to address those use-cases. Aggressively keep everything else |
| 67 | + private. Remember that the “private -> public” direction is way smoother than |
| 68 | + the “public -> private” one: in doubt, keep it private. |
| 69 | +* When thinking about use-cases, the general API motto applies: make what’s |
| 70 | + simple and common easy, and make what’s complex possible (80% / 20% rule). |
| 71 | + There might be a ~1% left that’s not addressed: that’s OK. Also, **make what’s |
| 72 | + wrong very hard**, if not impossible. |
| 73 | + |
| 74 | +As a good practice, always create new files and even classes with a leading |
| 75 | +underscore in their name. This way, everything is private by default and the |
| 76 | +only public surface is explicitly present in an `__init__.py` file. |
0 commit comments