From 5c767f4412090be975fecaa672f04540365abfd6 Mon Sep 17 00:00:00 2001 From: Zhan Rongrui <2742392377@qq.com> Date: Sat, 14 Oct 2023 15:45:40 +0800 Subject: [PATCH] format --- .pre-commit-config.yaml | 1 + pyproject.toml | 3 ++- src/paddlefx/legacy_module/translator.py | 4 ++-- src/paddlefx/pyeval.py | 4 ++-- src/paddlefx/utils.py | 2 +- src/paddlefx/variables/callable.py | 12 ++++++------ 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4d76568..1bb058a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,6 +15,7 @@ repos: hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --no-cache] + exclude: .cmake-format.py - repo: https://github.com/asottile/yesqa rev: v1.4.0 hooks: diff --git a/pyproject.toml b/pyproject.toml index cd1306e..5d718d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,8 @@ select = [ ] ignore = [ "UP015", - "Q000" + "Q000", + "F405" ] target-version = "py38" diff --git a/src/paddlefx/legacy_module/translator.py b/src/paddlefx/legacy_module/translator.py index 4a51832..e8cc805 100644 --- a/src/paddlefx/legacy_module/translator.py +++ b/src/paddlefx/legacy_module/translator.py @@ -128,7 +128,7 @@ def call_function(self, fn, args, kwargs): res = self.output.create_node('call_function', fn, args, kwargs) self.stack.push(res) elif is_custom_call: - raise NotImplementedError(f"custom_call is not supported") + raise NotImplementedError("custom_call is not supported") else: raise NotImplementedError(f"call function {fn} is not supported") @@ -237,7 +237,7 @@ def STORE_SUBSCR(self, inst): self.output.create_node('call_method', "__setitem__", [root, idx, value], {}) def POP_TOP(self, inst: Instruction): - value = self.stack.pop() + self.stack.pop() def STORE_FAST(self, inst: Instruction): self.f_locals[inst.argval] = self.stack.pop() diff --git a/src/paddlefx/pyeval.py b/src/paddlefx/pyeval.py index 0e622a1..0933cb1 100644 --- a/src/paddlefx/pyeval.py +++ b/src/paddlefx/pyeval.py @@ -62,10 +62,10 @@ def wrapper(self: PyEval, inst: Instruction): state = self.get_state() try: return inner_fn(self, inst) - except (BreakGraphError, NotImplementedError) as e: + except (BreakGraphError, NotImplementedError): # TODO: remove NotImplementedError logger.debug( - f"break_graph_if_unsupported triggered compile", exc_info=True + "break_graph_if_unsupported triggered compile", exc_info=True ) if not isinstance(self, PyEval): diff --git a/src/paddlefx/utils.py b/src/paddlefx/utils.py index f8e7e8b..cad5b51 100644 --- a/src/paddlefx/utils.py +++ b/src/paddlefx/utils.py @@ -61,7 +61,7 @@ def hashable(obj) -> bool: try: hash(obj) return True - except TypeError as e: + except TypeError: return False diff --git a/src/paddlefx/variables/callable.py b/src/paddlefx/variables/callable.py index 936da82..caa5e75 100644 --- a/src/paddlefx/variables/callable.py +++ b/src/paddlefx/variables/callable.py @@ -67,7 +67,7 @@ def __call__(self, tx: PyEvalBase, *args: VariableBase, **kwargs) -> VariableBas return result else: # basic layer ot = type(args[0].var) - obj_cls = type(args[0]) + target = '' model = ( tx.f_locals['self'] if 'self' in tx.f_locals else globals()['self'] @@ -82,7 +82,7 @@ def __call__(self, tx: PyEvalBase, *args: VariableBase, **kwargs) -> VariableBas elif fn.__module__.startswith("paddle"): # TODO: support multiple ouputs and containers ot = type(args[0].var) - obj_cls = type(args[0]) + output = graph.call_function(fn, args, kwargs, ot) return TensorVariable(None, node=output) elif inspect.isbuiltin(fn): @@ -95,7 +95,7 @@ def __call__(self, tx: PyEvalBase, *args: VariableBase, **kwargs) -> VariableBas if isinstance(attr, types.MethodType): # For method variables ot = type(args[0].var) - obj_cls = type(args[0]) + return CallableVariable(fn, tx=tx) else: # the attr could be callable function @@ -110,17 +110,17 @@ def __call__(self, tx: PyEvalBase, *args: VariableBase, **kwargs) -> VariableBas operator.iadd, ]: ot = type(args[0].var) - obj_cls = type(args[0]) + output = graph.call_function(fn, args, kwargs, ot) return TensorVariable(None, node=output) elif fn in [operator.gt, operator.lt, operator.ge, operator.le]: ot = type(args[0].var) - obj_cls = type(args[0]) + output = graph.call_function(fn, args, kwargs, ot) return TensorVariable(None, node=output) elif fn in [operator.is_, operator.is_not]: ot = type(args[0].var) - obj_cls = type(args[0]) + output = graph.call_function(fn, args, kwargs, ot) return TensorVariable(None, node=output) else: