singa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [singa] XJDKC edited a comment on pull request #697: New Model Layer Operator API
Date Sun, 24 May 2020 12:20:48 GMT

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:
users@infra.apache.org



Mime
View raw message