Skip to content

Commit

Permalink
[Tune/CI] Fix BOHB notebook example (#26473)
Browse files Browse the repository at this point in the history
Fixes the BOHB notebook example as found in #26410

Signed-off-by: Antoni Baum <antoni.baum@protonmail.com>
  • Loading branch information
Yard1 authored Jul 13, 2022
1 parent 5df66b9 commit 67a7ffa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
1 change: 0 additions & 1 deletion doc/source/tune/examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ py_test_run_all_notebooks(
"tune-xgboost.ipynb",
"nyc_taxi_basic_processing.ipynb", # REGRESSION
"ocr_example.ipynb", # REGRESSION
"bohb_example.ipynb", # REGRESSION
"horovod_simple.ipynb", # REGRESSION
"hyperopt_example.ipynb", # REGRESSION
"sigopt_example.ipynb", # REGRESSION
Expand Down
52 changes: 34 additions & 18 deletions doc/source/tune/examples/bohb_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"import ray\n",
"from ray import tune\n",
"from ray.air import session\n",
"from ray.tune.search import ConcurrencyLimiter\n",
"from ray.tune.schedulers.hb_bohb import HyperBandForBOHB\n",
"from ray.tune.search.bohb import TuneBOHB\n",
"import ConfigSpace as CS"
Expand Down Expand Up @@ -215,12 +214,12 @@
"execution_count": null,
"id": "dfb3ecad",
"metadata": {
"tags": [
"remove-cell"
],
"pycharm": {
"name": "#%%\n"
}
},
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -295,6 +294,9 @@
"source": [
"config_space = CS.ConfigurationSpace()\n",
"config_space.add_hyperparameter(\n",
" CS.Constant(\"steps\", 100)\n",
")\n",
"config_space.add_hyperparameter(\n",
" CS.UniformFloatHyperparameter(\"width\", lower=0, upper=20)\n",
")\n",
"config_space.add_hyperparameter(\n",
Expand All @@ -314,9 +316,12 @@
"metadata": {},
"outputs": [],
"source": [
"# As we are passing config space directly to the searcher,\n",
"# we need to define metric and mode in it as well, in addition\n",
"# to tune.run.\n",
"algo = TuneBOHB(\n",
" space=config_space,\n",
" metric=\"episode_reward_mean\",\n",
" metric=\"mean_loss\",\n",
" mode=\"max\",\n",
")\n",
"algo = tune.search.ConcurrencyLimiter(algo, max_concurrent=4)\n",
Expand All @@ -335,18 +340,16 @@
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"vscode": {
"languageId": "python"
}
},
"outputs": [],
"source": [
"analysis = tune.run(\n",
" objective,\n",
" config=config_space,\n",
" scheduler=scheduler,\n",
" search_alg=algo,\n",
" metric=\"mean_loss\",\n",
" mode=\"max\",\n",
" num_samples=num_samples,\n",
" name=\"bohb_exp_2\",\n",
" stop={\"training_iteration\": 100},\n",
Expand All @@ -367,11 +370,7 @@
"cell_type": "code",
"execution_count": null,
"id": "1ae613e4",
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [],
"source": [
"print(\"Best hyperparameters found were: \", analysis.best_config)"
Expand All @@ -394,12 +393,29 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.8.10 ('venv': venv)",
"language": "python",
"name": "python3"
},
"orphan": true
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
},
"orphan": true,
"vscode": {
"interpreter": {
"hash": "3c0d54d489a08ae47a06eae2fd00ff032d6cddb527c382959b7b2575f6a8167f"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
}

0 comments on commit 67a7ffa

Please sign in to comment.