Skip to content

Commit

Permalink
[CodeStyle][UP031] fix tools/* and a little python/paddle/base - …
Browse files Browse the repository at this point in the history
…part 7 (PaddlePaddle#65549)
  • Loading branch information
gouzil authored Jun 28, 2024
1 parent 418b6c7 commit 7196994
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 107 deletions.
3 changes: 1 addition & 2 deletions python/paddle/base/data_feeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ def convert_dtype(dtype: DTypeLike) -> str:

raise TypeError(
"dtype must be any of [bool, float16, uint16, float32, float64, int8, int16, "
"int32, int64, uint8, complex64, complex128, bfloat16], but received %s"
% dtype
f"int32, int64, uint8, complex64, complex128, bfloat16], but received {dtype}"
)


Expand Down
4 changes: 1 addition & 3 deletions python/paddle/base/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def create_dataset(self, datafeed_class="QueueDataset"):
dataset = globals()[datafeed_class]()
return dataset
except:
raise ValueError(
"datafeed class %s does not exist" % datafeed_class
)
raise ValueError(f"datafeed class {datafeed_class} does not exist")


class DatasetBase:
Expand Down
12 changes: 4 additions & 8 deletions python/paddle/base/device_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _gen_worker_desc(self, trainer_desc):
prog_id_to_worker = opt_info["program_id_to_worker"]
if prog_id_to_worker.get(program_id) is None:
raise ValueError(
"%s not found in program_id_to_worker" % program_id
f"{program_id} not found in program_id_to_worker"
)
worker = opt_info["program_id_to_worker"][program_id]
for i in worker.get_desc().dense_table:
Expand Down Expand Up @@ -311,7 +311,7 @@ def _gen_worker_desc(self, trainer_desc):
prog_id_to_worker = opt_info["program_id_to_worker"]
if prog_id_to_worker.get(program_id) is None:
raise ValueError(
"%s not found in program_id_to_worker" % program_id
f"{program_id} not found in program_id_to_worker"
)
worker = opt_info["program_id_to_worker"][program_id]
for i in worker.get_desc().dense_table:
Expand Down Expand Up @@ -425,9 +425,7 @@ def _gen_worker_desc(self, trainer_desc):
raise ValueError("opt_info must have program_id_to_worker")
prog_id_to_worker = opt_info["program_id_to_worker"]
if prog_id_to_worker.get(program_id) is None:
raise ValueError(
"%s not found in program_id_to_worker" % program_id
)
raise ValueError(f"{program_id} not found in program_id_to_worker")
worker = opt_info["program_id_to_worker"][program_id]
for i in worker.get_desc().dense_table:
if i.table_id in dense_table_set:
Expand Down Expand Up @@ -535,9 +533,7 @@ def _gen_worker_desc(self, trainer_desc):
raise ValueError("opt_info must have program_id_to_worker")
prog_id_to_worker = opt_info["program_id_to_worker"]
if prog_id_to_worker.get(program_id) is None:
raise ValueError(
"%s not found in program_id_to_worker" % program_id
)
raise ValueError(f"{program_id} not found in program_id_to_worker")
worker = opt_info["program_id_to_worker"][program_id]
for i in worker.get_desc().dense_table:
if i.table_id in dense_table_set:
Expand Down
23 changes: 8 additions & 15 deletions python/paddle/base/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,7 @@ def _add_feed_fetch_ops(
)
else:
warnings.warn(
"The variable %s is not found in program. It is not declared or is pruned."
% name
f"The variable {name} is not found in program. It is not declared or is pruned."
)

if use_fetch_v2:
Expand Down Expand Up @@ -1420,8 +1419,7 @@ def _pir_feed_data(self, program, feed, scope, data_op_infos):
if feed_name not in feed_target_names:
feed.pop(feed_name)
warnings.warn(
"The value %s is not found in program. It is not declared or is pruned."
% feed_name
f"The value {feed_name} is not found in program. It is not declared or is pruned."
)

def _fetch_data(self, fetch_list, fetch_var_name, scope):
Expand Down Expand Up @@ -1578,8 +1576,7 @@ def _update_feed(cls, program, feed):
if not global_block.has_var(feed_name):
feed.pop(feed_name)
warnings.warn(
"The variable %s is not found in program. It is not declared or is pruned."
% feed_name
f"The variable {feed_name} is not found in program. It is not declared or is pruned."
)

elif isinstance(feed, (list, tuple)):
Expand All @@ -1588,8 +1585,7 @@ def _update_feed(cls, program, feed):
if not global_block.has_var(feed_name):
each.pop(feed_name)
warnings.warn(
"The variable %s is not found in program. It is not declared or is pruned."
% feed_name
f"The variable {feed_name} is not found in program. It is not declared or is pruned."
)
return feed

Expand Down Expand Up @@ -1945,8 +1941,7 @@ def _run_impl(
feed = feed[0]
if not isinstance(feed, dict):
raise TypeError(
"feed requires dict as its Parameter. But you passed in %s"
% (type(feed))
f"feed requires dict as its Parameter. But you passed in {type(feed)}"
)
feed = self._update_feed(program, feed)

Expand Down Expand Up @@ -2037,7 +2032,7 @@ def _run_impl(
and varobj.belong_to_optimizer is False
and varname not in feed
):
raise ValueError('Need feed data for variable %s' % varname)
raise ValueError(f'Need feed data for variable {varname}')

acp._auto_checkpoint(self, program)

Expand Down Expand Up @@ -2094,8 +2089,7 @@ def _run_pir_impl(
feed = feed[0]
if not isinstance(feed, dict):
raise TypeError(
"feed requires dict as its Parameter. But you passed in %s"
% (type(feed))
f"feed requires dict as its Parameter. But you passed in {type(feed)}"
)

(
Expand Down Expand Up @@ -2974,8 +2968,7 @@ def _add_feed_ops(self, program, feed, feed_var_name):
)
else:
warnings.warn(
"The variable %s is not found in program. It is not declared or is pruned."
% name
f"The variable {name} is not found in program. It is not declared or is pruned."
)

return tmp_program
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/base/layer_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def input_dtype(self, input_param_name='input'):
def get_parameter(self, name):
param = self.main_program.global_block().var(name)
if not isinstance(param, Parameter):
raise ValueError("no Parameter name %s found" % name)
raise ValueError(f"no Parameter name {name} found")
return param

# TODO (jiabin): reconstruct this in LayerObjHelper and avoid dependency of bias_attr
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/base/layer_helper_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def to_variable(self, value, name=None):
return value
else:
raise TypeError(
"The type of input value is invalid, expected type is 'ndarray' or 'Variable', but received %s"
% type(value)
f"The type of input value is invalid, expected type is 'ndarray' or 'Variable', but received {type(value)}"
)

def _create_weight_normalize(self, attr, shape, dtype):
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/base/trainer_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _set_copy_table_config(self, config_dict):
if not isinstance(values, list):
values = [values]
if len(values) != 1:
raise ValueError("dependency len %s != 1" % len(values))
raise ValueError(f"dependency len {len(values)} != 1")
for value in values:
m.values.append(value)
config.dense_pull_after_copy = config_dict.get(
Expand Down
2 changes: 1 addition & 1 deletion tools/check_only_change_python_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_pr_files(self):
for f in files:
file_dict[PADDLE_ROOT + f.filename] = f.status
page += 1
print("pr modify files: %s" % file_dict)
print(f"pr modify files: {file_dict}")
return file_dict

def check_only_change_python_file(self):
Expand Down
2 changes: 1 addition & 1 deletion tools/diff_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
'''
if error:
for each_diff in diffs:
print("- %s" % each_diff)
print(f"- {each_diff}")
35 changes: 14 additions & 21 deletions tools/get_pr_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_pr_files(self):
if file_count == 30: # if pr file count = 31, nend to run all case
break
page += 1
print("pr modify files: %s" % file_dict)
print(f"pr modify files: {file_dict}")
return file_dict

def get_is_white_file(self, filename):
Expand Down Expand Up @@ -369,18 +369,14 @@ def get_pr_ut(self):
PRECISION_TEST_Cases_ratio = format(
float(len(ut_list)) / float(self.get_all_count()), '.2f'
)
print("filterFiles: %s" % filterFiles)
print(f"filterFiles: {filterFiles}")
print("ipipe_log_param_PRECISION_TEST: true")
print(f"ipipe_log_param_PRECISION_TEST_Cases_count: {len(ut_list)}")
print(
"ipipe_log_param_PRECISION_TEST_Cases_count: %s" % len(ut_list)
f"ipipe_log_param_PRECISION_TEST_Cases_ratio: {PRECISION_TEST_Cases_ratio}"
)
print(
"ipipe_log_param_PRECISION_TEST_Cases_ratio: %s"
% PRECISION_TEST_Cases_ratio
)
print(
"The unittests in prec delta is shown as following: %s"
% ut_list
f"The unittests in prec delta is shown as following: {ut_list}"
)
return '\n'.join(ut_list)
else:
Expand Down Expand Up @@ -419,13 +415,12 @@ def get_pr_ut(self):
f_judge_in_added_ut = True
if f_judge_in_added_ut:
print(
"Adding new unit tests not hit mapFiles: %s"
% f_judge
f"Adding new unit tests not hit mapFiles: {f_judge}"
)
else:
notHitMapFiles.append(f_judge)
elif file_dict[f] in ['removed']:
print("remove file not hit mapFiles: %s" % f_judge)
print(f"remove file not hit mapFiles: {f_judge}")
else:
if self.is_only_comment(f):
ut_list.append('comment_placeholder')
Expand All @@ -440,7 +435,7 @@ def get_pr_ut(self):
notHitMapFiles.append(f_judge) if file_dict[
f
] != 'removed' else print(
"remove file not hit mapFiles: %s" % f_judge
f"remove file not hit mapFiles: {f_judge}"
)
else:
if file_dict[f] not in ['removed']:
Expand All @@ -457,9 +452,9 @@ def get_pr_ut(self):
ut_list = list(set(ut_list))
if len(notHitMapFiles) != 0:
print("ipipe_log_param_PRECISION_TEST: false")
print("notHitMapFiles: %s" % notHitMapFiles)
print(f"notHitMapFiles: {notHitMapFiles}")
if len(filterFiles) != 0:
print("filterFiles: %s" % filterFiles)
print(f"filterFiles: {filterFiles}")
return ''
else:
if ut_list:
Expand All @@ -475,21 +470,19 @@ def get_pr_ut(self):
else:
print('PREC download prec_delta failed')
sys.exit(1)
print("hitMapFiles: %s" % hitMapFiles)
print(f"hitMapFiles: {hitMapFiles}")
print("ipipe_log_param_PRECISION_TEST: true")
print(
"ipipe_log_param_PRECISION_TEST_Cases_count: %s"
% len(ut_list)
f"ipipe_log_param_PRECISION_TEST_Cases_count: {len(ut_list)}"
)
PRECISION_TEST_Cases_ratio = format(
float(len(ut_list)) / float(self.get_all_count()), '.2f'
)
print(
"ipipe_log_param_PRECISION_TEST_Cases_ratio: %s"
% PRECISION_TEST_Cases_ratio
f"ipipe_log_param_PRECISION_TEST_Cases_ratio: {PRECISION_TEST_Cases_ratio}"
)
if len(filterFiles) != 0:
print("filterFiles: %s" % filterFiles)
print(f"filterFiles: {filterFiles}")
return '\n'.join(ut_list)


Expand Down
Loading

0 comments on commit 7196994

Please sign in to comment.