调整搜索空间 API#
本节介绍您可以用来定义搜索空间的功能。
小心
并非所有搜索算法都支持所有分布。特别是,tune.sample_from
和 tune.grid_search
通常不受支持。默认的 随机搜索和网格搜索 (tune.search.basic_variant.BasicVariantGenerator) 支持所有分布。
小技巧
避免在搜索空间中传递大型对象作为值,因为这会导致性能开销。使用 tune.with_parameters
来传递大型对象,或者从磁盘(确保所有节点都能访问文件)或云存储中加载它们。更多信息请参见 我如何避免瓶颈?。
对于一个高层次的概述,请看这个例子:
config = {
# Sample a float uniformly between -5.0 and -1.0
"uniform": tune.uniform(-5, -1),
# Sample a float uniformly between 3.2 and 5.4,
# rounding to multiples of 0.2
"quniform": tune.quniform(3.2, 5.4, 0.2),
# Sample a float uniformly between 0.0001 and 0.01, while
# sampling in log space
"loguniform": tune.loguniform(1e-4, 1e-2),
# Sample a float uniformly between 0.0001 and 0.1, while
# sampling in log space and rounding to multiples of 0.00005
"qloguniform": tune.qloguniform(1e-4, 1e-1, 5e-5),
# Sample a random float from a normal distribution with
# mean=10 and sd=2
"randn": tune.randn(10, 2),
# Sample a random float from a normal distribution with
# mean=10 and sd=2, rounding to multiples of 0.2
"qrandn": tune.qrandn(10, 2, 0.2),
# Sample a integer uniformly between -9 (inclusive) and 15 (exclusive)
"randint": tune.randint(-9, 15),
# Sample a random uniformly between -21 (inclusive) and 12 (inclusive (!))
# rounding to multiples of 3 (includes 12)
# if q is 1, then randint is called instead with the upper bound exclusive
"qrandint": tune.qrandint(-21, 12, 3),
# Sample a integer uniformly between 1 (inclusive) and 10 (exclusive),
# while sampling in log space
"lograndint": tune.lograndint(1, 10),
# Sample a integer uniformly between 1 (inclusive) and 10 (inclusive (!)),
# while sampling in log space and rounding to multiples of 2
# if q is 1, then lograndint is called instead with the upper bound exclusive
"qlograndint": tune.qlograndint(1, 10, 2),
# Sample an option uniformly from the specified choices
"choice": tune.choice(["a", "b", "c"]),
# Sample from a random function, in this case one that
# depends on another value from the search space
"func": tune.sample_from(lambda spec: spec.config.uniform * 0.01),
# Do a grid search over these values. Every value will be sampled
# ``num_samples`` times (``num_samples`` is the parameter you pass to ``tune.TuneConfig``,
# which is taken in by ``Tuner``)
"grid": tune.grid_search([32, 64, 128])
}
随机分布 API#
在 |
|
在 |
|
用于按不同数量级采样的工具。 |
|
用于按不同数量级采样的工具。 |
|
使用 |
|
使用 |
|
在 |
|
在 |
|
在 |
|
在 |
|
采样一个分类值。 |
网格搜索和自定义函数API#
指定一个值的网格以进行搜索。 |
|
指定tune应从此函数中采样配置值。 |
参考文献#
另请参阅 随机搜索和网格搜索 (tune.search.basic_variant.BasicVariantGenerator)。