From 693cfbc0a8e91e8c2d262fba2697df1f9620d39d Mon Sep 17 00:00:00 2001 From: Elizabeth Santorella Date: Fri, 11 Nov 2022 07:01:49 -0800 Subject: [PATCH 1/4] Expanding on docstrings in BoTorch `Model` Summary: Added content to docstrings in BoTorch `Model` to help people who may either be unfamiliar with torch `Module` or with what its methods (such as "forward") mean in the context of BoTorch models. Differential Revision: D41221005 fbshipit-source-id: 165ce67766acebc2f20fbd7dc16f5a5a193324b3 --- botorch/models/model.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/botorch/models/model.py b/botorch/models/model.py index 5d07760e20..413afade18 100644 --- a/botorch/models/model.py +++ b/botorch/models/model.py @@ -46,9 +46,22 @@ class Model(Module, ABC): r"""Abstract base class for BoTorch models. - Model cannot be used directly; it only defines an API for other BoTorch + `Model` cannot be used directly; it only defines an API for other BoTorch models. + `Model` subclasses `torch.nn.Module`. While a `Module` is most typically + encountered as a representation of a neural network layer, it can be used more + generally: see `documentation`_ on custom NN Modules. + + Subclassing `Module` provides several pieces of useful functionality: Attributes + of `Tensor` or `Module` type are automatically registered so they can be moved + and/or cast with `to`, automatically differentiated, and used with CUDA. Also, + `Model` subclasses are callable, provided that they implement a `forward` method. In + BoTorch, this typically computes the prior latent distribution at a point, e.g. + `multivariate_normal = SingleTaskGP(x)`. + + .. _NN: https://pytorch.org/tutorials/beginner/examples_nn/polynomial_module.html + Args: _has_transformed_inputs: A boolean denoting whether `train_inputs` are currently stored as transformed or not. @@ -215,7 +228,8 @@ def eval(self) -> Model: return super().eval() def train(self, mode: bool = True) -> Model: - r"""Puts the model in `train` mode and reverts to the original inputs. + r"""Put the model in `train` mode. Reverts to the original inputs if in `train` + mode (`mode=True`) or sets transformed inputs if in `eval` mode (`mode=False`). Args: mode: A boolean denoting whether to put in `train` or `eval` mode. From f66b780dadb15e9c4b73dd8746486e90c17a4d56 Mon Sep 17 00:00:00 2001 From: Elizabeth Santorella Date: Fri, 11 Nov 2022 11:30:13 -0500 Subject: [PATCH 2/4] Fixed URL; improved wording based on GH comments --- botorch/models/model.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/botorch/models/model.py b/botorch/models/model.py index 413afade18..680ac2273e 100644 --- a/botorch/models/model.py +++ b/botorch/models/model.py @@ -6,8 +6,8 @@ r"""Abstract base module for all BoTorch models. -Contains `Model`, the abstract base class for all BoTorch models, and -`ModelList`, a container for a list of Models. +The base API module contains `Model`, the abstract base class for all BoTorch models, +and `ModelList`, a container for a list of Models. """ from __future__ import annotations @@ -46,21 +46,18 @@ class Model(Module, ABC): r"""Abstract base class for BoTorch models. - `Model` cannot be used directly; it only defines an API for other BoTorch - models. + The `Model` base class cannot be used directly; it only defines an API for other + BoTorch models. `Model` subclasses `torch.nn.Module`. While a `Module` is most typically encountered as a representation of a neural network layer, it can be used more - generally: see `documentation`_ on custom NN Modules. + generally: see + `documentation `_ + on custom NN Modules. - Subclassing `Module` provides several pieces of useful functionality: Attributes - of `Tensor` or `Module` type are automatically registered so they can be moved - and/or cast with `to`, automatically differentiated, and used with CUDA. Also, - `Model` subclasses are callable, provided that they implement a `forward` method. In - BoTorch, this typically computes the prior latent distribution at a point, e.g. - `multivariate_normal = SingleTaskGP(x)`. - - .. _NN: https://pytorch.org/tutorials/beginner/examples_nn/polynomial_module.html + `Module` provides several pieces of useful functionality: A `Model`'s attributes of + `Tensor` or `Module` type are automatically registered so they can be moved and/or + cast with the `to` method, automatically differentiated, and used with CUDA. Args: _has_transformed_inputs: A boolean denoting whether `train_inputs` are currently @@ -69,7 +66,7 @@ class Model(Module, ABC): `_revert_to_original_inputs`. Note that this is necessary since transform / untransform cycle introduces numerical errors which lead to upstream errors during training. - """ + """ # noqa: E501 _has_transformed_inputs: bool = False _original_train_inputs: Optional[Tensor] = None From e62ec3686467fe54c5881d8493519bdad2c9e276 Mon Sep 17 00:00:00 2001 From: Elizabeth Santorella Date: Fri, 11 Nov 2022 11:31:29 -0500 Subject: [PATCH 3/4] one more minor wording change --- botorch/models/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botorch/models/model.py b/botorch/models/model.py index 680ac2273e..5330a04ce1 100644 --- a/botorch/models/model.py +++ b/botorch/models/model.py @@ -6,7 +6,7 @@ r"""Abstract base module for all BoTorch models. -The base API module contains `Model`, the abstract base class for all BoTorch models, +This module contains `Model`, the abstract base class for all BoTorch models, and `ModelList`, a container for a list of Models. """ From 9335ba9d776ab688f310789f7c0d5f1102523cb9 Mon Sep 17 00:00:00 2001 From: Elizabeth Santorella Date: Fri, 11 Nov 2022 11:47:42 -0500 Subject: [PATCH 4/4] removed one space --- botorch/models/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botorch/models/model.py b/botorch/models/model.py index 5330a04ce1..caa348a380 100644 --- a/botorch/models/model.py +++ b/botorch/models/model.py @@ -57,7 +57,7 @@ class Model(Module, ABC): `Module` provides several pieces of useful functionality: A `Model`'s attributes of `Tensor` or `Module` type are automatically registered so they can be moved and/or - cast with the `to` method, automatically differentiated, and used with CUDA. + cast with the `to` method, automatically differentiated, and used with CUDA. Args: _has_transformed_inputs: A boolean denoting whether `train_inputs` are currently