-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge: Enable single point precision via env vars (#226)
Added - env var for torch - env var for numpy - these are booleans that enforce usage of single precision if True, False by default Addressing suggestion from #223 Notes: - Did some very light testing via fulltest and setting the tox env vars to use single precision there - some tests expectedly fail due to numerical instability -> no action required - some tests fail because hypothesis generate incompatible floats --> likely fixed by using `st.floats(...,width=32)` if single precision is desired --> not done under the assumption we dont want tests enabled for single precision, would require flexible checking everywhere - some tests fail as constraints complain about combining Single and Double precision --> likely because `rhs` and `coefficients` are defined as python floats, hence 64 bit. This means using double precision with env vars also implies providing explicit 32bit floats in such fields (like `coefficients` or `rhs`), otherwise it wont work. This is not something I'd fix but perhaps mention in the userguide
- Loading branch information
Showing
4 changed files
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,6 +1,18 @@ | ||
"""Torch utilities shipped as separate module for lazy-loading.""" | ||
|
||
|
||
import os | ||
|
||
import torch | ||
|
||
DTypeFloatTorch = torch.float64 | ||
from baybe.utils.boolean import strtobool | ||
|
||
VARNAME_TORCH_USE_SINGLE_PRECISION = "BAYBE_TORCH_USE_SINGLE_PRECISION" | ||
"""Environment variable name for enforcing single precision in torch.""" | ||
|
||
DTypeFloatTorch = ( | ||
torch.float32 | ||
if strtobool(os.environ.get(VARNAME_TORCH_USE_SINGLE_PRECISION, "False")) | ||
else torch.float64 | ||
) | ||
"""Floating point data type used for torch tensors.""" |