Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeStyle][task 39] enable isort in python/paddle/base/framework.py(part3) #57839

Merged
merged 18 commits into from
Oct 9, 2023
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ extend_skip_glob = [
# These files do not need to be formatted,
# see .flake8 for more details
"python/paddle/utils/gast/**",
"python/paddle/base/framework.py",
]

[tool.ruff]
Expand Down
7 changes: 5 additions & 2 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import paddle from the source directory; please install paddlepaddle*.whl firstly.'''
)

# NOTE(SigureMo): We should place the import of base.core before other modules,
# because there are some initialization codes in base/core/__init__.py.
from .base import core # noqa: F401
from .batch import batch

# Do the *DUPLICATED* monkey-patch for the tensor object.
Expand Down Expand Up @@ -532,8 +535,8 @@

from .pir_utils import IrGuard

ir_change = IrGuard()
ir_change._switch_to_pir()
ir_guard = IrGuard()
ir_guard._switch_to_pir()

__all__ = [
'iinfo',
Expand Down
8 changes: 3 additions & 5 deletions python/paddle/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import sys
import atexit
import platform

# The legacy core need to be removed before "import core",
# in case of users installing paddlepaddle without -U option
Expand All @@ -32,6 +33,8 @@
except Exception as e:
raise e

from . import core

# import all class inside framework into base module
from . import framework
from .framework import (
Expand Down Expand Up @@ -138,11 +141,6 @@ def __bootstrap__():
Returns:
None
"""
import sys
import os
import platform
from . import core

# NOTE(zhiqiu): When (1)numpy < 1.19; (2) python < 3.7,
# unittest is always imported in numpy (maybe some versions not).
# so is_test is True and p2p is not inited.
Expand Down
53 changes: 26 additions & 27 deletions python/paddle/base/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap
import collections
from collections.abc import Iterable
from .wrapped_decorator import signature_safe_contextmanager, wrap_decorator
import copy
import functools
import multiprocessing
import os
import re
import subprocess
import sys
import textwrap
import threading
import traceback
import copy
from types import MethodType, FunctionType
import warnings
from collections.abc import Iterable
from types import FunctionType, MethodType

import numpy as np
import subprocess
import multiprocessing
import sys

from .proto import framework_pb2
from .proto import data_feed_pb2 # noqa: F401
import paddle.version as paddle_version

from . import core
from . import unique_name
from .. import pir
from paddle.base.libpaddle import DataType
import paddle.version as fluid_version
import warnings
import functools
from .variable_index import _getitem_static, _setitem_static, _setitem_impl_
import threading
from . import core, unique_name
from .libpaddle import DataType
from .proto import data_feed_pb2 # noqa: F401
from .proto import framework_pb2
from .variable_index import _getitem_static, _setitem_impl_, _setitem_static
from .wrapped_decorator import signature_safe_contextmanager, wrap_decorator

__all__ = []

Expand Down Expand Up @@ -503,10 +502,10 @@ def require_version(min_version, max_version=None):
)

version_installed = [
fluid_version.major,
fluid_version.minor,
fluid_version.patch,
fluid_version.rc,
paddle_version.major,
paddle_version.minor,
paddle_version.patch,
paddle_version.rc,
]
zero_version = ['0', '0', '0', '0']

Expand All @@ -524,15 +523,15 @@ def version_cmp(ver_a, ver_b):
"PaddlePaddle version in [{}, {}] required, but {} installed. "
"Maybe you are using a develop version, "
"please make sure the version is good with your code.".format(
min_version, max_version, fluid_version.full_version
min_version, max_version, paddle_version.full_version
)
)
else:
warnings.warn(
"PaddlePaddle version {} or higher is required, but {} installed, "
"Maybe you are using a develop version, "
"please make sure the version is good with your code.".format(
min_version, fluid_version.full_version
min_version, paddle_version.full_version
)
)
return
Expand All @@ -554,15 +553,15 @@ def version_cmp(ver_a, ver_b):
):
raise Exception(
"VersionError: PaddlePaddle version in [{}, {}] required, but {} installed.".format(
min_version, max_version, fluid_version.full_version
min_version, max_version, paddle_version.full_version
)
)
else:
if version_cmp(version_installed, min_version_to_check) < 0:
raise Exception(
"VersionError: PaddlePaddle version {} or higher is required, but {} installed, "
"please upgrade your PaddlePaddle to {} or other higher version.".format(
min_version, fluid_version.full_version, min_version
min_version, paddle_version.full_version, min_version
)
)

Expand Down Expand Up @@ -7704,8 +7703,8 @@ def _get_var(name, program=None):

@signature_safe_contextmanager
def dygraph_guard_if_declarative():
from .dygraph.base import in_to_static_mode
from .dygraph import Tracer
from .dygraph.base import in_to_static_mode

if in_to_static_mode():
# Under @paddle.jit.to_static decorator, we switch back dygraph mode temporarily.
Expand Down
8 changes: 4 additions & 4 deletions python/paddle/pir/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from paddle.base.libpaddle.pir import (
from paddle.base.libpaddle.pir import ( # noqa: F401
Program,
Block,
Operation,
Expand All @@ -22,8 +22,8 @@
fake_op_result,
is_fake_op_result,
Type,
) # noqa: F401
from paddle.base.libpaddle.pir import (
)
from paddle.base.libpaddle.pir import ( # noqa: F401
translate_to_new_ir,
set_global_program,
set_insertion_point,
Expand All @@ -32,7 +32,7 @@
check_unregistered_ops,
register_paddle_dialect,
PassManager,
) # noqa: F401
)

from . import core

Expand Down
4 changes: 2 additions & 2 deletions test/dygraph_to_static/test_origin_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import inspect
import sys
import unittest

Expand All @@ -23,11 +24,10 @@
OriginInfo,
attach_origin_info,
create_and_update_origin_info_map,
gast,
inspect,
unwrap,
)
from paddle.jit.dy2static.utils import ast_to_func
from paddle.utils import gast


def simple_func(x):
Expand Down