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
4a87ecc0
Commit
4a87ecc0
authored
Feb 28, 2021
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code clean
parent
0c0a5e9a
显示空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
27 行增加
和
30 行删除
+27
-30
source/sample/transformer/Utility.cpp
+3
-1
source/sample/transformer/submodel/Attention.cpp
+0
-1
source/sample/transformer/submodel/GLU.cpp
+0
-2
source/sample/transformer/train/Trainer.cpp
+1
-1
source/sample/transformer/translate/Search.cpp
+3
-4
source/sample/transformer/translate/Translator.cpp
+2
-2
source/sample/transformer/translate/Vocab.cpp
+4
-4
source/tensor/XDevice.cpp
+4
-1
source/tensor/core/arithmetic/MulAndShift.cpp
+2
-2
source/tensor/core/movement/Spread.cpp
+2
-2
source/tensor/core/reduce/ReduceSumAll.cpp
+0
-1
source/tensor/core/shape/Stack.cpp
+2
-4
source/tensor/test/TConvertDataType.cpp
+2
-2
source/tensor/test/TGather.cpp
+0
-1
source/tensor/test/TSetData.cpp
+1
-1
source/train/XWorkerJob.cpp
+1
-1
没有找到文件。
source/sample/transformer/Utility.cpp
查看文件 @
4a87ecc0
...
@@ -192,7 +192,9 @@ IntList SplitInt(const string& s, const string& delimiter)
...
@@ -192,7 +192,9 @@ IntList SplitInt(const string& s, const string& delimiter)
IntList
values
;
IntList
values
;
auto
indices
=
SplitToPos
(
s
,
delimiter
);
auto
indices
=
SplitToPos
(
s
,
delimiter
);
for
(
int
i
=
0
;
i
<
indices
.
Size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
indices
.
Size
();
i
++
)
{
values
.
Add
(
strtol
(
s
.
data
()
+
indices
[
i
],
nullptr
,
10
));
/* this line is with problem. Why do we need an IntList to keep an int64*/
values
.
Add
((
int
)
strtol
(
s
.
data
()
+
indices
[
i
],
nullptr
,
10
));
}
}
return
values
;
return
values
;
}
}
...
...
source/sample/transformer/submodel/Attention.cpp
查看文件 @
4a87ecc0
...
@@ -226,7 +226,6 @@ XTensor Attention::MakeRPRAttention(XTensor& k, XTensor& q, XTensor& v,
...
@@ -226,7 +226,6 @@ XTensor Attention::MakeRPRAttention(XTensor& k, XTensor& q, XTensor& v,
XTensor
qheads
;
XTensor
qheads
;
XTensor
vheads
;
XTensor
vheads
;
const
int
batchSize
=
q
.
GetDim
(
0
);
const
int
lenQ
=
q
.
GetDim
(
1
);
const
int
lenQ
=
q
.
GetDim
(
1
);
const
int
lenKV
=
k
.
GetDim
(
1
);
const
int
lenKV
=
k
.
GetDim
(
1
);
...
...
source/sample/transformer/submodel/GLU.cpp
查看文件 @
4a87ecc0
...
@@ -48,8 +48,6 @@ void GLU::InitModel(Config& config)
...
@@ -48,8 +48,6 @@ void GLU::InitModel(Config& config)
{
{
devID
=
config
.
devID
;
devID
=
config
.
devID
;
float
minmax
=
0
;
inSize
=
config
.
modelSize
;
inSize
=
config
.
modelSize
;
outSize
=
config
.
modelSize
;
outSize
=
config
.
modelSize
;
...
...
source/sample/transformer/train/Trainer.cpp
查看文件 @
4a87ecc0
...
@@ -334,7 +334,7 @@ void Trainer::Validate(const char* fn, const char* ofn, Model* model)
...
@@ -334,7 +334,7 @@ void Trainer::Validate(const char* fn, const char* ofn, Model* model)
}
}
int
bSize
=
output
.
GetDim
(
0
);
int
bSize
=
output
.
GetDim
(
0
);
int
length
=
output
.
GetDim
(
1
);
//
int length = output.GetDim(1);
labelOnehot
=
IndexToOnehot
(
label
,
vSizeTgt
,
0
);
labelOnehot
=
IndexToOnehot
(
label
,
vSizeTgt
,
0
);
lossTensor
=
CrossEntropy
(
output
,
labelOnehot
,
paddingDec
);
lossTensor
=
CrossEntropy
(
output
,
labelOnehot
,
paddingDec
);
...
...
source/sample/transformer/translate/Search.cpp
查看文件 @
4a87ecc0
...
@@ -322,7 +322,7 @@ void BeamSearch::Generate(StateBundle* prev, StateBundle* beam)
...
@@ -322,7 +322,7 @@ void BeamSearch::Generate(StateBundle* prev, StateBundle* beam)
/* keep the most promising candidates in the beam */
/* keep the most promising candidates in the beam */
TopK
(
score
,
scoreTopK
,
index
,
-
1
,
beamSize
,
true
);
TopK
(
score
,
scoreTopK
,
index
,
-
1
,
beamSize
,
true
);
float
lp
=
LengthPenalizer
::
GNMT
(
beam
->
nstep
,
alpha
);
//
float lp = LengthPenalizer::GNMT(beam->nstep, alpha);
CopyValues
(
index
,
indexCPU
);
CopyValues
(
index
,
indexCPU
);
CopyValues
(
index
,
preID
);
CopyValues
(
index
,
preID
);
...
@@ -493,8 +493,8 @@ void BeamSearch::Collect(StateBundle* beam)
...
@@ -493,8 +493,8 @@ void BeamSearch::Collect(StateBundle* beam)
/* check if this is the first end symbol. It is false
/* check if this is the first end symbol. It is false
if there have been end symbols in previously generated words. */
if there have been end symbols in previously generated words. */
bool
isCompleted
=
state
.
isCompleted
&&
//bool isCompleted = state.isCompleted &&
(
state
.
last
==
NULL
||
!
state
.
last
->
isCompleted
);
//
(state.last == NULL || !state.last->isCompleted);
/* we push the hypothesis into the heap when it is completed */
/* we push the hypothesis into the heap when it is completed */
if
((
state
.
isEnd
||
state
.
isCompleted
))
{
if
((
state
.
isEnd
||
state
.
isCompleted
))
{
...
@@ -557,7 +557,6 @@ void BeamSearch::Dump(IntList* output, XTensor* score)
...
@@ -557,7 +557,6 @@ void BeamSearch::Dump(IntList* output, XTensor* score)
}
}
}
}
int
count
=
0
;
bool
isCompleted
=
true
;
bool
isCompleted
=
true
;
/* we track the state from the end to the beginning */
/* we track the state from the end to the beginning */
...
...
source/sample/transformer/translate/Translator.cpp
查看文件 @
4a87ecc0
...
@@ -155,7 +155,7 @@ void Translator::Translate(const char* ifn, const char* sfn,
...
@@ -155,7 +155,7 @@ void Translator::Translate(const char* ifn, const char* sfn,
batchLoader
.
outputBuffer
.
Add
(
emptyRes
);
batchLoader
.
outputBuffer
.
Add
(
emptyRes
);
}
}
double
startDump
=
GetClockSec
();
//
double startDump = GetClockSec();
/* reorder the result */
/* reorder the result */
batchLoader
.
SortOutput
();
batchLoader
.
SortOutput
();
...
@@ -163,7 +163,7 @@ void Translator::Translate(const char* ifn, const char* sfn,
...
@@ -163,7 +163,7 @@ void Translator::Translate(const char* ifn, const char* sfn,
/* print the result to a file */
/* print the result to a file */
batchLoader
.
DumpRes
(
ofn
);
batchLoader
.
DumpRes
(
ofn
);
double
elapsed
=
GetClockSec
()
-
startDump
;
//
double elapsed = GetClockSec() - startDump;
LOG
(
"translation completed (word=%d, sent=%zu)"
,
LOG
(
"translation completed (word=%d, sent=%zu)"
,
wordCountTotal
,
batchLoader
.
inputBuffer
.
Size
()
+
batchLoader
.
emptyLines
.
Size
());
wordCountTotal
,
batchLoader
.
inputBuffer
.
Size
()
+
batchLoader
.
emptyLines
.
Size
());
...
...
source/sample/transformer/translate/Vocab.cpp
查看文件 @
4a87ecc0
...
@@ -34,14 +34,14 @@ void Vocab::Load(const string& src)
...
@@ -34,14 +34,14 @@ void Vocab::Load(const string& src)
/* get the vocab size and the start id */
/* get the vocab size and the start id */
f
>>
vsz
>>
sid
;
f
>>
vsz
>>
sid
;
startID
=
stol
(
sid
);
startID
=
(
int
)
stol
(
sid
);
vocabSize
=
stol
(
vsz
);
vocabSize
=
(
int
)
stol
(
vsz
);
string
word
,
id
;
string
word
,
id
;
for
(
int
i
=
0
;
i
<
vocabSize
-
startID
;
i
++
)
{
for
(
int
i
=
0
;
i
<
vocabSize
-
startID
;
i
++
)
{
f
>>
word
>>
id
;
f
>>
word
>>
id
;
word2id
[
word
]
=
stol
(
id
);
word2id
[
word
]
=
(
int
)
stol
(
id
);
id2word
[
stol
(
id
)]
=
word
;
id2word
[
(
int
)
stol
(
id
)]
=
word
;
}
}
f
.
close
();
f
.
close
();
...
...
source/tensor/XDevice.cpp
查看文件 @
4a87ecc0
...
@@ -182,10 +182,11 @@ void XDevice::Reset()
...
@@ -182,10 +182,11 @@ void XDevice::Reset()
XMem
*
mem
=
GMems
.
GetMem
(
devID
);
XMem
*
mem
=
GMems
.
GetMem
(
devID
);
mem
->
Free
();
mem
->
Free
();
#ifdef USE_CUDA
int
devIDReset
=
devID
;
int
devIDReset
=
devID
;
Clear
();
Clear
();
#ifdef USE_CUDA
if
(
devIDReset
>=
0
)
{
if
(
devIDReset
>=
0
)
{
int
devIDBackup
=
-
1
;
int
devIDBackup
=
-
1
;
cudaGetDevice
(
&
devIDBackup
);
cudaGetDevice
(
&
devIDBackup
);
...
@@ -195,6 +196,8 @@ void XDevice::Reset()
...
@@ -195,6 +196,8 @@ void XDevice::Reset()
cudaSetDevice
(
devIDBackup
);
cudaSetDevice
(
devIDBackup
);
}
}
#else
Clear
();
#endif
#endif
}
}
...
...
source/tensor/core/arithmetic/MulAndShift.cpp
查看文件 @
4a87ecc0
...
@@ -121,8 +121,8 @@ XTensor MulAndShift(const XTensor& x, MATRIX_TRANS_TYPE transposedX,
...
@@ -121,8 +121,8 @@ XTensor MulAndShift(const XTensor& x, MATRIX_TRANS_TYPE transposedX,
CheckNTErrors
(
x
.
order
>=
2
&&
w
.
order
>=
2
,
"Input tensors must have a order >= 2!"
);
CheckNTErrors
(
x
.
order
>=
2
&&
w
.
order
>=
2
,
"Input tensors must have a order >= 2!"
);
int
xn
=
transposedX
==
X_TRANS
?
x
.
dimSize
[
x
.
order
-
1
]
:
x
.
dimSize
[
x
.
order
-
2
];
int
xn
=
transposedX
==
X_TRANS
?
x
.
dimSize
[
x
.
order
-
1
]
:
x
.
dimSize
[
x
.
order
-
2
];
int
xm
=
transposedX
==
X_TRANS
?
x
.
dimSize
[
x
.
order
-
2
]
:
x
.
dimSize
[
x
.
order
-
1
];
//
int xm = transposedX == X_TRANS ? x.dimSize[x.order - 2] : x.dimSize[x.order - 1];
int
wn
=
transposedW
==
X_TRANS
?
w
.
dimSize
[
w
.
order
-
1
]
:
w
.
dimSize
[
w
.
order
-
2
];
//
int wn = transposedW == X_TRANS ? w.dimSize[w.order - 1] : w.dimSize[w.order - 2];
int
wm
=
transposedW
==
X_TRANS
?
w
.
dimSize
[
w
.
order
-
2
]
:
w
.
dimSize
[
w
.
order
-
1
];
int
wm
=
transposedW
==
X_TRANS
?
w
.
dimSize
[
w
.
order
-
2
]
:
w
.
dimSize
[
w
.
order
-
1
];
int
order
=
x
.
order
+
w
.
order
-
2
;
int
order
=
x
.
order
+
w
.
order
-
2
;
...
...
source/tensor/core/movement/Spread.cpp
查看文件 @
4a87ecc0
...
@@ -231,8 +231,8 @@ And this is a special spread function for backward computation of gather functio
...
@@ -231,8 +231,8 @@ And this is a special spread function for backward computation of gather functio
*/
*/
void
_SpreadForGather
(
XTensor
*
source
,
XTensor
*
collection
,
XTensor
*
index
)
void
_SpreadForGather
(
XTensor
*
source
,
XTensor
*
collection
,
XTensor
*
index
)
{
{
int
dim
=
0
;
//
int dim = 0;
int
order
=
source
->
order
;
//
int order = source->order;
CheckNTErrors
(
source
->
dataType
==
DEFAULT_DTYPE
,
"TODO!"
);
CheckNTErrors
(
source
->
dataType
==
DEFAULT_DTYPE
,
"TODO!"
);
CheckNTErrors
(
collection
->
GetDim
(
-
1
)
==
source
->
GetDim
(
-
1
),
"Illegal dimension!"
);
CheckNTErrors
(
collection
->
GetDim
(
-
1
)
==
source
->
GetDim
(
-
1
),
"Illegal dimension!"
);
...
...
source/tensor/core/reduce/ReduceSumAll.cpp
查看文件 @
4a87ecc0
...
@@ -72,7 +72,6 @@ sum all the items of the tensor (It should be optimized!)
...
@@ -72,7 +72,6 @@ sum all the items of the tensor (It should be optimized!)
void
_ReduceSumAll
(
const
XTensor
*
source
,
DTYPE
*
value
)
void
_ReduceSumAll
(
const
XTensor
*
source
,
DTYPE
*
value
)
{
{
int
*
dimSize
=
new
int
[
MAX_TENSOR_DIM_NUM
];
int
*
dimSize
=
new
int
[
MAX_TENSOR_DIM_NUM
];
float
dr
=
(
!
source
->
isSparse
)
?
1.0
F
:
source
->
denseRatio
;
XTensor
*
target
=
NewTensorBufV2
(
0
,
dimSize
,
source
->
dataType
,
source
->
denseRatio
,
source
->
devID
,
source
->
mem
);
XTensor
*
target
=
NewTensorBufV2
(
0
,
dimSize
,
source
->
dataType
,
source
->
denseRatio
,
source
->
devID
,
source
->
mem
);
target
->
SetTMPFlag
();
target
->
SetTMPFlag
();
...
...
source/tensor/core/shape/Stack.cpp
查看文件 @
4a87ecc0
...
@@ -43,13 +43,11 @@ void _Stack(const TensorList * smalls, XTensor * t, int dim)
...
@@ -43,13 +43,11 @@ void _Stack(const TensorList * smalls, XTensor * t, int dim)
int
blockSize
=
1
;
int
blockSize
=
1
;
int
blockNum
=
1
;
int
blockNum
=
1
;
int
gridSize
=
1
;
int
gridNum
=
1
;
int
gridNum
=
1
;
XTensor
*
smallsItem0
=
smalls
->
GetItem
(
0
);
XTensor
*
smallsItem0
=
smalls
->
GetItem
(
0
);
int
unitNum
=
smallsItem0
->
unitNum
;
//
int unitNum = smallsItem0->unitNum;
int
unitSize
=
smallsItem0
->
unitSize
;
int
unitSize
=
smallsItem0
->
unitSize
;
int
itemSize
=
unitNum
*
unitSize
;
for
(
int
i
=
0
;
i
<
smallsItem0
->
order
;
i
++
)
{
for
(
int
i
=
0
;
i
<
smallsItem0
->
order
;
i
++
)
{
if
(
i
>=
dim
)
if
(
i
>=
dim
)
...
@@ -129,7 +127,7 @@ bool CheckStackShape(const TensorList &smalls, XTensor &t, int dim)
...
@@ -129,7 +127,7 @@ bool CheckStackShape(const TensorList &smalls, XTensor &t, int dim)
XTensor
*
tensor
=
(
XTensor
*
)
smalls
.
GetItem
(
0
);
XTensor
*
tensor
=
(
XTensor
*
)
smalls
.
GetItem
(
0
);
int
order
=
tensor
->
order
;
int
order
=
tensor
->
order
;
for
(
int
i
=
0
;
i
<
tensor
->
order
;
i
++
)
{
for
(
int
i
=
0
;
i
<
order
;
i
++
)
{
if
(
i
<
dim
)
{
if
(
i
<
dim
)
{
if
(
t
.
GetDim
(
i
)
!=
tensor
->
GetDim
(
i
))
if
(
t
.
GetDim
(
i
)
!=
tensor
->
GetDim
(
i
))
return
false
;
return
false
;
...
...
source/tensor/test/TConvertDataType.cpp
查看文件 @
4a87ecc0
...
@@ -215,12 +215,12 @@ bool TestConvertDataType3()
...
@@ -215,12 +215,12 @@ bool TestConvertDataType3()
{
0.5
F
,
-
4.0
F
},
{
0.5
F
,
-
4.0
F
},
{
0.0
F
,
6.0
F
}
};
{
0.0
F
,
6.0
F
}
};
DTYPE
data2
[
2
][
3
]
=
{
{
1.0
F
,
2.0
F
,
3.0
F
},
/*
DTYPE data2[2][3] = { {1.0F, 2.0F, 3.0F},
{0.0F, 4.0F, 5.0F} };
{0.0F, 4.0F, 5.0F} };
DTYPE answer[3][3] = { {1.0F, -6.0F, -7.0F},
DTYPE answer[3][3] = { {1.0F, -6.0F, -7.0F},
{0.5F, -15.0F, -18.5F},
{0.5F, -15.0F, -18.5F},
{
0.0
F
,
24.0
F
,
30.0
F
}
};
{0.0F, 24.0F, 30.0F} };
*/
/* CPU test */
/* CPU test */
bool
cpuTest
=
true
;
bool
cpuTest
=
true
;
...
...
source/tensor/test/TGather.cpp
查看文件 @
4a87ecc0
...
@@ -67,7 +67,6 @@ bool TestGather1()
...
@@ -67,7 +67,6 @@ bool TestGather1()
DTYPE
answer
[
2
][
3
]
=
{
{
0.0
F
,
-
1.0
F
,
2.0
F
},
DTYPE
answer
[
2
][
3
]
=
{
{
0.0
F
,
-
1.0
F
,
2.0
F
},
{
1.0
F
,
2.0
F
,
4.0
F
}
};
{
1.0
F
,
2.0
F
,
4.0
F
}
};
int
dim
=
0
;
int
indexSize
=
2
;
int
indexSize
=
2
;
int
srcIndex
[
2
]
=
{
0
,
2
};
int
srcIndex
[
2
]
=
{
0
,
2
};
...
...
source/tensor/test/TSetData.cpp
查看文件 @
4a87ecc0
...
@@ -422,7 +422,7 @@ bool TestSetData6()
...
@@ -422,7 +422,7 @@ bool TestSetData6()
for
(
int
i
=
0
;
i
<
order
;
i
++
)
for
(
int
i
=
0
;
i
<
order
;
i
++
)
unitNum
*=
dimSize
[
i
];
unitNum
*=
dimSize
[
i
];
DTYPE
answer
[
5
]
=
{
5.2
F
,
3.2
F
,
1.2
F
,
-
0.8
F
,
-
2.8
F
};
//
DTYPE answer[5] = {5.2F, 3.2F, 1.2F, -0.8F, -2.8F};
/* CPU test */
/* CPU test */
bool
cpuTest
=
true
;
bool
cpuTest
=
true
;
...
...
source/train/XWorkerJob.cpp
查看文件 @
4a87ecc0
...
@@ -51,7 +51,7 @@ bool XWorkerJob::AddJobRefresh(XModel * paramKeeper)
...
@@ -51,7 +51,7 @@ bool XWorkerJob::AddJobRefresh(XModel * paramKeeper)
XList
args
(
1
);
XList
args
(
1
);
args
.
Add
(
paramKeeper
);
args
.
Add
(
paramKeeper
);
queue
.
EnqueueJob
(
&
XModel
::
Refresh
,
&
args
);
queue
.
EnqueueJob
(
(
void
*
)
&
paramKeeper
->
Refresh
,
&
args
);
return
true
;
return
true
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论