def graph_pat_4(): ''' elewise + broadcast ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([1, 1024], "float32", name="a0") a2 = gb.tensor([1014, 1024], "float32", name="a2") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a, 'b') c = gb.emit("Abs", b, 'c') d = gb.emit("Abs", c, 'd') e = gb.emit("Abs", d, 'e') f = gb.emit("Abs", e, 'f') g0 = gb.emit("Abs", a2, 'g0') # g0 = gb.emit("Abs", g0, 'g0') # g0 = gb.emit("Abs", g0, 'g0') # g0 = gb.emit("Abs", g0, 'g0') # g0 = gb.emit("Abs", g0, 'g0') # g0 = gb.emit("Abs", g0, 'g0') # g0 = gb.emit("Abs", g0, 'g0') g0 = gb.emit("Abs", g0, 'g0') g1 = gb.emit('Add', [f, g0], 'g1') g2 = gb.emit("Abs", g1, 'g2') g3 = gb.emit("Abs", g2, 'g3') g4 = gb.emit("Abs", g3, 'g4') gb.emit("Abs", g4, 'g5') return gb.get()[0]
def control_graph(shape): gb = model.GraphBuilder() with gb.graph_scope('control') as _: a1 = gb.tensor(shape, 'float32') a2 = gb.emit('Abs', a1) gb.emit('ControlDepend', a2) return gb.get()[0]
def graph_mo_1(): gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([1024, 1024], "float32", name="a0") a = gb.emit("Abs", a0, 'a') gb.emit("Abs", a, 'b') gb.emit("Abs", a, 'c') return gb.get()[0]
def reduce_graph(shape, reduce_axis): gb = model.GraphBuilder() with gb.graph_scope('reduce') as _: a1 = gb.tensor(shape, 'float32') a2 = gb.emit('Abs', a1) a3 = gb.emit('Abs', a2) gb.emit('ReduceSum', a3, 'C', attrs={'reduce_axis': reduce_axis}) return gb.get()[0]
def injective_graph(shape): gb = model.GraphBuilder() with gb.graph_scope('injective') as _: a1 = gb.tensor(shape, 'float32') a2 = gb.emit('Abs', a1) a3 = gb.emit('Abs', a2) gb.emit('Abs', a3) return gb.get()[0]
def graph_1(): gb = model.GraphBuilder() with gb.graph_scope("main"): a = gb.tensor([1024, 16], "float32", name="a") b = gb.emit("Abs", a, 'b') c = gb.emit("Abs", b, 'c') d = gb.emit("Abs", c, 'd') gb.emit("TensorAdd", [b, d], "e") return gb.get()[0]
def graph_mo_2(): gb = model.GraphBuilder() with gb.graph_scope("main") as g: a0 = gb.tensor([1024, 1024], "float32", name="a0") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a, 'b') c = gb.emit("Abs", b, 'c') g.set_output(b, c) return gb.get()[0]
def graph_2(): gb = model.GraphBuilder() with gb.graph_scope("main"): a = gb.tensor([1024, 16], "float32", name="a") b = gb.emit("Abs", a, 'b') c = gb.emit("Abs", b, 'c') d = gb.emit("ReduceSum", c, 'd', attrs={'reduce_axis': (1, )}) gb.emit("Sqrt", d, 'e') return gb.get()[0]
def graph_pat_2(): ''' multi output ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([1024, 1024], "float32", name="a0") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a, 'b') gb.emit("ReduceSum", b, 'c', attrs={'reduce_axis': (1,)}) gb.emit("ReduceSum", b, 'e', attrs={'reduce_axis': (1,)}) return gb.get()[0]
def graph_mo_4(): ''' two reduce ''' gb = model.GraphBuilder() with gb.graph_scope("main") as g: a0 = gb.tensor([1024, 1024], "float32", name="a0") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a, 'b') c = gb.emit("ReduceSum", a, 'c', attrs={'reduce_axis': (1,)}) g.set_output(b, c) return gb.get()[0]
def graph_1(): ''' ring, no succ_dep, no prev ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a = gb.tensor([10240, 16], "float32", name="a") b = gb.emit("Abs", a, 'b') c = gb.emit("Abs", b, 'c') d = gb.emit("Abs", c, 'd') gb.emit('Add', [b, d], 'e') return gb.get()[0]
def graph_pat_9(): ''' scalar ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([1024, 1024], "float32", name="a0") a1 = gb.tensor([1], "float32", name="a1") a = gb.emit("Maximum", a1, 'a') b = gb.emit("Mul", [a, a1], 'b') gb.emit('Mul', [b, a0], 'c') return gb.get()[0]
def graph_pat_8(): ''' reduce + reshape ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([1024, 1024], "float32", name="a0") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a, 'b') #c = gb.emit("Abs", b, 'b') c = gb.emit("ReduceSum", b, 'c', attrs={'reduce_axis': (1,)}) gb.emit("Add", [b, c], 'd') return gb.get()[0]
def graph_pat_1(): ''' split by reduce ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([1024, 1024], "float32", name="a0") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a, 'b') c = gb.emit("ReduceSum", b, 'c', attrs={'reduce_axis': (1,)}) d = gb.emit("Sqrt", c, 'd') gb.emit("Sqrt", d, 'f') return gb.get()[0]
def graph_pat_6(): ''' dimond ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([1024, 1024], "float32", name="a0") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a, 'b') c = gb.emit("Abs", a, 'c') gb.emit("Add", [b, c], 'd') gb.emit("Abs", c, 'f') # broke dimond return gb.get()[0]
def graph_3(): ''' no ring, 1 sibling node ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([10240, 16], "float32", name="a0") a1 = gb.tensor([10240, 16], "float32", name="a1") b = gb.emit("Abs", a0, 'b') c = gb.emit("Abs", a1, 'c') d = gb.emit("Abs", b, 'd') e = gb.emit('Add', [c, d], 'e') gb.emit("Abs", e, 'f') return gb.get()[0]
def graph_2(): ''' ring, succ_dep, no prev ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([10240, 16], "float32", name="a0") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a, 'b') c = gb.emit("Abs", a, 'c') d = gb.emit("Abs", b, 'd') e = gb.emit('Add', [c, d], 'e') gb.emit("Abs", e, 'f') return gb.get()[0]
def graph_pat_5(): ''' reduce + reshape ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([1024, 1024], "float32", name="a0") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a, 'b') c = gb.emit("ReduceSum", b, 'c', attrs={'reduce_axis': (1,)}) d = gb.emit("Abs", c, 'd') e = gb.tensor([512, 2048], "float32", name="e") gb.op("Reshape", e, [d]) return gb.get()[0]
def graph_6(): ''' no ring, tree down ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([10240, 16], "float32", name="a0") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a, 'b') gb.emit("Abs", b, 'd') gb.emit("Abs", b, 'e') c = gb.emit("Abs", a, 'c') gb.emit("Abs", c, 'f') gb.emit("Abs", c, 'g') return gb.get()[0]
def graph_pat_7(): ''' buddy of control op ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([1024, 1024], "float32", name="a0") a1 = gb.tensor([1024, 1024], "float32", name="a1") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a1, 'b') c = gb.emit("MakeTuple", [a, b], 'c') d = gb.tensor([1024, 1024], "float32", name="d") gb.op("AddN", d, [c]) gb.emit("Abs", d, 'f') graph = gb.get()[0] estimate.AddControlBuddy().visit_graph(graph) return graph
def graph_4(): ''' no ring, 2 sibling nodes in 1 step ''' gb = model.GraphBuilder() with gb.graph_scope("main"): a0 = gb.tensor([10240, 16], "float32", name="a0") a1 = gb.tensor([10240, 16], "float32", name="a1") b = gb.emit("Abs", a0, 'b') c = gb.emit("Abs", b, 'c') d = gb.emit("Abs", a1, 'd') e = gb.emit("Abs", d, 'e') f = gb.emit('Add', [c, e], 'f') gb.emit('Abs', f, 'g') h = gb.emit("Abs", d, 'h') i = gb.emit('Add', [c, h], 'i') gb.emit("Abs", i, 'j') return gb.get()[0]
def graph_5(): ''' no ring, 2 sibling step ''' gb = model.GraphBuilder() with gb.graph_scope("main") as g: a0 = gb.tensor([10240, 16], "float32", name="a0") a1 = gb.tensor([10240, 16], "float32", name="a1") a2 = gb.tensor([10240, 16], "float32", name="a2") a = gb.emit("Abs", a0, 'a') b = gb.emit("Abs", a1, 'b') c = gb.emit("Abs", b, 'c') d = gb.emit('Add', [a, c], 'd') gb.emit("Abs", d, 'e') f = gb.emit("Abs", a2, 'f') g = gb.emit('Add', [c, f], 'g') gb.emit("Abs", g, 'h') return gb.get()[0]