-
wandb ์ค์น, ๋ก๊ทธ์ธ์นดํ ๊ณ ๋ฆฌ ์์ 2024. 3. 10. 15:32๋ฐ์ํ
๋จธ์ ๋ฌ๋ ์คํ ๊ด๋ฆฌ ํด์๋ TensorBoard, Weights & Biases๊ฐ ์๋ค. ์ค๋์ Weights&Biases์ ๋ํด ์๊ฐํ๋ค.
wandb๋ ๋ฅ๋ฌ๋ ์คํ ๊ณผ์ ์์ ์๊ธธ ์ ์๋ ๋ค์ํ ์์น๋ค (์. loss function, metric)์ ํธ๋ฆฌํ๊ฒ ์๊ฐํํ๊ณ ํธ๋ํนํ๊ธฐ ์ข์ ํด์ด๋ค. ์ด๋ฆ์ ์๋ W์ B๋ ๋ฅ๋ฌ๋์์ ํํ ์ฌ์ฉํ๋ W(๊ฐ์ค์น), b(ํธํฅ)์ ๋ปํ๋ค. Weights and biases๋ฅผ ์ค์ฌ์ wandb๋ผ๊ณ ๋ถ๋ฅธ๋ค.
wandb๋ฅผ ์ฌ์ฉํ๋ฉด ๋ ๋น ๋ฅธ ๋ชจ๋ธ ๋น๋๊ฐ ๊ฐ๋ฅํ๊ณ , training progress๋ฅผ ๋น ์ง์์ด ์๊ฐํ ๊ฐ๋ฅํ๋ค. - architecture, hyperparameter, weights, model prediction, GPU usage, git commits, dataset
์ด๋ฌํ ์คํ์ 5์ค์ ์ฝ๋๋ก ๊ฐ๋ฅํ ๊น?! ---> "W&B"๋ก ๊ฐ๋ฅํ๋ค!
<Weights & Biases ๊ฐ ํ ์ ์๋ ์ผ>
- ํ์ต ์ ์ฌ์ฉ๋ ํ์ดํผ ํ๋ผ๋ฏธํฐ๋ค์ ์ ์ฅํ ์ ์์
- ํ์ตํ๋ ๊ฐ ์คํ๋ค์ ํ์ํ๊ณ , ๋น๊ตํ๊ณ , ์๊ฐํํ ์ ์์
- ํ์ต ํ๊ฒฝ์ ์์คํ ์ ์ด๋ป๊ฒ ์ฌ์ฉํ๊ณ ์๋์ง ๋ถ์ํ ์ ์์
- ๋ค๋ฅธ ์ฌ๋๋ค๊ณผ ํ์ ํ ์ ์์ (๋๋ฃ์ ํ๋ ์คํ์ ๊ณต์ ํ๊ฑฐ๋ ํ ๋ก ํ ๋, ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ์บก์ณํด์ ๋ณด๋ด์ผ ํ๋ ๋ฑ์ ๋ถํธํจ ํด๊ฒฐ)
- ๊ณผ๊ฑฐ ์คํ ๊ฒฐ๊ณผ๋ค์ ๋ณต์ ํ ์ ์์
- ํ์ดํผ ํ๋ผ๋ฏธํฐ ํ๋์ด ๊ฐ๋ฅํจ
- ์คํํ๋ ๋ชจ๋ ๊ธฐ๋ก๋ค์ ์๊ตฌ์ ์ผ๋ก ์ ์ฅํ ์ ์์
- Gradient flow, GPU system ๋ชจ๋ํฐ๋ง ๋ฑ
import wandb # 1. Start a W&B run wandb.init(project='gpt3') # 2. Save model inputs and hyperparameters config = wandb.config config.learning_rate = 0.01 # Model training code here ... # 3. Log metrics over time to visualize performance for i in range (10): wandb.log({"loss": loss})
- wandb ๋ก๊ทธ์ธ
wandb login
- wandb.config
wandb.init() wandb.config.epochs = 4 wandb.config.batch_size = 32 wandb.config.learning_rate = 0.001 wandb.config.architecture = "resnet"
๋จธ์ ๋ฌ๋ ๋ชจ๋ธ์ ์ฌ๋ฌ ํ์ดํผํ๋ผ๋ฏธํฐ์ ์ํคํ ์ฒ ๋ฑ์ ์ถ์ (Tracking๐)ํ๊ธฐ ์ํด์ wandb๋ฅผ ์ค์ ํ๋ ์ฝ๋์ด๋ค.
wandb ์ด๊ธฐํ๋ฅผ ์ํด wandb.init()์ผ๋ก ์์ํ๋ค. ์ด๋ wandb ์์คํ ์ ์ด๊ธฐํํ์ฌ ์คํ ์ถ์ ์ ์์ํ๊ฒ ํ๋ค.
์ด๊ธฐํํ ํ, wandb.config๋ฅผ ์ฌ์ฉํด ์ฌ๋ฌ ํ์ดํผํ๋ผ๋ฏธํฐ(epochs, batch_size, learning_rate)์ ์ํคํ ์ฒ๋ฅผ ์ค์ ํ ์ ์๋ค. ์ด๋ฌํ ์ค์ ๋ค์ ๋จธ์ ๋ฌ๋ ๋ชจ๋ธ์ด๋ ํ์ต ๊ณผ์ ์ ๋ค์ํ ํ๋ผ๋ฏธํฐ๋ฅผ ๊ธฐ๋กํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
- PyTorch framework์ integrationํ๊ธฐ (framework-agnostic)
import wandb # 1. Start a new run run = wandb.init(project="gpt4") # 2. Save model inputs and hyperparameters config = run.config config.dropout = 0.01 # 3. Log gradients and model parameters run.watch(model) for batch_idx, (data, target) in enumerate(train_loader): ... if batch_idx % args.log_interval == 0: # 4. Log metrics to visualize performance run.log({"loss": loss})
wandb๋ ๋ค์ํ ๋จธ์ ๋ฌ๋ ํ๋ ์์ํฌ์ ์ฌ์ฉ๊ฐ๋ฅํ๋ฐ, ์์ ์์ ๋ PyTorch๋ฅผ ์ฌ์ฉํ ์์์ด๋ค.
์ฐ์ wandb๋ฅผ importํ๊ณ wandb.init()์ ํธ์ถํ์ฌ ์ด๊ธฐํ๋ฅผ ํด์ค๋ค. ์ด๋ ํ๋ก์ ํธ ์ด๋ฆ์ ์ ๋ ฅํด์ค๋ค.
run.config์ ์ฌ์ฉํ์ฌ ๋ชจ๋ธ์ ํ์ดํผํ๋ผ๋ฏธํฐ๋ฅผ ์ค์ ํ๋ค.
run.watch(model)์ ์ฌ์ฉํ์ฌ Pytorch ๋ชจ๋ธ์ ๊ทธ๋๋์ธํธ๋ฅผ ์๋์ผ๋ก loggingํ๊ณ ๋คํธ์ํฌ architecture๋ฅผ ์ ์ฅํ๋ค.
training loop์์๋ ๊ฐ batch์ ๋ํด ํด๋น ์์ ์ ์ํํ๋ค. ํน์ ๊ฐ๊ฒฉ(args.log_interval)๋ง๋ค ์์ค๊ณผ ๊ฐ์ ์ค์ํ metric์ run.log({"loss": loss})๋ฅผ ์ฌ์ฉํ์ฌ ๋ก๊น ํ๋ค.
์ด๋ ๊ฒ ํจ์ผ๋ก์จ, wandb๋ pytorch ๋ฅผ ์ฌ์ฉํ๋ ๋์ ๋ชจ๋ธ์ ์ฑ๋ฅ, ํ์ดํผํ๋ผ๋ฏธํฐ, ๊ทธ๋ฆฌ๊ณ gradient flow๋ฑ์ ์ถ์ ํ๊ณ ์๊ฐํํ ์ ์๊ฒ ํด์ค๋ค.
์ฐธ๊ณ ์๋ฃ
https://github.com/wandb/examples
GitHub - wandb/examples: Example deep learning projects that use wandb's features.
Example deep learning projects that use wandb's features. - wandb/examples
github.com
W&B Docs | Weights & Biases Documentation
Weights & Biases is the machine learning platform for developers to build better models faster. Use W&B's lightweight, interoperable tools to quickly track experiments, version and iterate on datasets, evaluate model performance, reproduce models, visualiz
docs.wandb.ai