-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
add net_design doc #2547
add net_design doc #2547
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Network Design | ||
|
||
`Network` is the container and controller of a set of operators in a network, users can use `Network.addOp` to add operators into a network, | ||
and use `Network.runOps` to run all the operators in the network. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To conform to list API in Net class, we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
The `Network` will | ||
|
||
- manage all the operators contained in the network. | ||
- not own any `Variable`. | ||
|
||
# API | ||
|
||
To make the `Network` extendibe, a base class is defined like this | ||
|
||
```c++ | ||
// The minimum a network should be implemented. | ||
class BaseNetwork { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Named NetworkBase or Net is better ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Net seems wired without a prefix like "SimpleNet" or "DAGNet" and I will name it "NetworkBase" |
||
public: | ||
BaseNetwork(const NetDef& def, Scope *scope); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the purpose of decoupling Scope and Net, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
// run all the operators and return success(true) or not. | ||
virtual bool Run() = 0; | ||
|
||
protected: | ||
// the input variables feed into the network. | ||
std::vector<Variable*> external_inputs_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is not something named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that a net could read and/or write a variable, so we might have read-only and writable variables, other than input and output variables, associated with it? I am not sure if we should distinguish them, or just have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think As a "base network", we may inherit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because a Scope is passed in to std::vector<string> vars_; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// the corresponding output variables the network will write. | ||
std::vector<Variable*> external_outputs_; | ||
// scope which contains all the global variables visiable to this network. | ||
Scope *scope_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}; | ||
``` | ||
|
||
A simple implemention is as followed: | ||
|
||
```c++ | ||
class Network : public BaseNetwork { | ||
public: | ||
|
||
// Create an empty network. | ||
Network(const std::string& name, Scope *scope); | ||
|
||
// NetDef is the definition of a network, in some occasion, operators are created | ||
// dynamically by user one by one; but in some other occasion such as LSTM, all | ||
// the operators in the networks should be created during the construction | ||
// of the network. So a `NetDef` is provided to make the `Network` create a | ||
// network with all the operators described in `def`. | ||
Network(const std::string& name, const NetDef& def, Scope *scope); | ||
|
||
// add a operator which is identified as `type` and has attributes described | ||
// in `attr`. | ||
bool AddOp(const std::string &type, const OprAttr& attr); | ||
|
||
// run all operators in oprs_ sequentially. | ||
virtual bool Run() override; | ||
|
||
protected: | ||
// to make the network's structure more human-readable, each network will | ||
// has a `name` | ||
std::string name_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is useless at present. we can remove it from the design doc and add when it is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// the operations are owned by `Network`. | ||
std::vector<std::shared_ptr<Operator>> oprs_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The word "operator" usually shortened as "op", not "opr". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}; | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest that we move this design doc into
paddle/framework/net.md
, so we could keep the code (implementation) together with the design.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done