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

add net_design doc #2547

Closed
wants to merge 2 commits into from

Conversation

Superjomn
Copy link
Contributor

init

# Overfiew

整体设计上参考 caffe2的SimpleNet,即Net 是一组 operator 的集合,包含了operator相关的操作,比如Create, RunOps, Delete 等。

Copy link
Contributor

Choose a reason for hiding this comment

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

推荐design doc英文写 ,请参考目录下其他design doc,Interface 需要列出来,并简单描述一下
不应出现比如,设计文档是确定的方案,大家可以review和后续修改 : )

@@ -0,0 +1,14 @@
# Overfiew

整体设计上参考 caffe2的SimpleNet,即Net 是一组 operator 的集合,包含了operator相关的操作,比如Create, RunOps, Delete 等。
Copy link
Contributor

Choose a reason for hiding this comment

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

今天上午讨论的对外提供的接口包括:
AddOp
Run
这两个接口,
用户配置Net的接口为什么还需要Delete ?


- Net 管理其拥有的operator
- Net 本身不占用任何Variable资源
- Net 的调用方式类似 Functor,即 `output = net(inputs, scope)` ,其中
Copy link
Contributor

Choose a reason for hiding this comment

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

请确认一下,这里是显式调用Net.Run吧?


```c++
// The minimum a network should be implemented.
class BaseNetwork {
Copy link
Contributor

Choose a reason for hiding this comment

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

Named NetworkBase or Net is better ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"

@@ -0,0 +1,65 @@
# Network Design
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// The minimum a network should be implemented.
class BaseNetwork {
public:
BaseNetwork(const NetDef& def, Scope *scope);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Following the purpose of decoupling Scope and Net, scope should be passed to Net::Run other than to Net::Net.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


protected:
// the input variables feed into the network.
std::vector<Variable*> external_inputs_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As there is not something named internal_inputs_, here we should just name it inputs_? And analogously, rename external_outputs_ into outputs_?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 vars_.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think inputs and outputs should be distinguished because both of them are important properties of a network(a directed graph).

As a "base network", we may inherit NetworkBase and implement a DAG in the future, and inputs and outputs will directly determine a sub-graph of a DAG.


protected:
// the input variables feed into the network.
std::vector<Variable*> external_inputs_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because a Scope is passed in to Run other than the constructor, we don't have a chance to get Variable* here. Instead, we should have:

std::vector<string> vars_;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we have scope_, we are not decoupling Net from Workspace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// has a `name`
std::string name_;
// the operations are owned by `Network`.
std::vector<std::shared_ptr<Operator>> oprs_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should use unique_ptr here other than shared_ptr. The reason is in this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// has a `name`
std::string name_;
// the operations are owned by `Network`.
std::vector<std::shared_ptr<Operator>> oprs_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The word "operator" usually shortened as "op", not "opr".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

# 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

To conform to list API in Net class, we should use Run instead of RunOps here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

protected:
// to make the network's structure more human-readable, each network will
// has a `name`
std::string name_;
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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.

4 participants