Skip to content

Commit

Permalink
added tutorial (#185)
Browse files Browse the repository at this point in the history
* added tutorial

* added English version
  • Loading branch information
QazyBi authored Jul 9, 2023
1 parent ccd0ce8 commit b49e712
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Using the Weights and Biases Logger
[Video](https://www.youtube.com/watch?v=zgt2YFNEOMY&ab_channel=innofw) about using Weights and Biases in the `innofw` framework.

Add logger to the experiment config:

```yaml
# @package _global_
task: "image-segmentation"
defaults:
- override /models: semantic-segmentation/unet_smp.yaml
- override /datasets: semantic-segmentation/stroke_dataset.yaml
- override /losses: semantic-segmentation/focal_tversky_loss.yaml
- override /loggers: wandb # <-- add this line to use wandb logger
```
## Sweep
You can get acquainted with what a wandb sweep is in the [documentation](https://docs.wandb.ai/guides/sweeps).
Here we will consider how and where to create configuration files and how to run a sweep in the framework.
1. You need to create a configuration file. Example of a configuration file for a sweep (let's say the file: config/experiments/sweeps/SO_120323_example.yaml):
```yaml
# wandb sweep config
program: train.py
method: bayes
metric:
name: val_MulticlassJaccardIndex
goal: maximize

name: param_tuning_deeplabv3plus
project: uw_madison

parameters:

experiments:
value: "KG_260423_inwrg21_deeplab_uwmadison.yaml"

augmentations_train:
values: [none, 'position/random_horizontal_flip.yaml']

batch_size:
values: [ 64, 128, 256 ]

models.encoder_name:
values: ['resnet34', 'resnet50', 'resnet101']

optimizers:
values: ['lion.yaml', 'adam.yaml']

optimizers.lr:
min: 0.0035
max: 0.0070

epochs:
values: [15, 20]

command:
- ${env}
- python
- ${program}
- ${args_no_hyphens}
```
After this, you need to create a job using the `wandb sweep` command, providing the path to the file. Example of the command:

```bash
wandb sweep config/experiments/sweeps/config/experiments/sweeps/SO_120323_example.yaml
```
Expected command output:

```bash
wandb: Creating sweep from: config/experiments/sweeps/KG_280423_obwg91_sweep_test.yaml
wandb: Created sweep with ID: tx1o222v
wandb: View sweep at: https://wandb.ai/qb-1/uw_madison/sweeps/tx1o222v
wandb: Run sweep agent with: wandb agent qb-1/uw_madison/tx1o222v
```

You need to copy this part: `wandb agent qb-1/uw_madison/tx1o222v`

3. Now you can start the processes to carry out tasks from the job. Here is an example of starting two processes of our task on gpu=0, 2:

```
CUDA_VISIBLE_DEVICES=0 wandb agent qazybi/uwmadison/329fj23
```

```bash
CUDA_VISIBLE_DEVICES=2 wandb agent qazybi/uwmadison/329fj23
```

In case you encounter a `PermissionError`, try running the process in sudo mode:
```bash
CUDA_VISIBLE_DEVICES=2 sudo -E env "PATH=$PATH" wandb agent qazybi/uwmadison/329fj23```
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Использование логгера Weights and Biases

[Видео](https://www.youtube.com/watch?v=zgt2YFNEOMY&ab_channel=innofw) про использование Weights and Biases во фреймворке `innofw`.

добавить логгер в конфиг эксперимента

```yaml
# @package _global_
task: "image-segmentation"
defaults:
- override /models: semantic-segmentation/unet_smp.yaml
- override /datasets: semantic-segmentation/stroke_dataset.yaml
- override /losses: semantic-segmentation/focal_tversky_loss.yaml
- override /loggers: wandb # <-- add this line to use wandb logger
```
## Sweep
с тем что такое wandb sweep можно ознакомиться по [документации](https://docs.wandb.ai/guides/sweeps)
Здесь же мы рассмотрим как и где создать конфигурационные файлы и как запустить sweep во фреймворке.
1. Нужно создать конфигурационный файл. Пример конфигурационного файла для sweep(допустим файл: `config/experiments/sweeps/SO_120323_example.yaml`):

```yaml
# wandb sweep config
program: train.py
method: bayes
metric:
name: val_MulticlassJaccardIndex
goal: maximize
name: param_tuning_deeplabv3plus
project: uw_madison
parameters:
experiments:
value: "KG_260423_inwrg21_deeplab_uwmadison.yaml"
augmentations_train:
values: [none, 'position/random_horizontal_flip.yaml']
batch_size:
values: [ 64, 128, 256 ]
models.encoder_name:
values: ['resnet34', 'resnet50', 'resnet101']
optimizers:
values: ['lion.yaml', 'adam.yaml']
optimizers.lr:
min: 0.0035
max: 0.0070
epochs:
values: [15, 20]
command:
- ${env}
- python
- ${program}
- ${args_no_hyphens}
```

2. После этого надо будет создать job командой `wandb sweep` передав путь до файла. Пример команды:

```bash
wandb sweep config/experiments/sweeps/config/experiments/sweeps/SO_120323_example.yaml
```

Примерный вывод команды:

```bash
wandb: Creating sweep from: config/experiments/sweeps/KG_280423_obwg91_sweep_test.yaml
wandb: Created sweep with ID: tx1o222v
wandb: View sweep at: https://wandb.ai/qb-1/uw_madison/sweeps/tx1o222v
wandb: Run sweep agent with: wandb agent qb-1/uw_madison/tx1o222v
```

Нужно скопировать часть: `wandb agent qb-1/uw_madison/tx1o222v`

3. Теперь можно запустить процессы, чтобы выполнялись задачи с job-а. Вот пример запуска двух процессов нашей задачи на гпу=0, 2:

```bash
CUDA_VISIBLE_DEVICES=0 wandb agent qazybi/uwmadison/329fj23
```

```bash
CUDA_VISIBLE_DEVICES=2 wandb agent qazybi/uwmadison/329fj23
```

В случае если возникает ошибка `PermissionError`, попробуйте запустить процесс в режиме sudo:
```bash
CUDA_VISIBLE_DEVICES=2 sudo -E env "PATH=$PATH" wandb agent qazybi/uwmadison/329fj23
```

0 comments on commit b49e712

Please sign in to comment.