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 1 commit
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
28 changes: 24 additions & 4 deletions deepmd/pt/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
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)
numpy_to_torch_dtype_dict = {

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

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/utils/env.py#L14

Added line #L14 was not covered by tests
wanghan-iapcm marked this conversation as resolved.
Show resolved Hide resolved
np.float16: torch.float16,
np.float32: torch.float32,
np.float64: torch.float64,
}

GLOBAL_PT_FLOAT_PRECISION = numpy_to_torch_dtype_dict[GLOBAL_NP_FLOAT_PRECISION]

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

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/utils/env.py#L20

Added line #L20 was not covered by tests
SAMPLER_RECORD = os.environ.get("SAMPLER_RECORD", False)
try:
# only linux
Expand Down Expand Up @@ -52,3 +57,18 @@
torch.set_num_interop_threads(inter_nthreads)
if intra_nthreads > 0:
torch.set_num_threads(intra_nthreads)

__all__ = [

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

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/utils/env.py#L61

Added line #L61 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