未验证 提交 105bb929 编写于 作者: M Matsumoto Ruko 提交者: GitHub

Remove py36 code in .py files (#48426)

上级 d33d6db0
...@@ -68,16 +68,6 @@ class ParallelEnvArgs: ...@@ -68,16 +68,6 @@ class ParallelEnvArgs:
self.selected_devices = None self.selected_devices = None
def _py_supported_check():
if not sys.version_info >= (3, 4):
raise RuntimeError(
"Use `paddle.distributed.spawn` to start parallel training "
"requires python version greater than 3.4, if your python "
"is lower than this version, please use "
"`paddle.distributed.launch` instead."
)
def _options_valid_check(options): def _options_valid_check(options):
# `print_config` keeped as a debug options, not show to users # `print_config` keeped as a debug options, not show to users
supported_options = [ supported_options = [
...@@ -414,7 +404,6 @@ def _func_wrapper(func, args, error_queue, return_queue, env_dict, backend): ...@@ -414,7 +404,6 @@ def _func_wrapper(func, args, error_queue, return_queue, env_dict, backend):
class MultiprocessContext: class MultiprocessContext:
def __init__(self, processes, error_queues, return_queues): def __init__(self, processes, error_queues, return_queues):
_py_supported_check()
self.error_queues = error_queues self.error_queues = error_queues
# NOTE(chenweihang): The `spawn` method is mainly used # NOTE(chenweihang): The `spawn` method is mainly used
# to wrap the outermost execution function of the program for # to wrap the outermost execution function of the program for
...@@ -598,13 +587,6 @@ def spawn(func, args=(), nprocs=-1, join=True, daemon=False, **options): ...@@ -598,13 +587,6 @@ def spawn(func, args=(), nprocs=-1, join=True, daemon=False, **options):
if __name__ == '__main__': if __name__ == '__main__':
dist.spawn(train, args=(True,), nprocs=2, gpus='4,5') dist.spawn(train, args=(True,), nprocs=2, gpus='4,5')
""" """
# NOTE(chenweihang): [ why only supports python3.4+ ? ]
# Python supported setting the child process startup method
# since 3.4. The previous version can only use the default startup
# method, while the default startup method of Unix is fork, which
# cannot support CUDA runtime multi-process
_py_supported_check()
# Give an error hint when the users enter a configuration option # Give an error hint when the users enter a configuration option
# that does not exist # that does not exist
_options_valid_check(options) _options_valid_check(options)
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
import unittest import unittest
from parallel_dygraph_mnist import TestMnist from parallel_dygraph_mnist import TestMnist
...@@ -64,7 +63,7 @@ class TestParallelDygraphMnistXPU(TestDistBase): ...@@ -64,7 +63,7 @@ class TestParallelDygraphMnistXPU(TestDistBase):
class TestParallelDygraphMnistSpawn(TestDistSpawnRunner): class TestParallelDygraphMnistSpawn(TestDistSpawnRunner):
def test_mnist_with_spawn(self): def test_mnist_with_spawn(self):
if fluid.core.is_compiled_with_cuda() and sys.version_info >= (3, 4): if fluid.core.is_compiled_with_cuda():
self.check_dist_result_with_spawn(test_class=TestMnist, delta=1e-5) self.check_dist_result_with_spawn(test_class=TestMnist, delta=1e-5)
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
import unittest import unittest
from parallel_dygraph_no_sync import TestNoSync from parallel_dygraph_no_sync import TestNoSync
...@@ -80,7 +79,7 @@ class TestParallelDygraphNoSyncControlFlow(TestDistBase): ...@@ -80,7 +79,7 @@ class TestParallelDygraphNoSyncControlFlow(TestDistBase):
class TestParallelDygraphNoSyncSpawn(TestDistSpawnRunner): class TestParallelDygraphNoSyncSpawn(TestDistSpawnRunner):
def test_no_sync_with_spawn(self): def test_no_sync_with_spawn(self):
if fluid.core.is_compiled_with_cuda() and sys.version_info >= (3, 4): if fluid.core.is_compiled_with_cuda():
self.check_dist_result_with_spawn(test_class=TestNoSync, delta=1e-5) self.check_dist_result_with_spawn(test_class=TestNoSync, delta=1e-5)
...@@ -89,7 +88,7 @@ class TestParallelDygraphNoSyncUnusedParamSpawn(TestDistSpawnRunner): ...@@ -89,7 +88,7 @@ class TestParallelDygraphNoSyncUnusedParamSpawn(TestDistSpawnRunner):
args.find_unused_parameters = True args.find_unused_parameters = True
def test_no_sync_with_spawn(self): def test_no_sync_with_spawn(self):
if fluid.core.is_compiled_with_cuda() and sys.version_info >= (3, 4): if fluid.core.is_compiled_with_cuda():
self.check_dist_result_with_spawn( self.check_dist_result_with_spawn(
test_class=TestNoSyncUnusedParam, delta=1e-5 test_class=TestNoSyncUnusedParam, delta=1e-5
) )
...@@ -100,7 +99,7 @@ class TestParallelDygraphNoSyncControlFlowSpawn(TestDistSpawnRunner): ...@@ -100,7 +99,7 @@ class TestParallelDygraphNoSyncControlFlowSpawn(TestDistSpawnRunner):
args.find_unused_parameters = True args.find_unused_parameters = True
def test_no_sync_with_spawn(self): def test_no_sync_with_spawn(self):
if fluid.core.is_compiled_with_cuda() and sys.version_info >= (3, 4): if fluid.core.is_compiled_with_cuda():
self.check_dist_result_with_spawn( self.check_dist_result_with_spawn(
test_class=TestNoSyncControlFlow, delta=1e-5 test_class=TestNoSyncControlFlow, delta=1e-5
) )
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
import unittest import unittest
from parallel_dygraph_se_resnext import TestSeResNeXt from parallel_dygraph_se_resnext import TestSeResNeXt
...@@ -43,7 +42,7 @@ class TestParallelDygraphSeResNeXt(TestDistBase): ...@@ -43,7 +42,7 @@ class TestParallelDygraphSeResNeXt(TestDistBase):
class TestParallelDygraphSeResNeXtSpawn(TestDistSpawnRunner): class TestParallelDygraphSeResNeXtSpawn(TestDistSpawnRunner):
def test_se_resnext_with_spawn(self): def test_se_resnext_with_spawn(self):
if fluid.core.is_compiled_with_cuda() and sys.version_info >= (3, 4): if fluid.core.is_compiled_with_cuda():
self.check_dist_result_with_spawn( self.check_dist_result_with_spawn(
test_class=TestSeResNeXt, delta=0.01 test_class=TestSeResNeXt, delta=0.01
) )
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
import unittest import unittest
from parallel_dygraph_sparse_embedding import TestSparseEmbedding from parallel_dygraph_sparse_embedding import TestSparseEmbedding
...@@ -61,7 +60,7 @@ class TestParallelDygraphSparseEmdeddingFP64(TestDistBase): ...@@ -61,7 +60,7 @@ class TestParallelDygraphSparseEmdeddingFP64(TestDistBase):
class TestParallelDygraphSparseEmdeddingSpawn(TestDistSpawnRunner): class TestParallelDygraphSparseEmdeddingSpawn(TestDistSpawnRunner):
def test_sparse_embedding_with_spawn(self): def test_sparse_embedding_with_spawn(self):
if fluid.core.is_compiled_with_cuda() and sys.version_info >= (3, 4): if fluid.core.is_compiled_with_cuda():
self.check_dist_result_with_spawn( self.check_dist_result_with_spawn(
test_class=TestSparseEmbedding, delta=1e-5 test_class=TestSparseEmbedding, delta=1e-5
) )
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
import unittest import unittest
from parallel_dygraph_sparse_embedding_over_height import ( from parallel_dygraph_sparse_embedding_over_height import (
...@@ -47,7 +46,7 @@ class TestParallelDygraphSparseEmdeddingOverHeight(TestDistBase): ...@@ -47,7 +46,7 @@ class TestParallelDygraphSparseEmdeddingOverHeight(TestDistBase):
class TestParallelDygraphSparseEmdeddingOverHeightSpawn(TestDistSpawnRunner): class TestParallelDygraphSparseEmdeddingOverHeightSpawn(TestDistSpawnRunner):
def test_sparse_embedding_with_spawn(self): def test_sparse_embedding_with_spawn(self):
if fluid.core.is_compiled_with_cuda() and sys.version_info >= (3, 4): if fluid.core.is_compiled_with_cuda():
self.check_dist_result_with_spawn( self.check_dist_result_with_spawn(
test_class=TestSparseEmbeddingOverHeight, delta=1e-5 test_class=TestSparseEmbeddingOverHeight, delta=1e-5
) )
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
import unittest import unittest
from parallel_dygraph_unused_variables import TestSparseEmbeddingUnusedVars from parallel_dygraph_unused_variables import TestSparseEmbeddingUnusedVars
...@@ -51,7 +50,7 @@ class TestFleetDygraphUnusedVar(TestParallelDygraphUnusedVar): ...@@ -51,7 +50,7 @@ class TestFleetDygraphUnusedVar(TestParallelDygraphUnusedVar):
class TestSparseEmbeddingUnusedVarsSpawn(TestDistSpawnRunner): class TestSparseEmbeddingUnusedVarsSpawn(TestDistSpawnRunner):
def test_mnist_with_spawn(self): def test_mnist_with_spawn(self):
if fluid.core.is_compiled_with_cuda() and sys.version_info >= (3, 4): if fluid.core.is_compiled_with_cuda():
self.check_dist_result_with_spawn( self.check_dist_result_with_spawn(
test_class=TestSparseEmbeddingUnusedVars, delta=1e-5 test_class=TestSparseEmbeddingUnusedVars, delta=1e-5
) )
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
import unittest import unittest
import numpy as np import numpy as np
import os import os
import sys
from io import BytesIO from io import BytesIO
import tempfile import tempfile
...@@ -149,11 +148,7 @@ class TestSaveLoadPickle(unittest.TestCase): ...@@ -149,11 +148,7 @@ class TestSaveLoadPickle(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
paddle.save(save_dict, path, 5) paddle.save(save_dict, path, 5)
protocols = [ protocols = [2, 3, 4]
2,
]
if sys.version_info.major >= 3 and sys.version_info.minor >= 4:
protocols += [3, 4]
for protocol in protocols: for protocol in protocols:
paddle.save(save_dict, path, pickle_protocol=protocol) paddle.save(save_dict, path, pickle_protocol=protocol)
dict_load = paddle.load(path) dict_load = paddle.load(path)
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import sys
import unittest import unittest
import paddle import paddle
...@@ -1798,11 +1797,7 @@ class TestStaticSaveLoadPickle(unittest.TestCase): ...@@ -1798,11 +1797,7 @@ class TestStaticSaveLoadPickle(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
paddle.fluid.save(prog, path, 5) paddle.fluid.save(prog, path, 5)
protocols = [ protocols = [2, 3, 4]
2,
]
if sys.version_info.major >= 3 and sys.version_info.minor >= 4:
protocols += [3, 4]
for protocol in protocols: for protocol in protocols:
paddle.fluid.save(prog, path, protocol) paddle.fluid.save(prog, path, protocol)
# set var to zero # set var to zero
......
...@@ -17,7 +17,6 @@ import sys ...@@ -17,7 +17,6 @@ import sys
import time import time
import numpy as np import numpy as np
import struct import struct
from collections import namedtuple
__all__ = [] __all__ = []
...@@ -57,16 +56,7 @@ class ProgressBar: ...@@ -57,16 +56,7 @@ class ProgressBar:
) )
def _get_max_width(self): def _get_max_width(self):
if sys.version_info > (3, 3): from shutil import get_terminal_size
from shutil import get_terminal_size
else:
try:
from backports.shutil_get_terminal_size import get_terminal_size
except:
def get_terminal_size():
terminal_size = namedtuple("terminal_size", "columns lines")
return terminal_size(80, 24)
terminal_width, _ = get_terminal_size() terminal_width, _ = get_terminal_size()
terminal_width = terminal_width if terminal_width > 0 else 80 terminal_width = terminal_width if terminal_width > 0 else 80
......
...@@ -18,7 +18,6 @@ import paddle ...@@ -18,7 +18,6 @@ import paddle
# TODO: check serializing named tensor # TODO: check serializing named tensor
# TODO: check influence on autograd # TODO: check influence on autograd
import sys import sys
import warnings
import copy import copy
import threading import threading
from multiprocessing.util import register_after_fork from multiprocessing.util import register_after_fork
...@@ -34,14 +33,6 @@ def _supported_check(): ...@@ -34,14 +33,6 @@ def _supported_check():
return False return False
if not sys.version_info >= (3, 4):
warnings.warn(
"Use `paddle.multiprocessing` to share paddle tensor "
"requires python version greater than 3.4 ."
" `paddle.multiprocessing` will not take any effect !!!"
)
return False
return True return True
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
from PIL import Image from PIL import Image
import paddle import paddle
...@@ -246,15 +245,7 @@ class DatasetFolder(Dataset): ...@@ -246,15 +245,7 @@ class DatasetFolder(Dataset):
and class_to_idx is a dictionary. and class_to_idx is a dictionary.
""" """
if sys.version_info >= (3, 5): classes = [d.name for d in os.scandir(dir) if d.is_dir()]
# Faster and available in Python 3.5 and above
classes = [d.name for d in os.scandir(dir) if d.is_dir()]
else:
classes = [
d
for d in os.listdir(dir)
if os.path.isdir(os.path.join(dir, d))
]
classes.sort() classes.sort()
class_to_idx = {classes[i]: i for i in range(len(classes))} class_to_idx = {classes[i]: i for i in range(len(classes))}
return classes, class_to_idx return classes, class_to_idx
......
...@@ -21,10 +21,6 @@ import sys ...@@ -21,10 +21,6 @@ import sys
print("Testing SSL certificate checking for Python:", sys.version) print("Testing SSL certificate checking for Python:", sys.version)
if sys.version_info[:2] < (2, 7) or sys.version_info[:2] < (3, 4):
print("This version never checks SSL certs; skipping tests")
sys.exit(0)
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
from urllib.request import urlopen from urllib.request import urlopen
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册