Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

GruStepLayer parameter sharing issue

Open yu239-zz opened this issue 9 years ago • 2 comments

Currently the design is that if two GRU layers have the same para_prefix, then their parameters are shared.

GruStepLayer takes the first input's parameter name and creates a set of parameters: self.create_input_parameter(0, size * size * 3, [size, size * 3])

However, in GatedRecurrentUnit the parameter name is assigned to the second input (memory). Thus even when two GatedRecurrentUnits have the same para_prefix, the parameters will not be shared.

There is probably the same issue in other layers that use GruStepLayer, where para_prefix is not specified for the first input of GruStepLayer.

yu239-zz avatar Jan 26 '17 19:01 yu239-zz

@yu239 If you could provide some code example, it might help us understand the problem better.

wangyang59 avatar Jan 26 '17 20:01 wangyang59

@wangyang59 In the implementation of GatedRecurrentUnit: GruStepLayer( name=name, size=size, bias=Bias(parameter_name=para_prefix + "_gate.b"), inputs=[ input_layer_name, Input( out_memory, parameter_name=para_prefix + "_gate.w") ], active_type=active_type, active_gate_type=gate_active_type, )

The second entry (out_memory) of inputs has parameter name, but not the first one (input_layer_name). GruStepLayer creates the parameters as follows: self.create_input_parameter(0, size * size * 3, [size, size * 3])

'0' means the first input. Since para_prefix is not used for the first input, the parameters could never be shared.

A possible hack would be to assign the parameter name to the first input instead:

inputs=[ Input(input_layer_name, parameter_name=para_prefix + "_gate.w"), out_memory ]

In this way, two GatedRecurrentUnits that have the same para_prefix would share the same set of parameters.

yu239-zz avatar Jan 26 '17 22:01 yu239-zz