XJDKC edited a comment on pull request #697:
URL: https://github.com/apache/singa/pull/697#issuecomment-633222142


   Sorry, the example above is just to show how to create a layer, so I don't 
consider using the latest APIs. And there are no direct params in Model. If we 
let users override set_params/get_params,the code for every layer is quite 
similar.
   ```Python
       def get_params(self):
             self.param_names = ['W', 'b']
             super(LayerName, self).get_params()
       def set_params(self, **params):
             self.param_names = ['W', 'b']
             super(LayerName, self).set_params()
   ```
   So if users declare the names of params and states in \_\_init\_\_, we can 
handle them well and users just need to override three functions(\_\_init\_\_, 
initialize, forward). Another strategy is that we create a subclass of 
Tensor(named Param) and use that class to create params. In this way, we can 
distinguish params from all member variables.
   ```Python
        # self.W = Tensor(shape=w_shape, requires_grad=True, stores_grad=True)
        self.W = Param(shape=w_shape, requires_grad=True, stores_grad=True)
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to