Skip to content

Commit

Permalink
[CodeStyle][task 39] enable isort in python/paddle/base (part1) (Pa…
Browse files Browse the repository at this point in the history
…ddlePaddle#57413)

* enable isort rule in python/paddle/base

* fix bug

* fix bug

* fix bug
  • Loading branch information
ccsuzzh authored and jiahy0825 committed Oct 16, 2023
1 parent 9daac57 commit 10b0b0b
Show file tree
Hide file tree
Showing 30 changed files with 172 additions and 172 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ skip = ["build", "third_party", "__init__.py"]
extend_skip_glob = [
# These files do not need to be formatted,
# see .flake8 for more details
"python/paddle/base/**",
"python/paddle/utils/gast/**",
"python/paddle/base/core.py",
"python/paddle/base/framework.py",
]

[tool.ruff]
Expand Down
19 changes: 8 additions & 11 deletions python/paddle/base/backward.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .proto import framework_pb2

from paddle.base import framework as framework
from paddle.base import program_guard
from . import core
import collections
import copy
import logging
from . import unique_name
from . import log_helper
import paddle.base
from .data_feeder import check_type
import re
import warnings

from collections.abc import Sequence

import re
import paddle.base
from paddle.base import framework as framework
from paddle.base import program_guard

from . import core, log_helper, unique_name
from .data_feeder import check_type
from .proto import framework_pb2

__all__ = [
'append_backward',
Expand Down
19 changes: 9 additions & 10 deletions python/paddle/base/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import sys
import warnings
from . import framework
from .framework import cuda_places, cpu_places, xpu_places
from . import core

from . import core, framework
from .framework import cpu_places, cuda_places, xpu_places

__all__ = [
'CompiledProgram',
Expand Down Expand Up @@ -399,10 +399,11 @@ def convert_concrete_program(
"""
Convert the ConcreteProgram to IPUConcreteProgram.
"""
from ..base.dygraph.base import switch_to_static_graph
import paddle

from ..base import backward
from ..base.dygraph.base import switch_to_static_graph
from ..base.framework import device_guard
import paddle

inputs = concrete_program.inputs
outputs = concrete_program.outputs
Expand Down Expand Up @@ -508,14 +509,12 @@ def patch_program_cache(ipu_strategy):
Returns:
None
"""
from paddle.jit.dy2static import logging_utils
from paddle.jit.dy2static.partial_program import partial_program_from
from paddle.jit.dy2static.program_translator import (
MAX_TRACED_PROGRAM_COUNT,
CacheKey,
ProgramCache,
MAX_TRACED_PROGRAM_COUNT,
)
from paddle.jit.dy2static import logging_utils
from paddle.jit.dy2static.partial_program import (
partial_program_from,
)

old_getter = ProgramCache.__getitem__
Expand Down
3 changes: 2 additions & 1 deletion python/paddle/base/data_feed_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from paddle.base.proto import data_feed_pb2
from google.protobuf import text_format

from paddle.base.proto import data_feed_pb2

__all__ = ['DataFeedDesc']


Expand Down
13 changes: 7 additions & 6 deletions python/paddle/base/data_feeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from . import core
import numpy as np
import warnings
import struct
import warnings

import numpy as np

from ..ir import OpResult
from . import core
from .framework import (
Variable,
_cpu_num,
_cuda_ids,
default_main_program,
in_dygraph_mode,
in_pir_mode,
)
from .framework import _cpu_num, _cuda_ids

from ..ir import OpResult

__all__ = ['DataFeeder']

Expand Down
6 changes: 4 additions & 2 deletions python/paddle/base/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
# limitations under the License.
"""This is definition of dataset class, which is high performance IO."""

from paddle.base.proto import data_feed_pb2
from google.protobuf import text_format
from . import core

from paddle.base.proto import data_feed_pb2

from ..utils import deprecated
from . import core

__all__ = ['DatasetFactory', 'InMemoryDataset', 'QueueDataset']

Expand Down
3 changes: 2 additions & 1 deletion python/paddle/base/default_scope_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
invoked in a new local scope.
"""

import paddle.base.core
import threading

import paddle.base.core

__tl_scope__ = threading.local()

__all__ = [
Expand Down
16 changes: 9 additions & 7 deletions python/paddle/base/dygraph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ..wrapped_decorator import signature_safe_contextmanager, wrap_decorator
import decorator
import inspect
import sys
import warnings

import decorator
import numpy as np
from paddle.base import core
from paddle.base import framework

import paddle
from paddle.base import core, framework
from paddle.base.framework import global_var
from paddle.base.multiprocess_utils import CleanupFuncRegistrar
from .tracer import Tracer

from ..data_feeder import convert_dtype
import warnings
from ..framework import _get_paddle_place
import paddle
from ..wrapped_decorator import signature_safe_contextmanager, wrap_decorator
from .tracer import Tracer

__all__ = [
'no_grad',
Expand Down
10 changes: 4 additions & 6 deletions python/paddle/base/dygraph/math_op_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .. import core
from ..framework import (
convert_np_dtype_to_dtype_,
)
from .. import framework

import numpy as np

from paddle import _C_ops, _legacy_C_ops

from .. import core, framework
from ..framework import convert_np_dtype_to_dtype_

_supported_int_dtype_ = [
core.VarDesc.VarType.UINT8,
core.VarDesc.VarType.INT8,
Expand Down
34 changes: 17 additions & 17 deletions python/paddle/base/dygraph/tensor_patch_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@
# limitations under the License.

import inspect
import numpy as np
import warnings
import sys
import warnings

import numpy as np

import paddle
from .. import framework
from ..framework import convert_np_dtype_to_dtype_
from .. import core
from .. import unique_name
import paddle.profiler as profiler
import paddle.utils.deprecated as deprecated
from paddle import _C_ops
from paddle.base.data_feeder import (
_PADDLE_DTYPE_2_NUMPY_DTYPE,
convert_uint16_to_float,
)
from paddle.profiler.utils import in_profiler_mode

from .. import core, framework, unique_name
from ..framework import (
Variable,
EagerParamBase,
Parameter,
Variable,
_getitem_static,
_setitem_static,
_setitem_impl_,
EagerParamBase,
_setitem_static,
convert_np_dtype_to_dtype_,
)
from .base import switch_to_static_graph
from .math_op_patch import monkey_patch_math_tensor
from paddle.base.data_feeder import (
convert_uint16_to_float,
_PADDLE_DTYPE_2_NUMPY_DTYPE,
)
import paddle.utils.deprecated as deprecated
import paddle.profiler as profiler
from paddle.profiler.utils import in_profiler_mode
from paddle import _C_ops

_grad_scalar = None

Expand Down
3 changes: 1 addition & 2 deletions python/paddle/base/dygraph/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
# limitations under the License.


from paddle.base import core
from paddle.base import framework
from paddle import _C_ops, _legacy_C_ops
from paddle.base import core, framework

name_mapping = {
"graph_send_recv": {
Expand Down
3 changes: 2 additions & 1 deletion python/paddle/base/dygraph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .framework import dygraph_only
from paddle import _legacy_C_ops

from .framework import dygraph_only


@dygraph_only
def _append_activation_in_dygraph(
Expand Down
33 changes: 14 additions & 19 deletions python/paddle/base/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import copy
import logging
import os
import sys
import warnings
import numpy as np
from functools import lru_cache

from . import set_flags, get_flags
from .framework import Program, default_main_program
import numpy as np

from ..ir import OpResult
from .wrapped_decorator import signature_safe_contextmanager
from . import compiler, core, framework, get_flags, set_flags, unique_name
from .data_feeder import convert_dtype
from .framework import Variable, Operator, in_pir_mode

from .framework import (
convert_np_dtype_to_dtype_,
Operator,
Program,
Variable,
_apply_pass,
convert_np_dtype_to_dtype_,
default_main_program,
in_pir_mode,
paddle_type_to_proto_type,
)

from . import core
from . import unique_name
from . import compiler
from .trainer_factory import TrainerFactory
from .trainer_factory import FetchHandlerMonitor
import copy
from . import framework
from .incubate.checkpoint import auto_checkpoint as acp

from functools import lru_cache
from .trainer_factory import FetchHandlerMonitor, TrainerFactory
from .wrapped_decorator import signature_safe_contextmanager

__all__ = ['Executor', 'global_scope', 'scope_guard']

Expand Down Expand Up @@ -614,8 +609,8 @@ def _to_str(var):


def _prepare_fleet_executor():
from ..distributed.fleet.proto import fleet_executor_desc_pb2
from ..distributed.backup_env import getenv_or_backup
from ..distributed.fleet.proto import fleet_executor_desc_pb2

trainer_endpoints_str = getenv_or_backup("PADDLE_TRAINER_ENDPOINTS", "")
trainer_endpoints = trainer_endpoints_str.split(',')
Expand Down Expand Up @@ -945,7 +940,7 @@ def _get_program_and_executor(self, cached_data):
# print(f"Program after convert:\n {inner_program}", flush=True)
else:
build_strategy = None
from paddle.incubate.autograd import prim_enabled, prim2orig
from paddle.incubate.autograd import prim2orig, prim_enabled

if prim_enabled() and program == default_main_program():
prim2orig()
Expand Down
11 changes: 6 additions & 5 deletions python/paddle/base/incubate/checkpoint/auto_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import logging
import json
import logging
import os
import sys
import time
from threading import current_thread

from paddle.base import unique_name, compiler
from .checkpoint_saver import SerializableBase, CheckpointSaver, PaddleModel
from paddle.base.framework import in_dygraph_mode, Program
from paddle.base import compiler, unique_name
from paddle.base.framework import Program, in_dygraph_mode

from .checkpoint_saver import CheckpointSaver, PaddleModel, SerializableBase

g_train_epoch_range = None
g_checker = None
Expand Down
3 changes: 2 additions & 1 deletion python/paddle/base/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .data_feeder import check_type
import paddle

from .data_feeder import check_type

__all__ = ['set_global_initializer']

_global_weight_initializer_ = None
Expand Down
1 change: 1 addition & 0 deletions python/paddle/base/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging

from paddle.base.log_helper import get_logger

from . import reader
from .reader import *

Expand Down
Loading

0 comments on commit 10b0b0b

Please sign in to comment.