Skip to content

Commit

Permalink
Set min supported Python version to 3.8 (pytorch#93155)
Browse files Browse the repository at this point in the history
Also, grep for `if sys.version_info .cond. (3, 8)` and replaces them with appropriate action.

This is a last in a series of PRs that moved CI/CD away from testing PyTorch behavior against Python-3.7.

Fixes pytorch#80513

Pull Request resolved: pytorch#93155
Approved by: https://github.com/huydhn
  • Loading branch information
malfet authored and pytorchmergebot committed Jan 29, 2023
1 parent 0dceaf0 commit 5976f0b
Show file tree
Hide file tree
Showing 31 changed files with 60 additions and 627 deletions.
4 changes: 2 additions & 2 deletions .github/scripts/generate_ci_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class OperatingSystem:
build_configs=generate_binary_build_matrix.generate_wheels_matrix(
OperatingSystem.LINUX,
arches=["11.8"],
python_versions=["3.7"]),
python_versions=["3.8"]),
branches="master",
),
BinaryBuildWorkflow(
Expand All @@ -144,7 +144,7 @@ class OperatingSystem:
build_configs=generate_binary_build_matrix.generate_wheels_matrix(
OperatingSystem.LINUX,
arches=["11.6"],
python_versions=["3.7"]),
python_versions=["3.8"]),
branches="master",
),
BinaryBuildWorkflow(
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/generated-linux-binary-manywheel-master.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions caffe2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1855,13 +1855,8 @@ if(BUILD_PYTHON)
pycmd(PY_EXT_SUFFIX "
def get_ext_suffix():
import sys
if sys.version_info < (3, 8) and sys.platform == 'win32':
# Workaround for https://bugs.python.org/issue39825
import _imp
return _imp.extension_suffixes()[0]
else:
import sysconfig
return sysconfig.get_config_var('EXT_SUFFIX')
import sysconfig
return sysconfig.get_config_var('EXT_SUFFIX')
suffix = get_ext_suffix()
if suffix is not None:
Expand Down
10 changes: 1 addition & 9 deletions caffe2/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,10 @@

kernel32.LoadLibraryW.restype = ctypes.c_void_p
if with_load_library_flags:
kernel32.AddDllDirectory.restype = ctypes.c_void_p
kernel32.LoadLibraryExW.restype = ctypes.c_void_p

for dll_path in dll_paths:
if sys.version_info >= (3, 8):
os.add_dll_directory(dll_path)
elif with_load_library_flags:
res = kernel32.AddDllDirectory(dll_path)
if res is None:
err = ctypes.WinError(ctypes.get_last_error())
err.strerror += ' Error adding "{}" to the DLL directories.'.format(dll_path)
raise err
os.add_dll_directory(dll_path)

dlls = glob.glob(os.path.join(th_dll_path, '*.dll'))
path_patched = False
Expand Down
4 changes: 2 additions & 2 deletions mypy-nofollow.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ files =
test/test_utils.py

# Minimum version supported - variable annotations were introduced
# in Python 3.7
python_version = 3.7
# in Python 3.8
python_version = 3.8

[mypy-sympy]
ignore_missing_imports = True
Expand Down
2 changes: 1 addition & 1 deletion mypy-strict.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# files.

[mypy]
python_version = 3.7
python_version = 3.8
plugins = mypy_plugins/check_mypy_version.py

cache_dir = .mypy_cache/strict
Expand Down
4 changes: 2 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ files =
exclude = torch/include/|torch/csrc/|torch/distributed/elastic/agent/server/api.py|torch/testing/_internal|torch/distributed/fsdp/fully_sharded_data_parallel.py

# Minimum version supported - variable annotations were introduced
# in Python 3.7
python_version = 3.7
# in Python 3.8
python_version = 3.8


#
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
sys.exit(-1)

import platform
python_min_version = (3, 7, 0)
python_min_version = (3, 8, 0)
python_min_version_str = '.'.join(map(str, python_min_version))
if sys.version_info < python_min_version:
print("You are using Python {}. Python >={} is required.".format(platform.python_version(),
Expand Down
3 changes: 0 additions & 3 deletions test/jit/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ class TestDataclasses(JitTestCase):
def tearDownClass(cls):
torch._C._jit_clear_class_registry()

# We only support InitVar in JIT dataclasses for Python 3.8+ because it would be very hard
# to support without the `type` attribute on InitVar (see comment in _dataclass_impls.py).
@unittest.skipIf(sys.version_info < (3, 8), "InitVar not supported in Python < 3.8")
def test_init_vars(self):
@torch.jit.script
@dataclass(order=True)
Expand Down
3 changes: 0 additions & 3 deletions test/jit/test_jit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import sys
from textwrap import dedent
import unittest

import torch

Expand All @@ -30,7 +29,6 @@ def fn_positional_or_keyword_args_only(x, y):
torch._jit_internal.get_callable_argument_names(fn_positional_or_keyword_args_only))

# Tests that POSITIONAL_ONLY arguments are ignored.
@unittest.skipIf(sys.version_info < (3, 8), 'POSITIONAL_ONLY arguments are not supported before 3.8')
def test_get_callable_argument_names_positional_only(self):
code = dedent('''
def fn_positional_only_arg(x, /, y):
Expand Down Expand Up @@ -69,7 +67,6 @@ def fn_var_keyword_arg(**args):

# Tests that a function signature containing various different types of
# arguments are ignored.
@unittest.skipIf(sys.version_info < (3, 8), 'POSITIONAL_ONLY arguments are not supported before 3.8')
def test_get_callable_argument_names_hybrid(self):
code = dedent('''
def fn_hybrid_args(x, /, y, *args, **kwargs):
Expand Down
17 changes: 8 additions & 9 deletions test/jit/test_recursive_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,17 @@ def forward(self, t):

self.checkModule(M2(), (torch.randn(2, 2),))

if sys.version_info[:2] >= (3, 8):
class M3(torch.nn.Module):
x : typing.Final[int]
class M3(torch.nn.Module):
x : typing.Final[int]

def __init__(self):
super().__init__()
self.x = 2
def __init__(self):
super().__init__()
self.x = 2

def forward(self, t):
return t + self.x
def forward(self, t):
return t + self.x

self.checkModule(M3(), (torch.randn(2, 2),))
self.checkModule(M3(), (torch.randn(2, 2),))

def test_ignore_class(self):
@torch.jit.ignore
Expand Down
13 changes: 1 addition & 12 deletions test/test_cpp_extensions_aot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from itertools import repeat
import os
import re
import sys
from typing import Union
from typing import Union, get_args, get_origin
import unittest

import torch.testing._internal.common_utils as common
Expand All @@ -14,16 +13,6 @@
import torch.backends.cudnn
import torch.utils.cpp_extension

if sys.version_info >= (3, 8):
from typing import get_args, get_origin
else:
def get_args(tp):
return tp.__args__

def get_origin(tp):
if hasattr(tp, "__origin__"):
return tp.__origin__

try:
import pytest
HAS_PYTEST = True
Expand Down
3 changes: 1 addition & 2 deletions test/test_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3923,7 +3923,7 @@ def f():
t = node.outputsAt(0).type()
self.assertIsNotNone(t)

@unittest.skipIf(IS_WINDOWS and sys.version_info >= (3, 8), 'TODO: need to fix the test case')
@unittest.skipIf(IS_WINDOWS, 'TODO: need to fix the test case')
def test_unmatched_type_annotation(self):
message1 = re.escape("Number of type annotations (2) did not match the number of function parameters (1):")
message2 = 'def invalid2\\(a\\):\n\\s*~+\\.*\\s+<--- HERE\n\\s+# type: \\(Int, Int\\) -> Int\n\\s+return a \\+ 2'
Expand Down Expand Up @@ -14452,7 +14452,6 @@ def forward(self, point: Point):
m = torch.jit.script(M())
m(p)

@unittest.skipIf(sys.version_info < (3, 7, 0), "defaults keyword added in Python 3.8")
def test_namedtuple_default_values_using_factory_constructor(self):
Pair = namedtuple("Pair", ["x", "y"], defaults=(1, 2))

Expand Down
2 changes: 1 addition & 1 deletion tools/dynamo/verify_dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pkg_resources import packaging

MIN_CUDA_VERSION = packaging.version.parse("11.6")
MIN_PYTHON_VERSION = (3, 7)
MIN_PYTHON_VERSION = (3, 8)


class VerifyDynamoError(BaseException):
Expand Down
12 changes: 2 additions & 10 deletions torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,10 @@

kernel32.LoadLibraryW.restype = ctypes.c_void_p
if with_load_library_flags:
kernel32.AddDllDirectory.restype = ctypes.c_void_p
kernel32.LoadLibraryExW.restype = ctypes.c_void_p

for dll_path in dll_paths:
if sys.version_info >= (3, 8):
os.add_dll_directory(dll_path)
elif with_load_library_flags:
res = kernel32.AddDllDirectory(dll_path)
if res is None:
err = ctypes.WinError(ctypes.get_last_error())
err.strerror += f' Error adding "{dll_path}" to the DLL directories.'
raise err
os.add_dll_directory(dll_path)

try:
ctypes.CDLL('vcruntime140.dll')
Expand Down Expand Up @@ -441,7 +433,7 @@ def sym_min(a, b):
import torch._C as _C_for_compiled_check

# The __file__ check only works for Python 3.7 and above.
if sys.version_info >= (3, 7) and _C_for_compiled_check.__file__ is None:
if _C_for_compiled_check.__file__ is None:
raise ImportError(textwrap.dedent('''
Failed to load PyTorch C extensions:
It appears that PyTorch has loaded the `torch/_C` folder
Expand Down
17 changes: 1 addition & 16 deletions torch/_dynamo/bytecode_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@
HASLOCAL = set(dis.haslocal)
HASFREE = set(dis.hasfree)

if sys.version_info < (3, 8):

def stack_effect(opcode, arg, jump=None):
# jump= was added in python 3.8, we just ingore it here
if dis.opname[opcode] in ("NOP", "EXTENDED_ARG"):
# for some reason NOP isn't supported in python 3.7
return 0
return dis.stack_effect(opcode, arg)

else:
stack_effect = dis.stack_effect
stack_effect = dis.stack_effect


def remove_dead_code(instructions):
Expand Down Expand Up @@ -187,11 +177,6 @@ def stacksize_analysis(instructions):
low = min([x.low for x in stack_sizes.values()])
high = max([x.high for x in stack_sizes.values()])

if sys.version_info < (3, 8) and not fixed_point.value:
# This is a rare issue in python 3.7 that still needs debugging
# see test/test_nops.py::NopTests::test3
return low + 32

assert fixed_point.value, "failed to reach fixed point"
assert low >= 0
return high
2 changes: 0 additions & 2 deletions torch/_dynamo/bytecode_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,6 @@ def transform_code_object(code, transformations, safe=False):
"co_freevars",
"co_cellvars",
]
if sys.version_info < (3, 8):
keys.pop(1)
if sys.version_info >= (3, 10):
keys = list(map(lambda x: x.replace("co_lnotab", "co_linetable"), keys))
code_options = {k: getattr(code, k) for k in keys}
Expand Down
7 changes: 2 additions & 5 deletions torch/_dynamo/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def rot_n(self, n):
return [create_instruction("ROT_TWO")]
elif n == 3:
return [create_instruction("ROT_THREE")]
elif n == 4 and sys.version_info >= (3, 8):
elif n == 4:
return [create_instruction("ROT_FOUR")]
elif sys.version_info >= (3, 10):
return [create_instruction("ROT_N", n)]
Expand Down Expand Up @@ -343,7 +343,4 @@ def load_import_from(self, module_name, object_name):
)

def create_begin_finally(self):
if sys.version_info < (3, 8):
return self.create_load_const(None)
else:
return create_instruction("BEGIN_FINALLY")
return create_instruction("BEGIN_FINALLY")
7 changes: 1 addition & 6 deletions torch/_dynamo/resume_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ class ReenterWith:
def __call__(self, code_options, cleanup):
if sys.version_info < (3, 9):
with_cleanup_start = create_instruction("WITH_CLEANUP_START")
if sys.version_info < (3, 8):
begin_finally = create_instruction(
"LOAD_CONST", PyCodegen.get_const_index(code_options, None), None
)
else:
begin_finally = create_instruction("BEGIN_FINALLY")
begin_finally = create_instruction("BEGIN_FINALLY")
cleanup[:] = [
create_instruction("POP_BLOCK"),
begin_finally,
Expand Down
20 changes: 3 additions & 17 deletions torch/_dynamo/symbolic_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,11 +857,7 @@ def BEGIN_FINALLY(self, inst):

def WITH_CLEANUP_START(self, inst):
exit, exc = self.popn(2)
if sys.version_info < (3, 8):
assert exc.is_python_constant()
assert exc.as_python_constant() is None
else:
assert exc is None
assert exc is None
self.push(exc)
self.push(exit.call_function(self, [ConstantVariable(None)] * 3, {}))

Expand All @@ -871,13 +867,7 @@ def WITH_CLEANUP_FINISH(self, inst):

def END_FINALLY(self, inst):
tos = self.pop()
if sys.version_info < (3, 8):
# python3.7 and 3.8 can have END_FINALLY without BEGIN_FINALLY
assert tos is None or (
tos.is_python_constant() and tos.as_python_constant() is None
)
else:
assert tos is None
assert tos is None

def FOR_ITER(self, inst):
it = self.pop()
Expand Down Expand Up @@ -1191,11 +1181,7 @@ def BUILD_CONST_KEY_MAP(self, inst):
)

def MAP_ADD(self, inst):
if sys.version_info < (3, 8):
v, k = self.popn(2)
else:
k, v = self.popn(2)

k, v = self.popn(2)
assert inst.argval > 0
obj = self.stack[-inst.arg]
assert isinstance(obj, ConstDictVariable)
Expand Down
Loading

0 comments on commit 5976f0b

Please sign in to comment.