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

Update design doc for Python Layer #4698

Merged
merged 5 commits into from
Oct 16, 2017

Conversation

reyoung
Copy link
Collaborator

@reyoung reyoung commented Oct 11, 2017

This update is about how to implement layer function. The logic in this PR is as follow:

  1. There are around 150 lines of code to implement FullyConnected layer if we do not provide any common functions. So it is necessary to give a mechanism for code reusing.
  2. There is a comparison between global functions and a helper class. The disadvantages of global functions are 1) lack of a namespace. 2) Need to pass parameter every time.
    • There are two pieces of demo code for global functions and a helper class. It shows that a helper class can make code shorter and clearer.
  3. How to implement a layer helper class.


1. The layer developer can figure out how many common functions they can use by just typing `self.` in an IDE.
2. It is easy to understand and develop since inheritance is a common way to reuse code.
3. It is transparent for end-users since we can wrap a functor class to a function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe Add a Conclusion part that we choose Functor to build our layer.

self.kwargs = kwargs

def __call__(self):
raise NotImplementedError("LayerBase is a ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

complete the msg of LayerBase is a

We can provide a decorator to wrap a functor class as a function. The code is as follows.

```python
def export(name):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe export_layer or layer? make user be sure what this decorator is used for.

Copy link
Collaborator

@JiayiFeng JiayiFeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive!

@reyoung reyoung merged commit 790b9ce into PaddlePaddle:develop Oct 16, 2017
We not only use the fewer lines of code to write `fc_layer` but also make the code clearer to understand. At the same time, layer developers can figure out what function they can invoke by typing `helper.` in a python editor.


### Implementation of layer helper

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the new api be compatible with v2 api?

@reyoung reyoung deleted the feature/update_layer_design branch October 28, 2017 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants