Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
8
Issues
8
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
NiuTrans
NiuTrans.Tensor
Commits
7294cb66
Commit
7294cb66
authored
Jun 08, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code cleaning and better management of device
parent
fcc18004
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
39 行增加
和
15 行删除
+39
-15
source/sample/transformer/T2TBatchLoader.cpp
+10
-8
source/sample/transformer/T2TPredictor.cpp
+4
-1
source/sample/transformer/T2TTrainer.cpp
+6
-2
source/sample/transformer/Transformer.cpp
+1
-4
source/tensor/XTensor.cpp
+15
-0
source/tensor/XTensor.h
+3
-0
没有找到文件。
source/sample/transformer/T2TBatchLoader.cpp
查看文件 @
7294cb66
...
...
@@ -302,9 +302,10 @@ load a batch of sequences (for LM)
>> paddingEnc - padding of the input sequences
>> batchDec - the batch of the output sequences
>> paddingDec - padding of the output sequences
>> gold - gold standard
>> gold - gold standard (distribution of every position)
>> label - (gold standard) label index of every position
>> seqs - keep the sequences in an array
>> v
s
- vocabulary size
>> v
Size
- vocabulary size
>> sBatch - batch size of sequences
>> wBatch - batch size of words
>> isSorted - indicates whether the sequences are sorted by length
...
...
@@ -318,7 +319,7 @@ int T2TBatchLoader::LoadBatchLM(FILE * file,
XTensor
*
batchDec
,
XTensor
*
paddingDec
,
XTensor
*
gold
,
XTensor
*
label
,
int
*
seqs
,
int
v
s
,
int
sBatch
,
int
wBatch
,
int
v
Size
,
int
sBatch
,
int
wBatch
,
bool
isSorted
,
int
&
wCount
,
int
devID
,
XMem
*
mem
,
bool
isTraining
)
...
...
@@ -355,7 +356,7 @@ int T2TBatchLoader::LoadBatchLM(FILE * file,
int
dims
[
MAX_TENSOR_DIM_NUM
];
dims
[
0
]
=
sc
;
dims
[
1
]
=
max
;
dims
[
2
]
=
v
s
;
dims
[
2
]
=
v
Size
;
InitTensor2D
(
batchEnc
,
sc
,
max
,
X_INT
,
devID
,
mem
);
InitTensor2D
(
label
,
sc
,
max
,
X_INT
,
devID
,
mem
);
...
...
@@ -459,10 +460,11 @@ load a batch of sequences (for MT)
>> paddingEnc - padding of the input sequences
>> batchDec - the batch of the output sequences
>> paddingDec - padding of the output sequences
>> gold - gold standard
>> gold - gold standard (distribution of every position)
>> label - (gold standard) label index of every position
>> seqs - keep the sequences in an array
>> v
s
Enc - size of the encoder vocabulary
>> v
s
Dec - size of the decoder vocabulary
>> v
Size
Enc - size of the encoder vocabulary
>> v
Size
Dec - size of the decoder vocabulary
>> sBatch - batch size of sequences
>> wBatch - batch size of words
>> isSorted - indicates whether the sequences are sorted by length
...
...
@@ -476,7 +478,7 @@ int T2TBatchLoader::LoadBatchMT(FILE * file,
XTensor
*
batchDec
,
XTensor
*
paddingDec
,
XTensor
*
gold
,
XTensor
*
label
,
int
*
seqs
,
int
v
sEnc
,
int
vs
Dec
,
int
sBatch
,
int
wBatch
,
int
v
SizeEnc
,
int
vSize
Dec
,
int
sBatch
,
int
wBatch
,
bool
isSorted
,
int
&
ws
,
int
&
wCount
,
int
devID
,
XMem
*
mem
,
bool
isTraining
)
...
...
source/sample/transformer/T2TPredictor.cpp
查看文件 @
7294cb66
...
...
@@ -160,7 +160,7 @@ void T2TPredictor::Predict(T2TStateBundle * next, XTensor * encoding, XTensor *
dims
[
inputDec
.
order
-
1
]
=
inputDec
.
GetDim
(
-
1
);
XTensor
paddingDec
;
InitTensor
(
&
paddingDec
,
inputDec
.
order
,
dims
,
X_INT
);
InitTensor
(
&
paddingDec
,
inputDec
.
order
,
dims
,
X_INT
,
1.0
F
,
paddingEnc
->
devID
,
paddingEnc
->
mem
);
SetDataFixedInt
(
paddingDec
,
1
);
XTensor
maskDec
;
...
...
@@ -190,6 +190,9 @@ void T2TPredictor::Predict(T2TStateBundle * next, XTensor * encoding, XTensor *
selectTgt
.
SetInt
(
i
,
i
);
}
selectSrc
.
SetDevice
(
decoding
.
devID
,
decoding
.
mem
);
selectTgt
.
SetDevice
(
decoding
.
devID
,
decoding
.
mem
);
/* the decoder output of the last position */
decodingStep
=
CopyIndexed
(
decoding
,
decoding
.
order
-
2
,
selectSrc
,
selectTgt
);
...
...
source/sample/transformer/T2TTrainer.cpp
查看文件 @
7294cb66
...
...
@@ -344,7 +344,7 @@ void T2TTrainer::Test(const char * fn, const char * ofn, T2TModel * model)
batchLoader
.
ClearBuf
();
while
(
batchLoader
.
LoadBatch
(
file
,
model
->
isLM
,
&
batchEnc
,
&
paddingEnc
,
&
padding
Dec
,
&
paddingDec
,
&
gold
,
&
label
,
&
batchEnc
,
&
paddingEnc
,
&
batch
Dec
,
&
paddingDec
,
&
gold
,
&
label
,
seqs
,
vSize
,
vSizeTgt
,
1
,
1
,
false
,
ws
,
wc
,
devID
,
mem
,
false
))
{
...
...
@@ -369,8 +369,12 @@ void T2TTrainer::Test(const char * fn, const char * ofn, T2TModel * model)
XTensor
probs
;
InitTensor1D
(
&
probs
,
bSize
*
length
);
XTensor
labelOnehot
;
labelOnehot
=
IndexToOnehot
(
label
,
vSizeTgt
,
0
);
/* get probabilities */
float
prob
=
GetProb
(
&
output
,
&
gold
,
&
probs
);
float
prob
=
GetProb
(
&
output
,
&
labelOnehot
,
&
probs
);
/* dump the test result */
for
(
int
s
=
0
;
s
<
bSize
;
s
++
){
...
...
source/sample/transformer/Transformer.cpp
查看文件 @
7294cb66
...
...
@@ -81,11 +81,8 @@ int TransformerMain(int argc, const char ** argv)
if
(
strcmp
(
modelFN
,
""
))
model
.
Read
(
modelFN
);
/* test the model on the new data */
if
(
strcmp
(
testFN
,
""
)
&&
strcmp
(
outputFN
,
""
))
{
if
(
strcmp
(
testFN
,
""
)
&&
strcmp
(
outputFN
,
""
)){
/* beam search */
if
(
isBeamSearch
){
T2TTester
searcher
;
...
...
source/tensor/XTensor.cpp
查看文件 @
7294cb66
...
...
@@ -512,6 +512,21 @@ XTensor XTensor::Lin(DTYPE scale, DTYPE shift) const
}
/*
relocate the data on the target device
>> myDevId - target device id
>> myMem - memory pool on the target device
*/
void
XTensor
::
SetDevice
(
int
myDevId
,
XMem
*
myMem
)
{
if
(
myMem
!=
NULL
)
{
FlushToMem
(
myMem
);
}
else
{
ShowNTErrors
(
"TODO!"
);
}
}
/*
judge whether the two matrices are in the same type and size
>> a - input tensor
>> b - anther tensor to compare with
...
...
source/tensor/XTensor.h
查看文件 @
7294cb66
...
...
@@ -248,6 +248,9 @@ public:
/* linear transformation */
XTensor
Lin
(
DTYPE
scale
,
DTYPE
shift
=
0
)
const
;
/* relocate the data on the target device */
void
SetDevice
(
int
myDevId
,
XMem
*
myMem
=
NULL
);
/* judge whether the two matrices are in the same type and size */
static
bool
IsSameShaped
(
const
XTensor
*
a
,
const
XTensor
*
b
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论