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

tests: move init_models to setUpModule #3715

Merged
merged 5 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions deepmd/tf/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
)

import tensorflow
from packaging.version import (
Version,
)
from tensorflow.python.framework import (
tensor_util,
)
Expand All @@ -31,6 +34,7 @@
)
from deepmd.tf.env import (
GLOBAL_TF_FLOAT_PRECISION,
TF_VERSION,
op_module,
tf,
)
Expand Down Expand Up @@ -289,3 +293,8 @@
tf.reset_default_graph()
# TODO: remove this line when data_requirement is not a global variable
data_requirement.clear()
_TF_VERSION = Version(TF_VERSION)
if _TF_VERSION < Version("2.4.0"):
tf.train.experimental.disable_mixed_precision_graph_rewrite()

Check warning on line 298 in deepmd/tf/common.py

View check run for this annotation

Codecov / codecov/patch

deepmd/tf/common.py#L298

Added line #L298 was not covered by tests
else:
tf.mixed_precision.disable_mixed_precision_graph_rewrite()
9 changes: 6 additions & 3 deletions source/tests/pt/test_multitask.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
model_se_e2_a,
)

multitask_template_json = str(Path(__file__).parent / "water/multitask.json")
with open(multitask_template_json) as f:
multitask_template = json.load(f)

def setUpModule():
global multitask_template
multitask_template_json = str(Path(__file__).parent / "water/multitask.json")
with open(multitask_template_json) as f:
multitask_template = json.load(f)


class MultiTaskTrainTest:
Expand Down
4 changes: 4 additions & 0 deletions source/tests/tf/test_mixed_prec_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
Version,
)

from deepmd.tf.common import (
clear_session,
)
from deepmd.tf.env import (
TF_VERSION,
)
Expand Down Expand Up @@ -61,3 +64,4 @@ def tearDown(self):
_file_delete("model.ckpt-100.data-00000-of-00001")
_file_delete("input_v2_compat.json")
_file_delete("lcurve.out")
clear_session()
12 changes: 10 additions & 2 deletions source/tests/tf/test_model_compression_se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ def _init_models_exclude_types():
return INPUT, frozen_model, compressed_model


INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()
INPUT_ET, FROZEN_MODEL_ET, COMPRESSED_MODEL_ET = _init_models_exclude_types()
def setUpModule():
global \
INPUT, \
FROZEN_MODEL, \
COMPRESSED_MODEL, \
INPUT_ET, \
FROZEN_MODEL_ET, \
COMPRESSED_MODEL_ET
INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()
INPUT_ET, FROZEN_MODEL_ET, COMPRESSED_MODEL_ET = _init_models_exclude_types()


class TestDeepPotAPBC(unittest.TestCase):
Expand Down
12 changes: 10 additions & 2 deletions source/tests/tf/test_model_compression_se_a_ebd.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,16 @@ def _init_models_exclude_types():
return INPUT, frozen_model, compressed_model


INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()
INPUT_ET, FROZEN_MODEL_ET, COMPRESSED_MODEL_ET = _init_models_exclude_types()
def setUpModule():
global \
INPUT, \
FROZEN_MODEL, \
COMPRESSED_MODEL, \
INPUT_ET, \
FROZEN_MODEL_ET, \
COMPRESSED_MODEL_ET
INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()
INPUT_ET, FROZEN_MODEL_ET, COMPRESSED_MODEL_ET = _init_models_exclude_types()


class TestDeepPotAPBC(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def _init_models_exclude_types():
return INPUT, frozen_model, compressed_model


INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()
def setUpModule():
global INPUT, FROZEN_MODEL, COMPRESSED_MODEL
INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()


class TestDeepPotAPBC(unittest.TestCase):
Expand Down
12 changes: 10 additions & 2 deletions source/tests/tf/test_model_compression_se_atten.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,16 @@ def _init_models_exclude_types():
return inputs, frozen_models, compressed_models


INPUTS, FROZEN_MODELS, COMPRESSED_MODELS = _init_models()
INPUTS_ET, FROZEN_MODELS_ET, COMPRESSED_MODELS_ET = _init_models_exclude_types()
def setUpModule():
global \
INPUTS, \
FROZEN_MODELS, \
COMPRESSED_MODELS, \
INPUTS_ET, \
FROZEN_MODELS_ET, \
COMPRESSED_MODELS_ET
INPUTS, FROZEN_MODELS, COMPRESSED_MODELS = _init_models()
INPUTS_ET, FROZEN_MODELS_ET, COMPRESSED_MODELS_ET = _init_models_exclude_types()


@unittest.skipIf(
Expand Down
4 changes: 3 additions & 1 deletion source/tests/tf/test_model_compression_se_r.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def _init_models():
return INPUT, frozen_model, compressed_model


INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()
def setUpModule():
global INPUT, FROZEN_MODEL, COMPRESSED_MODEL
INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()


class TestDeepPotAPBC(unittest.TestCase):
Expand Down
4 changes: 3 additions & 1 deletion source/tests/tf/test_model_compression_se_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def _init_models():
return INPUT, frozen_model, compressed_model


INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()
def setUpModule():
global INPUT, FROZEN_MODEL, COMPRESSED_MODEL
INPUT, FROZEN_MODEL, COMPRESSED_MODEL = _init_models()


def tearDownModule():
Expand Down
Loading