Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter Attribute Design and initializers #5819

Closed
reyoung opened this issue Nov 22, 2017 · 3 comments
Closed

Parameter Attribute Design and initializers #5819

reyoung opened this issue Nov 22, 2017 · 3 comments

Comments

@reyoung
Copy link
Collaborator

reyoung commented Nov 22, 2017

We extract param_initializers from param_attr in PR #5760.

Problems

There are five arugments passed by param_attr before. They are learning rate, name, initializer and regularizer, trainable. If we extract all of them into a indivitual parameter, there could be several problems.

  1. The number of layer parameters are increased.
  • From fc(param_attr=...), to fc(param_name=..., param_initializer=..., param_regularizer=..., param_learning_rate=..., param_trainable=...)
  1. It is hard to add more field in param_attr.
  • Suppose we want to add a attribute to all parameter, like param_XXX. We will change all layers implementation now.
  1. It will provide a paradox of API meanings.
  • For example, if we set fc(use_bias=False, bias_initializer=UniformInitializer(-1.0, 1.0)). What does it mean?
  1. It is hard to specify attributes for multiple parameters.
  • For example. fc(input=[i1, i2], param_name=["w1", "w2"], size=100, param_learning_rate=[1.0, 0.5])

Solution

I think we may unify all arguments of parameter into one strong typed ParamAttr.

It could be

class ParamAttr(object):
   def __init__(self, name=None, initializer=None, regularizer=None, learning_rate=1.0, trainable=True):
      self.name = name
      self.initializer = initializer
      self.regularizer = regularizer
      self.learning_rate = learning_rate
      self.trainable = trainable

Users can specify parameter arugments by

fc(input=[i1, i2], param_attr=[
  ParamAttr(name='w1', initializer=Uniform(-1, 1)),
  ParamAttr(name='w2', initializer=Uniform(0, 1))
], bias_attr=False)
@reyoung
Copy link
Collaborator Author

reyoung commented Nov 22, 2017

BTW. This strong typed ParamAttr is a very common design in software development. It called ParameterObject.

@jacquesqiao
Copy link
Member

jacquesqiao commented Nov 22, 2017

one little problem, if one layer has multiple parameters, what should param_attr be like,:
what about

layer(input=[i1, i2], w1_attr=[
  ParamAttr(name='w1', initializer=Uniform(-1, 1)),
  ParamAttr(name='w2', initializer=Uniform(0, 1))
],w2_attr=[
  ParamAttr(name='w1', initializer=Uniform(-1, 1)),
  ParamAttr(name='w2', initializer=Uniform(0, 1))
], bias_attr=False)

@abhinavarora
Copy link
Contributor

Yes, if a layer will have multiple parameters, then we will have multiple ParamAttr objects.

@reyoung reyoung added this to the Release 0.11.0 milestone Nov 23, 2017
@reyoung reyoung mentioned this issue Nov 23, 2017
20 tasks
reyoung added a commit to reyoung/Paddle that referenced this issue Nov 28, 2017
reyoung added a commit that referenced this issue Nov 29, 2017
* Make param_attr as a strong typed class

Fix #5819
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants