Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ae39709e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
提交
ae39709e
编写于
8月 14, 2018
作者:
M
minqiyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish code
上级
55d7f55c
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
141 addition
and
134 deletion
+141
-134
paddle/fluid/framework/op_desc.cc
paddle/fluid/framework/op_desc.cc
+46
-39
paddle/fluid/framework/op_desc.h
paddle/fluid/framework/op_desc.h
+2
-0
python/paddle/dataset/cifar.py
python/paddle/dataset/cifar.py
+2
-3
python/paddle/dataset/common.py
python/paddle/dataset/common.py
+0
-1
python/paddle/dataset/conll05.py
python/paddle/dataset/conll05.py
+2
-2
python/paddle/dataset/movielens.py
python/paddle/dataset/movielens.py
+3
-3
python/paddle/dataset/wmt14.py
python/paddle/dataset/wmt14.py
+1
-1
python/paddle/dataset/wmt16.py
python/paddle/dataset/wmt16.py
+2
-2
python/paddle/fluid/backward.py
python/paddle/fluid/backward.py
+6
-6
python/paddle/fluid/compat.py
python/paddle/fluid/compat.py
+8
-8
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+6
-6
python/paddle/fluid/parallel_executor.py
python/paddle/fluid/parallel_executor.py
+4
-4
python/paddle/fluid/tests/unittests/test_compat.py
python/paddle/fluid/tests/unittests/test_compat.py
+54
-54
python/paddle/fluid/tests/unittests/test_dist_base.py
python/paddle/fluid/tests/unittests/test_dist_base.py
+2
-2
python/paddle/fluid/transpiler/memory_optimization_transpiler.py
...paddle/fluid/transpiler/memory_optimization_transpiler.py
+1
-1
python/paddle/reader/decorator.py
python/paddle/reader/decorator.py
+2
-2
未找到文件。
paddle/fluid/framework/op_desc.cc
浏览文件 @
ae39709e
...
...
@@ -208,49 +208,44 @@ void OpDesc::SetAttr(const std::string &name, const Attribute &v) {
proto
::
AttrType
attr_type
=
static_cast
<
proto
::
AttrType
>
(
v
.
which
()
-
1
);
if
(
attr_type
==
proto
::
AttrType
::
INTS
&&
boost
::
get
<
std
::
vector
<
int
>>
(
v
).
size
()
==
0u
)
{
proto
::
OpProto
proto
=
OpInfoMap
::
Instance
().
Get
(
Type
()).
Proto
();
// Find current attr via attr name and set the correct attribute value
for
(
int
i
=
0
;
i
!=
proto
.
attrs_size
();
++
i
)
{
const
proto
::
OpProto
::
Attr
&
attr
=
proto
.
attrs
(
i
);
if
(
attr
.
name
()
==
name
)
{
switch
(
attr
.
type
())
{
case
proto
::
AttrType
::
BOOLEANS
:
{
VLOG
(
11
)
<<
"SetAttr: "
<<
Type
()
<<
", "
<<
name
<<
" from INTS to BOOLEANS"
;
this
->
attrs_
[
name
]
=
std
::
vector
<
bool
>
();
break
;
}
case
proto
::
AttrType
::
INTS
:
{
VLOG
(
11
)
<<
"SetAttr: "
<<
Type
()
<<
", "
<<
name
<<
" from INTS to INTS"
;
this
->
attrs_
[
name
]
=
std
::
vector
<
int
>
();
break
;
}
case
proto
::
AttrType
::
FLOATS
:
{
VLOG
(
11
)
<<
"SetAttr: "
<<
Type
()
<<
", "
<<
name
<<
" from INTS to FLOATS"
;
this
->
attrs_
[
name
]
=
std
::
vector
<
float
>
();
break
;
}
case
proto
::
AttrType
::
STRINGS
:
{
VLOG
(
11
)
<<
"SetAttr: "
<<
Type
()
<<
", "
<<
name
<<
" from INTS to STRINGS"
;
this
->
attrs_
[
name
]
=
std
::
vector
<
std
::
string
>
();
break
;
}
case
proto
::
AttrType
::
BLOCKS
:
{
VLOG
(
11
)
<<
"SetAttr: "
<<
Type
()
<<
", "
<<
name
<<
" from INTS to BLOCKS"
;
this
->
SetBlocksAttr
(
name
,
std
::
vector
<
BlockDesc
*>
());
return
;
}
default:
PADDLE_THROW
(
"Wrong attr type %d"
,
attr
.
type
());
}
need_update_
=
true
;
const
proto
::
OpProto
::
Attr
&
attr
=
GetProtoAttr
(
name
);
switch
(
attr
.
type
())
{
case
proto
::
AttrType
::
BOOLEANS
:
{
VLOG
(
11
)
<<
"SetAttr: "
<<
Type
()
<<
", "
<<
name
<<
" from INTS to BOOLEANS"
;
this
->
attrs_
[
name
]
=
std
::
vector
<
bool
>
();
break
;
}
case
proto
::
AttrType
::
INTS
:
{
VLOG
(
11
)
<<
"SetAttr: "
<<
Type
()
<<
", "
<<
name
<<
" from INTS to INTS"
;
this
->
attrs_
[
name
]
=
std
::
vector
<
int
>
();
break
;
}
case
proto
::
AttrType
::
FLOATS
:
{
VLOG
(
11
)
<<
"SetAttr: "
<<
Type
()
<<
", "
<<
name
<<
" from INTS to FLOATS"
;
this
->
attrs_
[
name
]
=
std
::
vector
<
float
>
();
break
;
}
case
proto
::
AttrType
::
STRINGS
:
{
VLOG
(
11
)
<<
"SetAttr: "
<<
Type
()
<<
", "
<<
name
<<
" from INTS to STRINGS"
;
this
->
attrs_
[
name
]
=
std
::
vector
<
std
::
string
>
();
break
;
}
case
proto
::
AttrType
::
BLOCKS
:
{
VLOG
(
11
)
<<
"SetAttr: "
<<
Type
()
<<
", "
<<
name
<<
" from INTS to BLOCKS"
;
this
->
SetBlocksAttr
(
name
,
std
::
vector
<
BlockDesc
*>
());
return
;
}
default:
PADDLE_THROW
(
"Wrong attr type %d"
,
attr
.
type
());
}
need_update_
=
true
;
return
;
}
this
->
attrs_
[
name
]
=
v
;
...
...
@@ -280,6 +275,18 @@ Attribute OpDesc::GetAttr(const std::string &name) const {
return
it
->
second
;
}
const
proto
::
OpProto
::
Attr
&
OpDesc
::
GetProtoAttr
(
const
std
::
string
&
name
)
{
proto
::
OpProto
&
proto
=
OpInfoMap
::
Instance
().
Get
(
Type
()).
Proto
();
for
(
int
i
=
0
;
i
!=
proto
.
attrs_size
();
++
i
)
{
const
proto
::
OpProto
::
Attr
&
attr
=
proto
.
attrs
(
i
);
if
(
attr
.
name
()
==
name
)
{
return
attr
;
}
}
PADDLE_THROW
(
"Attribute %s is not found in proto %s"
,
name
,
proto
.
type
());
}
Attribute
OpDesc
::
GetNullableAttr
(
const
std
::
string
&
name
)
const
{
auto
it
=
attrs_
.
find
(
name
);
if
(
it
!=
attrs_
.
end
())
{
...
...
paddle/fluid/framework/op_desc.h
浏览文件 @
ae39709e
...
...
@@ -81,6 +81,8 @@ class OpDesc {
Attribute
GetAttr
(
const
std
::
string
&
name
)
const
;
const
proto
::
OpProto
::
Attr
&
GetProtoAttr
(
const
std
::
string
&
name
)
const
;
Attribute
GetNullableAttr
(
const
std
::
string
&
name
)
const
;
int
GetBlockAttr
(
const
std
::
string
&
name
)
const
;
...
...
python/paddle/dataset/cifar.py
浏览文件 @
ae39709e
...
...
@@ -55,9 +55,8 @@ def reader_creator(filename, sub_name, cycle=False):
def
reader
():
with
tarfile
.
open
(
filename
,
mode
=
'r'
)
as
f
:
names
=
[
each_item
.
name
for
each_item
in
f
if
sub_name
in
each_item
.
name
]
names
=
(
each_item
.
name
for
each_item
in
f
if
sub_name
in
each_item
.
name
)
while
True
:
for
name
in
names
:
...
...
python/paddle/dataset/common.py
浏览文件 @
ae39709e
...
...
@@ -20,7 +20,6 @@ import shutil
import
sys
import
importlib
import
paddle.dataset
import
paddle.fluid.compat
as
cpt
import
six.moves.cPickle
as
pickle
import
glob
...
...
python/paddle/dataset/conll05.py
浏览文件 @
ae39709e
...
...
@@ -90,8 +90,8 @@ def corpus_reader(data_path, words_name, props_name):
labels
=
[]
one_seg
=
[]
for
word
,
label
in
zip
(
words_file
,
props_file
):
word
=
cpt
.
to_
literal_str
(
word
.
strip
())
label
=
cpt
.
to_
literal_str
(
label
.
strip
().
split
())
word
=
cpt
.
to_
text
(
word
.
strip
())
label
=
cpt
.
to_
text
(
label
.
strip
().
split
())
if
len
(
label
)
==
0
:
# end of sentence
for
i
in
range
(
len
(
one_seg
[
0
])):
...
...
python/paddle/dataset/movielens.py
浏览文件 @
ae39709e
...
...
@@ -114,7 +114,7 @@ def __initialize_meta_info__():
categories_set
=
set
()
with
package
.
open
(
'ml-1m/movies.dat'
)
as
movie_file
:
for
i
,
line
in
enumerate
(
movie_file
):
line
=
cpt
.
to_
literal_str
(
line
,
encoding
=
'latin'
)
line
=
cpt
.
to_
text
(
line
,
encoding
=
'latin'
)
movie_id
,
title
,
categories
=
line
.
strip
().
split
(
'::'
)
categories
=
categories
.
split
(
'|'
)
for
c
in
categories
:
...
...
@@ -139,7 +139,7 @@ def __initialize_meta_info__():
USER_INFO
=
dict
()
with
package
.
open
(
'ml-1m/users.dat'
)
as
user_file
:
for
line
in
user_file
:
line
=
cpt
.
to_
literal_str
(
line
,
encoding
=
'latin'
)
line
=
cpt
.
to_
text
(
line
,
encoding
=
'latin'
)
uid
,
gender
,
age
,
job
,
_
=
line
.
strip
().
split
(
"::"
)
USER_INFO
[
int
(
uid
)]
=
UserInfo
(
index
=
uid
,
gender
=
gender
,
age
=
age
,
job_id
=
job
)
...
...
@@ -152,7 +152,7 @@ def __reader__(rand_seed=0, test_ratio=0.1, is_test=False):
with
zipfile
.
ZipFile
(
file
=
fn
)
as
package
:
with
package
.
open
(
'ml-1m/ratings.dat'
)
as
rating
:
for
line
in
rating
:
line
=
cpt
.
to_
literal_str
(
line
,
encoding
=
'latin'
)
line
=
cpt
.
to_
text
(
line
,
encoding
=
'latin'
)
if
(
rand
.
random
()
<
test_ratio
)
==
is_test
:
uid
,
mov_id
,
rating
,
_
=
line
.
strip
().
split
(
"::"
)
uid
=
int
(
uid
)
...
...
python/paddle/dataset/wmt14.py
浏览文件 @
ae39709e
...
...
@@ -55,7 +55,7 @@ def __read_to_dict(tar_file, dict_size):
out_dict
=
dict
()
for
line_count
,
line
in
enumerate
(
fd
):
if
line_count
<
size
:
out_dict
[
cpt
.
to_
literal_str
(
line
.
strip
())]
=
line_count
out_dict
[
cpt
.
to_
text
(
line
.
strip
())]
=
line_count
else
:
break
return
out_dict
...
...
python/paddle/dataset/wmt16.py
浏览文件 @
ae39709e
...
...
@@ -89,9 +89,9 @@ def __load_dict(tar_file, dict_size, lang, reverse=False):
with
open
(
dict_path
,
"rb"
)
as
fdict
:
for
idx
,
line
in
enumerate
(
fdict
):
if
reverse
:
word_dict
[
idx
]
=
cpt
.
to_
literal_str
(
line
.
strip
())
word_dict
[
idx
]
=
cpt
.
to_
text
(
line
.
strip
())
else
:
word_dict
[
cpt
.
to_
literal_str
(
line
.
strip
())]
=
idx
word_dict
[
cpt
.
to_
text
(
line
.
strip
())]
=
idx
return
word_dict
...
...
python/paddle/fluid/backward.py
浏览文件 @
ae39709e
...
...
@@ -103,8 +103,8 @@ def _some_in_set_(cands, s):
"""
if
len
(
cands
)
==
0
:
return
False
literal_set
=
cpt
.
to_
literal_str
(
s
)
literal_cands
=
cpt
.
to_
literal_str
(
cands
)
literal_set
=
cpt
.
to_
text
(
s
)
literal_cands
=
cpt
.
to_
text
(
cands
)
for
c
in
literal_cands
:
if
c
in
literal_set
:
return
True
...
...
@@ -117,7 +117,7 @@ def _strip_grad_suffix_(name):
e.g. x@GRAD ==> x
y@GRAD@RENAME@1 ==> y
"""
name
=
cpt
.
to_
literal_str
(
name
)
name
=
cpt
.
to_
text
(
name
)
pos
=
name
.
find
(
core
.
grad_var_suffix
())
return
name
[:
pos
]
if
pos
!=
-
1
else
name
...
...
@@ -127,7 +127,7 @@ def _append_grad_suffix_(name):
Append grad suffix to the given variable name
e.g. x ==> x@GRAD
"""
return
cpt
.
to_
literal_str
(
name
)
+
core
.
grad_var_suffix
()
return
cpt
.
to_
text
(
name
)
+
core
.
grad_var_suffix
()
def
_addup_repetitive_outputs_
(
op_descs
):
...
...
@@ -365,7 +365,7 @@ def _append_backward_ops_(block,
# Getting op's corresponding grad_op
grad_op_desc
,
op_grad_to_var
=
core
.
get_grad_op_desc
(
op
.
desc
,
cpt
.
to_
literal_str
(
no_grad_dict
[
block
.
idx
]),
grad_sub_block_list
)
cpt
.
to_
text
(
no_grad_dict
[
block
.
idx
]),
grad_sub_block_list
)
grad_op_descs
.
extend
(
grad_op_desc
)
grad_to_var
.
update
(
op_grad_to_var
)
...
...
@@ -600,7 +600,7 @@ def append_backward(loss, parameter_list=None, no_grad_set=None,
params_and_grads
=
[]
for
param
in
parameters
:
if
cpt
.
to_
literal_str
(
param
)
not
in
grad_info_map
:
if
cpt
.
to_
text
(
param
)
not
in
grad_info_map
:
continue
grad_info
=
grad_info_map
[
param
]
grad_block
=
grad_info
[
1
]
...
...
python/paddle/fluid/compat.py
浏览文件 @
ae39709e
...
...
@@ -17,7 +17,7 @@ import math
__all__
=
[
'long_type'
,
'to_
literal_str
'
,
'to_
text
'
,
'to_bytes'
,
'round'
,
'floor_division'
,
...
...
@@ -33,7 +33,7 @@ else:
# str and bytes related functions
def
to_
literal_str
(
obj
,
encoding
=
'utf-8'
,
inplace
=
False
):
def
to_
text
(
obj
,
encoding
=
'utf-8'
,
inplace
=
False
):
"""
All string in PaddlePaddle should be represented as a literal string.
This function will convert object to a literal string without any encoding.
...
...
@@ -60,23 +60,23 @@ def to_literal_str(obj, encoding='utf-8', inplace=False):
if
isinstance
(
obj
,
list
):
if
inplace
:
for
i
in
six
.
moves
.
xrange
(
len
(
obj
)):
obj
[
i
]
=
_to_
literal_str
(
obj
[
i
],
encoding
)
obj
[
i
]
=
_to_
text
(
obj
[
i
],
encoding
)
return
obj
else
:
return
[
_to_
literal_str
(
item
,
encoding
)
for
item
in
obj
]
return
[
_to_
text
(
item
,
encoding
)
for
item
in
obj
]
elif
isinstance
(
obj
,
set
):
if
inplace
:
for
item
in
obj
:
obj
.
remove
(
item
)
obj
.
add
(
_to_
literal_str
(
item
,
encoding
))
obj
.
add
(
_to_
text
(
item
,
encoding
))
return
obj
else
:
return
set
([
_to_
literal_str
(
item
,
encoding
)
for
item
in
obj
])
return
set
([
_to_
text
(
item
,
encoding
)
for
item
in
obj
])
else
:
return
_to_
literal_str
(
obj
,
encoding
)
return
_to_
text
(
obj
,
encoding
)
def
_to_
literal_str
(
obj
,
encoding
):
def
_to_
text
(
obj
,
encoding
):
"""
In Python3:
Decode the bytes type object to str type with specific encoding
...
...
python/paddle/fluid/framework.py
浏览文件 @
ae39709e
...
...
@@ -199,7 +199,7 @@ class Variable(object):
if
name
is
None
:
name
=
unique_name
.
generate
(
'_generated_var'
)
is_new_var
=
False
name
=
cpt
.
to_
literal_str
(
name
)
name
=
cpt
.
to_
text
(
name
)
self
.
desc
=
self
.
block
.
desc
.
find_var
(
cpt
.
to_bytes
(
name
))
if
self
.
desc
is
None
:
...
...
@@ -326,7 +326,7 @@ class Variable(object):
@
property
def
name
(
self
):
return
cpt
.
to_
literal_str
(
self
.
desc
.
name
())
return
cpt
.
to_
text
(
self
.
desc
.
name
())
@
name
.
setter
def
name
(
self
,
new_name
):
...
...
@@ -530,7 +530,7 @@ class Operator(object):
elif
isinstance
(
arg
,
six
.
binary_type
):
in_arg_names
.
append
(
arg
.
decode
())
else
:
in_arg_names
.
append
(
cpt
.
to_
literal_str
(
arg
.
name
))
in_arg_names
.
append
(
cpt
.
to_
text
(
arg
.
name
))
self
.
desc
.
set_input
(
in_proto
.
name
,
in_arg_names
)
else
:
self
.
desc
.
set_input
(
in_proto
.
name
,
[])
...
...
@@ -559,7 +559,7 @@ class Operator(object):
(
out_proto
.
name
,
len
(
out_args
)))
out_arg_names
=
[]
for
arg
in
out_args
:
out_arg_names
.
append
(
cpt
.
to_
literal_str
(
arg
.
name
))
out_arg_names
.
append
(
cpt
.
to_
text
(
arg
.
name
))
arg
.
op
=
self
self
.
desc
.
set_output
(
out_proto
.
name
,
out_arg_names
)
...
...
@@ -986,8 +986,8 @@ class Block(object):
Returns:
Variable: the Variable with the giving name.
"""
name
=
cpt
.
to_
literal_str
(
name
)
new_name
=
cpt
.
to_
literal_str
(
new_name
)
name
=
cpt
.
to_
text
(
name
)
new_name
=
cpt
.
to_
text
(
new_name
)
if
not
self
.
has_var
(
name
):
raise
ValueError
(
"var %s is not in current block"
%
name
)
...
...
python/paddle/fluid/parallel_executor.py
浏览文件 @
ae39709e
...
...
@@ -155,13 +155,13 @@ class ParallelExecutor(object):
self
.
executor
=
core
.
ParallelExecutor
(
self
.
_places
,
set
([
cpt
.
to_
literal_str
(
p
.
name
)
cpt
.
to_
text
(
p
.
name
)
for
p
in
main
.
global_block
().
iter_parameters
()
if
not
p
.
stop_gradient
]),
set
(
cpt
.
to_
literal_str
(
var
)
set
(
cpt
.
to_
text
(
var
)
for
var
in
self
.
persistable_vars
),
main
.
desc
,
cpt
.
to_
literal_str
(
loss_name
)
cpt
.
to_
text
(
loss_name
)
if
loss_name
else
six
.
u
(
''
),
scope
,
local_scopes
,
exec_strategy
,
build_strategy
,
num_trainers
,
trainer_id
)
self
.
scope
=
scope
...
...
@@ -275,7 +275,7 @@ class ParallelExecutor(object):
fetch_var_name
=
'@FETCHED_VAR_NAME@'
self
.
executor
.
run
(
cpt
.
to_
literal_str
(
fetch_list
),
cpt
.
to_literal_str
(
fetch_var_name
))
cpt
.
to_
text
(
fetch_list
),
cpt
.
to_text
(
fetch_var_name
))
arr
=
self
.
scope
.
find_var
(
fetch_var_name
).
get_lod_tensor_array
()
if
self
.
is_dist
:
...
...
python/paddle/fluid/tests/unittests/test_compat.py
浏览文件 @
ae39709e
...
...
@@ -26,44 +26,44 @@ class TestCompatible(unittest.TestCase):
self
.
assertEqual
(
cpt
.
int_type
,
int
)
self
.
assertEqual
(
cpt
.
long_type
,
int
)
def
test_to_
literal_str
(
self
):
def
test_to_
text
(
self
):
# Only support python2.x and python3.x now
self
.
assertTrue
(
six
.
PY2
|
six
.
PY3
)
if
six
.
PY2
:
# check None
self
.
assertIsNone
(
cpt
.
to_
literal_str
(
None
))
self
.
assertIsNone
(
cpt
.
to_
text
(
None
))
# check all string related types
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
str
(
""
)),
unicode
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
str
(
"123"
)),
unicode
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
b
""
),
unicode
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
b
""
),
unicode
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
u
""
),
unicode
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
u
""
),
unicode
))
self
.
assertEqual
(
u
""
,
cpt
.
to_
literal_str
(
str
(
""
)))
self
.
assertEqual
(
u
"123"
,
cpt
.
to_
literal_str
(
str
(
"123"
)))
self
.
assertEqual
(
u
""
,
cpt
.
to_
literal_str
(
b
""
))
self
.
assertEqual
(
u
"123"
,
cpt
.
to_
literal_str
(
b
"123"
))
self
.
assertEqual
(
u
""
,
cpt
.
to_
literal_str
(
u
""
))
self
.
assertEqual
(
u
"123"
,
cpt
.
to_
literal_str
(
u
"123"
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
str
(
""
)),
unicode
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
str
(
"123"
)),
unicode
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
b
""
),
unicode
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
b
""
),
unicode
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
u
""
),
unicode
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
u
""
),
unicode
))
self
.
assertEqual
(
u
""
,
cpt
.
to_
text
(
str
(
""
)))
self
.
assertEqual
(
u
"123"
,
cpt
.
to_
text
(
str
(
"123"
)))
self
.
assertEqual
(
u
""
,
cpt
.
to_
text
(
b
""
))
self
.
assertEqual
(
u
"123"
,
cpt
.
to_
text
(
b
"123"
))
self
.
assertEqual
(
u
""
,
cpt
.
to_
text
(
u
""
))
self
.
assertEqual
(
u
"123"
,
cpt
.
to_
text
(
u
"123"
))
# check list types, not inplace
l
=
[
""
]
l2
=
cpt
.
to_
literal_str
(
l
)
l2
=
cpt
.
to_
text
(
l
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
([
u
""
],
l2
)
l
=
[
""
,
"123"
]
l2
=
cpt
.
to_
literal_str
(
l
)
l2
=
cpt
.
to_
text
(
l
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
([
u
""
,
u
"123"
],
l2
)
l
=
[
""
,
b
'123'
,
u
"321"
]
l2
=
cpt
.
to_
literal_str
(
l
)
l2
=
cpt
.
to_
text
(
l
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
...
...
@@ -73,19 +73,19 @@ class TestCompatible(unittest.TestCase):
# check list types, inplace
l
=
[
""
]
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
([
u
""
],
l2
)
l
=
[
""
,
"123"
]
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
([
u
""
,
u
"123"
],
l2
)
l
=
[
""
,
b
"123"
,
u
"321"
]
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
...
...
@@ -93,19 +93,19 @@ class TestCompatible(unittest.TestCase):
# check set types, not inplace
l
=
set
(
""
)
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
False
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
False
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
(
set
(
u
""
),
l2
)
l
=
set
([
b
""
,
b
"123"
])
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
False
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
False
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
(
set
([
u
""
,
u
"123"
]),
l2
)
l
=
set
([
""
,
b
"123"
,
u
"321"
])
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
False
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
False
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
...
...
@@ -115,56 +115,56 @@ class TestCompatible(unittest.TestCase):
# check set types, inplace
l
=
set
(
""
)
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
(
set
(
u
""
),
l2
)
l
=
set
([
b
""
,
b
"123"
])
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
(
set
([
u
""
,
u
"123"
]),
l2
)
l
=
set
([
""
,
b
"123"
,
u
"321"
])
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
(
set
([
u
""
,
u
"123"
,
u
"321"
]),
l2
)
elif
six
.
PY3
:
self
.
assertIsNone
(
cpt
.
to_
literal_str
(
None
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
str
(
""
)),
str
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
str
(
"123"
)),
str
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
b
""
),
str
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
b
""
),
str
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
u
""
),
str
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
literal_str
(
u
""
),
str
))
self
.
assertEqual
(
""
,
cpt
.
to_
literal_str
(
str
(
""
)))
self
.
assertEqual
(
"123"
,
cpt
.
to_
literal_str
(
str
(
"123"
)))
self
.
assertEqual
(
""
,
cpt
.
to_
literal_str
(
b
""
))
self
.
assertEqual
(
"123"
,
cpt
.
to_
literal_str
(
b
"123"
))
self
.
assertEqual
(
""
,
cpt
.
to_
literal_str
(
u
""
))
self
.
assertEqual
(
"123"
,
cpt
.
to_
literal_str
(
u
"123"
))
self
.
assertIsNone
(
cpt
.
to_
text
(
None
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
str
(
""
)),
str
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
str
(
"123"
)),
str
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
b
""
),
str
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
b
""
),
str
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
u
""
),
str
))
self
.
assertTrue
(
isinstance
(
cpt
.
to_
text
(
u
""
),
str
))
self
.
assertEqual
(
""
,
cpt
.
to_
text
(
str
(
""
)))
self
.
assertEqual
(
"123"
,
cpt
.
to_
text
(
str
(
"123"
)))
self
.
assertEqual
(
""
,
cpt
.
to_
text
(
b
""
))
self
.
assertEqual
(
"123"
,
cpt
.
to_
text
(
b
"123"
))
self
.
assertEqual
(
""
,
cpt
.
to_
text
(
u
""
))
self
.
assertEqual
(
"123"
,
cpt
.
to_
text
(
u
"123"
))
# check list types, not inplace
l
=
[
""
]
l2
=
cpt
.
to_
literal_str
(
l
)
l2
=
cpt
.
to_
text
(
l
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
([
""
],
l2
)
l
=
[
""
,
"123"
]
l2
=
cpt
.
to_
literal_str
(
l
)
l2
=
cpt
.
to_
text
(
l
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
([
""
,
"123"
],
l2
)
l
=
[
""
,
b
"123"
,
u
"321"
]
l2
=
cpt
.
to_
literal_str
(
l
)
l2
=
cpt
.
to_
text
(
l
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertNotEqual
(
l
,
l2
)
...
...
@@ -172,19 +172,19 @@ class TestCompatible(unittest.TestCase):
# check list types, inplace
l
=
[
""
]
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
([
""
],
l2
)
l
=
[
""
,
b
"123"
]
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
([
""
,
"123"
],
l2
)
l
=
[
""
,
b
"123"
,
u
"321"
]
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
list
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
...
...
@@ -194,19 +194,19 @@ class TestCompatible(unittest.TestCase):
# check set types, not inplace
l
=
set
(
""
)
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
False
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
False
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
(
set
(
""
),
l2
)
l
=
set
([
b
""
,
b
"123"
])
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
False
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
False
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertNotEqual
(
l
,
l2
)
self
.
assertEqual
(
set
([
""
,
"123"
]),
l2
)
l
=
set
([
""
,
b
"123"
,
u
"321"
])
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
False
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
False
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertFalse
(
l
is
l2
)
self
.
assertNotEqual
(
l
,
l2
)
...
...
@@ -214,19 +214,19 @@ class TestCompatible(unittest.TestCase):
# check set types, inplace
l
=
set
(
""
)
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
(
set
(
""
),
l2
)
l
=
set
([
b
""
,
b
"123"
])
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
self
.
assertEqual
(
set
([
""
,
"123"
]),
l2
)
l
=
set
([
""
,
b
"123"
,
u
"321"
])
l2
=
cpt
.
to_
literal_str
(
l
,
inplace
=
True
)
l2
=
cpt
.
to_
text
(
l
,
inplace
=
True
)
self
.
assertTrue
(
isinstance
(
l2
,
set
))
self
.
assertTrue
(
l
is
l2
)
self
.
assertEqual
(
l
,
l2
)
...
...
python/paddle/fluid/tests/unittests/test_dist_base.py
浏览文件 @
ae39709e
...
...
@@ -186,7 +186,7 @@ class TestDistBase(unittest.TestCase):
env
=
env_local
)
local_proc
.
wait
()
out
,
err
=
local_proc
.
communicate
()
local_ret
=
cpt
.
to_
literal_str
(
out
)
local_ret
=
cpt
.
to_
text
(
out
)
sys
.
stderr
.
write
(
'local_loss: %s
\n
'
%
local_ret
)
sys
.
stderr
.
write
(
'local_stderr: %s
\n
'
%
err
)
...
...
@@ -224,7 +224,7 @@ class TestDistBase(unittest.TestCase):
tr1_proc
.
wait
()
out
,
err
=
tr0_proc
.
communicate
()
sys
.
stderr
.
write
(
'dist_stderr: %s
\n
'
%
err
)
loss_data0
=
cpt
.
to_
literal_str
(
out
)
loss_data0
=
cpt
.
to_
text
(
out
)
sys
.
stderr
.
write
(
'dist_loss: %s
\n
'
%
loss_data0
)
lines
=
loss_data0
.
split
(
"
\n
"
)
dist_first_loss
=
eval
(
lines
[
0
].
replace
(
" "
,
","
))[
0
]
...
...
python/paddle/fluid/transpiler/memory_optimization_transpiler.py
浏览文件 @
ae39709e
...
...
@@ -260,7 +260,7 @@ class ControlFlowGraph(object):
# memory allocated in order to reuse the memory.
_rename_arg_
(
self
.
_ops
,
x
,
cache_var
,
begin_idx
=
i
)
self
.
_program
.
block
(
block_desc
.
id
).
var
(
cpt
.
to_
literal_str
(
x
)).
desc
=
self
.
_find_var
(
cpt
.
to_
text
(
x
)).
desc
=
self
.
_find_var
(
block_desc
,
cache_var
,
is_forward
)
self
.
_update_graph
(
x
,
cache_var
,
begin_idx
=
i
)
break
...
...
python/paddle/reader/decorator.py
浏览文件 @
ae39709e
...
...
@@ -391,9 +391,9 @@ class PipeReader:
buff
=
self
.
process
.
stdout
.
read
(
self
.
bufsize
)
if
buff
:
if
self
.
file_type
==
"gzip"
:
decomp_buff
=
cpt
.
to_
literal_str
(
self
.
dec
.
decompress
(
buff
))
decomp_buff
=
cpt
.
to_
text
(
self
.
dec
.
decompress
(
buff
))
elif
self
.
file_type
==
"plain"
:
decomp_buff
=
cpt
.
to_
literal_str
(
buff
)
decomp_buff
=
cpt
.
to_
text
(
buff
)
else
:
raise
TypeError
(
"file_type %s is not allowed"
%
self
.
file_type
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录