Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
349e799e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
349e799e
编写于
3月 03, 2017
作者:
H
helinwang
提交者:
GitHub
3月 03, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1534 from helinwang/arg_sum
Rename Argument::sumCost to Argument::cost since Argument should not …
上级
044ad94a
3219c831
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
13 addition
and
15 deletion
+13
-15
paddle/api/Arguments.cpp
paddle/api/Arguments.cpp
+1
-3
paddle/api/PaddleAPI.h
paddle/api/PaddleAPI.h
+1
-1
paddle/api/test/testArguments.py
paddle/api/test/testArguments.py
+1
-1
paddle/gserver/tests/LayerGradUtil.cpp
paddle/gserver/tests/LayerGradUtil.cpp
+3
-3
paddle/parameter/Argument.h
paddle/parameter/Argument.h
+1
-1
paddle/trainer/Tester.cpp
paddle/trainer/Tester.cpp
+1
-1
paddle/trainer/Trainer.cpp
paddle/trainer/Trainer.cpp
+4
-4
paddle/trainer/TrainerInternal.cpp
paddle/trainer/TrainerInternal.cpp
+1
-1
未找到文件。
paddle/api/Arguments.cpp
浏览文件 @
349e799e
...
...
@@ -144,9 +144,7 @@ void Arguments::setSlotSequenceDim(size_t idx, IVector* vec) throw(RangeError) {
a
.
cpuSequenceDims
=
m
->
cast
<
paddle
::
IVector
>
(
vec
->
getSharedPtr
());
}
float
Arguments
::
sumCosts
()
const
{
return
paddle
::
Argument
::
sumCosts
(
m
->
outputs
);
}
float
Arguments
::
sum
()
const
{
return
paddle
::
Argument
::
sum
(
m
->
outputs
);
}
int64_t
Arguments
::
getBatchSize
(
size_t
idx
)
const
throw
(
RangeError
)
{
auto
&
a
=
m
->
getArg
(
idx
);
...
...
paddle/api/PaddleAPI.h
浏览文件 @
349e799e
...
...
@@ -453,7 +453,7 @@ public:
IVector
*
vec
)
throw
(
RangeError
);
void
setSlotSequenceDim
(
size_t
idx
,
IVector
*
vec
)
throw
(
RangeError
);
float
sum
Costs
()
const
;
float
sum
()
const
;
private:
static
Arguments
*
createByPaddleArgumentVector
(
void
*
ptr
);
...
...
paddle/api/test/testArguments.py
浏览文件 @
349e799e
...
...
@@ -22,7 +22,7 @@ class TestArguments(unittest.TestCase):
args
=
swig_paddle
.
Arguments
.
createArguments
(
1
)
args
.
setSlotValue
(
0
,
m
)
self
.
assertAlmostEqual
(
27.0
,
args
.
sum
Costs
())
self
.
assertAlmostEqual
(
27.0
,
args
.
sum
())
mat
=
args
.
getSlotValue
(
0
)
assert
isinstance
(
mat
,
swig_paddle
.
Matrix
)
...
...
paddle/gserver/tests/LayerGradUtil.cpp
浏览文件 @
349e799e
...
...
@@ -24,7 +24,7 @@ real getCostSum(LayerPtr& testLayer, MatrixPtr weights) {
if
(
weights
)
{
outArgs
[
0
].
value
->
dotMul
(
*
outArgs
[
0
].
value
,
*
weights
);
}
return
Argument
::
sum
Costs
(
outArgs
);
return
Argument
::
sum
(
outArgs
);
}
real
getDiffAndPrint
(
real
newCost1
,
...
...
@@ -241,7 +241,7 @@ void testBatchState(LayerPtr testLayer,
std
::
vector
<
Argument
>
args
;
args
.
push_back
(
out
);
EXPECT_EQ
(
0
,
Argument
::
sum
Costs
(
args
))
<<
"testBatchState failed"
;
EXPECT_EQ
(
0
,
Argument
::
sum
(
args
))
<<
"testBatchState failed"
;
for
(
size_t
seqId
=
0
;
seqId
<
numSequences
;
++
seqId
)
{
start
[
seqId
]
+=
seqLens
[
seqId
];
}
...
...
@@ -672,7 +672,7 @@ void testLayerGradKernel(TestConfig testConf,
outArgs
[
0
].
value
->
dotMul
(
*
testLayer
->
getOutput
().
value
,
*
weights
);
}
real
cost
=
Argument
::
sum
Costs
(
outArgs
);
real
cost
=
Argument
::
sum
(
outArgs
);
LOG
(
INFO
)
<<
" cost "
<<
cost
;
EXPECT_FALSE
(
std
::
isnan
(
cost
));
...
...
paddle/parameter/Argument.h
浏览文件 @
349e799e
...
...
@@ -163,7 +163,7 @@ struct Argument {
:
sequenceStartPositions
->
getData
(
false
);
}
static
inline
real
sum
Costs
(
const
std
::
vector
<
Argument
>&
arguments
)
{
static
inline
real
sum
(
const
std
::
vector
<
Argument
>&
arguments
)
{
real
cost
=
0
;
for
(
auto
&
arg
:
arguments
)
{
if
(
arg
.
value
)
{
...
...
paddle/trainer/Tester.cpp
浏览文件 @
349e799e
...
...
@@ -208,7 +208,7 @@ real Tester::forwardOneBatch(const DataBatch& dataBatch,
return
0.0
;
// In this case, there is no meaning to calculate cost
}
return
Argument
::
sum
Costs
(
outArgs
);
return
Argument
::
sum
(
outArgs
);
}
void
Tester
::
testOnePassBatch
(
int
passId
)
{
...
...
paddle/trainer/Trainer.cpp
浏览文件 @
349e799e
...
...
@@ -310,7 +310,7 @@ real Trainer::checkGradient() {
std
::
vector
<
Argument
>
outArgs
;
trainerInternal_
.
getGradientMachine
()
->
forward
(
inArgs
,
&
outArgs
,
PASS_GC
);
real
cost
=
Argument
::
sum
Costs
(
outArgs
);
real
cost
=
Argument
::
sum
(
outArgs
);
LOG
(
INFO
)
<<
"original cost="
<<
cost
;
trainerInternal_
.
getGradientMachine
()
->
backward
();
...
...
@@ -340,7 +340,7 @@ real Trainer::checkGradient() {
parameter
->
getBuf
(
PARAMETER_VALUE
)
->
copyFrom
(
newPara
);
parameter
->
setValueUpdated
();
trainerInternal_
.
getGradientMachine
()
->
forward
(
inArgs
,
&
outArgs
,
PASS_GC
);
real
newCost1
=
Argument
::
sum
Costs
(
outArgs
);
real
newCost1
=
Argument
::
sum
(
outArgs
);
for
(
size_t
i
=
0
;
i
<
dim
;
++
i
)
{
newp
[
i
]
=
oldp
[
i
]
-
step
*
d
[
i
];
...
...
@@ -349,7 +349,7 @@ real Trainer::checkGradient() {
parameter
->
getBuf
(
PARAMETER_VALUE
)
->
copyFrom
(
newPara
);
parameter
->
setValueUpdated
();
trainerInternal_
.
getGradientMachine
()
->
forward
(
inArgs
,
&
outArgs
,
PASS_GC
);
real
newCost2
=
Argument
::
sum
Costs
(
outArgs
);
real
newCost2
=
Argument
::
sum
(
outArgs
);
real
trueDelta
=
0.5
*
(
newCost1
-
newCost2
);
real
diff
=
(
1e-20
+
trueDelta
)
/
(
1e-20
+
delta
)
-
1
;
...
...
@@ -575,7 +575,7 @@ real Trainer::calcGradient(const DataBatch& dataBatch,
trainerInternal_
.
getGradientMachine
()
->
forwardBackward
(
inArgs
,
&
outArgs
,
PASS_TRAIN
);
real
cost
=
Argument
::
sum
Costs
(
outArgs
);
real
cost
=
Argument
::
sum
(
outArgs
);
offset
=
0
;
for
(
auto
&
para
:
parameters
)
{
...
...
paddle/trainer/TrainerInternal.cpp
浏览文件 @
349e799e
...
...
@@ -134,7 +134,7 @@ void TrainerInternal::trainOneBatch(int64_t batchId,
real
cost
=
0
;
{
REGISTER_TIMER
(
"sumCost"
);
cost
=
Argument
::
sum
Costs
(
*
outArgs
);
cost
=
Argument
::
sum
(
*
outArgs
);
}
if
(
batchId
%
intconfig_
->
log_period
==
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录