効率的なHyperParameter Tuning|Ray
HyperParameterの効率的な調整
Intro.
最も基本的な方法はgridvs randomです.
Grid Layout
learning rate 0.1, 0.01, 0.001 → ...
batchsize 32, 64, 128 → ...
これらの組合せを適用して最適なスーパーパラメータを探します.
Random Layout
言ったように、ランダムに適用します.
Ray
特長
Code
data_dir = os.path.abspath("./data")
load_data(data_dir)
# search space 지정
config = {
"l1": tune.sample_from(lambda _: 2 ** np.random.randint(2, 9)),
"l2": tune.sample_from(lambda _: 2 ** np.random.randint(2, 9)),
"lr": tune.loguniform(1e-4, 1e-1),
"batch_size": tune.choice([2, 4, 8, 16])
}
# 학습 스케줄링 알고리즘 지정
scheduler = ASHAScheduler( # 가망이 없는 것들 제외하는 알고리즘
metric="loss",
mode="min",
max_t=max_num_epochs,
grace_period=1,
reduction_factor=2)
# 결과 출력 양식 지정
reporter = CLIReporter( # command line 출력
# parameter_columns=["l1", "l2", "lr", "batch_size"],
metric_columns=["loss", "accuracy", "training_iteration"])
# 병렬처리양식으로 실행
result = tune.run(
partial(train_cifar, data_dir=data_dir),# 데이터 쪼개기
# 한번 trial시 사용하는 cpu,gpu
resources_per_trial={"cpu": 2, "gpu": gpus_per_trial},
config=config,
num_samples=num_samples,
scheduler=scheduler,
progress_reporter=reporter)
# 가장 좋은 결과 가져오기
best_trial = result.get_best_trial("loss", "min", "last")
print("Best trial config: {}".format(best_trial.config))
print("Best trial final validation loss: {}".format(
best_trial.last_result["loss"]))
print("Best trial final validation accuracy: {}".format(
best_trial.last_result["accuracy"]))
best_trained_model = Net(best_trial.config["l1"], best_trial.config["l2"])
しかし、良いデータは超パラメータ調整よりも重要であることを忘れないでください.Reference
この問題について(効率的なHyperParameter Tuning|Ray), 我々は、より多くの情報をここで見つけました https://velog.io/@bo-lim/효율적인-Hyperparameter-Tuning-Rayテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol