Ray 2.7.2

  • 欢迎来到 Ray !

Ray

  • 概述「100%」
  • 入门
  • 安装「100%」
  • 用例「100%」
  • 示例库「1%」
  • 生态「3%」
  • Ray 核心「100%」
  • Ray 数据「75%」
  • Ray 训练「0%」
  • Ray 调参「0%」
    • 入门
    • 关键概念
    • 用户指南
    • Ray Tune 示例
    • Ray Tune 问答
    • Ray Tune API
      • Tune Execution (tune.Tuner)
      • Tune Experiment Results (tune.ResultGrid)
      • Training in Tune (tune.Trainable, session.report)
      • Tune Search Space API
      • Tune Search Algorithms (tune.search)
        • ray.tune.search.basic_variant.BasicVariantGenerator
        • ray.tune.search.ax.AxSearch
        • ray.tune.search.bayesopt.BayesOptSearch
        • ray.tune.search.bohb.TuneBOHB
        • ray.tune.search.flaml.BlendSearch
        • ray.tune.search.flaml.CFO
        • ray.tune.search.dragonfly.DragonflySearch
        • ray.tune.search.hebo.HEBOSearch
        • ray.tune.search.hyperopt.HyperOptSearch
        • ray.tune.search.nevergrad.NevergradSearch
        • ray.tune.search.optuna.OptunaSearch
        • ray.tune.search.sigopt.SigOptSearch
        • ray.tune.search.skopt.SkOptSearch
        • ray.tune.search.zoopt.ZOOptSearch
        • ray.tune.search.Repeater
        • ray.tune.search.ConcurrencyLimiter
        • ray.tune.search.Searcher
        • ray.tune.search.Searcher.suggest
        • ray.tune.search.Searcher.save
        • ray.tune.search.Searcher.restore
        • ray.tune.search.Searcher.on_trial_result
        • ray.tune.search.Searcher.on_trial_complete
        • ray.tune.search.create_searcher
      • Tune Trial Schedulers (tune.schedulers)
      • Tune Stopping Mechanisms (tune.stopper)
      • Tune Console Output (Reporters)
      • Syncing in Tune (train.SyncConfig)
      • Tune Loggers (tune.logger)
      • Tune Callbacks (tune.Callback)
      • Environment variables used by Ray Tune
      • Tune Scikit-Learn API (tune.sklearn)
      • External library integrations for Ray Tune
      • Tune Internals
      • Tune Client API
      • Tune CLI (Experimental)
  • Ray Serve
  • Ray RLlib
  • 更多类库「40%」
  • Ray 集群「100%」
  • 监控调试「100%」
  • 参考「20%」
  • 开发者指引「30%」
  • 安全「100%」
Theme by the Executable Book Project
  • repository
  • open issue
  • suggest edit
  • .rst
Contents
  • Saving and Restoring Tune Search Algorithms
  • Random search and grid search (tune.search.basic_variant.BasicVariantGenerator)
  • Ax (tune.search.ax.AxSearch)
  • Bayesian Optimization (tune.search.bayesopt.BayesOptSearch)
  • BOHB (tune.search.bohb.TuneBOHB)
  • BlendSearch (tune.search.flaml.BlendSearch)
  • CFO (tune.search.flaml.CFO)
  • Dragonfly (tune.search.dragonfly.DragonflySearch)
  • HEBO (tune.search.hebo.HEBOSearch)
  • HyperOpt (tune.search.hyperopt.HyperOptSearch)
  • Nevergrad (tune.search.nevergrad.NevergradSearch)
  • Optuna (tune.search.optuna.OptunaSearch)
  • SigOpt (tune.search.sigopt.SigOptSearch)
  • Scikit-Optimize (tune.search.skopt.SkOptSearch)
  • ZOOpt (tune.search.zoopt.ZOOptSearch)
  • Repeated Evaluations (tune.search.Repeater)
  • ConcurrencyLimiter (tune.search.ConcurrencyLimiter)
  • Custom Search Algorithms (tune.search.Searcher)
  • Shim Instantiation (tune.create_searcher)

Tune Search Algorithms (tune.search)

Contents

  • Saving and Restoring Tune Search Algorithms
  • Random search and grid search (tune.search.basic_variant.BasicVariantGenerator)
  • Ax (tune.search.ax.AxSearch)
  • Bayesian Optimization (tune.search.bayesopt.BayesOptSearch)
  • BOHB (tune.search.bohb.TuneBOHB)
  • BlendSearch (tune.search.flaml.BlendSearch)
  • CFO (tune.search.flaml.CFO)
  • Dragonfly (tune.search.dragonfly.DragonflySearch)
  • HEBO (tune.search.hebo.HEBOSearch)
  • HyperOpt (tune.search.hyperopt.HyperOptSearch)
  • Nevergrad (tune.search.nevergrad.NevergradSearch)
  • Optuna (tune.search.optuna.OptunaSearch)
  • SigOpt (tune.search.sigopt.SigOptSearch)
  • Scikit-Optimize (tune.search.skopt.SkOptSearch)
  • ZOOpt (tune.search.zoopt.ZOOptSearch)
  • Repeated Evaluations (tune.search.Repeater)
  • ConcurrencyLimiter (tune.search.ConcurrencyLimiter)
  • Custom Search Algorithms (tune.search.Searcher)
  • Shim Instantiation (tune.create_searcher)

Tune Search Algorithms (tune.search)#

Tune’s Search Algorithms are wrappers around open-source optimization libraries for efficient hyperparameter selection. Each library has a specific way of defining the search space - please refer to their documentation for more details. Tune will automatically convert search spaces passed to Tuner to the library format in most cases.

You can utilize these search algorithms as follows:

from ray import train, tune
from ray.tune.search.optuna import OptunaSearch

def train_fn(config):
    # This objective function is just for demonstration purposes
    train.report({"loss": config["param"]})

tuner = tune.Tuner(
    train_fn,
    tune_config=tune.TuneConfig(
        search_alg=OptunaSearch(),
        num_samples=100,
        metric="loss",
        mode="min",
    ),
    param_space={"param": tune.uniform(0, 1)},
)
results = tuner.fit()

Saving and Restoring Tune Search Algorithms#

Certain search algorithms have save/restore implemented, allowing reuse of searchers that are fitted on the results of multiple tuning runs.

search_alg = HyperOptSearch()

tuner_1 = tune.Tuner(
    train_fn,
    tune_config=tune.TuneConfig(search_alg=search_alg)
)
results_1 = tuner_1.fit()

search_alg.save("./my-checkpoint.pkl")

# Restore the saved state onto another search algorithm,
# in a new tuning script

search_alg2 = HyperOptSearch()
search_alg2.restore("./my-checkpoint.pkl")

tuner_2 = tune.Tuner(
    train_fn,
    tune_config=tune.TuneConfig(search_alg=search_alg2)
)
results_2 = tuner_2.fit()

Tune automatically saves searcher state inside the current experiment folder during tuning. See Result logdir: ... in the output logs for this location.

Note that if you have two Tune runs with the same experiment folder, the previous state checkpoint will be overwritten. You can avoid this by making sure air.RunConfig(name=...) is set to a unique identifier:

search_alg = HyperOptSearch()
tuner_1 = tune.Tuner(
    train_fn,
    tune_config=tune.TuneConfig(
        num_samples=5,
        search_alg=search_alg,
    ),
    run_config=air.RunConfig(
        name="my-experiment-1",
        storage_path="~/my_results",
    )
)
results = tuner_1.fit()

search_alg2 = HyperOptSearch()
search_alg2.restore_from_dir(
  os.path.join("~/my_results", "my-experiment-1")
)

Random search and grid search (tune.search.basic_variant.BasicVariantGenerator)#

The default and most basic way to do hyperparameter search is via random and grid search. Ray Tune does this through the BasicVariantGenerator class that generates trial variants given a search space definition.

The BasicVariantGenerator is used per default if no search algorithm is passed to Tuner.

basic_variant.BasicVariantGenerator([...])

Uses Tune's variant generation for resolving variables.

Ax (tune.search.ax.AxSearch)#

ax.AxSearch([space, metric, mode, ...])

Uses Ax to optimize hyperparameters.

Bayesian Optimization (tune.search.bayesopt.BayesOptSearch)#

bayesopt.BayesOptSearch([space, metric, ...])

Uses fmfn/BayesianOptimization to optimize hyperparameters.

BOHB (tune.search.bohb.TuneBOHB)#

BOHB (Bayesian Optimization HyperBand) is an algorithm that both terminates bad trials and also uses Bayesian Optimization to improve the hyperparameter search. It is available from the HpBandSter library.

Importantly, BOHB is intended to be paired with a specific scheduler class: HyperBandForBOHB.

In order to use this search algorithm, you will need to install HpBandSter and ConfigSpace:

$ pip install hpbandster ConfigSpace

See the BOHB paper for more details.

bohb.TuneBOHB([space, bohb_config, metric, ...])

BOHB suggestion component.

BlendSearch (tune.search.flaml.BlendSearch)#

BlendSearch is an economical hyperparameter optimization algorithm that combines combines local search with global search. It is backed by the FLAML library. It allows the users to specify a low-cost initial point as input if such point exists.

In order to use this search algorithm, you will need to install flaml:

$ pip install 'flaml[blendsearch]'

See the BlendSearch paper and documentation in FLAML BlendSearch documentation for more details.

flaml.BlendSearch

alias of ray.tune.search.flaml.flaml_search._DummyErrorRaiser

CFO (tune.search.flaml.CFO)#

CFO (Cost-Frugal hyperparameter Optimization) is a hyperparameter search algorithm based on randomized local search. It is backed by the FLAML library. It allows the users to specify a low-cost initial point as input if such point exists.

In order to use this search algorithm, you will need to install flaml:

$ pip install flaml

See the CFO paper and documentation in FLAML CFO documentation for more details.

flaml.CFO

alias of ray.tune.search.flaml.flaml_search._DummyErrorRaiser

Dragonfly (tune.search.dragonfly.DragonflySearch)#

dragonfly.DragonflySearch([optimizer, ...])

Uses Dragonfly to optimize hyperparameters.

HEBO (tune.search.hebo.HEBOSearch)#

hebo.HEBOSearch([space, metric, mode, ...])

Uses HEBO (Heteroscedastic Evolutionary Bayesian Optimization) to optimize hyperparameters.

HyperOpt (tune.search.hyperopt.HyperOptSearch)#

hyperopt.HyperOptSearch([space, metric, ...])

A wrapper around HyperOpt to provide trial suggestions.

Nevergrad (tune.search.nevergrad.NevergradSearch)#

nevergrad.NevergradSearch([optimizer, ...])

Uses Nevergrad to optimize hyperparameters.

Optuna (tune.search.optuna.OptunaSearch)#

optuna.OptunaSearch([space, metric, mode, ...])

A wrapper around Optuna to provide trial suggestions.

SigOpt (tune.search.sigopt.SigOptSearch)#

You will need to use the SigOpt experiment and space specification to specify your search space.

sigopt.SigOptSearch([space, name, ...])

A wrapper around SigOpt to provide trial suggestions.

Scikit-Optimize (tune.search.skopt.SkOptSearch)#

skopt.SkOptSearch([optimizer, space, ...])

Uses Scikit Optimize (skopt) to optimize hyperparameters.

ZOOpt (tune.search.zoopt.ZOOptSearch)#

zoopt.ZOOptSearch([algo, budget, dim_dict, ...])

A wrapper around ZOOpt to provide trial suggestions.

Repeated Evaluations (tune.search.Repeater)#

Use ray.tune.search.Repeater to average over multiple evaluations of the same hyperparameter configurations. This is useful in cases where the evaluated training procedure has high variance (i.e., in reinforcement learning).

By default, Repeater will take in a repeat parameter and a search_alg. The search_alg will suggest new configurations to try, and the Repeater will run repeat trials of the configuration. It will then average the search_alg.metric from the final results of each repeated trial.

Warning

It is recommended to not use Repeater with a TrialScheduler. Early termination can negatively affect the average reported metric.

Repeater(searcher[, repeat, set_index])

A wrapper algorithm for repeating trials of same parameters.

ConcurrencyLimiter (tune.search.ConcurrencyLimiter)#

Use ray.tune.search.ConcurrencyLimiter to limit the amount of concurrency when using a search algorithm. This is useful when a given optimization algorithm does not parallelize very well (like a naive Bayesian Optimization).

ConcurrencyLimiter(searcher, max_concurrent)

A wrapper algorithm for limiting the number of concurrent trials.

Custom Search Algorithms (tune.search.Searcher)#

If you are interested in implementing or contributing a new Search Algorithm, provide the following interface:

Searcher([metric, mode])

Abstract class for wrapping suggesting algorithms.

Searcher.suggest(trial_id)

Queries the algorithm to retrieve the next set of parameters.

Searcher.save(checkpoint_path)

Save state to path for this search algorithm.

Searcher.restore(checkpoint_path)

Restore state for this search algorithm

Searcher.on_trial_result(trial_id, result)

Optional notification for result during training.

Searcher.on_trial_complete(trial_id[, ...])

Notification for the completion of trial.

If contributing, make sure to add test cases and an entry in the function described below.

Shim Instantiation (tune.create_searcher)#

There is also a shim function that constructs the search algorithm based on the provided string. This can be useful if the search algorithm you want to use changes often (e.g., specifying the search algorithm via a CLI option or config file).

create_searcher(search_alg, **kwargs)

Instantiate a search algorithm based on the given string.

previous

ray.tune.sample_from

next

ray.tune.search.basic_variant.BasicVariantGenerator

谢谢你的反馈!
是否能帮助到你?
是
否
反馈
提交

By The Ray Team
© Copyright 2024, The Ray Team.