Skip to content

Commit

Permalink
fix python2 (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceci3 authored Feb 5, 2021
1 parent e0e4086 commit e40ed0f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions paddleslim/core/dygraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def extract_vars(inputs):
vars.append(_value)
else:
_logger.warn(
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}."
"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)
)
elif isinstance(inputs, (tuple, list)):
for _value in inputs:
vars.extend(extract_vars(_value))
if len(vars) == 0:
_logger.warn(f"Extract none variables from inputs.")
_logger.warn("Extract none variables from inputs.")
return vars


Expand Down
6 changes: 3 additions & 3 deletions paddleslim/dygraph/prune/filter_pruner.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def prune_var(self, var_name, pruned_dims, pruned_ratio, apply="impretive"):
"""
if var_name in self.skip_vars:
_logger.warn(
f"{var_name} is skiped beacause it is not support for pruning derectly."
"{} is skiped beacause it is not support for pruning derectly.".format(var_name)
)
return
if isinstance(pruned_dims, int):
Expand All @@ -340,7 +340,7 @@ def prune_var(self, var_name, pruned_dims, pruned_ratio, apply="impretive"):
'var': param,
'value': np.array(param.value().get_tensor())
})
_logger.debug(f"set value of {param.name} into group")
_logger.debug("set value of {} into group".format(param.name))

mask = self.cal_mask(var_name, pruned_ratio, group_dict)
for _name in group_dict:
Expand All @@ -356,7 +356,7 @@ def prune_var(self, var_name, pruned_dims, pruned_ratio, apply="impretive"):
src_mask = self._transform_mask(src_mask, trans)
current_mask = src_mask
assert len(current_mask) == var_shape[dims[
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)}"
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))
plan.add(_name, PruningMask(dims, current_mask, pruned_ratio))
if apply == "lazy":
plan.apply(self.model, lazy=True)
Expand Down
2 changes: 1 addition & 1 deletion paddleslim/prune/group_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def collect_convs(params, graph, visited={}):
param = graph.var(_param)
if param is None:
_logger.warning(
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."
"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)
)
groups.append([])
continue
Expand Down
4 changes: 2 additions & 2 deletions paddleslim/prune/prune_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _prune_op(self, op, var, pruned_axis, pruned_idx, visited=None):
_logger.debug("\nfrom: {}\nto: {}\npruned_axis: {}; var: {}".format(
self.op, op, pruned_axis, var.name()))
_logger.debug(
f"visit {op.type()} by var [{var.name()}] on axis [{pruned_axis}];\t visited={self.visited}\n"
"visit {} by var [{}] on axis [{}];\t visited={}\n".format(op.type(), var.name(), pruned_axis, self.visited)
)
walker = cls(op, pruned_params=self.pruned_params, visited=self.visited)
walker.prune(var, pruned_axis, pruned_idx)
Expand Down Expand Up @@ -123,7 +123,7 @@ def _is_depthwise_conv(self, op):
def _prune(self, var, pruned_axis, pruned_idx):

if self._is_depthwise_conv(self.op):
_logger.debug(f"Meet conv2d who is depthwise conv2d actually.")
_logger.debug("Meet conv2d who is depthwise conv2d actually.")
walker = depthwise_conv2d(
self.op, self.pruned_params, visited=self.visited)
walker._prune(var, pruned_axis, pruned_idx)
Expand Down
2 changes: 1 addition & 1 deletion paddleslim/prune/pruner.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def prune(self,
op.attr("groups") * new_shape[pruned_axis] /
origin_shape[pruned_axis])
_logger.debug(
f"change groups of conv({param.name()}) from {op.attr('groups')} to {new_groups}; origin_shape: {origin_shape}; new_shape: {new_shape}"
"change groups of conv({}) from {} to {}; origin_shape: {}; new_shape: {}".format(param.name(), op.attr('groups'), new_groups, origin_shape, new_shape)
)
op.set_attr("groups", new_groups)

Expand Down

0 comments on commit e40ed0f

Please sign in to comment.