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
ac6ed3a1
Commit
ac6ed3a1
authored
Feb 17, 2020
by
huchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for beam search (tested with beam size 2)
parent
99097e41
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
4 行增加
和
22 行删除
+4
-22
source/sample/transformer/T2TPredictor.cpp
+1
-16
source/sample/transformer/T2TSearch.cpp
+3
-6
没有找到文件。
source/sample/transformer/T2TPredictor.cpp
查看文件 @
ac6ed3a1
...
@@ -101,25 +101,10 @@ void T2TPredictor::Create(T2TModel* model, XTensor* top, const XTensor* input, i
...
@@ -101,25 +101,10 @@ void T2TPredictor::Create(T2TModel* model, XTensor* top, const XTensor* input, i
InitTensorV2
(
&
state
->
nstep
,
input
->
order
,
dims
,
X_FLOAT
,
1.0
F
,
input
->
devID
);
InitTensorV2
(
&
state
->
nstep
,
input
->
order
,
dims
,
X_FLOAT
,
1.0
F
,
input
->
devID
);
InitTensorV2
(
&
state
->
endMark
,
input
->
order
,
dims
,
X_INT
,
1.0
F
,
input
->
devID
);
InitTensorV2
(
&
state
->
endMark
,
input
->
order
,
dims
,
X_INT
,
1.0
F
,
input
->
devID
);
/*float* data = new float[state->probPath.unitNum];
state
->
probPath
.
SetZeroAll
();
for (int i = 0; i < state->probPath.unitNum; ++i) {
data[i] = -1e20F;
if (i % beamSize == 0)
data[i] = 0;
}
state->probPath.SetData(data, state->probPath.unitNum);
delete[] data;*/
SetDataFixed
(
state
->
probPath
,
-
1e9
F
);
for
(
int
i
=
0
;
i
<
state
->
probPath
.
unitNum
;
++
i
)
{
if
(
i
%
beamSize
==
0
)
state
->
probPath
.
Set
(
0.0
F
,
i
);
}
state
->
nstep
.
SetZeroAll
();
state
->
nstep
.
SetZeroAll
();
state
->
endMark
.
SetZeroAll
();
state
->
endMark
.
SetZeroAll
();
state
->
stateNum
=
0
;
state
->
stateNum
=
0
;
}
}
...
...
source/sample/transformer/T2TSearch.cpp
查看文件 @
ac6ed3a1
...
@@ -285,11 +285,11 @@ void T2TSearch::Generate(T2TStateBundle* beam)
...
@@ -285,11 +285,11 @@ void T2TSearch::Generate(T2TStateBundle* beam)
XTensor
mask
;
XTensor
mask
;
InitTensorV2
(
&
mask
,
1
,
dimMask
,
X_FLOAT
,
1.0
F
,
-
1
);
InitTensorV2
(
&
mask
,
1
,
dimMask
,
X_FLOAT
,
1.0
F
,
-
1
);
mask
.
SetZeroAll
();
mask
.
SetZeroAll
();
mask
.
Set1D
(
-
1e
20
F
,
0
);
mask
.
Set1D
(
-
1e
9
F
,
0
);
mask
.
Set1D
(
-
1e
20
F
,
1
);
mask
.
Set1D
(
-
1e
9
F
,
1
);
mask
.
SetDevice
(
score
.
devID
,
score
.
mem
);
mask
.
SetDevice
(
score
.
devID
,
score
.
mem
);
//
_SumDim(&score, &mask, 2);
_SumDim
(
&
score
,
&
mask
,
2
);
score
.
Reshape
(
order
,
dimsBeam
);
score
.
Reshape
(
order
,
dimsBeam
);
/* keep the most promissing candidates in the beam */
/* keep the most promissing candidates in the beam */
...
@@ -324,9 +324,6 @@ void T2TSearch::Generate(T2TStateBundle* beam)
...
@@ -324,9 +324,6 @@ void T2TSearch::Generate(T2TStateBundle* beam)
for
(
int
j
=
0
;
j
<
beamSize
;
j
++
)
for
(
int
j
=
0
;
j
<
beamSize
;
j
++
)
indexGPU
.
SetInt
(
i
*
stride
+
indexGPU
.
GetInt
(
i
+
j
),
i
+
j
);
indexGPU
.
SetInt
(
i
*
stride
+
indexGPU
.
GetInt
(
i
+
j
),
i
+
j
);
}
}
/*for (int i = 0; i < indexGPU.unitNum; i++) {
indexGPU.SetInt(i + indexGPU.GetInt(i), i);
}*/
CheckNTErrors
(
IsSameShaped
(
prob
,
probPath
),
"Wrong tensor shape!"
);
CheckNTErrors
(
IsSameShaped
(
prob
,
probPath
),
"Wrong tensor shape!"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论