forked from PaddlePaddle/Paddle
-
Couldn't load subscription status.
- Fork 0
nnvm graph
乔龙飞 edited this page Jun 16, 2017
·
8 revisions
class Graph {
public:
// outputs of the computation graph.
std::vector<NodeEntry> outputs;
std::unordered_map<std::string, std::shared_ptr<any> > attrs;
private:
// internal structure of indexed graph
std::shared_ptr<const IndexedGraph> indexed_graph_;
};class IndexedGraph {
private:
// Node pointers in CSR structure.
std::vector<Node> nodes_;
// Index to all input nodes.
std::vector<uint32_t> input_nodes_;
// Index to all mutable input nodes.
std::unordered_set<uint32_t> mutable_input_nodes_;
// space to store the outputs entries
std::vector<NodeEntry> outputs_;
// mapping from node to index.
std::unordered_map<const nnvm::Node*, uint32_t> node2index_;
// CSR pointer of node entries
std::vector<size_t> entry_rptr_;
// space to store input entries of each
std::vector<NodeEntry> input_entries_;
// control flow dependencies
std::vector<uint32_t> control_deps_;
};int NNGraphCreate(SymbolHandle symbol, GraphHandle *graph) {
Graph* g = new Graph();
g->outputs = static_cast<Symbol*>(symbol)->outputs;
*graph = g;
}int NNGraphGetSymbol(GraphHandle graph, SymbolHandle *symbol) {
Symbol* s = new Symbol();
s->outputs = static_cast<Graph*>(graph)->outputs;
*symbol = s;
}class Symbol {
std::vector<NodeEntry> outputs;
};inline void DFSVisit(const std::vector<NodeEntry>& heads, FVisit fvisit);import mxnet as mx
a = mx.sym.Variable('a')
b = mx.sym.Variable('b')
c = a + b
print c.tojson(){
"nodes": [
{
"op": "null",
"name": "a",
"inputs": []
},
{
"op": "null",
"name": "b",
"inputs": []
},
{
"op": "elemwise_add",
"name": "_plus0",
"inputs": [[0, 0, 0], [1, 0, 0]]
}
],
"arg_nodes": [0, 1],
"node_row_ptr": [0, 1, 2, 3],
"heads": [[2, 0, 0]],
"attrs": {"mxnet_version": ["int", 1000]}
}import mxnet as mx
data = mx.symbol.Variable('data')
fc1 = mx.symbol.FullyConnected(data=data, name='fc1', num_hidden=128)
mlp = mx.symbol.SoftmaxOutput(data=fc1, name='softmax')
print mlp.tojson(){
"nodes": [
{
"op": "null",
"name": "data",
"inputs": []
},
{
"op": "null",
"name": "fc1_weight",
"attr": {"num_hidden": "128"},
"inputs": []
},
{
"op": "null",
"name": "fc1_bias",
"attr": {"num_hidden": "128"},
"inputs": []
},
{
"op": "FullyConnected",
"name": "fc1",
"attr": {"num_hidden": "128"},
"inputs": [[0, 0, 0], [1, 0, 0], [2, 0, 0]]
},
{
"op": "null",
"name": "softmax_label",
"inputs": []
},
{
"op": "SoftmaxOutput",
"name": "softmax",
"inputs": [[3, 0, 0], [4, 0, 0]]
}
],
"arg_nodes": [0, 1, 2, 4],
"node_row_ptr": [0, 1, 2, 3, 4, 5, 6],
"heads": [[5, 0, 0]],
"attrs": {"mxnet_version": ["int", 1000]}
}