Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/H-Coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ jobs:
if: needs.build.outputs.can-skip != 'true'
runs-on:
group: Fleet-H-single-card
timeout-minutes: 60
timeout-minutes: 90
env:
PIP_CACHE_DIR: /root/.cache/pip
CACHE_DIR: /root/.cache
Expand Down
3 changes: 0 additions & 3 deletions python/paddle/_typing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Backport
from .backport import EllipsisType as EllipsisType

# Basic
from .basic import (
NestedList as NestedList,
Expand Down
24 changes: 0 additions & 24 deletions python/paddle/_typing/backport.py

This file was deleted.

3 changes: 1 addition & 2 deletions python/paddle/_typing/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from __future__ import annotations

from collections.abc import Sequence
from types import EllipsisType
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -25,8 +26,6 @@
import numpy.typing as npt
from typing_extensions import Never, TypeAlias

from .backport import EllipsisType

if TYPE_CHECKING:
from paddle import ParamAttr, Tensor
from paddle.nn.initializer import Initializer
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/jit/dy2static/convert_call_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ def _get_module_functions(module):
@functools.lru_cache
def get_module_defining_path(module: ModuleType) -> str | None:
def _remove_module_init_suffix(file_path: str) -> str:
# TODO(SigureMo): use removesuffix after Python 3.9
return re.sub(r"__init__.py$", "", file_path)
return file_path.removesuffix("__init__.py")

if not hasattr(module, "__file__") or module.__file__ is None:
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
ResumeFnNameFactory,
list_contain_by_id,
list_find_index_by_id,
no_eval_frame,
)
from ..instruction_utils import (
apply_instr_pass,
Expand Down Expand Up @@ -93,10 +92,7 @@ def get_pycode_attributes() -> list[str]:
if sys.version_info >= (3, 11):
pycode_attributes.append("co_qualname")
pycode_attributes.append("co_firstlineno")
if sys.version_info >= (3, 10):
pycode_attributes.append("co_linetable")
else:
pycode_attributes.append("co_lnotab")
pycode_attributes.append("co_linetable")
if sys.version_info >= (3, 11):
pycode_attributes.append("co_exceptiontable")
pycode_attributes += [
Expand Down Expand Up @@ -145,12 +141,9 @@ def gen_new_opcode(
"""
bytecode, linetable = assemble(instrs, code_options["co_firstlineno"])

if sys.version_info >= (3, 10):
# Python deprecated co_lnotab in 3.10, use co_linetable instead
# https://peps.python.org/pep-0626/
code_options["co_linetable"] = linetable
else:
code_options["co_lnotab"] = linetable
# Python 3.10+ uses co_linetable.
# https://peps.python.org/pep-0626/
code_options["co_linetable"] = linetable
code_options["co_code"] = bytecode
code_options["co_nlocals"] = len(code_options["co_varnames"])
code_options["co_stacksize"] = stacksize(instrs)
Expand Down Expand Up @@ -198,7 +191,7 @@ def assemble(
if sys.version_info >= (3, 11):
# End hook for Python 3.11
linetable.extend(calc_linetable(None, len(code)))
elif sys.version_info >= (3, 10):
else:
# End hook for Python 3.10
linetable.extend(calc_linetable(0, len(code)))

Expand Down Expand Up @@ -240,31 +233,6 @@ def update_cursor(starts_line: int | None, code_length: int):
if starts_line is not None:
cur_lineno = starts_line

def calc_lnotab(starts_line: int, code_length: int):
"""
Calculates the lnotab for Python 3.8 and 3.9.
https://github.com/python/cpython/blob/3.9/Objects/lnotab_notes.txt

Args:
starts_line (int): The line number where the instruction starts.
code_length (int): The length of the code.

Returns:
list[int]: The lnotab.
"""
nonlocal cur_lineno, cur_bytecode
line_offset = starts_line - cur_lineno
byte_offset = code_length - cur_bytecode
result = []

while line_offset or byte_offset:
line_offset_step = min(max(line_offset, -128), 127)
byte_offset_step = min(max(byte_offset, 0), 255)
result.extend((byte_offset_step, to_byte(line_offset_step)))
line_offset -= line_offset_step
byte_offset -= byte_offset_step
return result

def calc_linetable_py310(starts_line: int, code_length: int):
"""
Calculates the linetable for Python 3.10.
Expand Down Expand Up @@ -337,10 +305,8 @@ def calc_linetable_py311(starts_line: int | None, code_length: int):

if sys.version_info >= (3, 11):
return calc_linetable_py311, update_cursor
elif sys.version_info >= (3, 10):
return calc_linetable_py310, update_cursor
else:
return calc_lnotab, update_cursor
return calc_linetable_py310, update_cursor


def compile_exception_table():
Expand Down Expand Up @@ -872,26 +838,8 @@ def gen_rot_n(self, n):
if sys.version_info >= (3, 11):
for i in range(n, 1, -1):
self.add_instr("SWAP", arg=i)
elif sys.version_info >= (3, 10):
self.add_instr("ROT_N", arg=n)
else:
if n <= 4:
self.add_instr("ROT_" + ["TWO", "THREE", "FOUR"][n - 2])
else:

def rot_n_fn(n):
vars = [f"var{i}" for i in range(n)]
rotated = reversed(vars[-1:] + vars[:-1])
fn = eval(f"lambda {','.join(vars)}: ({','.join(rotated)})")
fn = no_eval_frame(fn)
fn.__name__ = f"rot_{n}_fn"
return fn

self.gen_build_tuple(n)
self.gen_load_const(rot_n_fn(n))
self.gen_rot_n(2)
self.add_instr("CALL_FUNCTION_EX", arg=0)
self.gen_unpack_sequence(n)
self.add_instr("ROT_N", arg=n)

def gen_shift_n(self, s: int, n: int):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from __future__ import annotations

import sys
import types
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -344,11 +343,7 @@ def send(self, /, value: VariableBase):
inline_gen_executor = OpcodeInlineGeneratorExecutor(
self.vframe, self.code_var, self.graph
)
if sys.version_info < (3, 10) and self.vframe.lasti == 0:
assert isinstance(value, ConstantVariable)
assert value.value is None
else:
self.vframe.stack.push(value)
self.vframe.stack.push(value)
with EventGuard(
f"Inline Gen Call: {inline_gen_executor.vframe.code.co_name}, file {inline_gen_executor.vframe.code.co_filename}, line {int(inline_gen_executor.vframe.code.co_firstlineno)}"
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,7 @@ def relocate_jump_target(instructions: list[Instruction]) -> bool:
if instr.opname in REL_BWD_JUMP:
new_arg = -new_arg

if sys.version_info >= (3, 10):
new_arg //= 2
new_arg //= 2
_, invert_jump = correct_jump_direction(instr, new_arg)
has_inverted_jump = has_inverted_jump or invert_jump
assert instr.arg is not None
Expand Down
4 changes: 1 addition & 3 deletions python/paddle/static/python_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def eliminate_positional_or_keyword_only(
code.co_filename,
code.co_name,
code.co_firstlineno,
code.co_linetable
if sys.version_info >= (3, 10)
else code.co_lnotab,
code.co_linetable,
code.co_freevars,
code.co_cellvars,
)
Expand Down
7 changes: 1 addition & 6 deletions test/sot/test_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from __future__ import annotations

import sys
import unittest
from dataclasses import dataclass, field

Expand Down Expand Up @@ -161,11 +160,7 @@ class ComplexDataClass:
a: int
b: int = 0
c: int = field(default=1)
d: int = (
field(default_factory=lambda: 2, kw_only=True)
if sys.version_info >= (3, 10)
else field(default_factory=lambda: 2)
)
d: int = field(default_factory=lambda: 2, kw_only=True)


def create_dataclass_with_a():
Expand Down
8 changes: 4 additions & 4 deletions test/sot/test_info_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def test_case(self):

serialized = BreakGraphReasonInfo.json_report(history)
deserialized = BreakGraphReasonInfo.restore_from_string(
serialized[5:-6] # remove `<sot>` and `</sot>`
) # `removeprefix` & `removesuffix` are only available from python3.9
serialized.removeprefix("<sot>").removesuffix("</sot>")
)

origin_reasons_dict, _ = BreakGraphReasonInfo.classify(history)
origin_reasons2count = {
Expand All @@ -111,8 +111,8 @@ def test_case(self):

serialized = SubGraphInfo.json_report(history)
deserialized = SubGraphInfo.restore_from_string(
serialized[5:-6] # remove `<sot>` and `</sot>`
) # `removeprefix` & `removesuffix` are only available from python3.9
serialized.removeprefix("<sot>").removesuffix("</sot>")
)

self.assertEqual(history, deserialized)

Expand Down