Skip to content
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

pt: apply global user set precision to pt #3220

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions deepmd/pt/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
import torch

from deepmd.env import (
GLOBAL_ENER_FLOAT_PRECISION,
GLOBAL_NP_FLOAT_PRECISION,
get_default_nthreads,
set_default_nthreads,
)

PRECISION = os.environ.get("PRECISION", "float64")
GLOBAL_NP_FLOAT_PRECISION = getattr(np, PRECISION)
GLOBAL_PT_FLOAT_PRECISION = getattr(torch, PRECISION)
GLOBAL_ENER_FLOAT_PRECISION = getattr(np, PRECISION)
SAMPLER_RECORD = os.environ.get("SAMPLER_RECORD", False)
try:
# only linux
Expand Down Expand Up @@ -43,6 +41,7 @@
"int32": torch.int32,
"int64": torch.int64,
}
GLOBAL_PT_FLOAT_PRECISION = PRECISION_DICT[np.dtype(GLOBAL_NP_FLOAT_PRECISION).name]

Check warning on line 44 in deepmd/pt/utils/env.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/utils/env.py#L44

Added line #L44 was not covered by tests
DEFAULT_PRECISION = "float64"

# throw warnings if threads not set
Expand All @@ -52,3 +51,18 @@
torch.set_num_interop_threads(inter_nthreads)
if intra_nthreads > 0:
torch.set_num_threads(intra_nthreads)

__all__ = [

Check warning on line 55 in deepmd/pt/utils/env.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/utils/env.py#L55

Added line #L55 was not covered by tests
"GLOBAL_ENER_FLOAT_PRECISION",
"GLOBAL_NP_FLOAT_PRECISION",
"GLOBAL_PT_FLOAT_PRECISION",
"DEFAULT_PRECISION",
"PRECISION_DICT",
"SAMPLER_RECORD",
"NUM_WORKERS",
"DEVICE",
"JIT",
"CACHE_PER_SYS",
"ENERGY_BIAS_TRAINABLE",
"LOCAL_RANK",
]
Loading