Skip to content

Commit 48941c5

Browse files
committed
leaffunc:新增dropout
1 parent 4798b72 commit 48941c5

17 files changed

Lines changed: 262 additions & 174 deletions

File tree

doc/excuter/op-mem-cuda/list.md

Lines changed: 74 additions & 74 deletions
Large diffs are not rendered by default.

doc/excuter/op-mem-ompsimd/list.md

Lines changed: 72 additions & 72 deletions
Large diffs are not rendered by default.

excuter/cpp-common/src/deepx/tf/tffactory.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,14 @@ namespace deepx::tf
103103
// 为每个tftype生成一个表格
104104
for (const auto &[tftype, tfs] : tf_by_type) {
105105
ss << "### " << tftype << "\n\n";
106-
ss << "| Operation | Author | Func Def | Math Formula | IR Instruction |\n";
107-
ss << "|-----------|--------|------------|--------------|----------------|\n";
106+
ss << "| Operation | Author | Math Formula | IR Instruction |\n";
107+
ss << "|-----------|--------|--------------|----------------|\n";
108108

109109
for (const auto &tf : tfs) {
110110
ss << "| " << tf->name << " | ";
111111
ss << (tf->metadata.author.empty() ? " none " : tf->metadata.author) << " | ";
112-
ss << tf->to_string(false, true) << " | ";
113112
ss << tf->math_formula() << " | ";
114-
ss << tf->to_string(false, true) << " |\n";
113+
ss << stdutil::escape_markdown(tf->to_string(false, true)) << " |\n";
115114
}
116115

117116
ss << "\n";

excuter/cpp-common/src/stdutil/string.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,49 @@ namespace stdutil
88
str.erase(str.find_last_not_of(" ") + 1);
99
}
1010

11-
void trim(string &str,const string &chars)
11+
void trim(string &str, const string &chars)
1212
{
1313
str.erase(0, str.find_first_not_of(chars));
1414
str.erase(str.find_last_not_of(chars) + 1);
1515
}
16+
17+
string escape_markdown(const string &str)
18+
{
19+
std::string result;
20+
for (char c : str)
21+
{
22+
switch (c)
23+
{
24+
case '\\':
25+
result += "\\\\";
26+
break;
27+
case '\"':
28+
result += "\\\"";
29+
break;
30+
case '\'':
31+
result += "\\\'";
32+
break;
33+
case '\n':
34+
result += "\\n";
35+
break;
36+
case '\t':
37+
result += "\\t";
38+
break;
39+
case '\r':
40+
result += "\\r";
41+
break;
42+
case '\b':
43+
result += "\\b";
44+
break;
45+
case '\f':
46+
result += "\\f";
47+
break;
48+
default:
49+
// 普通字符直接添加
50+
result += c;
51+
}
52+
}
53+
return result;
54+
}
55+
1656
} // namespace stdutil

excuter/cpp-common/src/stdutil/string.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace stdutil
1010
void trimspace(string &str);
1111
void trim(string &str,const string &chars=" \t\n\r\f\v");
1212

13+
string escape_markdown(const string &str);
1314
}
1415

1516

front/py/deepx/nn/functional/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010
from .authormap import defaultauthor
1111

1212
from .reduce import mean
13-
1413
from .activite import *
15-
1614
from .elementwise import *
1715
from .normalization import *
16+
from .changeshape import *
1817
__all__ = [
1918

2019
#leaffunc
2120
"newtensor","rnewtensor","printtensor","load", #life
2221
"printtensor","save",#io
2322
"constant","constant_","full","zeros","ones","uniform","uniform_","arange","arange_","kaiming_uniform","kaiming_uniform_",
24-
"add","sub","mul","div","sqrt","pow","exp","log",
23+
"add","sub","mul","div","sqrt","pow","exp","log","invert","todtype","dropout",
2524
"matmul",
2625
"reducemax","reducemin","sum","prod",
2726
"reshape","permute","transpose","concat","broadcastTo","indexselect",

front/py/deepx/nn/functional/authormap.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
'powscalar':'miaobyte',
3030
'rpowscalar':'miaobyte',
3131
'sqrt':'miaobyte',
32+
'dropout':'miaobyte',
3233
#changeshape
3334
'reshape':'miaobyte',
3435
'transpose':'miaobyte',

front/py/deepx/nn/functional/leaffunc_elementwise.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,26 @@ def rpow(a:Number,b:Tensor,out:Union[Tensor,str]=None)->Tensor:
5353
log=create_A_tf_C('log')
5454

5555
#invert
56-
invert=create_A_tf_C('invert')
56+
invert=create_A_tf_C('invert')
57+
58+
#todtype
59+
def todtype(t:Tensor,dest:Tensor):
60+
assert isinstance(t,Tensor)
61+
assert isinstance(dest,Tensor)
62+
assert t.shape==dest.shape
63+
64+
from .rtf_elementwise import rtf_todtype
65+
rtf_todtype(t,dest)
66+
67+
#dropout
68+
def dropout(a:Tensor, p:float, out:Union[Tensor,str]='')->Tensor:
69+
assert isinstance(a,Tensor)
70+
outtensor=out
71+
if isinstance(out,str) or out is None:
72+
outtensor=newtensor(a.shape,dtype=a.dtype,name=out)
73+
assert a.shape==outtensor.shape
74+
75+
from .rtf_elementwise import rtf_dropout
76+
rtf_dropout(a,p,outtensor,defaultauthor['dropout'])
77+
return out
78+

front/py/deepx/nn/functional/leaffunc_life.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ def rnewtensor(t:Tensor):
2121
def copytensor(t:Tensor,out:Tensor):
2222
from .rtf_life import rtf_copytensor
2323
rtf_copytensor(t,out)
24-
25-
def todtype(t:Tensor,dest:Tensor):
26-
assert isinstance(t,Tensor)
27-
assert isinstance(dest,Tensor)
28-
assert t.shape==dest.shape
2924

30-
from .rtf_life import rtf_todtype
31-
rtf_todtype(t,dest)
3225

3326
def deltensor(t:Tensor):
3427
from .rtf_life import rtf_deltensor

front/py/deepx/nn/functional/rtf_elementwise.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from deepx.scheduler import send
44
from .rtf import A_B_op_C,A_scalar_op_C,A_op_C
55

6+
67
def rtf_add(a:Tensor, b:Tensor, out:Tensor, author='miaobyte')->Tensor:
78
A_B_op_C("add",a,b,out,author)
89
return out
@@ -107,4 +108,18 @@ def rtf_minscalar(a:Tensor, b:float, out:Tensor, author='miaobyte')->Tensor:
107108

108109
def rtf_invert(a:Tensor, out:Tensor, author='miaobyte')->Tensor:
109110
A_op_C("invert",a,out,author)
111+
return out
112+
113+
def rtf_todtype(t:Tensor,dest:Tensor):
114+
assert isinstance(t,Tensor)
115+
assert isinstance(dest,Tensor)
116+
assert t.shape==dest.shape
117+
118+
args=[Param.tensor(t)]
119+
returns=[Param.tensor(dest)]
120+
ir=DeepxIR("todtype", args, returns,'')
121+
send(ir)
122+
123+
def rtf_dropout(a:Tensor, p:float, out:Tensor, author='miaobyte')->Tensor:
124+
A_B_op_C("dropout",a,p,out,author)
110125
return out

0 commit comments

Comments
 (0)