|
| 1 | +# Online Reproducibility |
| 2 | + |
| 3 | +## Add new secret PERSONAL_GITHUB_TOKEN. |
| 4 | + |
| 5 | +- Create a personal access token |
| 6 | + |
| 7 | +https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token |
| 8 | + |
| 9 | +- Create a new secret and name it `PERSONAL_GITHUB_TOKEN` |
| 10 | + |
| 11 | +## Grant GitHub access to DVC Remote |
| 12 | + |
| 13 | +You need to grant GitHub access to the DVC Remote. |
| 14 | + |
| 15 | +Get the credentials. |
| 16 | + |
| 17 | +```bash |
| 18 | +cat ".dvc/tmp/gdrive-user-credentials.json" |
| 19 | +``` |
| 20 | + |
| 21 | +And create a new GitHub secret called `GDRIVE_CREDENTIALS_DATA` to store them. |
| 22 | + |
| 23 | +With this, GitHub runners will be able to pull and push all the changes generated by the pipeline. |
| 24 | + |
| 25 | +## Pull Request workflow |
| 26 | + |
| 27 | +You can create a new *GitHub actions workflow* that runs when a new Pull Request is created. |
| 28 | + |
| 29 | +This workflow will use `DVC` to reproduce the pipeline and update the large artifacts tracked by DVC. |
| 30 | + |
| 31 | +In addition it will use `CML` to post a **report** with the `DVC` metrics, params, and plots ([cml send-comment](https://cml.dev/doc/ref/send-comment)). It will also update the artifacts tracked by Git ([cml pr](https://cml.dev/doc/ref/pr)) |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +<details> |
| 38 | +<summary>Create and fill `.github/workflows/on_pr.yml`</summary> |
| 39 | + |
| 40 | +```yaml |
| 41 | +name: DVC & CML Workflow |
| 42 | + |
| 43 | +on: |
| 44 | + pull_request: |
| 45 | + |
| 46 | + # Allows you to run this workflow manually from the Actions tab |
| 47 | + workflow_dispatch: |
| 48 | + |
| 49 | +jobs: |
| 50 | + build: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + container: docker://ghcr.io/iterative/cml:latest |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v2 |
| 56 | + with: |
| 57 | + fetch-depth: 0 |
| 58 | + |
| 59 | + - name: Setup |
| 60 | + run: | |
| 61 | + pip install -r requirements.txt |
| 62 | +
|
| 63 | + - name: Run DVC pipeline |
| 64 | + env: |
| 65 | + GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }} |
| 66 | + GDRIVE_CREDENTIALS_DATA: ${{ secrets.GDRIVE_CREDENTIALS_DATA }} |
| 67 | + run: | |
| 68 | + dvc repro --pull |
| 69 | +
|
| 70 | + - name: Share changes |
| 71 | + env: |
| 72 | + GDRIVE_CREDENTIALS_DATA: ${{ secrets.GDRIVE_CREDENTIALS_DATA }} |
| 73 | + run: | |
| 74 | + dvc push |
| 75 | +
|
| 76 | + - name: Create a P.R. with CML |
| 77 | + env: |
| 78 | + REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + run: | |
| 80 | + cml pr --auto-merge "dvc.lock" "outs/*.json" "outs/eval" "outs/train_metrics" |
| 81 | +
|
| 82 | + - name: CML Report |
| 83 | + env: |
| 84 | + REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + run: | |
| 86 | + echo "## Metrics & Params" >> report.md |
| 87 | +
|
| 88 | + dvc exp diff main --show-md >> report.md |
| 89 | + cml send-comment --pr --update report.md |
| 90 | + |
| 91 | + echo "## Plots" >> report.md |
| 92 | +
|
| 93 | + echo "### Eval Loss" >> report.md |
| 94 | + dvc plots diff \ |
| 95 | + --target outs/train_metrics/scalars/eval_loss.tsv --show-vega main > vega.json |
| 96 | + vl2png vega.json -s 1.5 | cml-publish --md >> report.md |
| 97 | +
|
| 98 | + echo "### Eval Accuracy" >> report.md |
| 99 | + dvc plots diff \ |
| 100 | + --target outs/train_metrics/scalars/eval_accuracy.tsv --show-vega main > vega.json |
| 101 | + vl2png vega.json -s 1.5 | cml-publish --md >> report.md |
| 102 | +
|
| 103 | + echo "### Confusion Matrix" >> report.md |
| 104 | + dvc plots diff \ |
| 105 | + --target outs/eval/plots/confusion_matrix.json --show-vega main > vega.json |
| 106 | + vl2png vega.json -s 1.5 | cml-publish --md >> report.md |
| 107 | +
|
| 108 | + cml send-comment --pr --update report.md |
| 109 | +``` |
| 110 | +</details> |
| 111 | +
|
| 112 | +## Reproduce Online |
| 113 | +
|
| 114 | +And now you can reproduce the pipeline from the web: |
| 115 | +
|
| 116 | +### From GitHub UI |
| 117 | +
|
| 118 | +- Edit `params.yaml` from the GitHub Interface. |
| 119 | + |
| 120 | +- Change `train.epochs`. |
| 121 | + |
| 122 | +- Select `Create a new branch for this commit and start a pull request` |
| 123 | + |
| 124 | +### From Studio |
| 125 | + |
| 126 | +- Go to https://studio.iterative.ai (It's free) |
| 127 | +- Connect your GitHub account. |
| 128 | +- Add a new view. |
| 129 | + |
| 130 | +> More info: https://dvc.org/doc/studio |
| 131 | + |
| 132 | +- Click on `Run new experiment` button. |
| 133 | + |
| 134 | +## More compute |
| 135 | + |
| 136 | +In the above workflow we are using the default GitHub runners to train our model. |
| 137 | + |
| 138 | +While this is enough for our use case (small dataset, small model), your project would often require more compute resources. |
| 139 | + |
| 140 | +[CML Self-Hosted Runners](https://cml.dev/doc/self-hosted-runners) allows you to allocate cloud instances (or on-premise machines) and use them in your GitHub actions workflow. |
0 commit comments