29 #ifndef NNVM_PASS_FUNCTIONS_H_ 30 #define NNVM_PASS_FUNCTIONS_H_ 50 ret.
attrs[
"json"] = std::make_shared<any>(json_str);
61 return ret.
GetAttr<std::string>(
"json");
72 return ret.
GetAttr<std::string>(
"graphir");
86 return ApplyPass(std::move(src),
"OrderMutation");
100 std::string shape_attr_key =
"") {
101 if (shape_inputs.size() != 0) {
102 graph.
attrs[
"shape_inputs"] = std::make_shared<any>(std::move(shape_inputs));
104 if (shape_attr_key.length() != 0) {
105 graph.
attrs[
"shape_attr_key"] = std::make_shared<any>(std::move(shape_attr_key));
107 return ApplyPass(std::move(graph),
"InferShape");
121 std::string dtype_attr_key =
"") {
122 if (dtype_inputs.size() != 0) {
123 graph.
attrs[
"dtype_inputs"] = std::make_shared<any>(std::move(dtype_inputs));
125 if (dtype_attr_key.length() != 0) {
126 graph.
attrs[
"dtype_attr_key"] = std::make_shared<any>(std::move(dtype_attr_key));
128 return ApplyPass(std::move(graph),
"InferType");
146 std::string device_group_attr_key,
148 std::string device_copy_op) {
149 graph.
attrs[
"device_group_attr_key"] = std::make_shared<any>(std::move(device_group_attr_key));
150 graph.
attrs[
"device_assign_map"] = std::make_shared<any>(std::move(device_assign_map));
151 graph.
attrs[
"device_copy_op"] = std::make_shared<any>(std::move(device_copy_op));
152 return ApplyPass(std::move(graph),
"PlaceDevice");
172 std::vector<NodeEntry> ys,
173 std::vector<NodeEntry> xs,
174 std::vector<NodeEntry> ys_out_grad,
175 std::function<
NodeEntry(std::vector<NodeEntry>&& inputs)> aggregate_fun =
nullptr,
176 std::function<
int(
const Node& node)> mirror_fun =
nullptr,
178 attr_hint_fun =
nullptr,
179 std::vector<const Op*> zero_ops = std::vector<const Op*>(),
180 std::string copy_op_str = std::string()) {
181 graph.
attrs[
"grad_ys"] = std::make_shared<any>(std::move(ys));
183 graph.
attrs[
"grad_xs"] = std::make_shared<any>(std::move(xs));
184 graph.
attrs[
"grad_ys_out_grad"] = std::make_shared<any>(std::move(ys_out_grad));
185 if (aggregate_fun !=
nullptr) {
186 graph.
attrs[
"grad_aggregate_fun"] = std::make_shared<any>(aggregate_fun);
189 if (mirror_fun !=
nullptr) {
190 graph.
attrs[
"grad_mirror_fun"] = std::make_shared<any>(mirror_fun);
193 if (attr_hint_fun !=
nullptr) {
194 graph.
attrs[
"attr_hint_fun"] = std::make_shared<any>(attr_hint_fun);
197 if (zero_ops.size()) {
198 graph.
attrs[
"zero_ops"] = std::make_shared<any>(std::move(zero_ops));
201 if (copy_op_str != std::string()) {
202 graph.
attrs[
"copy_op"] = std::make_shared<any>(std::move(copy_op_str));
205 return ApplyPass(std::move(graph),
"Gradient");
210 #endif // NNVM_PASS_FUNCTIONS_H_
Graph InferType(Graph graph, DTypeVector dtype_inputs, std::string dtype_attr_key="")
Infer types in the graph given the information.
Definition: pass_functions.h:119
Graph Gradient(Graph graph, std::vector< NodeEntry > ys, std::vector< NodeEntry > xs, std::vector< NodeEntry > ys_out_grad, std::function< NodeEntry(std::vector< NodeEntry > &&inputs)> aggregate_fun=nullptr, std::function< int(const Node &node)> mirror_fun=nullptr, std::function< NodeEntry(const NodeEntry &src, const NodeEntry &like)> attr_hint_fun=nullptr, std::vector< const Op * > zero_ops=std::vector< const Op * >(), std::string copy_op_str=std::string())
Get the gradient graph whose outputs are gradients of xs wrt to ys.
Definition: pass_functions.h:170
Graph OrderMutation(Graph src)
Add control flow dependencies between nodes.
Definition: pass_functions.h:85
Graph ApplyPass(Graph src, const std::string &pass)
Apply one pass to the graph.
Definition: pass.h:63
std::unordered_map< std::string, int > DeviceAssignMap
The result holder of device of each operator in the graph.
Definition: graph_attr_types.h:112
std::unordered_map< std::string, std::shared_ptr< any > > attrs
attributes of a graph Note that attribute is shared pointer and can be shared across graphs...
Definition: graph.h:61
Data structures that can appear in graph attributes.
Node represents an operation in a computation graph.
Definition: node.h:156
Graph PlaceDevice(Graph graph, std::string device_group_attr_key, DeviceAssignMap device_assign_map, std::string device_copy_op)
Place the devices for each operator in the graph.
Definition: pass_functions.h:145
Symbolic computation graph. This is the intermediate representation for optimization pass...
Definition: graph.h:47
std::string PrintGraphIR(Graph graph)
Print graph ir.
Definition: pass_functions.h:70
std::vector< TShape > ShapeVector
The result holder of shape of each NodeEntry in the graph.
Definition: graph_attr_types.h:61
an entry that represents output data from a node
Definition: node.h:52
std::vector< int > DTypeVector
The result holder of type of each NodeEntry in the graph.
Definition: graph_attr_types.h:76
Pass that can be applied to a graph.
const T & GetAttr(const std::string &attr_name) const
Get the immutable attribute from attrs.
Definition: graph.h:248
Graph LoadJSON(const std::string &json_str)
Load a graph from JSON string, redirects to "LoadJSON" pass.
Definition: pass_functions.h:48
Graph InferShape(Graph graph, ShapeVector shape_inputs, std::string shape_attr_key="")
Infer shapes in the graph given the information.
Definition: pass_functions.h:98
Configuration of nnvm as well as basic data structure.
std::string SaveJSON(Graph graph)
Save a graph to json, redirects to "SaveJSON" pass.
Definition: pass_functions.h:59