Skip to content

Commit

Permalink
Fix imports in MBM tutorials (#2732)
Browse files Browse the repository at this point in the history
Summary:
`ax.modelbridge.registry.Models` has been renamed to `Generators`. This diff updates the tutorials to utilize the new name.

Pull Request resolved: #2732

Reviewed By: esantorella

Differential Revision: D69210338

Pulled By: saitcakmak

fbshipit-source-id: d417f3904828b597b801be780c3b29eb5a432bbe
  • Loading branch information
saitcakmak authored and facebook-github-bot committed Feb 6, 2025
1 parent e8749df commit 8bda455
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
6 changes: 3 additions & 3 deletions tutorials/custom_acquisition/custom_acquisition.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -580,20 +580,20 @@
"outputs": [],
"source": [
"from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy\n",
"from ax.modelbridge.registry import Models\n",
"from ax.modelbridge.registry import Generators\n",
"\n",
"\n",
"gs = GenerationStrategy(\n",
" steps=[\n",
" # Quasi-random initialization step\n",
" GenerationStep(\n",
" model=Models.SOBOL,\n",
" model=Generators.SOBOL,\n",
" num_trials=5, # How many trials should be produced from this generation step\n",
" model_kwargs={\"seed\": 999}, # Any kwargs you want passed into the model\n",
" ),\n",
" # Bayesian optimization step using the custom acquisition function\n",
" GenerationStep(\n",
" model=Models.BOTORCH_MODULAR,\n",
" model=Generators.BOTORCH_MODULAR,\n",
" num_trials=-1, # No limitation on how many trials should be produced from this step\n",
" # For `BOTORCH_MODULAR`, we pass in kwargs to specify what surrogate or acquisition function to use.\n",
" # `acquisition_options` specifies the set of additional arguments to pass into the input constructor.\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,10 @@
"showInput": false
},
"source": [
"### Instantiate a `BoTorchModel` in Ax\n",
"### Instantiate a `BoTorchGenerator` in Ax\n",
"\n",
"A `BoTorchModel` in Ax encapsulates both the surrogate -- which `Ax` calls a `Surrogate` and BoTorch calls a `Model` -- and an acquisition function. Here, we will only specify the custom surrogate and let Ax choose the default acquisition function.\n",
"A `BoTorchGenerator` in Ax encapsulates both the surrogate -- which `Ax` calls a `Surrogate` and BoTorch calls a `Model` -- and an acquisition function. Here, we will only specify the custom surrogate and let Ax choose the default acquisition function.\n",
"\n",
"Most models should work with the base `Surrogate` in Ax, except for BoTorch `ModelListGP`, which works with `ListSurrogate`.\n",
"Note that the `Model` (e.g., the `SimpleCustomGP`) must implement `construct_inputs`, as this is used to construct the inputs required for instantiating a `Model` instance from the experiment data."
]
},
Expand All @@ -188,11 +187,11 @@
},
"outputs": [],
"source": [
"from ax.models.torch.botorch_modular.model import BoTorchModel\n",
"from ax.models.torch.botorch_modular.model import BoTorchGenerator\n",
"from ax.models.torch.botorch_modular.surrogate import Surrogate, SurrogateSpec\n",
"from ax.models.torch.botorch_modular.utils import ModelConfig\n",
"\n",
"ax_model = BoTorchModel(\n",
"ax_model = BoTorchGenerator(\n",
" surrogate=Surrogate(\n",
" surrogate_spec=SurrogateSpec(\n",
" model_configs=[\n",
Expand Down Expand Up @@ -230,11 +229,11 @@
"source": [
"### Combine with a `ModelBridge`\n",
"\n",
"`Model`s in Ax require a `ModelBridge` to interface with `Experiment`s. A `ModelBridge` takes the inputs supplied by the `Experiment` and converts them to the inputs expected by the `Model`. For a `BoTorchModel`, we use `TorchModelBridge`. The Modular BoTorch interface creates the `BoTorchModel` and the `TorchModelBridge` in a single step, as follows:\n",
"`Model`s in Ax require a `ModelBridge` to interface with `Experiment`s. A `ModelBridge` takes the inputs supplied by the `Experiment` and converts them to the inputs expected by the `Model`. For a `BoTorchGenerator`, we use `TorchModelBridge`. The Modular BoTorch interface creates the `BoTorchGenerator` and the `TorchModelBridge` in a single step, as follows:\n",
"\n",
"```\n",
"from ax.modelbridge.registry import Models\n",
"model_bridge = Models.BOTORCH_MODULAR(\n",
"from ax.modelbridge.registry import Generators\n",
"model_bridge = Generators.BOTORCH_MODULAR(\n",
" experiment=experiment,\n",
" data=data,\n",
" surrogate=Surrogate(SimpleCustomGP),\n",
Expand Down Expand Up @@ -308,19 +307,19 @@
"outputs": [],
"source": [
"from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy\n",
"from ax.modelbridge.registry import Models\n",
"from ax.modelbridge.registry import Generators\n",
"\n",
"\n",
"gs = GenerationStrategy(\n",
" steps=[\n",
" # Quasi-random initialization step\n",
" GenerationStep(\n",
" model=Models.SOBOL,\n",
" model=Generators.SOBOL,\n",
" num_trials=5, # How many trials should be produced from this generation step\n",
" ),\n",
" # Bayesian optimization step using the custom acquisition function\n",
" GenerationStep(\n",
" model=Models.BOTORCH_MODULAR,\n",
" model=Generators.BOTORCH_MODULAR,\n",
" num_trials=-1, # No limitation on how many trials should be produced from this step\n",
" # For `BOTORCH_MODULAR`, we pass in kwargs to specify what surrogate or acquisition function to use.\n",
" model_kwargs={\n",
Expand Down Expand Up @@ -1809,10 +1808,10 @@
},
"outputs": [],
"source": [
"from ax.modelbridge.registry import Models\n",
"from ax.modelbridge.registry import Generators\n",
"\n",
"\n",
"sobol = Models.SOBOL(exp.search_space)\n",
"sobol = Generators.SOBOL(exp.search_space)\n",
"\n",
"for i in range(5):\n",
" trial = exp.new_trial(generator_run=sobol.gen(1))\n",
Expand Down Expand Up @@ -1878,7 +1877,7 @@
"source": [
"with fast_smoke_test():\n",
" for i in range(NUM_EVALS - 5):\n",
" model_bridge = Models.BOTORCH_MODULAR(\n",
" model_bridge = Generators.BOTORCH_MODULAR(\n",
" experiment=exp,\n",
" data=exp.fetch_data(),\n",
" surrogate_spec=SurrogateSpec(\n",
Expand Down

0 comments on commit 8bda455

Please sign in to comment.