Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
926e1077
P
Paddle
项目概览
机器未来
/
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看板
提交
926e1077
编写于
8月 24, 2018
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
version
上级
14242eae
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
102 addition
and
3 deletion
+102
-3
paddle/fluid/framework/CMakeLists.txt
paddle/fluid/framework/CMakeLists.txt
+3
-1
paddle/fluid/framework/framework.proto
paddle/fluid/framework/framework.proto
+12
-1
paddle/fluid/framework/program_desc.cc
paddle/fluid/framework/program_desc.cc
+8
-0
paddle/fluid/framework/program_desc.h
paddle/fluid/framework/program_desc.h
+2
-0
paddle/fluid/framework/version.cc
paddle/fluid/framework/version.cc
+28
-0
paddle/fluid/framework/version.h
paddle/fluid/framework/version.h
+30
-0
paddle/fluid/inference/io.cc
paddle/fluid/inference/io.cc
+3
-0
paddle/fluid/pybind/protobuf.cc
paddle/fluid/pybind/protobuf.cc
+4
-1
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+4
-0
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+3
-0
python/paddle/fluid/io.py
python/paddle/fluid/io.py
+5
-0
未找到文件。
paddle/fluid/framework/CMakeLists.txt
浏览文件 @
926e1077
...
...
@@ -116,7 +116,9 @@ cc_library(operator SRCS operator.cc DEPS op_info device_context tensor scope gl
endif
(
NOT WIN32
)
cc_test
(
operator_test SRCS operator_test.cc DEPS operator op_registry device_context
)
cc_library
(
proto_desc SRCS var_desc.cc op_desc.cc block_desc.cc program_desc.cc DEPS shape_inference op_info operator glog
)
cc_library
(
version SRCS version.cc
)
cc_library
(
proto_desc SRCS var_desc.cc op_desc.cc block_desc.cc program_desc.cc DEPS shape_inference op_info operator glog version
)
cc_library
(
op_registry SRCS op_registry.cc DEPS op_proto_maker op_info operator glog proto_desc
)
nv_test
(
op_registry_test SRCS op_registry_test.cc DEPS op_registry
)
...
...
paddle/fluid/framework/framework.proto
浏览文件 @
926e1077
...
...
@@ -16,6 +16,13 @@ syntax = "proto2";
option
optimize_for
=
LITE_RUNTIME
;
package
paddle
.
framework.proto
;
// Any incompatible changes to ProgramDesc and its dependencies should
// raise the version defined version.h.
//
// Serailization and Deserialization codes should be modified in a way
// that supports old versions following the version and compatibility policy.
message
Version
{
optional
int64
version
=
1
[
default
=
-
1
];
}
enum
AttrType
{
INT
=
0
;
FLOAT
=
1
;
...
...
@@ -180,4 +187,8 @@ message BlockDesc {
// for more details.
// TODO(panyx0718): A model can have multiple programs. Need a
// way to distinguish them. Maybe ID or name?
message
ProgramDesc
{
repeated
BlockDesc
blocks
=
1
;
}
message
ProgramDesc
{
repeated
BlockDesc
blocks
=
1
;
optional
Version
version
=
2
;
}
paddle/fluid/framework/program_desc.cc
浏览文件 @
926e1077
...
...
@@ -15,6 +15,7 @@ limitations under the License. */
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/framework/block_desc.h"
#include "paddle/fluid/framework/feed_fetch_type.h"
#include "paddle/fluid/framework/version.h"
namespace
paddle
{
namespace
framework
{
...
...
@@ -31,6 +32,10 @@ void ProgramDesc::Flush() {
for
(
auto
&
block
:
blocks_
)
{
block
->
Flush
();
}
// If not loaded, use current code version.
if
(
desc_
.
version
().
version
()
<
0
)
{
desc_
.
mutable_version
()
->
set_version
(
kCurProgramVersion
);
}
}
proto
::
ProgramDesc
*
ProgramDesc
::
Proto
()
{
...
...
@@ -38,7 +43,10 @@ proto::ProgramDesc *ProgramDesc::Proto() {
return
&
desc_
;
}
int
ProgramDesc
::
Version
()
const
{
return
desc_
.
version
().
version
();
}
ProgramDesc
::
ProgramDesc
()
{
desc_
.
mutable_version
()
->
set_version
(
kCurProgramVersion
);
auto
*
block
=
desc_
.
mutable_blocks
()
->
Add
();
block
->
set_idx
(
kRootBlockIndex
);
block
->
set_parent_idx
(
kNoneBlockIndex
);
...
...
paddle/fluid/framework/program_desc.h
浏览文件 @
926e1077
...
...
@@ -57,6 +57,8 @@ class ProgramDesc {
proto
::
ProgramDesc
*
Proto
();
int
Version
()
const
;
// The output variable of feed_op is referenced as feed_target.
// This function is used to collect the output variable's name of all
// feed_ops.
...
...
paddle/fluid/framework/version.cc
0 → 100644
浏览文件 @
926e1077
/* Copyright (c) 2016 PaddlePaddle Authors. 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. */
#include "paddle/fluid/framework/version.h"
#include <algorithm>
namespace
paddle
{
namespace
framework
{
bool
IsProgramVersionSupported
(
int
version
)
{
static
int
num_supported
=
sizeof
(
kSupportedProgramVersion
)
/
sizeof
(
kSupportedProgramVersion
[
0
]);
return
std
::
find
(
kSupportedProgramVersion
,
kSupportedProgramVersion
+
num_supported
,
version
)
!=
kSupportedProgramVersion
+
num_supported
;
}
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/version.h
0 → 100644
浏览文件 @
926e1077
/* Copyright (c) 2016 PaddlePaddle Authors. 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. */
#pragma once
namespace
paddle
{
namespace
framework
{
// The program version the current codes generate.
constexpr
int
kCurProgramVersion
=
0
;
// The program version that was generated by previous or current codes
// and supported by current codes.
constexpr
int
kSupportedProgramVersion
[]
=
{
0
};
bool
IsProgramVersionSupported
(
int
version
);
}
// namespace framework
}
// namespace paddle
paddle/fluid/inference/io.cc
浏览文件 @
926e1077
...
...
@@ -20,6 +20,7 @@ limitations under the License. */
#include "paddle/fluid/framework/block_desc.h"
#include "paddle/fluid/framework/feed_fetch_type.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/version.h"
#include "paddle/fluid/platform/cpu_helper.h"
#include "paddle/fluid/pybind/pybind.h"
...
...
@@ -124,6 +125,7 @@ std::unique_ptr<framework::ProgramDesc> Load(framework::Executor* executor,
std
::
unique_ptr
<
framework
::
ProgramDesc
>
main_program
(
new
framework
::
ProgramDesc
(
program_desc_str
));
PADDLE_ENFORCE
(
framework
::
IsProgramVersionSupported
(
main_program
->
Version
()));
LoadPersistables
(
executor
,
scope
,
*
main_program
,
dirname
,
""
);
return
main_program
;
...
...
@@ -138,6 +140,7 @@ std::unique_ptr<framework::ProgramDesc> Load(
std
::
unique_ptr
<
framework
::
ProgramDesc
>
main_program
(
new
framework
::
ProgramDesc
(
program_desc_str
));
PADDLE_ENFORCE
(
framework
::
IsProgramVersionSupported
(
main_program
->
Version
()));
LoadPersistables
(
executor
,
scope
,
*
main_program
,
""
,
param_filename
);
return
main_program
;
...
...
paddle/fluid/pybind/protobuf.cc
浏览文件 @
926e1077
...
...
@@ -137,7 +137,10 @@ void BindProgramDesc(pybind11::module *m) {
PADDLE_ENFORCE
(
desc
->
ParseFromString
(
data
),
"Fail to parse ProgramDesc from string. This could "
"be a bug of Paddle."
);
});
})
.
def
(
"_version"
,
[](
pd
::
ProgramDesc
&
self
)
->
int64_t
{
return
self
.
Proto
()
->
version
().
version
();
});
}
void
BindBlockDesc
(
pybind11
::
module
*
m
)
{
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
926e1077
...
...
@@ -517,6 +517,10 @@ All parameter, weight, gradient are variables in Paddle.
m
.
def
(
"init_glog"
,
framework
::
InitGLOG
);
m
.
def
(
"init_devices"
,
[](
bool
init_p2p
)
{
framework
::
InitDevices
(
init_p2p
);
});
m
.
def
(
"_supported_version"
,
[]()
{
std
::
vector
<
int
>
supported_versions
;
return
supported_versions
;
});
m
.
def
(
"is_compiled_with_cuda"
,
IsCompiledWithCUDA
);
m
.
def
(
"is_compiled_with_dist"
,
IsCompiledWithDIST
);
...
...
python/paddle/fluid/framework.py
浏览文件 @
926e1077
...
...
@@ -1564,6 +1564,9 @@ class Program(object):
"""
return
self
.
desc
def
_version
(
self
):
return
self
.
desc
.
_version
()
def
clone
(
self
,
for_test
=
False
):
"""
Create a new, duplicated program.
...
...
python/paddle/fluid/io.py
浏览文件 @
926e1077
...
...
@@ -750,6 +750,11 @@ def load_inference_model(dirname,
program_desc_str
=
f
.
read
()
program
=
Program
.
parse_from_string
(
program_desc_str
)
# TODO(panyx0718): Link to our version and compatibility guide.
if
program
.
_version
()
!=
0
:
raise
ValueError
(
"Unsupported program version: %d
\n
"
%
program
.
_version
())
# Binary data also need versioning.
load_persistables
(
executor
,
dirname
,
program
,
params_filename
)
if
pserver_endpoints
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录