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
2736ad16
Commit
2736ad16
authored
Feb 28, 2021
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixes and a new class XConfig
parent
327fb820
显示空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
142 行增加
和
60 行删除
+142
-60
source/tensor/XConfig.cpp
+33
-0
source/tensor/XConfig.h
+40
-0
source/trainer/XLeader.cpp
+19
-5
source/trainer/XLeader.h
+12
-2
source/trainer/XNetTemplate.cpp
+14
-14
source/trainer/XNetTemplate.h
+20
-12
source/trainer/XWorkerJob.cpp
+3
-23
source/trainer/XWorkerJob.h
+1
-4
没有找到文件。
source/tensor/XConfig.cpp
0 → 100644
查看文件 @
2736ad16
/*
* NiuTrans.Tensor - an open-source tensor library
* Copyright (C) 2021
* Natural Language Processing Lab, Northeastern University
* and
* NiuTrans Research
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* this class keeps a batch of paramters.
*
* $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2021-02-28
*/
#include "XConfig.h"
namespace
nts
{
// namespace nts(NiuTrans.Tensor)
}
//
namespace
nts
(
NiuTrans
.
Tensor
)
\ No newline at end of file
source/tensor/XConfig.h
0 → 100644
查看文件 @
2736ad16
/*
* NiuTrans.Tensor - an open-source tensor library
* Copyright (C) 2021
* Natural Language Processing Lab, Northeastern University
* and
* NiuTrans Research
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* this class defines a parameter keeper.
*
* $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2021-02-28
* A new semester begins today.
*/
#ifndef __XCONFIG_H__
#define __XCONFIG_H__
#include "XGlobal.h"
#include "XUtility.h"
namespace
nts
{
// namespace nts(NiuTrans.Tensor)
}
// namespace nts(NiuTrans.Tensor)
#endif
\ No newline at end of file
source/trainer/XLeader.cpp
查看文件 @
2736ad16
...
...
@@ -40,7 +40,7 @@ namespace nts {
XLeader
::
XLeader
()
{
id
=
-
1
;
data
Loade
r
=
NULL
;
data
Distributo
r
=
NULL
;
}
/* de-constructor */
...
...
@@ -60,11 +60,26 @@ int XLeader::GetID()
return
id
;
}
/*
set the communication mode
>> myMode - the mode
*/
void
XLeader
::
SetMode
(
XLEADER_MODE
myMode
)
{
mode
=
myMode
;
}
/* set the data loader */
void
XLeader
::
SetDataLoader
(
DataLoaderBase
*
myDataLoader
)
void
XLeader
::
SetDataDistributor
(
DataDistributeBase
*
myDataDistributor
)
{
CheckNTErrors
(
myDataDistributor
!=
NULL
,
"The input of XLeader::SetDataLoader should not be NULL!"
);
dataDistributor
=
myDataDistributor
;
}
/* run the leader (this is the core process) */
void
XLeader
::
Run
()
{
CheckNTErrors
(
myDataLoader
!=
NULL
,
"The input of XLeader::SetDataLoader should not be NULL!"
);
dataLoader
=
myDataLoader
;
}
}
/* end of the nts (NiuTrans.Tensor) namespace */
\ No newline at end of file
source/trainer/XLeader.h
查看文件 @
2736ad16
...
...
@@ -55,8 +55,11 @@ protected:
/* id of the leader */
int
id
;
/* communication mode */
XLEADER_MODE
mode
;
/* data loader */
Data
LoaderBase
*
dataLoade
r
;
Data
DistributeBase
*
dataDistributo
r
;
public
:
...
...
@@ -72,8 +75,15 @@ public:
/* get id */
int
GetID
();
/* set the communication mode */
void
SetMode
(
XLEADER_MODE
myMode
);
/* set the data loader */
void
SetDataLoader
(
DataLoaderBase
*
myDataLoader
);
void
SetDataDistributor
(
DataDistributeBase
*
myDataLoader
);
/* run the leader (this is the core process) */
virtual
void
Run
();
};
...
...
source/trainer/XNetTemplate.cpp
查看文件 @
2736ad16
...
...
@@ -35,45 +35,45 @@ namespace nts { // namespace nts(NiuTrans.Tensor)
*******************************/
/* constructor */
Data
LoaderBase
::
DataLoader
Base
()
Data
DistributeBase
::
DataDistribute
Base
()
{
MUTEX_INIT
(
loadMutex
);
}
/* de-constructor */
Data
LoaderBase
::~
DataLoader
Base
()
Data
DistributeBase
::~
DataDistribute
Base
()
{
MUTEX_DELE
(
loadMutex
);
}
/*
open data file
*/
bool
Data
LoaderBase
::
Open
(
XList
*
args
)
/*
* start the job (e.g., open the file)
*/
bool
Data
DistributeBase
::
Start
(
XList
*
args
)
{
ShowNTErrors
(
"Data
LoaderBase::Open
must be overloaded!"
);
ShowNTErrors
(
"Data
DistributeBase::Start
must be overloaded!"
);
return
true
;
}
/*
close data file
*/
bool
Data
LoaderBase
::
Close
(
XList
*
args
)
/*
end the job (e.g., close the file)
*/
bool
Data
DistributeBase
::
End
(
XList
*
args
)
{
ShowNTErrors
(
"Data
LoaderBase::Close
must be overloaded!"
);
ShowNTErrors
(
"Data
DistributeBase::End
must be overloaded!"
);
return
true
;
}
/*
load
a batch of samples */
bool
Data
LoaderBase
::
Load
Batch
(
XList
*
args
)
/*
get
a batch of samples */
bool
Data
DistributeBase
::
Get
Batch
(
XList
*
args
)
{
ShowNTErrors
(
"Data
LoaderBase::Load
Batch must be overloaded!"
);
ShowNTErrors
(
"Data
DistributeBase::Get
Batch must be overloaded!"
);
return
true
;
}
/*
load
a batch of samples (for multi-threading) */
bool
Data
LoaderBase
::
Load
BatchSafe
(
XList
*
args
)
/*
get
a batch of samples (for multi-threading) */
bool
Data
DistributeBase
::
Get
BatchSafe
(
XList
*
args
)
{
bool
r
;
MUTEX_LOCK
(
loadMutex
);
r
=
Load
Batch
(
args
);
r
=
Get
Batch
(
args
);
MUTEX_UNLOCK
(
loadMutex
);
return
r
;
...
...
source/trainer/XNetTemplate.h
查看文件 @
2736ad16
...
...
@@ -35,8 +35,16 @@
namespace
nts
{
// namespace nts(NiuTrans.Tensor)
/* data loader template */
class
DataLoaderBase
/*
data distributor template. It distribute batches of data to workers.
The use of data distributor follows:
Start() -> GetBatch() -> ... -> GetBatch() -> End()
In addition, GetBatch() should be thread-safe, and thus could be
called by different threads simultaneously.
*/
class
DataDistributeBase
{
protected
:
/* mutex of batch loading */
...
...
@@ -44,26 +52,26 @@ protected:
public
:
/* constructor */
Data
Loader
Base
();
Data
Distribute
Base
();
/* de-constructor */
~
Data
Loader
Base
();
~
Data
Distribute
Base
();
/*
open data file
*/
/*
start the job (e.g., open the file)
*/
virtual
bool
Open
(
XList
*
args
);
bool
Start
(
XList
*
args
);
/*
close data file
*/
/*
end the job (e.g., close the file)
*/
virtual
bool
Close
(
XList
*
args
);
bool
End
(
XList
*
args
);
/*
load
a batch of samples */
/*
get
a batch of samples */
virtual
bool
Load
Batch
(
XList
*
args
);
bool
Get
Batch
(
XList
*
args
);
protected
:
/*
load
a batch of samples (for multi-threading) */
bool
Load
BatchSafe
(
XList
*
args
);
/*
get
a batch of samples (for multi-threading) */
bool
Get
BatchSafe
(
XList
*
args
);
};
/* neural network template */
...
...
source/trainer/XWorkerJob.cpp
查看文件 @
2736ad16
...
...
@@ -57,34 +57,14 @@ bool XWorkerJob::AddJobRefresh(XModel * paramKeeper)
}
/*
add a new job of input generation
>> inputGenerator - the input generator
>> rawData - the data to be processed (input of the generator)
>> inputs - the generated inputs (output of the generator)
<< return - succeeded or not
*/
bool
XWorkerJob
::
AddJobNewInput
(
void
*
inputGenerator
,
XList
*
rawData
,
XList
*
inputs
)
{
CheckNTErrors
(
inputGenerator
!=
NULL
,
"no input generator!"
);
XList
args
;
args
.
AddList
(
rawData
);
args
.
AddList
(
inputs
);
queue
.
EnqueueJob
(
inputGenerator
,
&
args
);
return
true
;
}
/*
add a new job of neural network forward and backward computation (with the input)
>> func - the function that runs the neural network
>> func - the function that calls the run of the neural network
>> net - the neural network
>> inputs - inputs of the neural network
>> outputs - outputs of the neural network
>> net - the neural network
<< return - succeeded or not
*/
bool
XWorkerJob
::
AddJobNeuralNet
(
void
*
func
,
XList
*
inputs
,
XList
*
outputs
,
void
*
net
)
bool
XWorkerJob
::
AddJobNeuralNet
(
void
*
func
,
void
*
net
,
XList
*
inputs
,
XList
*
outputs
)
{
CheckNTErrors
(
func
!=
NULL
,
"no input function!"
);
CheckNTErrors
(
net
!=
NULL
,
"no input neural network!"
);
...
...
source/trainer/XWorkerJob.h
查看文件 @
2736ad16
...
...
@@ -50,11 +50,8 @@ public:
/* add a new job of model refreshment */
bool
AddJobRefresh
(
XModel
*
paramKeeper
);
/* add a new job of input generation */
bool
AddJobNewInput
(
void
*
inputGenerator
,
XList
*
rawData
,
XList
*
inputs
);
/* add a new job of neural network forward and backward computation (with the input) */
bool
AddJobNeuralNet
(
void
*
func
,
XList
*
inputs
,
XList
*
outputs
,
void
*
net
);
bool
AddJobNeuralNet
(
void
*
func
,
void
*
net
,
XList
*
inputs
,
XList
*
outputs
);
};
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论