Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
csdn_franckjun
Paddle
提交
5c530ea8
P
Paddle
项目概览
csdn_franckjun
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5c530ea8
编写于
12月 19, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
export const value to python
上级
6f791260
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
91 addition
and
12 deletion
+91
-12
paddle/pybind/CMakeLists.txt
paddle/pybind/CMakeLists.txt
+1
-1
paddle/pybind/const_value.cc
paddle/pybind/const_value.cc
+29
-0
paddle/pybind/const_value.h
paddle/pybind/const_value.h
+26
-0
paddle/pybind/pybind.cc
paddle/pybind/pybind.cc
+2
-0
python/paddle/v2/fluid/framework.py
python/paddle/v2/fluid/framework.py
+15
-3
python/paddle/v2/fluid/tests/test_batch_norm_op.py
python/paddle/v2/fluid/tests/test_batch_norm_op.py
+1
-0
python/paddle/v2/fluid/tests/test_const_value.py
python/paddle/v2/fluid/tests/test_const_value.py
+11
-0
python/paddle/v2/fluid/tests/test_operator.py
python/paddle/v2/fluid/tests/test_operator.py
+1
-1
python/paddle/v2/fluid/tests/test_program.py
python/paddle/v2/fluid/tests/test_program.py
+3
-5
python/paddle/v2/fluid/tests/test_recurrent_op.py
python/paddle/v2/fluid/tests/test_recurrent_op.py
+2
-2
未找到文件。
paddle/pybind/CMakeLists.txt
浏览文件 @
5c530ea8
if
(
WITH_PYTHON
)
cc_library
(
paddle_pybind SHARED
SRCS pybind.cc exception.cc protobuf.cc
SRCS pybind.cc exception.cc protobuf.cc
const_value.cc
DEPS pybind python backward proto_desc paddle_memory executor prune init
${
GLOB_OP_LIB
}
)
endif
(
WITH_PYTHON
)
...
...
paddle/pybind/const_value.cc
0 → 100644
浏览文件 @
5c530ea8
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
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. */
#include "const_value.h"
#include "paddle/framework/operator.h"
namespace
paddle
{
namespace
pybind
{
void
BindConstValue
(
pybind11
::
module
&
m
)
{
m
.
def
(
"kEmptyVarName"
,
[]
{
return
framework
::
kEmptyVarName
;
});
m
.
def
(
"kTempVarName"
,
[]
{
return
framework
::
kTempVarName
;
});
m
.
def
(
"kGradVarSuffix"
,
[]
{
return
framework
::
kGradVarSuffix
;
});
m
.
def
(
"kZeroVarSuffix"
,
[]
{
return
framework
::
kZeroVarSuffix
;
});
}
}
// namespace pybind
}
// namespace paddle
paddle/pybind/const_value.h
0 → 100644
浏览文件 @
5c530ea8
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
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. */
#pragma once
#include <Python.h>
#include "paddle/platform/enforce.h"
#include "pybind11/pybind11.h"
namespace
py
=
pybind11
;
namespace
paddle
{
namespace
pybind
{
extern
void
BindConstValue
(
pybind11
::
module
&
m
);
}
// namespace pybind
}
// namespace paddle
paddle/pybind/pybind.cc
浏览文件 @
5c530ea8
...
...
@@ -30,6 +30,7 @@ limitations under the License. */
#include "paddle/operators/net_op.h"
#include "paddle/platform/enforce.h"
#include "paddle/platform/place.h"
#include "paddle/pybind/const_value.h"
#include "paddle/pybind/exception.h"
#include "paddle/pybind/pybind.h"
#include "paddle/pybind/tensor_py.h"
...
...
@@ -431,6 +432,7 @@ All parameter, weight, gradient are variables in Paddle.
BindBlockDesc
(
m
);
BindVarDsec
(
m
);
BindOpDesc
(
m
);
BindConstValue
(
m
);
py
::
class_
<
framework
::
LoDRankTable
>
(
m
,
"LodRankTable"
)
.
def
(
"items"
,
[](
framework
::
LoDRankTable
&
table
)
{
...
...
python/paddle/v2/fluid/framework.py
浏览文件 @
5c530ea8
import
collections
import
contextlib
import
numpy
as
np
from
.
import
core
import
proto.framework_pb2
as
framework_pb2
import
google.protobuf.message
import
contextlib
from
.
import
core
__all__
=
[
'Block'
,
'Variable'
,
'Program'
,
'Operator'
,
'default_startup_program'
,
...
...
@@ -12,6 +12,18 @@ __all__ = [
'switch_main_program'
]
EMPTY_VAR_NAME
=
core
.
kEmptyVarName
()
TEMP_VAR_NAME
=
core
.
kTempVarName
()
GRAD_VAR_SUFFIX
=
core
.
kGradVarSuffix
()
ZERO_VAR_SUFFIX
=
core
.
kZeroVarSuffix
()
def
grad_var_name
(
var_name
):
"""
return gradient name for a certain var name
"""
return
var_name
+
GRAD_VAR_SUFFIX
def
unique_name
(
prefix
):
"""
...
...
python/paddle/v2/fluid/tests/test_batch_norm_op.py
浏览文件 @
5c530ea8
...
...
@@ -3,6 +3,7 @@ import numpy as np
from
op_test
import
OpTest
import
paddle.v2.fluid.core
as
core
from
paddle.v2.fluid.op
import
Operator
from
paddle.v2.fluid.framewor
import
grad_var_name
def
grad_var_name
(
var_name
):
...
...
python/paddle/v2/fluid/tests/test_const_value.py
0 → 100644
浏览文件 @
5c530ea8
import
unittest
import
paddle.v2.fluid.framework
as
framework
class
ConditionalBlock
(
unittest
.
TestCase
):
def
test_const_value
(
self
):
self
.
assertEqual
(
framework
.
GRAD_VAR_SUFFIX
,
"@GRAD"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/v2/fluid/tests/test_operator.py
浏览文件 @
5c530ea8
import
unittest
import
paddle.v2.fluid.op
as
op
import
paddle.v2.fluid.core
as
core
import
paddle.v2.fluid.proto.framework_pb2
as
framework_pb2
...
...
python/paddle/v2/fluid/tests/test_program.py
浏览文件 @
5c530ea8
from
__future__
import
print_function
import
unittest
from
paddle.v2.fluid.framework
import
Program
,
default_main_program
,
program_guard
from
paddle.v2.fluid.framework
import
Program
,
default_main_program
,
program_guard
,
grad_var_name
import
paddle.v2.fluid.layers
as
layers
main_program
=
default_main_program
()
...
...
@@ -109,12 +109,10 @@ class TestProgram(unittest.TestCase):
self
.
assertEqual
(
add_op
.
idx
,
1
)
param_to_grad
=
prog
.
append_backward
(
mean_out
,
set
())
def
grad_name
(
name
):
return
name
+
"@GRAD"
for
var_name
in
(
"mul.x"
,
"mul.y"
,
"mul.out"
,
"add.y"
,
"add.out"
,
"mean.out"
):
self
.
assertEqual
(
param_to_grad
[
var_name
][
0
],
grad_name
(
var_name
))
self
.
assertEqual
(
param_to_grad
[
var_name
][
0
],
grad_var_name
(
var_name
))
self
.
assertEqual
(
param_to_grad
[
var_name
][
1
],
0
)
expect_ops
=
[
...
...
python/paddle/v2/fluid/tests/test_recurrent_op.py
浏览文件 @
5c530ea8
import
unittest
import
paddle.v2.fluid.layers
as
layers
from
paddle.v2.fluid.framework
import
Program
from
paddle.v2.fluid.framework
import
Program
,
grad_var_name
from
paddle.v2.fluid.executor
import
Executor
from
paddle.v2.fluid.backward
import
append_backward_ops
import
numpy
as
np
...
...
@@ -164,7 +164,7 @@ class RecurrentOpTest1(unittest.TestCase):
for
x
in
self
.
data_field
}
fetch_list
=
[
self
.
main_program
.
global_block
().
var
(
x
+
"@GRAD"
)
self
.
main_program
.
global_block
().
var
(
grad_var_name
(
x
)
)
for
x
in
self
.
data_field
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录