paddleslim.core package

class paddleslim.core.GraphWrapper(program=None, in_nodes=[], out_nodes=[])

Bases: object

It is a wrapper of paddle.fluid.framework.IrGraph with some special functions for paddle slim framework.

Parameters:
  • program (framework.Program) – A program with
  • in_nodes (dict) – A dict to indicate the input nodes of the graph. The key is user-defined and human-readable name. The value is the name of Variable.
  • out_nodes (dict) – A dict to indicate the input nodes of the graph. The key is user-defined and human-readable name. The value is the name of Variable.
all_parameters()

Get all the parameters in this graph.

Returns:A list of VarWrapper instances.
Return type:list<VarWrapper>
clone(for_test=False)

Clone a new graph from current graph.

Returns:The wrapper of a new graph.
Return type:(GraphWrapper)
get_param_by_op(op)

Get the parameters used by target operator.

infer_shape()

Update the groups of convolution layer according to current filters. It is used after loading pruned parameters from file.

is_parameter(var)

Whether the given variable is parameter.

Parameters:var (VarWrapper) – The given varibale.
is_persistable(var)

Whether the given variable is persistable.

Parameters:var (VarWrapper) – The given varibale.
next_ops(op)

Get all the next operators of target operator.

Parameters:op (OpWrapper) – Target operator.
Returns:A list of operators.
Return type:list<OpWrapper>
numel_params()

Get the number of elements in all parameters.

ops()

Return all operator nodes included in the graph as a set.

pre_ops(op)

Get all the previous operators of target operator.

Parameters:op (OpWrapper) – Target operator.
Returns:A list of operators.
Return type:list<OpWrapper>
program()

Get the program in current wrapper.

update_groups_of_conv()
update_param_shape(scope)

Update the shape of parameters in the graph according to tensors in scope. It is used after loading pruned parameters from file.

var(name)

Get the variable by variable name.

vars()

Get all the variables.

class paddleslim.core.VarWrapper(var, graph)

Bases: object

inputs()

Get all the operators that use this variable as output.

Returns:A list of operators.
Return type:list<OpWrapper>
is_parameter()
name()

Get the name of the variable.

outputs()

Get all the operators that use this variable as input.

Returns:A list of operators.
Return type:list<OpWrapper>
set_shape(shape)

Set the shape of the variable.

shape()

Get the shape of the varibale.

class paddleslim.core.OpWrapper(op, graph)

Bases: object

all_inputs()

Get all the input variables of this operator.

all_outputs()

Get all the output variables of this operator.

attr(name)

Get the attribute by name.

Parameters:name (str) – the attribute name.
Returns:The attribute value. The return value can be any valid attribute type.
Return type:bool|int|str|float|list
idx()

Get the id of this operator.

inputs(name)

Get all the varibales by the input name.

is_bwd_op()

Whether this operator is backward op.

is_opt_op()

Whether this operator is optimizer op.

outputs(name)

Get all the varibales by the output name.

set_attr(key, value)

Set the value of attribute by attribute’s name.

Parameters:
  • key (str) – the attribute name.
  • value (bool|int|str|float|list) – the value of the attribute.
type()

Get the type of this operator.

class paddleslim.core.Registry(name)

Bases: object

get(key)
module_dict
name
register(cls)

Submodules

paddleslim.core.graph_wrapper module

class paddleslim.core.graph_wrapper.GraphWrapper(program=None, in_nodes=[], out_nodes=[])

Bases: object

It is a wrapper of paddle.fluid.framework.IrGraph with some special functions for paddle slim framework.

Parameters:
  • program (framework.Program) – A program with
  • in_nodes (dict) – A dict to indicate the input nodes of the graph. The key is user-defined and human-readable name. The value is the name of Variable.
  • out_nodes (dict) – A dict to indicate the input nodes of the graph. The key is user-defined and human-readable name. The value is the name of Variable.
all_parameters()

Get all the parameters in this graph.

Returns:A list of VarWrapper instances.
Return type:list<VarWrapper>
clone(for_test=False)

Clone a new graph from current graph.

Returns:The wrapper of a new graph.
Return type:(GraphWrapper)
get_param_by_op(op)

Get the parameters used by target operator.

infer_shape()

Update the groups of convolution layer according to current filters. It is used after loading pruned parameters from file.

is_parameter(var)

Whether the given variable is parameter.

Parameters:var (VarWrapper) – The given varibale.
is_persistable(var)

Whether the given variable is persistable.

Parameters:var (VarWrapper) – The given varibale.
next_ops(op)

Get all the next operators of target operator.

Parameters:op (OpWrapper) – Target operator.
Returns:A list of operators.
Return type:list<OpWrapper>
numel_params()

Get the number of elements in all parameters.

ops()

Return all operator nodes included in the graph as a set.

pre_ops(op)

Get all the previous operators of target operator.

Parameters:op (OpWrapper) – Target operator.
Returns:A list of operators.
Return type:list<OpWrapper>
program()

Get the program in current wrapper.

update_groups_of_conv()
update_param_shape(scope)

Update the shape of parameters in the graph according to tensors in scope. It is used after loading pruned parameters from file.

var(name)

Get the variable by variable name.

vars()

Get all the variables.

class paddleslim.core.graph_wrapper.VarWrapper(var, graph)

Bases: object

inputs()

Get all the operators that use this variable as output.

Returns:A list of operators.
Return type:list<OpWrapper>
is_parameter()
name()

Get the name of the variable.

outputs()

Get all the operators that use this variable as input.

Returns:A list of operators.
Return type:list<OpWrapper>
set_shape(shape)

Set the shape of the variable.

shape()

Get the shape of the varibale.

class paddleslim.core.graph_wrapper.OpWrapper(op, graph)

Bases: object

all_inputs()

Get all the input variables of this operator.

all_outputs()

Get all the output variables of this operator.

attr(name)

Get the attribute by name.

Parameters:name (str) – the attribute name.
Returns:The attribute value. The return value can be any valid attribute type.
Return type:bool|int|str|float|list
idx()

Get the id of this operator.

inputs(name)

Get all the varibales by the input name.

is_bwd_op()

Whether this operator is backward op.

is_opt_op()

Whether this operator is optimizer op.

outputs(name)

Get all the varibales by the output name.

set_attr(key, value)

Set the value of attribute by attribute’s name.

Parameters:
  • key (str) – the attribute name.
  • value (bool|int|str|float|list) – the value of the attribute.
type()

Get the type of this operator.

paddleslim.core.registry module

class paddleslim.core.registry.Registry(name)

Bases: object

get(key)
module_dict
name
register(cls)