Skip to content

Commit 7ed46a2

Browse files
committed
feat(pt): add torch.compile support
1 parent ab6e300 commit 7ed46a2

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

deepmd/pt/entrypoints/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ def train(
251251
output: str = "out.json",
252252
) -> None:
253253
log.info("Configuration path: %s", input_file)
254-
env.CUSTOM_OP_USE_JIT = True
254+
if not env.COMPILE:
255+
env.CUSTOM_OP_USE_JIT = True
255256
if LOCAL_RANK == 0:
256257
SummaryPrinter()()
257258
with open(input_file) as fin:

deepmd/pt/train/training.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
get_sampler_from_params,
5454
)
5555
from deepmd.pt.utils.env import (
56+
COMPILE,
5657
DEVICE,
5758
JIT,
5859
LOCAL_RANK,
@@ -413,9 +414,13 @@ def get_lr(lr_params):
413414
self.lr_exp = get_lr(config["learning_rate"])
414415

415416
# JIT
416-
if JIT:
417+
if JIT or COMPILE:
417418
self.model = torch.jit.script(self.model)
418-
419+
if COMPILE:
420+
self.model = torch.compile(
421+
self.model,
422+
dynamic=True,
423+
)
419424
# Model Wrapper
420425
self.wrapper = ModelWrapper(self.model, self.loss, model_params=model_params)
421426
self.start_step = 0

deepmd/pt/utils/env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
CACHE_PER_SYS = 5 # keep at most so many sets per sys in memory
4747
ENERGY_BIAS_TRAINABLE = True
4848
CUSTOM_OP_USE_JIT = False
49+
COMPILE = True
4950

5051
PRECISION_DICT = {
5152
"float16": torch.float16,

0 commit comments

Comments
 (0)