Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions front/py/deepx/nn/functional/elementwise.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Optional, Union
from deepx import Tensor
from deepx.autograd import Graph,DataNode,OpNode
from deepx.nn import DeepxIR
from deepx.nn import DeepxIR,Param
from deepx.scheduler import send
from .changeshape import broadcast_shape
def _A_elementwiseop_C(
a:Tensor,
op:str=None,
out:Union[Tensor,str]="")->Tensor:
out:Union[Tensor,str]="",author='miaobyte')->Tensor:
g=a.graph

opnode = g.add_op(op)
Expand All @@ -20,15 +20,15 @@ def _A_elementwiseop_C(
outtensor=out
outtensor.node.add_input(opnode)
if g.eager:
ir=DeepxIR(op, a.dtype, [a.node.name], [outtensor.node.name])
ir=DeepxIR(op, [a.node.name], [outtensor.node.name],author)
send(ir)
return outtensor

def _A_B_elementwiseop_C(
a:Tensor,
b: Tensor,
op:str=None,
out:Union[Tensor,str]="")->Tensor:
out:Union[Tensor,str]="",author='miaobyte')->Tensor:
g=a.graph
if g is None:
g=b.graph
Expand All @@ -53,14 +53,14 @@ def _A_B_elementwiseop_C(
outtensor=out
outtensor.node.add_input(opnode)
if g.eager:
ir=DeepxIR(op, A.dtype, [A.node.name, B.node.name], [outtensor.node.name])
ir=DeepxIR(op, [A.node.name, B.node.name], [outtensor.node.name],author)
send(ir)
return outtensor
def _A_b_elementwiseop_C(
a:Tensor,
b: Union[ float, int] ,
op:str=None,
out:Union[Tensor,str]="")->Tensor:
out:Union[Tensor,str]="",author='miaobyte')->Tensor:
g=a.graph
opnode = g.add_op(op)
opnode.add_input(a.node)
Expand All @@ -74,14 +74,14 @@ def _A_b_elementwiseop_C(
outtensor=out
outtensor.node.add_input(opnode)
if g.eager:
ir=DeepxIR(op, a.dtype, [a.node.name,b], [outtensor.node.name])
ir=DeepxIR(op, [a.node.name,b], [outtensor.node.name],author)
send(ir)
return outtensor
def _a_B_elementwiseop_C(
a: Union[ float, int] ,
b: Tensor,
op:str=None,
out:Union[Tensor,str]="")->Tensor:
out:Union[Tensor,str]="",author='miaobyte')->Tensor:
g=b.graph
opnode = g.add_op(op)
opnode.add_input(g.add_var("",a))
Expand All @@ -95,7 +95,7 @@ def _a_B_elementwiseop_C(
outtensor=out
outtensor.node.add_input(opnode)
if g.eager:
ir=DeepxIR(op, b.dtype, [a,b.node.name], [outtensor.node.name])
ir=DeepxIR(op, [a,b.node.name], [outtensor.node.name],author)
send(ir)
return outtensor

Expand All @@ -106,7 +106,7 @@ def _a_B_elementwiseop_C(
def add(
a:Tensor,
b: Optional[Union[Tensor, float, int]] = None,
out:Union[Tensor,str]='')->Tensor:
out:Union[Tensor,str]='',author='miaobyte')->Tensor:
if isinstance(b,Tensor):
return _A_B_elementwiseop_C(a,b,"add",out)
else:
Expand All @@ -120,7 +120,7 @@ def add(
def sub(
a:Tensor,
b: Optional[Union[Tensor, float, int]] = None,
out:Union[Tensor,str]='')->Tensor:
out:Union[Tensor,str]='',author='miaobyte')->Tensor:
if isinstance(b,Tensor):
return _A_B_elementwiseop_C(a,b,"sub",out)
else:
Expand All @@ -133,7 +133,7 @@ def sub(
def mul(
a:Tensor,
b: Optional[Union[Tensor, float, int]] = None,
out:Union[Tensor,str]='')->Tensor:
out:Union[Tensor,str]='',author='miaobyte')->Tensor:
if isinstance(b,Tensor):
return _A_B_elementwiseop_C(a,b,"mul",out)
else:
Expand All @@ -147,7 +147,7 @@ def mul(
def div(
a: Optional[Union[Tensor, float, int]] = None,
b: Optional[Union[Tensor, float, int]] = None,
out:Union[Tensor,str]='')->Tensor:
out:Union[Tensor,str]='',author='miaobyte')->Tensor:
if isinstance(b,Tensor) and isinstance(a,Tensor):
return _A_B_elementwiseop_C(a,b,"div",out)
else:
Expand Down
14 changes: 7 additions & 7 deletions front/py/deepx/nn/functional/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

from deepx import Tensor
from deepx.autograd.graph import OpNode
from deepx.nn.deepxir import DeepxIR
from deepx.nn.deepxir import DeepxIR,Param
from deepx.scheduler import send

OpNode.register("constant")

def constant(t:Tensor, value:Optional[Union[
float,int]]=None) -> Tensor:
float,int]]=None,author='miaobyte') -> Tensor:
opnode = t.graph.add_op("constant")
argnode=t.graph.add_var('',value)
opnode.add_input(argnode)
t.node.add_input(opnode)
if t.graph.eager:
ir=DeepxIR("constant", t.dtype, [value], [t.node.name])
ir=DeepxIR("constant", [Param(t.node.name, 'tensor', t.dtype),Param(value)], [],author)
send(ir)
return t

Expand All @@ -39,7 +39,7 @@ def ones(*size, dtype=None, device=None,
name:Union[str]='')->Tensor:
return full(*size, value=1, dtype=dtype, device=device,name=name)

def arange(start=0, end=None, step=1,dtype=None, device=None,name:Union[Tensor,str]='')->Tensor:
def arange(start=0, end=None, step=1,dtype=None, device=None,name:Union[Tensor,str]='',author='miaobyte')->Tensor:
outtensor=None
if isinstance(name,str):
shape=[end-start]
Expand All @@ -49,12 +49,12 @@ def arange(start=0, end=None, step=1,dtype=None, device=None,name:Union[Tensor,s
outtensor=name
g=outtensor.graph
if g.eager:
ir=DeepxIR("arange", outtensor.dtype, [start,step], [outtensor.node.name])
ir=DeepxIR("arange", [outtensor.node.name,start,step], [],author)
send(ir)
return outtensor

OpNode.register("uniform")
def uniform(t:Tensor,low=0, high=1,seed:int=0)->Tensor:
def uniform(t:Tensor,low=0, high=1,seed:int=0,author='miaobyte')->Tensor:
if low >= high:
raise ValueError(f"low({low})必须小于high({high})")
if t is None:
Expand All @@ -68,7 +68,7 @@ def uniform(t:Tensor,low=0, high=1,seed:int=0)->Tensor:
opnode.add_input(g.add_var('',seed))
t.node.add_input(opnode)
if t.graph.eager:
ir=DeepxIR("uniform", t.dtype, [low, high,seed], [t.node.name])
ir=DeepxIR("uniform", [t.node.name,low, high,seed], [],author)
send(ir)
return t

Expand Down
76 changes: 38 additions & 38 deletions front/py/examples/2_ir/1_init_zeroones.dot
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,55 @@
digraph {
rankdir=TB
node [shape=record]
134462353640752 [label="t1
132815942520016 [label="t1
(3, 4, 5)" color=skyblue fillcolor=aliceblue fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460378946608 [label=constant color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
134460378946848 [label="var_1
132813646230768 [label=constant color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
132814271881056 [label="var_1
0" color=orange fillcolor=moccasin fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377149792 [label="t2
132813645298272 [label="t2
(3, 4, 5)" color=skyblue fillcolor=aliceblue fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377149936 [label=constant color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
134460377150032 [label="var_2
132813645298464 [label=constant color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
132813645298080 [label="var_2
1" color=orange fillcolor=moccasin fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377150272 [label=add color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
134460377150464 [label="t3
132813645298704 [label=add color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
132813645298512 [label="t3
(3, 4, 5)" color=skyblue fillcolor=aliceblue fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377150560 [label="t4
132813645298800 [label="t4
(3, 4, 5)" color=skyblue fillcolor=aliceblue fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377150800 [label=constant color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
134460377150752 [label="var_3
132813645299136 [label=constant color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
132813645299088 [label="var_3
0.5" color=orange fillcolor=moccasin fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377150896 [label=add color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
134460377151040 [label="t5
132813645298944 [label=add color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
132813645299424 [label="t5
(3, 4, 5)" color=skyblue fillcolor=aliceblue fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377151472 [label="tensor_6
132813645299664 [label="tensor_6
(3, 4, 5)" color=skyblue fillcolor=aliceblue fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377151568 [label=constant color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
134460377151520 [label="var_4
132813645293616 [label=constant color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
132813645293664 [label="var_4
0" color=orange fillcolor=moccasin fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377151712 [label=uniform color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
134460377151232 [label="var_5
132813645293280 [label=uniform color=darkslategray fillcolor=lightgray fontname="Courier Bold" labeljust=l shape=box style=filled]
132813645299616 [label="var_5
-0.5477225575051661" color=orange fillcolor=moccasin fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377151904 [label="var_6
132813645293568 [label="var_6
0.5477225575051661" color=orange fillcolor=moccasin fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460377151856 [label="var_7
132813645293424 [label="var_7
0" color=orange fillcolor=moccasin fontname="Sans-Serif" labeljust=l shape=box style=filled]
134460378946608 -> 134462353640752 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460378946848 -> 134460378946608 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377149936 -> 134460377149792 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377150032 -> 134460377149936 [arrowsize=0.8 color=gray40 penwidth=1.2]
134462353640752 -> 134460377150272 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377149792 -> 134460377150272 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377150272 -> 134460377150464 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377150800 -> 134460377150560 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377150752 -> 134460377150800 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377150560 -> 134460377150896 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377150464 -> 134460377150896 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377150896 -> 134460377151040 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377151568 -> 134460377151472 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377151712 -> 134460377151472 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377151520 -> 134460377151568 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377151232 -> 134460377151712 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377151904 -> 134460377151712 [arrowsize=0.8 color=gray40 penwidth=1.2]
134460377151856 -> 134460377151712 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813646230768 -> 132815942520016 [arrowsize=0.8 color=gray40 penwidth=1.2]
132814271881056 -> 132813646230768 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645298464 -> 132813645298272 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645298080 -> 132813645298464 [arrowsize=0.8 color=gray40 penwidth=1.2]
132815942520016 -> 132813645298704 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645298272 -> 132813645298704 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645298704 -> 132813645298512 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645299136 -> 132813645298800 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645299088 -> 132813645299136 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645298800 -> 132813645298944 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645298512 -> 132813645298944 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645298944 -> 132813645299424 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645293616 -> 132813645299664 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645293280 -> 132813645299664 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645293664 -> 132813645293616 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645299616 -> 132813645293280 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645293568 -> 132813645293280 [arrowsize=0.8 color=gray40 penwidth=1.2]
132813645293424 -> 132813645293280 [arrowsize=0.8 color=gray40 penwidth=1.2]
}
Loading