Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
df371329
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
df371329
编写于
3月 01, 2017
作者:
Q
qingqing01
提交者:
GitHub
3月 01, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1482 from qingqing01/data_convert
Fix dataprovider_converter when using only one GPU
上级
91f13e48
566e5f1f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
29 addition
and
7 deletion
+29
-7
paddle/api/PaddleAPI.h
paddle/api/PaddleAPI.h
+3
-0
paddle/api/Util.cpp
paddle/api/Util.cpp
+2
-0
paddle/py_paddle/dataprovider_converter.py
paddle/py_paddle/dataprovider_converter.py
+19
-6
python/paddle/v2/tests/test_data_feeder.py
python/paddle/v2/tests/test_data_feeder.py
+5
-1
未找到文件。
paddle/api/PaddleAPI.h
浏览文件 @
df371329
...
@@ -47,6 +47,9 @@ void setUseGpu(bool useGpu);
...
@@ -47,6 +47,9 @@ void setUseGpu(bool useGpu);
/// Return true if this py_paddle is compiled in GPU Version
/// Return true if this py_paddle is compiled in GPU Version
bool
isGpuVersion
();
bool
isGpuVersion
();
/// Return FLAGS_trainer_count
int
getTrainerCount
();
/// The Error of IO Operation. Such as file not found, etc.
/// The Error of IO Operation. Such as file not found, etc.
class
IOError
{};
class
IOError
{};
...
...
paddle/api/Util.cpp
浏览文件 @
df371329
...
@@ -54,5 +54,7 @@ bool isGpuVersion() {
...
@@ -54,5 +54,7 @@ bool isGpuVersion() {
#endif
#endif
}
}
int
getTrainerCount
()
{
return
FLAGS_trainer_count
;
}
static_assert
(
NUM_PARAMETER_TYPES
==
paddle
::
NUM_PARAMETER_TYPES
,
static_assert
(
NUM_PARAMETER_TYPES
==
paddle
::
NUM_PARAMETER_TYPES
,
"The Parameter Type should be same in core/api and core/common"
);
"The Parameter Type should be same in core/api and core/common"
);
paddle/py_paddle/dataprovider_converter.py
浏览文件 @
df371329
...
@@ -26,6 +26,15 @@ class IScanner(object):
...
@@ -26,6 +26,15 @@ class IScanner(object):
if
not
isinstance
(
self
.
input_type
,
dp2
.
InputType
):
if
not
isinstance
(
self
.
input_type
,
dp2
.
InputType
):
raise
ValueError
(
"input type should be dataprovider2.InputType"
)
raise
ValueError
(
"input type should be dataprovider2.InputType"
)
self
.
pos
=
pos
self
.
pos
=
pos
# data_in_gpu is used to indicate whether to create argument on GPU
# or not in GPU mode. Now if using one thread (trainer_count=1),
# trainer uses NeuralNetwork which needs to create argument on GPU
# before calling forward function. So, set data_in_gpu to True.
# Otherwise, trainer uses MultiGradientMachine which will transfer
# data from CPU to GPU in the forward function, set data_in_gpu to
# False in this case.
self
.
data_in_gpu
=
swig_paddle
.
isUsingGpu
(
)
and
swig_paddle
.
getTrainerCount
()
==
1
def
scan
(
self
,
dat
):
def
scan
(
self
,
dat
):
pass
pass
...
@@ -53,7 +62,8 @@ class DenseScanner(IScanner):
...
@@ -53,7 +62,8 @@ class DenseScanner(IScanner):
assert
isinstance
(
argument
,
swig_paddle
.
Arguments
)
assert
isinstance
(
argument
,
swig_paddle
.
Arguments
)
if
self
.
__mat__
.
dtype
!=
numpy
.
float32
:
if
self
.
__mat__
.
dtype
!=
numpy
.
float32
:
self
.
__mat__
=
self
.
__mat__
.
astype
(
numpy
.
float32
)
self
.
__mat__
=
self
.
__mat__
.
astype
(
numpy
.
float32
)
m
=
swig_paddle
.
Matrix
.
createDenseFromNumpy
(
self
.
__mat__
,
True
,
False
)
m
=
swig_paddle
.
Matrix
.
createDenseFromNumpy
(
self
.
__mat__
,
True
,
self
.
data_in_gpu
)
argument
.
setSlotValue
(
self
.
pos
,
m
)
argument
.
setSlotValue
(
self
.
pos
,
m
)
...
@@ -75,10 +85,13 @@ class SparseBinaryScanner(IScanner):
...
@@ -75,10 +85,13 @@ class SparseBinaryScanner(IScanner):
def
finish_scan
(
self
,
argument
):
def
finish_scan
(
self
,
argument
):
assert
isinstance
(
argument
,
swig_paddle
.
Arguments
)
assert
isinstance
(
argument
,
swig_paddle
.
Arguments
)
m
=
swig_paddle
.
Matrix
.
createSparse
(
self
.
__height__
,
m
=
swig_paddle
.
Matrix
.
createSparse
(
self
.
input_type
.
dim
,
self
.
__height__
,
len
(
self
.
__cols__
),
self
.
input_type
.
dim
,
len
(
self
.
__value__
)
==
0
)
len
(
self
.
__cols__
),
len
(
self
.
__value__
)
==
0
,
False
,
# trans
False
)
# TODO supoort GPU
assert
isinstance
(
m
,
swig_paddle
.
Matrix
)
assert
isinstance
(
m
,
swig_paddle
.
Matrix
)
m
.
sparseCopyFrom
(
self
.
__rows__
,
self
.
__cols__
,
self
.
__value__
)
m
.
sparseCopyFrom
(
self
.
__rows__
,
self
.
__cols__
,
self
.
__value__
)
argument
.
setSlotValue
(
self
.
pos
,
m
)
argument
.
setSlotValue
(
self
.
pos
,
m
)
...
@@ -102,7 +115,7 @@ class IndexScanner(IScanner):
...
@@ -102,7 +115,7 @@ class IndexScanner(IScanner):
self
.
__ids__
.
append
(
dat
)
self
.
__ids__
.
append
(
dat
)
def
finish_scan
(
self
,
argument
):
def
finish_scan
(
self
,
argument
):
ids
=
swig_paddle
.
IVector
.
create
(
self
.
__ids__
)
ids
=
swig_paddle
.
IVector
.
create
(
self
.
__ids__
,
self
.
data_in_gpu
)
assert
isinstance
(
argument
,
swig_paddle
.
Arguments
)
assert
isinstance
(
argument
,
swig_paddle
.
Arguments
)
argument
.
setSlotIds
(
self
.
pos
,
ids
)
argument
.
setSlotIds
(
self
.
pos
,
ids
)
...
...
python/paddle/v2/tests/test_data_feeder.py
浏览文件 @
df371329
...
@@ -235,4 +235,8 @@ class DataFeederTest(unittest.TestCase):
...
@@ -235,4 +235,8 @@ class DataFeederTest(unittest.TestCase):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
api
.
initPaddle
(
"--use_gpu=0"
)
api
.
initPaddle
(
"--use_gpu=0"
)
unittest
.
main
()
suite
=
unittest
.
TestLoader
().
loadTestsFromTestCase
(
DataFeederTest
)
unittest
.
TextTestRunner
().
run
(
suite
)
if
api
.
isGpuVersion
():
api
.
setUseGpu
(
True
)
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录