Skip to content

Commit

Permalink
[CodeStyle][UP031] fix some /python/paddle/ - part 18 (PaddlePaddle…
Browse files Browse the repository at this point in the history
  • Loading branch information
gouzil authored Jun 30, 2024
1 parent 8c7e50e commit 9e8d712
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 19 deletions.
10 changes: 5 additions & 5 deletions python/paddle/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
f"""NOTE: You may need to run \"set PATH={executable_path};%PATH%\"
if you encounters \"DLL load failed\" errors. If you have python
installed in other directory, replace \"{executable_path}\" with your own
directory. The original error is: \n {str(e)}"""
directory. The original error is: \n {e}"""
)
else:
raise ImportError(
Expand Down Expand Up @@ -78,7 +78,7 @@ def avx_supported():
except Exception as e:
sys.stderr.write(
'Can not get the AVX flag from /proc/cpuinfo.\n'
'The original error is: %s\n' % str(e)
f'The original error is: {e}\n'
)
return has_avx
elif sysstr == 'darwin':
Expand All @@ -89,7 +89,7 @@ def avx_supported():
except Exception as e:
sys.stderr.write(
'Can not get the AVX flag from machdep.cpu.features.\n'
'The original error is: %s\n' % str(e)
f'The original error is: {e}\n'
)
if not has_avx:
import subprocess
Expand Down Expand Up @@ -173,11 +173,11 @@ def asm_func(code_str, restype=ctypes.c_uint32, argtypes=()):
except Exception as e:
sys.stderr.write(
'Failed getting the AVX flag on Windows.\n'
'The original error is: %s\n' % str(e)
f'The original error is: {e}\n'
)
return (retval & (1 << avx_bit)) > 0
else:
sys.stderr.write('Do not get AVX flag on %s\n' % sysstr)
sys.stderr.write(f'Do not get AVX flag on {sysstr}\n')
return False


Expand Down
4 changes: 2 additions & 2 deletions python/paddle/distributed/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def sync_params_buffers(
for _, param in model._obtain_parameters_buffers().items():
if not isinstance(param, core.eager.Tensor):
raise TypeError(
"The data type of '%s' must be core.eager.Tensor" % param.name
f"The data type of '{param.name}' must be core.eager.Tensor"
)

if is_model_parallel:
Expand Down Expand Up @@ -916,7 +916,7 @@ def _check_var_exists(var_name):
if var is None:
raise ValueError(
"paddle.distributed initialize error, "
"environment variable %s is needed, but not set." % var_name
f"environment variable {var_name} is needed, but not set."
)


Expand Down
4 changes: 2 additions & 2 deletions python/paddle/framework/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def set_default_dtype(d):
else:
raise TypeError(
"set_default_dtype only supports [float16, float32, float64] "
", but received %s" % d.__name__
f", but received {d.__name__}"
)
else:
if isinstance(d, paddle.dtype):
Expand All @@ -67,7 +67,7 @@ def set_default_dtype(d):
else:
raise TypeError(
"set_default_dtype only supports [float16, float32, float64, bfloat16] "
", but received %s" % str(d)
f", but received {d}"
)

LayerHelperBase.set_default_dtype(d)
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/pir/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def convert_np_dtype_to_dtype_(np_dtype):
if dtype in np_type_to_paddle_type.keys():
return np_type_to_paddle_type[dtype]
else:
raise ValueError("Not supported numpy dtype %s" % dtype)
raise ValueError(f"Not supported numpy dtype {dtype}")


# program is a global instance.
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/profiler/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def export_chrome_tracing(
def handle_fn(prof):
nonlocal worker_name
if not worker_name:
worker_name = f"host_{socket.gethostname()}pid_{str(os.getpid())}"
worker_name = f"host_{socket.gethostname()}pid_{os.getpid()}"
now = datetime.datetime.now()
filename = '{}_time_{}.paddle_trace.json'.format(
worker_name, now.strftime('%Y_%m_%d_%H_%M_%S_%f')
Expand Down Expand Up @@ -309,7 +309,7 @@ def export_protobuf(
def handle_fn(prof):
nonlocal worker_name
if not worker_name:
worker_name = f"host_{socket.gethostname()}pid_{str(os.getpid())}"
worker_name = f"host_{socket.gethostname()}pid_{os.getpid()}"
now = datetime.datetime.now()
filename = '{}_time_{}.paddle_trace.pb'.format(
worker_name, now.strftime('%Y_%m_%d_%H_%M_%S_%f')
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/regularizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __call__(
return decay

def __str__(self) -> str:
return "L1Decay, coeff=%f" % self._coeff
return f"L1Decay, coeff={self._coeff:f}"


class L2Decay(WeightDecayRegularizer):
Expand Down Expand Up @@ -273,4 +273,4 @@ def __call__(
return decay

def __str__(self) -> str:
return "L2Decay, coeff=%f" % self._coeff
return f"L2Decay, coeff={self._coeff:f}"
4 changes: 1 addition & 3 deletions python/paddle/text/datasets/conll05.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ def _load_anno(self):
lbl_seq.append('B-' + cur_tag)
is_in_bracket = True
else:
raise RuntimeError(
'Unexpected label: %s' % l
)
raise RuntimeError(f'Unexpected label: {l}')

self.sentences.append(sentences)
self.predicates.append(verb_list[i])
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/utils/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ def wrapper(*args: _InputT.args, **kwargs: _InputT.kwargs) -> _RetT:
f'API "{func.__module__}.{func.__name__}" has been deprecated.'
)

warningmsg = "\033[93m\nWarning:\n%s \033[0m" % (msg)
warningmsg = f"\033[93m\nWarning:\n{msg} \033[0m"
# ensure ANSI escape sequences print correctly in cmd and powershell
if sys.platform.lower() == 'win32':
warningmsg = "\nWarning:\n%s " % (msg)
warningmsg = f"\nWarning:\n{msg} "

v_current = parse_version(paddle.__version__)
v_current += [0] * (4 - len(v_current))
Expand Down

0 comments on commit 9e8d712

Please sign in to comment.