Skip to content

Commit

Permalink
[CodeStyle] Fix pass multiple arg to error message (PaddlePaddle#65575)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: gouzil <66515297+gouzil@users.noreply.github.com>
  • Loading branch information
SigureMo and gouzil authored Jun 30, 2024
1 parent 16e38c7 commit 8c7e50e
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 35 deletions.
3 changes: 1 addition & 2 deletions python/paddle/base/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1459,8 +1459,7 @@ def _get_targets(_optimize_ops, _fetch_list, item):
_fetch_list.append(item)
else:
raise TypeError(
"The item in fetch_list should be str, variable or optimize_op, but received %s.",
type(item),
f"The item in fetch_list should be str, variable or optimize_op, but received {type(item)}.",
)

for index, item in enumerate(fetch_list):
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/base/layers/math_op_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def safe_get_dtype(var):
try:
dtype = var.dtype
except:
raise ValueError("Cannot get data type from %s", var.name)
raise ValueError(f"Cannot get data type from {var.name}")
return dtype

def current_block(var):
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/device/cuda/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def wrap_cuda_graph(function, mode="thread_local", memory_pool="default"):
memory_pool_id = CoreCUDAGraph.gen_new_memory_pool_id()
else:
raise ValueError(
"memory_pool should be one of default or new under static graph mode, but got",
memory_pool,
f"memory_pool should be one of default or new under static graph mode, but got {memory_pool}",
)
return _cuda_graph_guard(
mode + ';' + str(memory_pool_id) + ';' + graph_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def _init_server(self, *args, **kwargs):
return

if not os.path.isdir(model_dirname):
raise ValueError("There is no directory named '%s'", model_dirname)
raise ValueError(f"There is no directory named '{model_dirname}'")

# load dense
paddle.static.load_vars(
Expand Down
6 changes: 2 additions & 4 deletions python/paddle/distributed/ps/utils/ps_program_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def __init__(self, pass_ctx):
super().__init__(pass_ctx)
if self.ps_mode != DistributedMode.GEO:
raise ValueError(
"ps mode: {} not matched {}",
format(self.ps_mode, "GeoPsProgramBuilder"),
f"ps mode: {self.ps_mode} not matched GeoPsProgramBuilder",
)

def _build_trainer_programs(self):
Expand Down Expand Up @@ -180,8 +179,7 @@ def __init__(self, pass_ctx):
and self.ps_mode != DistributedMode.ASYNC
):
raise ValueError(
"ps mode: {} not matched {}",
format(self.ps_mode, "PsProgramBuilder"),
f"ps mode: {self.ps_mode} not matched PsProgramBuilder"
)

def _build_trainer_programs(self):
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/distributed/ps/utils/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ def get_dense_send_context(
def get_geo_trainer_send_context(attrs):
if attrs['ps_mode'] != DistributedMode.GEO:
raise ValueError(
"ps mode: {} not matched {}",
format(attrs['ps_mode'], "get_geo_trainer_send_context"),
f"ps mode: {attrs['ps_mode']} not matched get_geo_trainer_send_context",
)
send_ctx = {}
trainer_id = get_role_id(attrs['role_maker'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _init_transpiler_server(self, model_dir=None):

if model_dir:
if not os.path.isdir(model_dir):
raise ValueError("There is no directory named '%s'", model_dir)
raise ValueError(f"There is no directory named '{model_dir}'")

sparse_varnames = self.compiled_config.get_sparse_varname_on_ps(
True
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/incubate/distributed/models/moe/moe_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def __init__(
elif isinstance(gate, NaiveGate):
self.top_k = gate.top_k
elif isinstance(gate, BaseGate):
raise TypeError("Unimplemented gate type: ", type(gate))
raise TypeError(f"Unimplemented gate type: {type(gate)}")
else:
raise TypeError("gate's type must be either dict or moe.BaseGate")
self.gate = gate
Expand Down
6 changes: 2 additions & 4 deletions python/paddle/nn/functional/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4516,15 +4516,13 @@ def adaptive_log_softmax_with_loss(
if input.dim() != 2:
raise ValueError(
'1D label tensor expects 2D input tensors, '
'but found inputs with size',
input.shape,
f'but found inputs with size {input.shape}'
)
elif targt_dim == 0:
if input.dim() != 1:
raise ValueError(
'0D label tensor expects 1D input tensors, '
'but found inputs with size',
input.shape,
f'but found inputs with size {input.shape}'
)
else:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/nn/initializer/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def forward(
value_name = "int8_values"
values = [int(v) for v in np_value.flat]
else:
raise ValueError("Unsupported dtype %s", self._value.dtype)
raise ValueError(f"Unsupported dtype {self._value.dtype}")
if self._value.size > 1024 * 1024 * 1024:
raise ValueError(
"The size of input is too big. Please consider "
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/nn/initializer/bilinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def forward(
value_name = "values"
values = [float(v) for v in weight.flat]
else:
raise TypeError("Unsupported dtype %s", var.dtype)
raise TypeError(f"Unsupported dtype {var.dtype}")

if np.prod(shape) > 1024 * 1024:
raise ValueError("The size of input is too big. ")
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/nn/initializer/normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def __init__(
if isinstance(self._mean, complex):
if self._mean.real != self._mean.imag:
raise ValueError(
"if mean is a complex number, its real part should equal imag part, ",
f"but got real part: {self._mean.real} != imag part: {self._mean.imag}",
"if mean is a complex number, its real part should equal imag part, "
f"but got real part: {self._mean.real} != imag part: {self._mean.imag}"
)
self._mean = self._mean.real

Expand Down
13 changes: 4 additions & 9 deletions python/paddle/nn/layer/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ def append_activation(self, input_var, act=None, use_cudnn=None):
if isinstance(act, str):
act = {'type': act}
else:
raise TypeError(
str(act) + " should be unicode or str in %s ", self.name
)
raise TypeError(f"{act} should be unicode or str in {self.name}")

if (use_cudnn is not None) and use_cudnn:
act['use_cudnn'] = use_cudnn
Expand Down Expand Up @@ -2491,8 +2489,7 @@ def float(
excluded_layers = list(excluded_layers)
else:
raise TypeError(
"excluded_layers should be type nn.Layer or list, but got %s.",
type(excluded_layers).__name__,
f"excluded_layers should be type nn.Layer or list, but got {type(excluded_layers).__name__}.",
)

def layer_trans(layer):
Expand Down Expand Up @@ -2558,8 +2555,7 @@ def float16(
excluded_layers = list(excluded_layers)
else:
raise TypeError(
"excluded_layers should be type nn.Layer or list, but got %s.",
type(excluded_layers).__name__,
f"excluded_layers should be type nn.Layer or list, but got {type(excluded_layers).__name__}.",
)

def layer_trans(layer):
Expand Down Expand Up @@ -2626,8 +2622,7 @@ def bfloat16(
excluded_layers = list(excluded_layers)
else:
raise TypeError(
"excluded_layers should be type nn.Layer or list, but got %s.",
type(excluded_layers).__name__,
f"excluded_layers should be type nn.Layer or list, but got {type(excluded_layers).__name__}.",
)

def layer_trans(layer):
Expand Down
8 changes: 4 additions & 4 deletions python/paddle/tensor/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,12 @@ def gaussian(
core.DataType.COMPLEX128,
]:
raise TypeError(
"if mean is a complex number, dtype should be complex64 or complex128, ",
"if mean is a complex number, dtype should be complex64 or complex128, "
f"but got dtype = {dtype}",
)
if mean.real != mean.imag:
raise ValueError(
"The mean of complex gaussian distribution should be a complex number with ",
"The mean of complex gaussian distribution should be a complex number with "
f"real part equal imaginary part, but got {mean.real} != {mean.imag}",
)
mean = mean.real
Expand Down Expand Up @@ -778,12 +778,12 @@ def gaussian_(
core.DataType.COMPLEX128,
]:
raise TypeError(
"if mean is a complex number, x's dtype should be complex64 or complex128, ",
"if mean is a complex number, x's dtype should be complex64 or complex128, "
f"but dtype = {x.dtype}",
)
if mean.real != mean.imag:
raise ValueError(
"The mean of complex gaussian distribution should be a complex number with ",
"The mean of complex gaussian distribution should be a complex number with "
f"real part equal imaginary part, but got {mean.real} != {mean.imag}",
)
mean = mean.real
Expand Down

0 comments on commit 8c7e50e

Please sign in to comment.