Skip to content

Model contrib guidelines #5315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
31fadbe
Adding multiweight support for shufflenetv2 prototype models
jdsgomes Oct 29, 2021
1e578b7
Revert "Adding multiweight support for shufflenetv2 prototype models"
jdsgomes Oct 29, 2021
85e4429
Merge branch 'pytorch:main' into main
jdsgomes Oct 29, 2021
4e3d900
Adding multiweight support for shufflenetv2 prototype models
jdsgomes Oct 29, 2021
615b612
Revert "Adding multiweight support for shufflenetv2 prototype models"
jdsgomes Oct 29, 2021
a0bbece
Merge branch 'pytorch:main' into main
jdsgomes Oct 31, 2021
ba966f4
Merge branch 'pytorch:main' into main
jdsgomes Nov 1, 2021
6cdd49b
Merge branch 'pytorch:main' into main
jdsgomes Dec 10, 2021
d4f1638
Merge branch 'pytorch:main' into main
jdsgomes Dec 17, 2021
8626002
Merge branch 'pytorch:main' into main
jdsgomes Jan 24, 2022
f18f86f
Remove module vs method name clash
jdsgomes Jan 24, 2022
5c3668f
Merge branch 'main' into fix-giou-naming-bug
jdsgomes Jan 24, 2022
977414f
Merge branch 'pytorch:main' into main
jdsgomes Jan 26, 2022
67e95d2
Merge branch 'pytorch:main' into main
jdsgomes Jan 28, 2022
95f1271
add model contribution guidelines
jdsgomes Jan 29, 2022
1f79d42
update CONTRIBUTING_MODELS.md
jdsgomes Jan 29, 2022
2592c8d
Merge branch 'main' into model-contrib-guidelines
jdsgomes Jan 29, 2022
d8ab592
Fix formatting and typo
jdsgomes Jan 29, 2022
480683d
fix in-document links
jdsgomes Jan 29, 2022
9a3de4a
Merge branch 'main' into model-contrib-guidelines
jdsgomes Jan 29, 2022
74b5219
Update CONTRIBUTING.md
jdsgomes Jan 30, 2022
e06c180
remove Implementation Details section
jdsgomes Jan 31, 2022
8df96a9
Merge branch 'main' into model-contrib-guidelines
jdsgomes Feb 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ You can also choose to only build a subset of the examples by using the
example ``EXAMPLES_PATTERN="transforms" make html`` will only build the examples
with "transforms" in their name.

### New model
### New architecture or improved model weights

More details on how to add a new model will be provided later. Please, do not send any PR with a new model without discussing
it in an issue as, most likely, it will not be accepted.
Please refer to the guidelines in [Contributing to Torchvision - Models](https://github.com/pytorch/vision/blob/main/CONTRIBUTING_MODELS.md).

### New dataset

Expand Down
65 changes: 65 additions & 0 deletions CONTRIBUTING_MODELS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Contributing to Torchvision - Models

- [New Model Architectures - Overview](#new-model-architectures---overview)

- [New Weights for Existing Model Architectures](#new-weights-for-existing-model-architectures)

## New Model Architectures - Overview

For someone who would be interested in adding a model architecture, it is also expected to train the model, so here are a few important considerations:

- Training big models requires lots of resources and the cost quickly adds up

- Reproducing models is fun but also risky as you might not always get the results reported on the paper. It might require a huge amount of effort to close the gap

- The contribution might not get merged if we significantly lack in terms of accuracy, speed etc

- Including new models in TorchVision might not be the best approach, so other options such as releasing the model through to [Pytorch Hub](https://pytorch.org/hub/) should be considered

So, before starting any work and submitting a PR there are a few critical things that need to be taken into account in order to make sure the planned contribution is within the context of TorchVision, and the requirements and expectations are discussed beforehand. If this step is skipped and a PR is submitted without prior discussion it will almost certainly be rejected.

### 1. Preparation work

- Start by looking into this [issue](https://github.com/pytorch/vision/issues/2707) in order to have an idea of the models that are being considered, express your willingness to add a new model and discuss with the community whether or not this model should be included in TorchVision. It is very important at this stage to make sure that there is an agreement on the value of having this model in TorchVision and there is no one else already working on it.

- If the decision is to include the new model, then please create a new ticket which will be used for all design and implementation discussions prior to the PR. One of the TorchVision maintainers will reach out at this stage and this will be your POC from this point onwards in order to provide support, guidance and regular feedback.

### 2. Implement the model

Please take a look at existing models in TorchVision to get familiar with the idioms. Also please look at recent contributions for new models. If in doubt about any design decisions you can ask for feedback on the issue created in step 1. Example of things to take into account:

- The implementation should be as close as possible to the canonical implementation/paper
- The PR must include the code implementation, documentation and tests
- It should also extend the existing reference scripts used to train the model
- The weights need to reproduce closely the results of the paper in terms of accuracy, even though the final weights to be deployed will be those trained by the TorchVision maintainers
- The PR description should include commands/configuration used to train the model, so that the TorchVision maintainers can easily run them to verify the implementation and generate the final model to be released
- Make sure we re-use existing components as much as possible (inheritance)
- New primitives (transforms, losses, etc) can be added if necessary, but the final location will be determined after discussion with the dedicated maintainer
- Please take a look at the detailed [implementation and documentation guidelines](https://github.com/pytorch/vision/issues/5319) for a fine grain list of things not to be missed

### 3. Train the model with reference scripts

To validate the new model against the common benchmark, as well as to generate pre-trained weights, you must use TorchVision’s reference scripts to train the model.

Make sure all logs and a final (or best) checkpoint are saved, because it is expected that a submission shows that a model has been successfully trained and the results are in line with the original paper/repository. This will allow the reviewers to quickly check the validity of the submission, but please note that the final model to be released will be re-trained by the maintainers in order to verify reproducibility, ensure that the changes occurred during the PR review did not introduce any bugs, and to avoid moving around a large amount of data (including all checkpoints and logs).

### 4. Submit a PR

Submit a PR and tag the assigned maintainer. This PR should:

- Link the original ticket
- Provide a link for the original paper and the original repository if available
- Highlight the important test metrics and how they compare to the original paper
- Highlight any design choices that deviate from the original paper/implementation and rationale for these choices

## New Weights for Existing Model Architectures

The process of improving existing models, for instance improving accuracy by retraining the model with a different set of hyperparameters or augmentations, is the following:

1. Open a ticket and discuss with the community and maintainers whether this improvement should be added to TorchVision. Note that to add new weights the improvement should be significant.

2. Train the model using TorchVision reference scripts. You can add new primitives (transforms, losses, etc) when necessary, but the final location will be determined after discussion with the dedicated maintainer.

3. Open a PR with the new weights, together with the training logs and the checkpoint chosen so the reviewers can verify the submission. Details on how the model was trained, i.e., the training command using the reference scripts, should be included in the PR.

4. The PR reviewers should replicate the results on their side to verify the submission and if all goes well the new weights should be ready to be released!