Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8627ef33
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看板
提交
8627ef33
编写于
8月 01, 2018
作者:
C
chenweihang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: simplify unittest function
上级
964d631c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
8 addition
and
19 deletion
+8
-19
python/paddle/fluid/tests/unittests/test_memory_usage.py
python/paddle/fluid/tests/unittests/test_memory_usage.py
+8
-19
未找到文件。
python/paddle/fluid/tests/unittests/test_memory_usage.py
浏览文件 @
8627ef33
...
...
@@ -19,7 +19,7 @@ import contextlib
import
unittest
def
train_simulator
(
use_cuda
,
test_batch_size
=
10
):
def
train_simulator
(
test_batch_size
=
10
):
if
test_batch_size
<=
0
:
raise
ValueError
(
"batch_size should be a positive integeral value, "
"but got batch_size={}"
.
format
(
test_batch_size
))
...
...
@@ -34,14 +34,7 @@ def train_simulator(use_cuda, test_batch_size=10):
sgd_optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
0.001
)
sgd_optimizer
.
minimize
(
avg_cost
)
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
uci_housing
.
train
(),
buf_size
=
500
),
batch_size
=
test_batch_size
)
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
# Calculate memory usage in current network config
lower_usage
,
upper_usage
,
unit
=
fluid
.
contrib
.
memory_usage
(
fluid
.
default_main_program
(),
batch_size
=
test_batch_size
)
...
...
@@ -50,21 +43,17 @@ def train_simulator(use_cuda, test_batch_size=10):
class
TestMemoryUsage
(
unittest
.
TestCase
):
def
test_cpu
(
self
):
with
self
.
program_scope_guard
():
train_simulator
(
use_cuda
=
False
)
def
test_cpu_with_unit_KB
(
self
):
def
test_with_unit_B
(
self
):
with
self
.
program_scope_guard
():
train_simulator
(
use_cuda
=
False
,
test_batch_size
=
1000
)
train_simulator
()
def
test_
cpu_with_unit_M
B
(
self
):
def
test_
with_unit_K
B
(
self
):
with
self
.
program_scope_guard
():
train_simulator
(
use_cuda
=
False
,
test_batch_size
=
100
000
)
train_simulator
(
test_batch_size
=
1
000
)
def
test_
cuda
(
self
):
def
test_
with_unit_MB
(
self
):
with
self
.
program_scope_guard
():
train_simulator
(
use_cuda
=
True
)
train_simulator
(
test_batch_size
=
100000
)
@
contextlib
.
contextmanager
def
program_scope_guard
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录