hyperparam search의 자동화
the space of possible model 탐색
controller는 hyperparameter 조합을 생성합니다.
(the controller lives on the Weights & Biases server)
controller가 생성한 hyperparameter 조합을 이용하여 model을 학습시킨 뒤 결과를 Sweep server에 기록합니다.
( Agents live on your machine(s).)
이 부분은 기존 code에 wandb를 추가하라는 내용인데 구체적으로는 다음 내용들을 추가해야합니다.
여기 가면 좀 더 자세한 sweep config를 확인할 수 있습니다!
https://docs.wandb.ai/guides/sweeps/define-sweep-configuration
sweep_id = wandb.sweep(
sweep=sweep_configuration,
project='my-first-sweep'
)
wandb.init()으로 api 실행 -> wandb에 기록 시작
+ wandb.config를 설정된 값을 가져올 수 있습니다. ex) lr = wandb.config.lr
기록할 정보 설정 wandb.log()
wandb.log({
'epoch': epoch,
'train_acc': train_acc,
'train_loss': train_loss,
'val_acc': val_acc,
'val_loss': val_loss
})
여기서 우리가 탐색하고자 하는 the space of possible model과 탐색 전략(random, grid, bayes)과 metric을 설정할 수 있습니다.
# 2: Define the search space
sweep_configuration = {
'method': 'random',
'metric': {'goal': 'minimize', 'name': 'score'},
'parameters':
{
'x': {'max': 0.1, 'min': 0.01},
'y': {'values': [1, 3, 7]},
}
}
wandb가 제공하는 hyperparam search 전략이 3가지가 있는데 그 중 하나를 선택할 수 있습니다.
Sweep Server 시작 (글에서 Sweep Server를 central controller로 표현했습니다.)
sweep_id = wandb.sweep(
sweep=sweep_configuration,
project='my-first-sweep'
)
the agent가 the central sweep server에서 이번에 실험할 하이퍼파라미터를 가져오고 실험합니다.
이때 function에는 training func이 들어갑니다!
여기서 실행할 횟수도 정할 수 있습니다.
wandb.agent(sweep_id, function=main, count=10)
이건 wandb에 접속해서 확인할 수 있습니다.
Both the W&B Sweep and the W&B Run must be in the same project. Therefore, the name you provide when you initialize Weights & Biases (wandb.init) must match the name of the project you provide when you initialize a W&B Sweep (wandb.sweep).
-> init에서의 프로젝트 이름과 sweep_Id에서의 프로젝트 이름은 항상 같아야 한다!