Skip to content

Commit 7298e5f

Browse files
zhaoyingliaAurelius84
authored andcommitted
[AutoParallel] fix unittest with paddle.distributed.launch (PaddlePaddle#44439)
* fix unittest * fix log_dir * _enable_legacy_dygraph
1 parent d977bf7 commit 7298e5f

File tree

8 files changed

+21
-18
lines changed

8 files changed

+21
-18
lines changed

python/paddle/distributed/auto_parallel/process_group.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
import paddle
1818
import paddle.fluid.core as core
19+
1920
from ..collective import _get_global_env
2021
from ..collective import _new_ring_id
2122
from ...fluid.framework import _non_static_mode
2223
from ...fluid.layers.tensor import fill_constant
24+
from paddle.fluid.framework import _enable_legacy_dygraph
2325

2426

2527
def get_all_process_groups():
@@ -134,7 +136,8 @@ def instantiate(self):
134136

135137
# TODO(shenliang03): This is a temporary solution to solve the problem of
136138
# hang caused by cross-creation of new_group
137-
paddle.framework._in_legacy_dygraph()
139+
paddle.disable_static()
140+
_enable_legacy_dygraph()
138141
paddle.set_device('gpu:%d' %
139142
paddle.distributed.ParallelEnv().dev_id)
140143
tmp = paddle.to_tensor(

python/paddle/fluid/tests/unittests/auto_parallel/test_auto_parallel_relaunch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_relaunch(self):
126126
coverage_args = []
127127

128128
cmd = [sys.executable, "-u"] + coverage_args + [
129-
"-m", "launch", "--log_dir", self.temp_dir.name,
129+
"-m", "paddle.distributed.launch", "--log_dir", self.temp_dir.name,
130130
"--cluster_topo_path", cluster_json_path, "--rank_mapping_path",
131131
mapping_json_path, "--enable_auto_mapping", "True",
132132
launch_model_path

python/paddle/fluid/tests/unittests/auto_parallel/test_converter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import tempfile
1516
import unittest
1617
import os
1718
import sys
@@ -32,18 +33,17 @@ def test_converter(self):
3233
else:
3334
coverage_args = []
3435

36+
tmp_dir = tempfile.TemporaryDirectory()
3537
cmd = [sys.executable, "-u"] + coverage_args + [
36-
"-m", "launch", "--gpus", "0,1", launch_model_path
38+
"-m", "paddle.distributed.launch", "--devices", "0,1", "--log_dir",
39+
tmp_dir.name, launch_model_path
3740
]
3841

3942
process = subprocess.Popen(cmd)
4043
process.wait()
4144
self.assertEqual(process.returncode, 0)
4245

43-
# Remove unnecessary files
44-
log_path = os.path.join(file_dir, "log")
45-
if os.path.exists(log_path):
46-
shutil.rmtree(log_path)
46+
tmp_dir.cleanup()
4747

4848
def test_input_invalid(self):
4949
with self.assertRaises(ValueError):

python/paddle/fluid/tests/unittests/auto_parallel/test_engine_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def test_engine_api(self):
3434

3535
tmp_dir = tempfile.TemporaryDirectory()
3636
cmd = [sys.executable, "-u"] + coverage_args + [
37-
"-m", "launch", "--gpus", "0,1", "--log_dir", tmp_dir.name,
38-
launch_model_path
37+
"-m", "paddle.distributed.launch", "--devices", "0,1", "--log_dir",
38+
tmp_dir.name, launch_model_path
3939
]
4040

4141
process = subprocess.Popen(cmd)

python/paddle/fluid/tests/unittests/auto_parallel/test_engine_api_dp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def test_engine_api(self):
3434

3535
tmp_dir = tempfile.TemporaryDirectory()
3636
cmd = [sys.executable, "-u"] + coverage_args + [
37-
"-m", "launch", "--gpus", "0,1", "--log_dir", tmp_dir.name,
38-
launch_model_path
37+
"-m", "paddle.distributed.launch", "--devices", "0,1", "--log_dir",
38+
tmp_dir.name, launch_model_path
3939
]
4040

4141
process = subprocess.Popen(cmd)

python/paddle/fluid/tests/unittests/auto_parallel/test_high_order_grad.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import tempfile
1516
import unittest
1617
import os
1718
import sys
@@ -31,18 +32,17 @@ def test_dp2(self):
3132
else:
3233
coverage_args = []
3334

35+
tmp_dir = tempfile.TemporaryDirectory()
3436
cmd = [sys.executable, "-u"] + coverage_args + [
35-
"-m", "launch", "--gpus", "0,1", launch_model_path
37+
"-m", "paddle.distributed.launch", "--devices", "0,1", "--log_dir",
38+
tmp_dir.name, launch_model_path
3639
]
3740

3841
process = subprocess.Popen(cmd)
3942
process.wait()
4043
self.assertEqual(process.returncode, 0)
4144

42-
# Remove unnecessary files
43-
log_path = os.path.join(file_dir, "log")
44-
if os.path.exists(log_path):
45-
shutil.rmtree(log_path)
45+
tmp_dir.cleanup()
4646

4747

4848
if __name__ == "__main__":

python/paddle/fluid/tests/unittests/auto_parallel/test_relaunch_with_gpt_planner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_relaunch_with_planner(self):
5656
coverage_args = []
5757

5858
cmd = [sys.executable, "-u"] + coverage_args + [
59-
"-m", "launch", "--log_dir", self.temp_dir.name,
59+
"-m", "paddle.distributed.launch", "--log_dir", self.temp_dir.name,
6060
"--cluster_topo_path", cluster_json_path, "--rank_mapping_path",
6161
mapping_json_path, "--enable_auto_mapping", "True",
6262
launch_model_path

python/paddle/fluid/tests/unittests/auto_parallel/test_relaunch_with_planner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_relaunch_with_planner(self):
5656
coverage_args = []
5757

5858
cmd = [sys.executable, "-u"] + coverage_args + [
59-
"-m", "launch", "--log_dir", self.temp_dir.name,
59+
"-m", "paddle.distributed.launch", "--log_dir", self.temp_dir.name,
6060
"--cluster_topo_path", cluster_json_path, "--rank_mapping_path",
6161
mapping_json_path, "--enable_auto_mapping", "True",
6262
launch_model_path

0 commit comments

Comments
 (0)