-
Notifications
You must be signed in to change notification settings - Fork 419
LearnedObjective and PairwiseGP dtype fixes and cleanup #2006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
51c1125
upcast for mixed precision in PairwiseGP with learned objective; dtyp…
esantorella 0b5821b
remove file added accidentally
esantorella 1a0ce83
Merge remote-tracking branch 'origin' into pairwisegp_dtype_fixes
esantorella f724395
Apply suggestions from code review
esantorella 9428c0f
Suggestions from code review
esantorella f2f41d6
remove incorrect warning
esantorella 7eab772
warnings stacklevel lint
esantorella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
import torch | ||
from botorch.acquisition.objective import PosteriorTransform | ||
from botorch.exceptions import UnsupportedError | ||
|
||
from botorch.exceptions.warnings import _get_single_precision_warning, InputDataWarning | ||
from botorch.models.likelihoods.pairwise import ( | ||
PairwiseLikelihood, | ||
PairwiseProbitLikelihood, | ||
|
@@ -167,12 +169,17 @@ class PairwiseGP(Model, GP, FantasizeMixin): | |
|
||
def __init__( | ||
self, | ||
datapoints: Tensor, | ||
comparisons: Tensor, | ||
datapoints: Optional[Tensor], | ||
comparisons: Optional[Tensor], | ||
Comment on lines
+172
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we update the docstring with what happens when these are |
||
likelihood: Optional[PairwiseLikelihood] = None, | ||
covar_module: Optional[ScaleKernel] = None, | ||
input_transform: Optional[InputTransform] = None, | ||
**kwargs, | ||
*, | ||
jitter: float = 1e-6, | ||
xtol: Optional[float] = None, | ||
consolidate_rtol: float = 0.0, | ||
consolidate_atol: float = 1e-4, | ||
maxfev: Optional[int] = None, | ||
) -> None: | ||
r""" | ||
Args: | ||
|
@@ -184,22 +191,35 @@ def __init__( | |
covar_module: Covariance module. | ||
input_transform: An input transform that is applied in the model's | ||
forward pass. | ||
jitter: Value added to diagonal for numerical stability in | ||
`psd_safe_cholesky`. | ||
xtol: Stopping creteria in scipy.optimize.fsolve used to find f_map | ||
in `PairwiseGP._update`. If None, default behavior is handled by | ||
`PairwiseGP._update`. | ||
consolidate_rtol: `rtol` passed to `consolidate_duplicates`. | ||
consolidate_atol: `atol` passed to `consolidate_duplicates`. | ||
maxfev: The maximum number of calls to the function in | ||
scipy.optimize.fsolve. If None, default behavior is handled by | ||
`PairwiseGP._update`. | ||
""" | ||
super().__init__() | ||
# Input data validation | ||
if datapoints is not None and datapoints.dtype == torch.float32: | ||
warnings.warn( | ||
_get_single_precision_warning(str(datapoints.dtype)), | ||
category=InputDataWarning, | ||
) | ||
if comparisons is not None and comparisons.dtype.is_floating_point: | ||
warnings.warn( | ||
"An integer dtype is expected for `comparisons`.", InputDataWarning | ||
) | ||
esantorella marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Set optional parameters | ||
# Explicitly set jitter for numerical stability in psd_safe_cholesky | ||
self._jitter = kwargs.get("jitter", 1e-6) | ||
# Stopping creteria in scipy.optimize.fsolve used to find f_map in _update() | ||
# If None, set to 1e-6 by default in _update | ||
self._xtol = kwargs.get("xtol") | ||
# atol rtol for consolidate_duplicates | ||
self._consolidate_rtol = kwargs.get("consolidate_rtol", 0) | ||
self._consolidate_atol = kwargs.get("consolidate_atol", 1e-4) | ||
# The maximum number of calls to the function in scipy.optimize.fsolve | ||
# If None, set to 100 by default in _update | ||
# If zero, then 100*(N+1) is used by default by fsolve; | ||
self._maxfev = kwargs.get("maxfev") | ||
self._jitter = jitter | ||
self._xtol = xtol | ||
self._consolidate_rtol = consolidate_rtol | ||
self._consolidate_atol = consolidate_atol | ||
self._maxfev = maxfev | ||
|
||
if input_transform is not None: | ||
input_transform.to(datapoints) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not make this a constant?