Skip to content

Commit e40ed0f

Browse files
authored
fix python2 (#660)
1 parent e0e4086 commit e40ed0f

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

paddleslim/core/dygraph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ def extract_vars(inputs):
6161
vars.append(_value)
6262
else:
6363
_logger.warn(
64-
f"Variable is excepted, but get an element with type({type(_value)}) from inputs whose type is dict. And the key of element is {_key}."
64+
"Variable is excepted, but get an element with type({}) from inputs whose type is dict. And the key of element is {}.".format(type(_value), _key)
6565
)
6666
elif isinstance(inputs, (tuple, list)):
6767
for _value in inputs:
6868
vars.extend(extract_vars(_value))
6969
if len(vars) == 0:
70-
_logger.warn(f"Extract none variables from inputs.")
70+
_logger.warn("Extract none variables from inputs.")
7171
return vars
7272

7373

paddleslim/dygraph/prune/filter_pruner.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def prune_var(self, var_name, pruned_dims, pruned_ratio, apply="impretive"):
320320
"""
321321
if var_name in self.skip_vars:
322322
_logger.warn(
323-
f"{var_name} is skiped beacause it is not support for pruning derectly."
323+
"{} is skiped beacause it is not support for pruning derectly.".format(var_name)
324324
)
325325
return
326326
if isinstance(pruned_dims, int):
@@ -340,7 +340,7 @@ def prune_var(self, var_name, pruned_dims, pruned_ratio, apply="impretive"):
340340
'var': param,
341341
'value': np.array(param.value().get_tensor())
342342
})
343-
_logger.debug(f"set value of {param.name} into group")
343+
_logger.debug("set value of {} into group".format(param.name))
344344

345345
mask = self.cal_mask(var_name, pruned_ratio, group_dict)
346346
for _name in group_dict:
@@ -356,7 +356,7 @@ def prune_var(self, var_name, pruned_dims, pruned_ratio, apply="impretive"):
356356
src_mask = self._transform_mask(src_mask, trans)
357357
current_mask = src_mask
358358
assert len(current_mask) == var_shape[dims[
359-
0]], f"The length of current_mask must be equal to the size of dimension to be pruned on. But get: len(current_mask): {len(current_mask)}; var_shape: {var_shape}; dims: {dims}; var name: {_name}; len(mask): {len(mask)}"
359+
0]], "The length of current_mask must be equal to the size of dimension to be pruned on. But get: len(current_mask): {}; var_shape: {}; dims: {}; var name: {}; len(mask): {}".format(len(current_mask), var_shape, dims, _name, len(mask))
360360
plan.add(_name, PruningMask(dims, current_mask, pruned_ratio))
361361
if apply == "lazy":
362362
plan.apply(self.model, lazy=True)

paddleslim/prune/group_param.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def collect_convs(params, graph, visited={}):
6060
param = graph.var(_param)
6161
if param is None:
6262
_logger.warning(
63-
f"Cann't found relative variables of {_param} because {_param} is not in target program or model. Please make sure {_param} is in your program if you are using static API of PaddlePaddle. And make sure your model in correctly mode and contains {_param} if you are using dynamic API of PaddlePaddle."
63+
"Cann't found relative variables of {} because {} is not in target program or model. Please make sure {} is in your program if you are using static API of PaddlePaddle. And make sure your model in correctly mode and contains {} if you are using dynamic API of PaddlePaddle.".format(_param, _param, _param, _param)
6464
)
6565
groups.append([])
6666
continue

paddleslim/prune/prune_walker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _prune_op(self, op, var, pruned_axis, pruned_idx, visited=None):
9595
_logger.debug("\nfrom: {}\nto: {}\npruned_axis: {}; var: {}".format(
9696
self.op, op, pruned_axis, var.name()))
9797
_logger.debug(
98-
f"visit {op.type()} by var [{var.name()}] on axis [{pruned_axis}];\t visited={self.visited}\n"
98+
"visit {} by var [{}] on axis [{}];\t visited={}\n".format(op.type(), var.name(), pruned_axis, self.visited)
9999
)
100100
walker = cls(op, pruned_params=self.pruned_params, visited=self.visited)
101101
walker.prune(var, pruned_axis, pruned_idx)
@@ -123,7 +123,7 @@ def _is_depthwise_conv(self, op):
123123
def _prune(self, var, pruned_axis, pruned_idx):
124124

125125
if self._is_depthwise_conv(self.op):
126-
_logger.debug(f"Meet conv2d who is depthwise conv2d actually.")
126+
_logger.debug("Meet conv2d who is depthwise conv2d actually.")
127127
walker = depthwise_conv2d(
128128
self.op, self.pruned_params, visited=self.visited)
129129
walker._prune(var, pruned_axis, pruned_idx)

paddleslim/prune/pruner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def prune(self,
144144
op.attr("groups") * new_shape[pruned_axis] /
145145
origin_shape[pruned_axis])
146146
_logger.debug(
147-
f"change groups of conv({param.name()}) from {op.attr('groups')} to {new_groups}; origin_shape: {origin_shape}; new_shape: {new_shape}"
147+
"change groups of conv({}) from {} to {}; origin_shape: {}; new_shape: {}".format(param.name(), op.attr('groups'), new_groups, origin_shape, new_shape)
148148
)
149149
op.set_attr("groups", new_groups)
150150

0 commit comments

Comments
 (0)