ray.tune文档总结


原文档请看这里
https://docs.ray.io/en/latest/tune/key-concepts.html


tune.run

执行超参数调整、用于管理实验,例如 日志检查、提前停止
tune.run(trainable, num_samples=10) #确定将并行运行的实验次数,10次

config指定超参数的搜索方法

tune.uniform(-5,-1):均匀浮动在-5到-1
tune.quniform(3.2, 5.4, 0.2) :3.2到5.4,0.2的增量
tune.loguniform(1e-4, 1e-1) : log space的小数均匀浮动
tune.qloguniform(1e-4, 1e-1, 5e-5) : 小数均匀增加
tune.randn(10, 2) :正态分布,均值10,标准差2
tune.qrandn(10, 2, 0.2) :10到2, 0.2的减量
tune.randint(-9, 15):-9到15的随机整数
tune.qrandint(-21, 12, 3) :-21到12,3的增量,(包含12)
tune.lograndint(1, 10):log space的随机整数
tune.qlograndint(1, 10, 2):Round to increments of 2
tune.choice([“a”, “b”, “c”]):统一选择一个
tune.sample_from(lambda spec: spec.config.uniform * 0.01):取决于func
tune.grid_search([32, 64, 128]) :搜索这些所有值

ConcurrencyLimiter搜索算法

为了优化训练过程的超参数,需要使用搜索算法来帮助建议更好的超参数
search_alg=ConcurrencyLimiter(
BayesOptSearch(random_search_steps=4),
max_concurrent=2)
限制两个同时进行的试验(否则我们将以随机搜索告终)

scheduler试验调度程序

Trial Scheduler 可以停止/暂停/调整正在运行的试验的超参数,使您的超参数调整过程更快。
asha_scheduler = ASHAScheduler(
time_attr=‘training_iteration’,
metric=‘episode_reward_mean’,
mode=‘max’,
max_t=100,
grace_period=10,
reduction_factor=3,
brackets=1)
tune.run( … , scheduler=asha_scheduler)

time_attr ( str ) – 用于比较时间的训练结果属性,str需要单调增加
metric ( str ) – 训练结果目标值属性。停止程序将使用此属性。如果 None 但传递了一种模式,则默认情况下将使用ray.tune.result.DEFAULT_METRIC。
mode ( str ) – {min, max} 之一。确定目标是最小化还是最大化度量属性。
max_t ( float ) – 每次试验的最大时间单位。在 max_t 时间单位(由 time_attr 确定)过去后,试验将停止。
grace_period ( float ) – 只停止至少这么久的试验。单位与time_attr命名的属性相同。
reduction_factor ( float ) – 用于设置减半率和数量。这只是一个无单位标量。
brackets( int ) – 括号的数量。每个括号都有不同的减半率,由减少因子指定

分析

tune.run返回一个Analysis对象,其中包含可用于分析训练的方法。
analysis = tune.run(trainable, search_alg=algo, stop={“training_iteration”: 20})

best_trial = analysis.best_trial # Get best trial
best_config = analysis.best_config # Get best trial’s hyperparameters
best_logdir = analysis.best_logdir # Get best trial’s logdir
best_checkpoint = analysis.best_checkpoint # Get best trial’s best checkpoint
best_result = analysis.best_result # Get best trial’s last results
best_result_df = analysis.best_result_df # Get best result as pandas dataframe

该对象还可以将所有训练运行作为数据帧检索,允许您对结果进行临时数据分析。
df_results = analysis.results_df为每个试验获得一个带有最后结果的数据帧
df = analysis.dataframe(metric=“score”, mode=“max”)获取特定得分或模式的结果数据帧

资源(并行、GPU、分布式)

如果您的机器上有4个cpu,这将一次运行2个并发试验。
tune.run(trainable, num_samples=10, resources_per_trial={“cpu”: 2})如果您的机器上有4个cpu,这将一次运行2个并发试验。
tune.run(trainable, num_samples=10, resources_per_trial={“gpu”: 1})如果你有8个gpu,这将一次运行8次试验。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值