Skip to content

Commit

Permalink
[Dy2St] pir dy2st unittest verification - Part 7 (PaddlePaddle#59016)
Browse files Browse the repository at this point in the history
  • Loading branch information
gouzil authored and SecretXV committed Nov 28, 2023
1 parent 9dab3de commit c68c792
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
16 changes: 10 additions & 6 deletions test/dygraph_to_static/test_closure_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import inspect
import unittest

from dygraph_to_static_utils_new import Dy2StTestBase, test_legacy_and_pir
from dygraph_to_static_utils_new import (
Dy2StTestBase,
test_legacy_and_pir_exe_and_pir_api,
)
from numpy import append

import paddle
Expand Down Expand Up @@ -194,6 +197,7 @@ def init_dygraph_func(self):
{'func': set('i'), 'test_normal_argument': set('x')},
]

@test_legacy_and_pir_exe_and_pir_api
def test_main(self):
if self.judge_type == 'push_pop_vars':
for push_pop_vars, func in zip(
Expand Down Expand Up @@ -260,7 +264,7 @@ def init_dygraph_func(self):


class TestPushPopTrans(Dy2StTestBase):
@test_legacy_and_pir
@test_legacy_and_pir_exe_and_pir_api
def test(self):
def vlist_of_dict(x):
ma = {'a': []}
Expand All @@ -271,7 +275,7 @@ def vlist_of_dict(x):
x = paddle.to_tensor([3])
print(paddle.jit.to_static(vlist_of_dict)(x))

@test_legacy_and_pir
@test_legacy_and_pir_exe_and_pir_api
def test2(self):
import numpy as np

Expand All @@ -284,7 +288,7 @@ def vlist_of_dict(x):
x = paddle.to_tensor([3])
print(paddle.jit.to_static(vlist_of_dict)(x))

@test_legacy_and_pir
@test_legacy_and_pir_exe_and_pir_api
def test3(self):
import numpy as np

Expand All @@ -297,7 +301,7 @@ def vlist_of_dict(x):
x = paddle.to_tensor([3])
print(paddle.jit.to_static(vlist_of_dict)(x))

@test_legacy_and_pir
@test_legacy_and_pir_exe_and_pir_api
def test4(self):
import numpy as np

Expand All @@ -310,7 +314,7 @@ def vlist_of_dict(x):
x = paddle.to_tensor([3])
print(paddle.jit.to_static(vlist_of_dict)(x))

@test_legacy_and_pir
@test_legacy_and_pir_exe_and_pir_api
def test5(self):
import numpy as np

Expand Down
7 changes: 5 additions & 2 deletions test/dygraph_to_static/test_gradient_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import unittest

import numpy as np
from dygraph_to_static_utils_new import Dy2StTestBase, test_legacy_and_pir
from dygraph_to_static_utils_new import (
Dy2StTestBase,
test_legacy_and_pir_exe_and_pir_api,
)

import paddle

Expand All @@ -38,7 +41,7 @@ def forward(self, x):


class TestGradientAggregationInDy2Static(Dy2StTestBase):
@test_legacy_and_pir
@test_legacy_and_pir_exe_and_pir_api
def test_to_static(self):
def simplenet_grad(inp, to_static=False):
net = SimpleNet()
Expand Down
9 changes: 8 additions & 1 deletion test/dygraph_to_static/test_jit_property_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

import unittest

from dygraph_to_static_utils_new import Dy2StTestBase
from dygraph_to_static_utils_new import (
Dy2StTestBase,
test_legacy_and_pir_exe_and_pir_api,
)

import paddle

Expand All @@ -33,18 +36,22 @@ def setUp(self):
self.a = a
self.b = b

@test_legacy_and_pir_exe_and_pir_api
def test_property_save(self):
self.assertEqual(self.a.get_float('a'), self.b.get_float('a'))
self.assertEqual(self.a.get_float(0), 1.0)

@test_legacy_and_pir_exe_and_pir_api
def test_size(self):
self.assertEqual(self.b.size(), 2)
self.assertEqual(self.a.size(), 2)

@test_legacy_and_pir_exe_and_pir_api
def test_load_float(self):
with self.assertRaises(ValueError):
self.a.get_float(1)

@test_legacy_and_pir_exe_and_pir_api
def test_set(self):
"""test property set."""
try:
Expand Down
8 changes: 5 additions & 3 deletions test/dygraph_to_static/test_se_resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@
PRINT_STEP = 2
STEP_NUM = 10

place = base.CUDAPlace(0) if base.is_compiled_with_cuda() else base.CPUPlace()
place = (
paddle.CUDAPlace(0) if paddle.is_compiled_with_cuda() else paddle.CPUPlace()
)

# Note: Set True to eliminate randomness.
# 1. For one operation, cuDNN has several algorithms,
# some algorithm results are non-deterministic, like convolution algorithms.
if base.is_compiled_with_cuda():
base.set_flags({'FLAGS_cudnn_deterministic': True})
if paddle.is_compiled_with_cuda():
paddle.set_flags({'FLAGS_cudnn_deterministic': True})

train_parameters = {
"learning_strategy": {
Expand Down
1 change: 0 additions & 1 deletion test/dygraph_to_static/test_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from paddle.static.nn import cond


@paddle.jit.to_static
def fun1():
a = paddle.to_tensor(1)
b = paddle.to_tensor(2)
Expand Down

0 comments on commit c68c792

Please sign in to comment.