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
1c9973c9
Commit
1c9973c9
authored
Mar 14, 2021
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates
parent
b87c6f74
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
53 行增加
和
12 行删除
+53
-12
source/train/TTrain.cpp
+18
-5
source/train/TTrain.h
+3
-3
source/train/XLeader.cpp
+1
-1
source/train/XOptimizer.cpp
+3
-3
source/train/XTrainer.cpp
+24
-0
source/train/XTrainer.h
+4
-0
没有找到文件。
source/train/TTrain.cpp
查看文件 @
1c9973c9
...
...
@@ -80,18 +80,20 @@ void TestTrain()
config
.
Add
(
"lrate"
,
0.001
F
);
config
.
Add
(
"nstep"
,
100000
);
config
.
Add
(
"nepoch"
,
5
);
config
.
Add
(
"jobdev0"
,
-
1
);
//
config.Add("jobdev1", -1);
//
config.Add("jobdev2", -1);
config
.
Add
(
"jobdev0"
,
0
);
config
.
Add
(
"jobdev1"
,
-
1
);
config
.
Add
(
"jobdev2"
,
-
1
);
//config.Add("jobdev3", -1);
//config.Add("jobdev4", -1);
int
serverDevID
=
config
.
GetInt
(
"jobdev0"
,
-
1
);
TTDataLoader
loader
;
loader
.
SetFileName
(
"ttrain.txt"
);
loader
.
SetBatchSize
(
config
.
GetInt
(
"batchsize"
,
TT_BATCH_SIZE
));
TTModel
model
;
model
.
Init
(
config
,
-
1
);
model
.
Init
(
config
,
serverDevID
);
tmpTT
=
model
.
params
[
0
].
param
;
...
...
@@ -218,6 +220,10 @@ bool TTDataLoader::GetBatchSimple(XList * inputs, XList * golds)
/* constructor */
TTModel
::
TTModel
()
{
devID
=
-
1
;
vSize
=
0
;
eSize
=
0
;
hSize
=
0
;
}
/* de-constructor */
...
...
@@ -236,11 +242,13 @@ initialize the model
>> myConfig - configuration
>> devID - device id
*/
void
TTModel
::
Init
(
XConfig
&
myConfig
,
int
d
evID
)
void
TTModel
::
Init
(
XConfig
&
myConfig
,
int
myD
evID
)
{
Clear
();
SetConfig
(
myConfig
);
devID
=
myDevID
;
vSize
=
MAX_INT_IN_TTRAIN
+
1
;
eSize
=
config
.
GetInt
(
"esize"
,
TT_EMBEDDING_SIZE
);
hSize
=
config
.
GetInt
(
"hsize"
,
TT_HIDDEN_SIZE
);
...
...
@@ -331,6 +339,11 @@ bool TTModel::RunSimple(XList * inputs, XList * outputs, XList * golds, XList* l
XTensor
*
loss
=
(
XTensor
*
)
losses
->
GetItem
(
0
);
XTensor
goldOneHot
;
/* place all input data on the correct device */
input
->
FlushToDevice
(
devID
);
output
->
FlushToDevice
(
devID
);
gold
->
FlushToDevice
(
devID
);
XNet
net
;
/* create the neural network and run it */
...
...
source/train/TTrain.h
查看文件 @
1c9973c9
...
...
@@ -49,8 +49,8 @@ namespace nts { // namespace nts(NiuTrans.Tensor)
#define MAX_SAMPLE_LINE_LENGTH 128
#define MAX_SAMPLE_SIZE 4
#define TT_BATCH_SIZE 256
#define TT_EMBEDDING_SIZE
64
#define TT_HIDDEN_SIZE
256
#define TT_EMBEDDING_SIZE
128
#define TT_HIDDEN_SIZE
512
extern
XTensor
*
tmpTT
;
...
...
@@ -136,7 +136,7 @@ public:
void
SetConfig
(
XConfig
&
myConfig
);
/* initialize the parameters */
void
Init
(
XConfig
&
myConfig
,
int
d
evID
);
void
Init
(
XConfig
&
myConfig
,
int
myD
evID
);
/* create the model */
void
Forward
(
int
devID
,
XTensor
*
input
,
XTensor
*
output
);
...
...
source/train/XLeader.cpp
查看文件 @
1c9973c9
...
...
@@ -265,7 +265,7 @@ void XLeader::AddJobWorker(XModel * model, int n, int * ids)
}
/* we clone the input model */
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++
)
{
for
(
int
i
=
1
;
i
<
n
;
i
++
)
{
XWorkerJob
*
worker
=
new
XWorkerJob
();
worker
->
SetModel
(
model
->
Clone
(
ids
[
i
]));
jworkers
.
Add
(
worker
);
...
...
source/train/XOptimizer.cpp
查看文件 @
1c9973c9
...
...
@@ -63,9 +63,9 @@ void XOptimizer::Clear()
void
XOptimizer
::
ShowSettings
()
{
XPRINT
(
1
,
stderr
,
"[INFO] Optimizer Setup:
\n
"
);
XPRINT
1
(
1
,
stderr
,
" nstep = %d
\n
"
,
nstep
);
XPRINT
1
(
1
,
stderr
,
" nepoch = %d
\n
"
,
nepoch
);
XPRINT
1
(
1
,
stderr
,
" lrate = %.3f
\n
"
,
lrate
);
XPRINT
2
(
1
,
stderr
,
"%25s = %d
\n
"
,
"nstep
"
,
nstep
);
XPRINT
2
(
1
,
stderr
,
"%25s = %d
\n
"
,
"nepoch
"
,
nepoch
);
XPRINT
2
(
1
,
stderr
,
"%25s = %.3f
\n
"
,
"lrate
"
,
lrate
);
}
/*
...
...
source/train/XTrainer.cpp
查看文件 @
1c9973c9
...
...
@@ -102,6 +102,7 @@ void XTrainer::Run(XConfig * config, DataDistributeBase * dataDistributor,
GetDevIDs
(
config
,
ids
,
jobNum
,
MAX_DEVICE_NUM_TRAINING
);
optimizer
->
ShowSettings
();
this
->
ShowSettings
(
config
);
/* create the server and workers */
XLeader
leader
;
...
...
@@ -148,4 +149,27 @@ void XTrainer::Run(XConfig * config, DataDistributeBase * dataDistributor,
delete
[]
ids
;
}
/* show settings of training */
void
XTrainer
::
ShowSettings
(
XConfig
*
config
)
{
int
workerNum
=
0
;
int
*
ids
=
new
int
[
MAX_DEVICE_NUM_TRAINING
];
GetDevIDs
(
config
,
ids
,
workerNum
,
MAX_DEVICE_NUM_TRAINING
);
XPRINT
(
1
,
stderr
,
"[INFO] Training Setup:
\n
"
);
XPRINT2
(
1
,
stderr
,
"%25s = %d
\n
"
,
"nworker"
,
workerNum
);
if
(
workerNum
>
0
)
{
XPRINT2
(
1
,
stderr
,
"%25s = device[%d]
\n
"
,
"worker0(server)"
,
ids
[
0
]);
for
(
int
i
=
1
;
i
<
workerNum
;
i
++
)
{
char
name
[
32
];
sprintf
(
name
,
"worker%d"
,
i
);
XPRINT2
(
1
,
stderr
,
"%25s = device[%d]
\n
"
,
name
,
ids
[
i
]);
}
}
delete
[]
ids
;
}
}
/* end of the nts (NiuTrans.Tensor) namespace */
source/train/XTrainer.h
查看文件 @
1c9973c9
...
...
@@ -77,6 +77,9 @@ public:
virtual
void
Run
(
XConfig
*
config
,
DataDistributeBase
*
dataDistributor
,
XModel
*
model
,
XOptimizer
*
optimizer
);
/* show settings of training */
void
ShowSettings
(
XConfig
*
config
);
};
}
#endif // __XTRAINER_H__
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论