|
| 1 | +# Week 2 home assignment |
| 2 | + |
| 3 | +This assignment consists of 4 parts: you can earn the full amount of points by completing the first two and either of |
| 4 | +tasks 3 and 4 (or both of them for bonus points). |
| 5 | +However, completing tasks 3 or 4 without the first two will not give you any points. |
| 6 | + |
| 7 | +# Problem statement |
| 8 | +You are given a small codebase that should train an **unconditional** [Denoising Diffusion Probabilistic Model](https://arxiv.org/abs/2006.11239) |
| 9 | +on the CIFAR-10 dataset. |
| 10 | +However, this project contains several bugs of different severity, and even some of the tests are written incorrectly. |
| 11 | +A correct implementation will achieve *somewhat* decent results after training for 100 epochs (~2 hours on an average GPU), |
| 12 | +but you should not expect much in terms of quality. |
| 13 | +In this homework, we are going to have a deeper look at the training pipeline, try to fix any errors we find and make |
| 14 | +the code more reliable and reproducible. |
| 15 | + |
| 16 | +# Task 1 (6.5 points) |
| 17 | +Implement *correct* tests for the training pipeline. |
| 18 | +Specifically, have a look at the current [tests](./tests) folder: it contains several files with tests, |
| 19 | +some of which fail, fail sometimes or are plainly incorrect. |
| 20 | +Your task is to identify the bugs and make the test suite pass deterministically: this will involve changes |
| 21 | +both to `modeling` and to `tests`, as some parts of the testing code need to be modified as well. |
| 22 | + |
| 23 | +In your report, please tell us how you found the bugs in all parts of the code. |
| 24 | +You can find the original implementation of DDPM that we use in this assignment, but giving it as an explanation for |
| 25 | +your fixes will give you no points. |
| 26 | +Obviously, "solving" the assignment by removing all tests or having unreasonably high thresholds will not earn |
| 27 | +you a good grade as well. |
| 28 | + |
| 29 | +After that, implement the `test_training` function in `test_pipeline.py` that runs an integration test for the |
| 30 | +entire training procedure with different hyperparameters and expects different outcomes. |
| 31 | +This test should increase the coverage of the `modeling.training` file (measured by [pytest-cov](https://github.com/pytest-dev/pytest-cov)) to **>80%**. |
| 32 | + |
| 33 | +Importantly, you should ensure that your test code running the actual model can run both on CPU and GPU. |
| 34 | +Since training on CPU even for 1 epoch might take too long, you need to implement training on a subset of data. |
| 35 | + |
| 36 | + |
| 37 | +# Task 2 (1.5 points) |
| 38 | +Implement logging of the metrics and artifacts during training with [Weights and Biases](https://wandb.ai/site). |
| 39 | +You should log the following values: |
| 40 | +* Training loss and the learning rate |
| 41 | +* All training hyperparameters (including batch size, number of epochs etc., as well as all model and diffusion hyperparameters) |
| 42 | +* Inputs to the model (1 batch is enough) and samples from it after each epoch |
| 43 | + |
| 44 | +However, you should **NOT** log the training code for the model. |
| 45 | + |
| 46 | +Logging the hyperparameters and metrics will likely involve some refactoring of the original codebase. |
| 47 | +You can either place the necessary hyperparameters in a config file or simply have them as constants/argparse defaults |
| 48 | +defined somewhere reasonable in the training code. |
| 49 | + |
| 50 | +After finishing this task, train the model for at least 100 epochs with default hyperparameters and attach the link to |
| 51 | +your W&B project containing this run to the final report. |
| 52 | + |
| 53 | +# Task 3 (2 points) |
| 54 | +Improve the configuration process of this pipeline using the [Hydra](https://hydra.cc/) library. |
| 55 | +You should create a config that allows adjusting at least the following attributes: |
| 56 | +* Peak learning rate and optimizer momentum |
| 57 | +* Optimizer (Adam by default, at least SGD should be supported) |
| 58 | +* Training batch size and the number of epochs |
| 59 | +* Number of workers in the dataloader |
| 60 | +* Existence of random flip augmentations |
| 61 | + |
| 62 | +Demonstrate that your integration works by running at least three *complete* runs (less than 100 epochs is OK) |
| 63 | +with hyperparameters changed via the config file. |
| 64 | +From these runs, it should be evident that changing hyperparameters affects the training procedure. |
| 65 | +Here, you should log the config using [run.log_artifact](https://docs.wandb.ai/ref/python/run#log_artifact) |
| 66 | +and show that this changes the hyperparameters of the run in W&B. |
| 67 | + |
| 68 | +# Task 4 (2 points) |
| 69 | +Make the pipeline reproducible using [Data Version Control](https://dvc.org/). |
| 70 | +You should end up with a `dvc.yaml` that represents two stages of your experiment with corresponding inputs and outputs: |
| 71 | +getting the data (yes, you need to refactor that part of the code) and training the model itself. |
| 72 | +Also, you should specify the relevant code and configuration as dependencies of the corresponding pipeline stages. |
| 73 | +Lastly, after running your code, you should have a `dvc.lock` that stores hashes of all artifacts in your pipeline. |
| 74 | +Submit both `dvc.yaml` and `dvc.lock` as parts of your solution. |
| 75 | + |
| 76 | +Importantly, modifying any of the relevant modules or hyperparameters should trigger an invalidation of the |
| 77 | +corresponding pipeline stages: that is, `dvc repro` should do nothing if and only if `dvc.lock` is consistent with |
| 78 | +hashes of all dependencies in the pipeline. |
| 79 | + |
| 80 | +If you have also done the Hydra configuration assignment, make sure to check out [this guide](https://dvc.org/doc/user-guide/experiment-management/hydra-composition) |
| 81 | +on integrating Hydra with DVC experiment management. |
| 82 | + |
| 83 | +# Submission format |
| 84 | +When submitting this assignment, you should attach a .zip archive that contains: |
| 85 | +- The source code with all your fixes and improvements |
| 86 | +- A Markdown/PDF report in the root of the project folder that: |
| 87 | + 1. Details the changes you made to the original code (we will run `diff` and see if everything is explained) |
| 88 | + 2. Tells how to run the modified code (i.e., which command line arguments you have added and how to use them) |
| 89 | + 3. Describes your process of fixing and adding new tests for Task 1 and reports the test coverage |
| 90 | + 4. Gives a link to the Weights and Biases project with all necessary logs for tasks 2 and 3 |
| 91 | +- If you solved Tasks 3 or 4, please ensure that the archived project contains the corresponding configuration/lock files as well. |
| 92 | +- An updated `requirements.txt` file, if your solution requires new dependencies such as `wandb`, `hydra-core` or `dvc`. |
0 commit comments