Skip to content

Commit

Permalink
replace lazy with functools.lru_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
iProzd committed Feb 29, 2024
1 parent ad7227d commit 35598d2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
4 changes: 2 additions & 2 deletions deepmd/pt/train/training.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import functools
import logging
import time
from copy import (
Expand Down Expand Up @@ -38,7 +39,6 @@
from deepmd.pt.utils.dataloader import (
BufferedIterator,
get_weighted_sampler,
lazy,
)
from deepmd.pt.utils.env import (
DEVICE,
Expand Down Expand Up @@ -214,7 +214,7 @@ def get_single_model(
_validation_data.add_data_requirement(_data_requirement)
if not resuming:

@lazy
@functools.lru_cache
def get_sample():
sampled = make_stat_input(
_training_data.systems,
Expand Down
17 changes: 0 additions & 17 deletions deepmd/pt/utils/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,3 @@ def get_weighted_sampler(training_data, prob_style, sys_prob=False):
with torch.device("cpu"):
sampler = WeightedRandomSampler(probs, len_sampler, replacement=True)
return sampler


class LazyFunction:
def __init__(self, func):
self.func = func
self.result = None
self.called = False

def __call__(self, *args, **kwargs):
if not self.called:
self.result = self.func(*args, **kwargs)
self.called = True
return self.result


def lazy(func):
return LazyFunction(func)

0 comments on commit 35598d2

Please sign in to comment.