Skip to content

Commit

Permalink
formatting in logging
Browse files Browse the repository at this point in the history
  • Loading branch information
SkafteNicki committed Nov 6, 2023
1 parent 944153e commit 3ac906e
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions s4_debugging_and_logging/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,46 @@ collaboration and sharing of results.
## ❔ Exercises

1. Start by creating an account at [wandb](https://wandb.ai/site). I recommend using your github account but feel
free to choose what you want. When you are logged in you should get an API key of length 40. Copy this for later
use (HINT: if you forgot to copy the API key, you can find it under settings).
free to choose what you want. When you are logged in you should get an API key of length 40. Copy this for later
use (HINT: if you forgot to copy the API key, you can find it under settings).

2. Next install wandb on your laptop

```bash
pip install wandb
```
```bash
pip install wandb
```

3. Now connect to your wandb account

```bash
wandb login
```
```bash
wandb login
```

you will be asked to provide the 40 length API key. The connection should be remain open to the wandb server
even when you close the terminal, such that you do not have to login each time. If using `wandb` in a notebook
you need to manually close the connection using `wandb.finish()`.
you will be asked to provide the 40 length API key. The connection should be remain open to the wandb server
even when you close the terminal, such that you do not have to login each time. If using `wandb` in a notebook
you need to manually close the connection using `wandb.finish()`.
4. With it all setup we are now ready to incorporate `wandb` into our code. The interface is fairly simple, and
this [guide](https://docs.wandb.ai/guides/integrations/pytorch) should give enough hints to get you through
the exercise. (HINT: the two methods you need to call are `wandb.init` and `wandb.log`). To start with, logging
the training loss of your model will be enough.
this [guide](https://docs.wandb.ai/guides/integrations/pytorch) should give enough hints to get you through
the exercise. (HINT: the two methods you need to call are `wandb.init` and `wandb.log`). To start with, logging
the training loss of your model will be enough.
5. After running your model, checkout the webpage. Hopefully you should be able to see at least one run with something
logged.
logged.
6. Now log something else than scalar values. This could be a image, a histogram or a matplotlib figure. In all
cases the logging is still going to use `wandb.log` but you need extra calls to `wandb.Image` etc. depending
on what you choose to log.
cases the logging is still going to use `wandb.log` but you need extra calls to `wandb.Image` etc. depending
on what you choose to log.
7. Finally, lets create a report that you can share. Click the **Create report** button and include some of the
graphs/plots/images that you have generated in the report.
graphs/plots/images that you have generated in the report.
8. To make sure that you have completed todays exercises, make the report shareable by clicking the *Share* button
and create *view-only-link*. Send the link to my email `[email protected]`, so I can checkout your awesome work 😃
and create *view-only-link*. Send the link to my email `[email protected]`, so I can checkout your awesome work 😃
9. When calling `wandb.init` you have two arguments called `project` and `entity`. Make sure that you understand these
and try them out. It will come in handy for your group work as they essentially allows multiple users to upload their
own runs to the same project in `wandb`.
and try them out. It will come in handy for your group work as they essentially allows multiple users to upload their
own runs to the same project in `wandb`.
10. Wandb also comes with build in feature for doing [hyperparameter sweeping](https://docs.wandb.ai/guides/sweeps)
which can be beneficial to get a better working model. Look through the documentation on how to do a hyperparameter
Expand All @@ -85,32 +85,32 @@ collaboration and sharing of results.
previous exercise, it needs to happen automatically. Lets therefore look into how we can do that.
1. First we need to generate an authentication key, or more precise an API key. This is in general the way any
service (like a docker container) can authenticate. Start by going <https://wandb.ai/home>, click your profile
icon in the upper right corner and then go to settings. Scroll down to the danger zone and generate a new API
key and finally copy it.
service (like a docker container) can authenticate. Start by going <https://wandb.ai/home>, click your profile
icon in the upper right corner and then go to settings. Scroll down to the danger zone and generate a new API
key and finally copy it.
2. Next create a new docker file called `wandb.docker` and add the following code
```dockerfile
FROM python:3.9
RUN apt update && \
apt install --no-install-recommends -y build-essential gcc && \
apt clean && rm -rf /var/lib/apt/lists/*
RUN pip install wandb
COPY s4_debugging_and_logging/exercise_files/wandb_tester.py wandb_tester.py
ENTRYPOINT ["python", "-u", "wandb_tester.py"]
```
```dockerfile
FROM python:3.9
RUN apt update && \
apt install --no-install-recommends -y build-essential gcc && \
apt clean && rm -rf /var/lib/apt/lists/*
RUN pip install wandb
COPY s4_debugging_and_logging/exercise_files/wandb_tester.py wandb_tester.py
ENTRYPOINT ["python", "-u", "wandb_tester.py"]
```
please take a look at the script being copied into the image and afterwards build the docker image.
please take a look at the script being copied into the image and afterwards build the docker image.
3. When we want to run the image, what we need to do is including a environment variables that contains the API key
we generated. This will then authenticate the docker container with the wandb server:
we generated. This will then authenticate the docker container with the wandb server:
```bash
docker run -e WANDB_API_KEY=<your-api-key> wandb:latest
```
```bash
docker run -e WANDB_API_KEY=<your-api-key> wandb:latest
```
Try running it an confirm that the results are uploaded to the wandb server.
Try running it an confirm that the results are uploaded to the wandb server.
12. Feel free to experiment more with `wandb` as it is a great tool for logging, organizing and sharing experiments.
Expand All @@ -122,7 +122,6 @@ We want to stress that the combination of tools presented in this course may not
projects, and we recommend finding a setup that fits you. That said, each framework provide specific features
that the others does not.
\
Finally, we want to note that we during the course really try to showcase a lot of open source frameworks, Wandb is not
one. It is free to use for personal usage (with a few restrictions) but for enterprise it does require a license. If you
are eager to only work with open-source tools we highly recommend trying out [MLFlow](https://mlflow.org/) which offers
Expand Down

0 comments on commit 3ac906e

Please sign in to comment.