Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
Emmay
NiuTrans.Tensor
Commits
37b7e09b
Commit
37b7e09b
authored
Jul 20, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the bug in dimension setting in the back propagation of Merge
parent
9e5887dd
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
26 行增加
和
28 行删除
+26
-28
source/network/XBackwardShape.cpp
+11
-9
source/sample/fnnlm/FNNLM.cpp
+8
-12
source/tensor/core/shape/Merge.cpp
+3
-3
source/tensor/core/shape/Split.cpp
+4
-4
没有找到文件。
source/network/XBackwardShape.cpp
查看文件 @
37b7e09b
...
...
@@ -71,9 +71,11 @@ dE/da = split(dE/dc)
void
XShapeGrad
::
GradMerge
(
XTensor
*
node
)
{
XLink
&
income
=
node
->
income
;
CheckNTErrors
(
income
.
tailNum
==
0
,
"Wrong input tensor number for MERGE!"
);
XTensor
*
input
=
income
.
tails
[
0
];
CheckNTErrors
(
income
.
tailNum
==
1
,
"Wrong input tensor number for MERGE!"
);
CheckNTErrors
(
node
->
order
==
input
->
order
-
1
,
"wrong tensor orders!"
);
int
whereToMerge
=
income
.
GetParamInt
(
0
);
int
leadDim
=
income
.
GetParamInt
(
1
);
...
...
@@ -95,13 +97,13 @@ void XShapeGrad::GradMerge(XTensor * node)
}
dims
[
0
]
=
-
dims
[
0
];
XTensor
gradInputSmall
(
input
->
order
-
leadDim
,
dims
,
input
->
dataType
,
input
->
denseRatio
,
input
->
devID
,
input
->
mem
);
input
->
dataType
,
input
->
denseRatio
,
input
->
devID
,
input
->
mem
);
dims
[
whereToMerge
-
leadDim
]
*=
dims
[
0
];
XTensor
gradNodeSmall
(
node
->
order
-
leadDim
,
dims
,
node
->
dataType
,
node
->
denseRatio
,
node
->
devID
,
node
->
mem
);
XTensor
gradNodeSmall
(
node
->
order
-
leadDim
,
dims
+
leadDim
+
1
,
node
->
dataType
,
node
->
denseRatio
,
node
->
devID
,
node
->
mem
);
/* we can simply split the gradient tensor
if the input is used in merging only */
...
...
@@ -109,7 +111,7 @@ void XShapeGrad::GradMerge(XTensor * node)
for
(
int
i
=
0
;
i
<
blockNum
;
i
++
){
gradNodeSmall
.
data
=
(
char
*
)
node
->
grad
->
data
+
i
*
blockSize
;
gradInputSmall
.
data
=
(
char
*
)
input
->
grad
->
data
+
i
*
blockSize
;
_Split
(
&
gradNodeSmall
,
&
gradInputSmall
,
whereToMerge
-
leadDim
,
input
->
dimSize
[
leadDim
]);
_Split
(
&
gradNodeSmall
,
&
gradInputSmall
,
whereToMerge
-
leadDim
-
1
,
input
->
dimSize
[
leadDim
]);
}
}
...
...
@@ -123,7 +125,7 @@ void XShapeGrad::GradMerge(XTensor * node)
for
(
int
i
=
0
;
i
<
blockNum
;
i
++
){
gradNodeSmall
.
data
=
(
char
*
)
node
->
grad
->
data
+
i
*
blockSize
;
gradInputSmall
.
data
=
(
char
*
)
input
->
grad
->
data
+
i
*
blockSize
;
_Split
(
&
gradNodeSmall
,
&
gradInputSmallBuf
,
whereToMerge
-
leadDim
,
input
->
dimSize
[
leadDim
]);
_Split
(
&
gradNodeSmall
,
&
gradInputSmallBuf
,
whereToMerge
-
leadDim
-
1
,
input
->
dimSize
[
leadDim
]);
_Sum
(
&
gradInputSmall
,
&
gradInputSmallBuf
,
&
gradInputSmall
);
}
}
...
...
source/sample/fnnlm/FNNLM.cpp
查看文件 @
37b7e09b
...
...
@@ -73,8 +73,7 @@ void MakeWordBatch(XTensor &batch, NGram * ngrams, int ngramNum, int n, int vSiz
void
Forward
(
XTensor
inputs
[],
XTensor
&
output
,
FNNModel
&
model
,
FNNNet
&
net
);
void
Backward
(
XTensor
inputs
[],
XTensor
&
output
,
XTensor
&
gold
,
LOSS_FUNCTION_NAME
loss
,
FNNModel
&
model
,
FNNModel
&
grad
,
FNNNet
&
net
);
void
FBInOne
(
XTensor
inputs
[],
XTensor
&
output
,
XTensor
&
gold
,
LOSS_FUNCTION_NAME
loss
,
FNNModel
&
model
,
XNet
&
net
);
void
ForwardAutoDiff
(
XTensor
inputs
[],
XTensor
&
output
,
FNNModel
&
model
);
/*
entry of the program
...
...
@@ -415,7 +414,10 @@ void Train(const char * train, bool isShuffled, FNNModel &model)
}
else
{
/* forward + backward process */
FBInOne
(
inputs
,
output
,
gold
,
CROSSENTROPY
,
model
,
autoDiffer
);
ForwardAutoDiff
(
inputs
,
output
,
model
);
/* automatic differentiation */
autoDiffer
.
Backward
(
output
,
gold
,
CROSSENTROPY
);
/* update model parameters */
Update
(
model
,
grad
,
learningRate
,
true
);
...
...
@@ -902,17 +904,14 @@ void Backward(XTensor inputs[], XTensor &output, XTensor &gold, LOSS_FUNCTION_NA
}
/*
forward
+ backward in one procedure
forward
process (with tensor connections)
>> inputs - input word representations
>> output - output probability
>> gold - gold standard
>> loss - loss function name
>> model - the fnn model
*/
void
FBInOne
(
XTensor
inputs
[],
XTensor
&
output
,
XTensor
&
gold
,
LOSS_FUNCTION_NAME
loss
,
FNNModel
&
model
,
XNet
&
net
)
void
ForwardAutoDiff
(
XTensor
inputs
[],
XTensor
&
output
,
FNNModel
&
model
)
{
int
batchSize
=
gold
.
GetDim
(
0
);
int
batchSize
=
inputs
[
0
]
.
GetDim
(
0
);
int
n
=
model
.
n
;
int
depth
=
model
.
hDepth
;
...
...
@@ -945,9 +944,6 @@ void FBInOne(XTensor inputs[], XTensor &output, XTensor &gold,
/* output layer */
output
=
LogSoftmax
(
MMul
(
hidden
,
model
.
outputW
)
+
b
,
1
);
/* automatic differentiation */
net
.
Backward
(
output
);
}
/*
...
...
source/tensor/core/shape/Merge.cpp
查看文件 @
37b7e09b
...
...
@@ -49,7 +49,7 @@ void _Merge(const XTensor * s, XTensor * t, int whereToMerge, int leadingDim)
CheckNTErrors
((
s
!=
NULL
&&
t
!=
NULL
),
"Invalid tensors!"
);
CheckNTErrors
((
s
->
devID
==
t
->
devID
||
(
s
->
devID
<
0
&&
t
->
devID
<
0
)),
"the data must be kept on the same device!"
);
"the data must be kept on the same device!"
);
CheckNTErrors
((
s
->
unitNum
==
t
->
unitNum
&&
s
->
unitSize
==
t
->
unitSize
),
"Unmatched tensors!"
);
CheckNTErrors
((
s
->
order
==
t
->
order
+
1
),
"Unmatched tensors!"
);
...
...
@@ -58,11 +58,11 @@ void _Merge(const XTensor * s, XTensor * t, int whereToMerge, int leadingDim)
for
(
int
i
=
0
;
i
<
s
->
order
;
i
++
)
{
if
(
i
==
whereToMergeRDI
)
{
CheckNTErrors
((
t
->
dimSizeRDI
[
i
]
==
s
->
dimSizeRDI
[
i
]
*
s
->
dimSizeRDI
[
leadingDimRDI
]),
"Unmatched tensor sizes!"
);
"Unmatched tensor sizes!"
);
}
else
if
(
i
>
leadingDimRDI
)
{
CheckNTErrors
((
s
->
dimSizeRDI
[
i
-
1
]
==
t
->
dimSizeRDI
[
i
]),
"Unmatched tensor sizes!"
);
"Unmatched tensor sizes!"
);
}
}
...
...
source/tensor/core/shape/Split.cpp
查看文件 @
37b7e09b
...
...
@@ -41,7 +41,7 @@ void _Split(const XTensor * s, XTensor * t, int whereToSplit, int splitNum)
{
CheckNTErrors
((
s
&&
t
),
"Invalid tensors!"
);
CheckNTErrors
((
s
->
devID
==
t
->
devID
||
(
s
->
devID
<
0
&&
t
->
devID
<
0
)),
"the data must be kept on the same device!"
);
"the data must be kept on the same device!"
);
CheckNTErrors
((
s
->
unitNum
==
t
->
unitNum
&&
s
->
unitSize
==
t
->
unitSize
),
"Unmatched tensors!"
);
CheckNTErrors
((
s
->
order
==
t
->
order
-
1
),
"Unmatched tensors!"
);
...
...
@@ -51,11 +51,11 @@ void _Split(const XTensor * s, XTensor * t, int whereToSplit, int splitNum)
for
(
int
i
=
0
;
i
<
s
->
order
;
i
++
)
{
if
(
i
==
whereToSplitRDI
)
{
CheckNTErrors
((
s
->
dimSizeRDI
[
i
]
==
t
->
dimSizeRDI
[
i
]
*
splitNum
),
"Unmatched tensor sizes!"
);
"Unmatched tensor sizes!"
);
}
else
{
CheckNTErrors
((
s
->
dimSizeRDI
[
i
]
==
t
->
dimSizeRDI
[
i
]),
"Unmatched tensor sizes!"
);
"Unmatched tensor sizes!"
);
}
}
...
...
@@ -301,7 +301,7 @@ void Split(const XTensor &big, XList &smalls, int whereToSplit, int splitNum)
XLink
::
AddParamToHeadInt
(
s
,
whereToSplit
);
/* it is tricky here that we keep the id of each
block, rather than the total number of splits */
block, rather than the total number of
the
splits */
XLink
::
AddParamToHeadInt
(
s
,
i
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论