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
杨迪
NiuTrans.Tensor
Commits
ac5afe2b
Commit
ac5afe2b
authored
Jun 12, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new code
parent
47ecabf8
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
26 行增加
和
19 行删除
+26
-19
source/sample/transformer/T2TPredictor.cpp
+1
-0
source/sample/transformer/T2TSearch.cpp
+9
-8
source/tensor/core/arithmetic/SumDim.cu
+7
-4
source/tensor/core/movement/CopyValues.cpp
+5
-4
source/tensor/core/movement/CopyValues.cu
+4
-3
没有找到文件。
source/sample/transformer/T2TPredictor.cpp
查看文件 @
ac5afe2b
...
...
@@ -206,6 +206,7 @@ void T2TPredictor::Predict(T2TStateBundle * next, XTensor * encoding, XTensor *
/* the decoder output of the last position */
decodingStep
=
CopyIndexed
(
decoding
,
decoding
.
order
-
2
,
selectSrc
,
selectTgt
);
/* generate the output probabilities */
m
->
outputLayer
->
Make
(
decodingStep
,
output
);
...
...
source/sample/transformer/T2TSearch.cpp
查看文件 @
ac5afe2b
...
...
@@ -158,26 +158,27 @@ void T2TSearch::Score(T2TStateBundle * prev, T2TStateBundle * beam)
_SumDim
(
&
prob
,
&
probPathPrev
,
&
score
,
0
);
InitTensor
(
&
len
,
&
lenPrev
);
InitTensor
(
&
lp
,
&
lenPrev
);
_ScaleAndShift
(
&
lenPrev
,
&
len
,
1.0
F
,
1.0
F
);
//
_ScaleAndShift(&lenPrev, &len, 1.0F, 1.0F);
/* the GNMT-like length penalty */
lp
=
T2TLengthPenalizer
::
GNMT
(
len
,
alpha
);
//
lp = T2TLengthPenalizer::GNMT(len, alpha);
lp
.
Reshape
(
lp
.
unitNum
);
/* score = log-prob/lp */
_DivDim
(
&
score
,
&
lp
,
&
score
,
0
);
//
_DivDim(&score, &lp, &score, 0);
InitTensor
(
&
mask
,
&
prev
->
endMark
);
CopyValues
(
prev
->
endMark
,
mask
);
_ScaleAndShiftMe
(
&
mask
,
-
1e9
F
);
//
CopyValues(prev->endMark, mask);
//
_ScaleAndShiftMe(&mask, -1e9F);
mask
.
Reshape
(
mask
.
unitNum
);
/* mask the completed hypotheses so that they cannot
be involved in further sorting and beam search. */
_SumDim
(
&
score
,
&
mask
,
&
score
,
0
);
//
_SumDim(&score, &mask, &score, 0);
prob
.
Reshape
(
order
,
dims
);
score
.
Reshape
(
order
,
dims
);
...
...
@@ -227,9 +228,9 @@ void T2TSearch::Generate(T2TStateBundle * beam)
score
.
Reshape
(
order
,
dimsBeam
);
/* keep the most promissing candidates in the beam */
TopK
(
score
,
scoreTopK
,
index
,
-
1
,
beamSize
);
//
TopK(score, scoreTopK, index, -1, beamSize);
CopyValues
(
scoreTopK
,
preID
);
CopyValues
(
index
,
preID
);
int
sizeVocab
=
score
.
GetDim
(
-
1
);
...
...
source/tensor/core/arithmetic/SumDim.cu
查看文件 @
ac5afe2b
...
...
@@ -84,15 +84,18 @@ void KernelAddWithCol(T * a, T * b, T * c, int rowNum, int colNum, int blockSize
int colIndex = blockDim.x * blockIdx.x + threadIdx.x;
int row = blockDim.y * blockIdx.y + threadIdx.y;
int col = colIndex %
colNum
;
int block = colIndex /
colNum
;
int col = colIndex %
blockSize
;
int block = colIndex /
blockSize
;
if(row >= rowNum || block >= blockNum)
return;
if(threadIdx.x == 0)
if(threadIdx.x == 0){
printf("(%d %d) ", row, block);
bv[threadIdx.y] = b[row];
}
/*
__syncthreads();
int offset = block * blockSize + row * colNum + col;
...
...
@@ -100,7 +103,7 @@ void KernelAddWithCol(T * a, T * b, T * c, int rowNum, int colNum, int blockSize
if(betaFired)
c[offset] = a[offset] + bv[threadIdx.y] * beta;
else
c[offset] = a[offset] + bv[threadIdx.y];
c[offset] = a[offset] + bv[threadIdx.y];
*/
}
/*
...
...
source/tensor/core/movement/CopyValues.cpp
查看文件 @
ac5afe2b
...
...
@@ -41,7 +41,8 @@ void _CopyValues(const XTensor * s, XTensor * t, XStream * stream)
CheckNTErrors
(
s
!=
NULL
&&
t
!=
NULL
,
"The input tensor and output tensor must be nonempty!"
);
CheckNTErrors
(
s
->
data
!=
NULL
,
"Cannot copy an empty data array!"
);
CheckNTErrors
(
t
->
data
!=
NULL
,
"Cannot copy to an empty data array!"
);
CheckNTErrors
(
s
->
unitNum
==
t
->
unitNum
,
"Unmatched data item number!"
);
CheckNTErrors
(
s
->
unitSize
==
t
->
unitSize
,
"Incompatible data types in value copy."
);
CheckNTErrors
(
s
->
unitNum
==
t
->
unitNum
,
"The data items are be the same."
);
if
((
s
->
dataType
==
X_FLOAT16
&&
t
->
dataType
==
X_FLOAT
)
||
(
s
->
dataType
==
X_FLOAT
&&
t
->
dataType
==
X_FLOAT16
))
{
...
...
@@ -90,9 +91,9 @@ void _CopyValues(const XTensor * s, const int sBeg, const int sLen, XTensor * t,
CheckNTErrors
(
s
!=
NULL
&&
t
!=
NULL
,
"The input tensor and output tensor must be nonempty!"
);
CheckNTErrors
(
s
->
data
!=
NULL
,
"Cannot copy an empty data array!"
);
CheckNTErrors
(
t
->
data
!=
NULL
,
"Cannot copy to an empty data array!"
);
CheckNTErrors
(
s
->
unitSize
==
t
->
unitSize
,
"
The input tensors must be of the same unit size!
"
);
CheckNTErrors
(
s
->
order
>
sBeg
&&
sBeg
>=
0
&&
sLen
<=
s
->
unitNum
,
"Wrong segment on the source side
"
);
CheckNTErrors
(
t
->
order
>
tBeg
&&
tBeg
>=
0
,
"Wrong segment on the target side
"
);
CheckNTErrors
(
s
->
unitSize
==
t
->
unitSize
,
"
Incompatible data types in value copy.
"
);
CheckNTErrors
(
s
Beg
>=
0
&&
sBeg
+
sLen
<=
s
->
unitNum
,
"Wrong segment of the source data array
"
);
CheckNTErrors
(
t
Beg
>=
0
&&
tBeg
+
sLen
<=
t
->
unitNum
,
"Wrong segment of the target data array
"
);
if
(
!
s
->
isSparse
&&
!
t
->
isSparse
)
{
XMemCopy
((
char
*
)
t
->
data
+
tBeg
*
t
->
unitSize
,
t
->
devID
,
...
...
source/tensor/core/movement/CopyValues.cu
查看文件 @
ac5afe2b
...
...
@@ -37,10 +37,11 @@ copy a range of elements from a source vector to a target vector
*/
void _CudaCopyValues(const XTensor * s, XTensor * t, XStream * stream)
{
CheckNTErrors(
(s != NULL && t != NULL)
, "The input tensor and output tensor must be nonempty!");
CheckNTErrors(
s != NULL && t != NULL
, "The input tensor and output tensor must be nonempty!");
CheckNTErrors(s->dataType == t->dataType, "Unmatched data type!");
CheckNTErrors((s->unitSize == t->unitSize), "Incompatible vectors in value copy.");
CheckNTErrors((s->denseRatio <= s->denseRatio), "Incompatible vectors in value copy.");
CheckNTErrors(s->unitSize == t->unitSize, "Incompatible data types in value copy.");
CheckNTErrors(s->unitNum == t->unitNum, "The data items are be the same.");
CheckNTErrors(s->denseRatio <= t->denseRatio, "Incompatible vectors in value copy.");
/* dense -> dense */
if (!s->isSparse && !t->isSparse) {
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论