Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
7f794ea5
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看板
提交
7f794ea5
编写于
7月 30, 2018
作者:
M
minqiyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace the overfix of 2to3 with six.string_types
上级
ce4eba3b
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
52 addition
and
39 deletion
+52
-39
python/paddle/fluid/clip.py
python/paddle/fluid/clip.py
+4
-3
python/paddle/fluid/data_feeder.py
python/paddle/fluid/data_feeder.py
+14
-9
python/paddle/fluid/executor.py
python/paddle/fluid/executor.py
+4
-3
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+4
-4
python/paddle/fluid/graphviz.py
python/paddle/fluid/graphviz.py
+2
-1
python/paddle/fluid/io.py
python/paddle/fluid/io.py
+0
-3
python/paddle/fluid/layer_helper.py
python/paddle/fluid/layer_helper.py
+2
-1
python/paddle/fluid/op.py
python/paddle/fluid/op.py
+1
-1
python/paddle/fluid/param_attr.py
python/paddle/fluid/param_attr.py
+3
-1
python/paddle/fluid/tests/unittests/benchmark.py
python/paddle/fluid/tests/unittests/benchmark.py
+3
-1
python/paddle/fluid/tests/unittests/test_parallel_op.py
python/paddle/fluid/tests/unittests/test_parallel_op.py
+11
-10
python/paddle/fluid/unique_name.py
python/paddle/fluid/unique_name.py
+2
-1
python/paddle/reader/creator.py
python/paddle/reader/creator.py
+2
-1
未找到文件。
python/paddle/fluid/clip.py
浏览文件 @
7f794ea5
...
...
@@ -13,6 +13,7 @@
# limitations under the License.
import
copy
import
six
import
functools
from
.
import
layers
...
...
@@ -246,8 +247,8 @@ class GradientClipByGlobalNorm(BaseGradientClipAttr):
"""
def
__init__
(
self
,
clip_norm
,
group_name
=
"default_group"
):
if
not
isinstance
(
group_name
,
s
tr
):
raise
TypeError
(
"'group_name' must be a
basestring."
)
if
not
isinstance
(
group_name
,
s
ix
.
string_types
):
raise
TypeError
(
"'group_name' must be a
%s."
%
(
six
.
string_types
)
)
self
.
clip_norm
=
clip_norm
self
.
group_name
=
group_name
...
...
@@ -312,7 +313,7 @@ def set_gradient_clip(clip, param_list=None, program=None):
program
=
framework
.
default_main_program
()
if
param_list
is
None
:
param_list
=
program
.
block
(
0
).
all_parameters
()
if
all
(
isinstance
(
elem
,
s
tr
)
for
elem
in
param_list
):
if
all
(
isinstance
(
elem
,
s
ix
.
string_types
)
for
elem
in
param_list
):
param_list
=
[
program
.
block
(
0
).
var
(
elem
)
for
elem
in
param_list
]
if
not
all
(
isinstance
(
elem
,
framework
.
Parameter
)
for
elem
in
param_list
):
raise
TypeError
(
...
...
python/paddle/fluid/data_feeder.py
浏览文件 @
7f794ea5
...
...
@@ -15,7 +15,8 @@
from
.
import
core
import
numpy
import
os
import
six.moves
as
six
import
six
from
six.moves
import
zip
,
range
,
xrange
import
multiprocessing
from
.framework
import
Variable
,
default_main_program
...
...
@@ -52,7 +53,7 @@ class DataToLoDTensorConverter(object):
self
.
data
=
[]
self
.
lod
=
[]
for
i
in
six
.
range
(
lod_level
):
for
i
in
six
.
moves
.
range
(
lod_level
):
self
.
lod
.
append
([])
def
feed
(
self
,
data
):
...
...
@@ -141,7 +142,7 @@ class DataFeeder(object):
if
program
is
None
:
program
=
default_main_program
()
for
each_var
in
feed_list
:
if
isinstance
(
each_var
,
s
tr
):
if
isinstance
(
each_var
,
s
ix
.
string_types
):
each_var
=
program
.
block
(
0
).
var
(
each_var
)
if
not
isinstance
(
each_var
,
Variable
):
raise
TypeError
(
"Feed list should contain a list of variable"
)
...
...
@@ -173,7 +174,7 @@ class DataFeeder(object):
dict: the result of conversion.
"""
converter
=
[]
for
lod_level
,
shape
,
dtype
in
six
.
zip
(
for
lod_level
,
shape
,
dtype
in
six
.
moves
.
zip
(
self
.
feed_lod_level
,
self
.
feed_shapes
,
self
.
feed_dtypes
):
converter
.
append
(
DataToLoDTensorConverter
(
...
...
@@ -186,10 +187,12 @@ class DataFeeder(object):
assert
len
(
each_sample
)
==
len
(
converter
),
(
"The number of fields in data (%s) does not match "
+
"len(feed_list) (%s)"
)
%
(
len
(
each_sample
),
len
(
converter
))
for
each_converter
,
each_slot
in
six
.
zip
(
converter
,
each_sample
):
for
each_converter
,
each_slot
in
six
.
moves
.
zip
(
converter
,
each_sample
):
each_converter
.
feed
(
each_slot
)
ret_dict
=
{}
for
each_name
,
each_converter
in
six
.
zip
(
self
.
feed_names
,
converter
):
for
each_name
,
each_converter
in
six
.
moves
.
zip
(
self
.
feed_names
,
converter
):
ret_dict
[
each_name
]
=
each_converter
.
done
()
return
ret_dict
...
...
@@ -211,12 +214,14 @@ class DataFeeder(object):
if
isinstance
(
self
.
place
,
core
.
CUDAPlace
):
places
=
[
core
.
CUDAPlace
(
i
)
for
i
in
six
.
xrange
(
self
.
_get_number_of_places_
(
num_places
))
for
i
in
six
.
moves
.
xrange
(
self
.
_get_number_of_places_
(
num_places
))
]
else
:
places
=
[
core
.
CPUPlace
()
for
_
in
six
.
xrange
(
self
.
_get_number_of_places_
(
num_places
))
for
_
in
six
.
moves
.
xrange
(
self
.
_get_number_of_places_
(
num_places
))
]
if
len
(
iterable
)
!=
len
(
places
):
...
...
@@ -226,7 +231,7 @@ class DataFeeder(object):
"must be same."
)
place
=
self
.
place
for
p
,
batch
in
six
.
zip
(
places
,
iterable
):
for
p
,
batch
in
six
.
moves
.
zip
(
places
,
iterable
):
self
.
place
=
p
yield
self
.
feed
(
batch
)
self
.
place
=
place
...
...
python/paddle/fluid/executor.py
浏览文件 @
7f794ea5
...
...
@@ -14,6 +14,7 @@
import
numpy
as
np
import
contextlib
import
six
from
.framework
import
Program
,
default_main_program
,
Variable
from
.
import
core
...
...
@@ -211,7 +212,7 @@ def _get_program_cache_key(feed, fetch_list):
return
var
.
desc
.
name
()
elif
isinstance
(
var
,
str
):
return
var
elif
isinstance
(
var
,
s
tr
):
elif
isinstance
(
var
,
s
ix
.
string_types
):
return
str
(
var
)
else
:
raise
TypeError
(
str
(
var
)
+
" should be Variable or str"
)
...
...
@@ -229,8 +230,8 @@ class Executor(object):
to feed map and fetch_list. Feed map provides input data for the program. fetch_list provides
the variables(or names) that user want to get after program run. Note: the executor will run all
operators in the program but not only the operators dependent by the fetch_list.
It store the global variables into the global scope, and create a local scope for the temporary
variables. The local scope contents will be discarded after every minibatch forward/backward finished.
It store the global variables into the global scope, and create a local scope for the temporary
variables. The local scope contents will be discarded after every minibatch forward/backward finished.
But the global scope variables will be persistent through different runs.
All of ops in program will be running in sequence.
...
...
python/paddle/fluid/framework.py
浏览文件 @
7f794ea5
...
...
@@ -524,12 +524,12 @@ class Operator(object):
%
(
in_proto
.
name
,
len
(
in_args
)))
in_arg_names
=
[]
for
arg
in
in_args
:
if
is
subclass
(
arg
.
__class__
,
six
.
string_types
):
if
is
instance
(
arg
,
six
.
string_types
):
in_arg_names
.
append
(
arg
)
elif
isinstance
(
arg
,
six
.
binary_type
):
in_arg_names
.
append
(
arg
.
decode
())
else
:
if
is
subclass
(
arg
.
name
.
__class__
,
six
.
string_types
):
if
is
instance
(
arg
.
name
,
six
.
string_types
):
in_arg_names
.
append
(
arg
.
name
)
elif
isinstance
(
arg
.
name
,
six
.
binary_type
):
in_arg_names
.
append
(
arg
.
name
.
decode
())
...
...
@@ -561,7 +561,7 @@ class Operator(object):
(
out_proto
.
name
,
len
(
out_args
)))
out_arg_names
=
[]
for
arg
in
out_args
:
if
is
subclass
(
arg
.
name
.
__class__
,
six
.
string_types
):
if
is
instance
(
arg
.
name
,
six
.
string_types
):
out_arg_names
.
append
(
arg
.
name
)
elif
isinstance
(
arg
.
name
,
six
.
binary_type
):
out_arg_names
.
append
(
arg
.
name
.
decode
())
...
...
@@ -911,7 +911,7 @@ class Block(object):
Returns:
Variable: the Variable with the giving name.
"""
if
not
is
subclass
(
name
.
__class__
,
six
.
string_types
):
if
not
is
instance
(
name
,
six
.
string_types
):
if
not
isinstance
(
name
,
six
.
binary_type
):
raise
TypeError
(
"var require string as parameter, but get %s instead."
%
...
...
python/paddle/fluid/graphviz.py
浏览文件 @
7f794ea5
...
...
@@ -14,12 +14,13 @@
import
os
import
random
import
six
import
subprocess
import
logging
def
crepr
(
v
):
if
type
(
v
)
is
str
or
type
(
v
)
is
str
:
if
isinstance
(
v
,
six
.
string_types
)
:
return
'"%s"'
%
v
return
str
(
v
)
...
...
python/paddle/fluid/io.py
浏览文件 @
7f794ea5
...
...
@@ -612,9 +612,6 @@ def save_inference_model(dirname,
if
not
(
all
(
isinstance
(
name
,
six
.
text_type
)
for
name
in
feeded_var_names
)):
import
sys
print
([
type
(
name
)
for
name
in
feeded_var_names
])
sys
.
stdout
.
flush
()
raise
ValueError
(
"'feed_var_names' should be a list of str."
)
else
:
...
...
python/paddle/fluid/layer_helper.py
浏览文件 @
7f794ea5
...
...
@@ -14,6 +14,7 @@
import
copy
import
itertools
import
six
from
.framework
import
Variable
,
Parameter
,
default_main_program
,
default_startup_program
,
dtype_is_floating
from
.
import
unique_name
...
...
@@ -398,7 +399,7 @@ class LayerHelper(object):
act
=
self
.
kwargs
.
get
(
'act'
,
None
)
if
act
is
None
:
return
input_var
if
isinstance
(
act
,
s
tr
):
if
isinstance
(
act
,
s
ix
.
string_types
):
act
=
{
'type'
:
act
}
if
'use_cudnn'
in
self
.
kwargs
and
self
.
kwargs
.
get
(
'use_cudnn'
):
...
...
python/paddle/fluid/op.py
浏览文件 @
7f794ea5
...
...
@@ -32,7 +32,7 @@ def get_all_op_protos():
def
is_str
(
s
):
return
isinstance
(
s
,
s
tr
)
or
isinstance
(
s
,
str
)
return
isinstance
(
s
,
s
ix
.
string_types
)
class
OpDescCreationMethod
(
object
):
...
...
python/paddle/fluid/param_attr.py
浏览文件 @
7f794ea5
...
...
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
six
from
.initializer
import
Initializer
,
Xavier
,
Constant
from
.regularizer
import
WeightDecayRegularizer
...
...
@@ -134,7 +136,7 @@ class ParamAttr(object):
return
[
ParamAttr
.
_to_attr
(
a
)
for
a
in
arg
]
elif
isinstance
(
arg
,
ParamAttr
):
return
arg
elif
isinstance
(
arg
,
s
tr
)
or
isinstance
(
arg
,
str
):
elif
isinstance
(
arg
,
s
ix
.
string_types
):
return
ParamAttr
(
name
=
arg
)
elif
isinstance
(
arg
,
Initializer
):
return
ParamAttr
(
initializer
=
arg
)
...
...
python/paddle/fluid/tests/unittests/benchmark.py
浏览文件 @
7f794ea5
...
...
@@ -16,6 +16,7 @@ import numpy as np
import
unittest
import
time
import
itertools
import
six
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
...
...
@@ -40,7 +41,8 @@ class BenchmarkSuite(OpTest):
expect_t
=
np
.
array
(
item_cpu_out
)
actual
=
item_gpu_out
actual_t
=
np
.
array
(
item_gpu_out
)
var_name
=
variable
if
isinstance
(
variable
,
str
)
else
variable
.
name
var_name
=
variable
if
isinstance
(
variable
,
six
.
string_types
)
else
variable
.
name
self
.
assertTrue
(
np
.
allclose
(
actual_t
,
expect_t
,
atol
=
atol
),
...
...
python/paddle/fluid/tests/unittests/test_parallel_op.py
浏览文件 @
7f794ea5
...
...
@@ -18,6 +18,7 @@ import paddle.fluid as fluid
from
paddle.fluid.layers.device
import
get_places
import
paddle.fluid.profiler
as
profiler
import
numpy
import
six
class
BaseParallelForTest
(
unittest
.
TestCase
):
...
...
@@ -25,20 +26,20 @@ class BaseParallelForTest(unittest.TestCase):
"""
Run the unittest for parallel.for
Args:
callback(callable): A callable function returns a generator. There
are two yields in the generator function. The first yield
returns the data layers, and the second yield returns the loss.
The modified data variables will be sent back during the first
callback(callable): A callable function returns a generator. There
are two yields in the generator function. The first yield
returns the data layers, and the second yield returns the loss.
The modified data variables will be sent back during the first
yield.
feed(dict): The executor feeding dictionary.
fetch(list|basestr): The fetch name lists.
fetch(list|basestr): The fetch name lists.
Returns:
None
Raises:
AssertionError when the computation of cpu, parallel.for in cpu,
AssertionError when the computation of cpu, parallel.for in cpu,
gpu, parallel.for in gpu are different.
"""
...
...
@@ -95,14 +96,14 @@ class BaseParallelForTest(unittest.TestCase):
"""
Run a single test, returns the fetch values
Args:
place(Place): the computation place.
use_parallel(bool): Whether use parallel.for or not.
place(Place): the computation place.
use_parallel(bool): Whether use parallel.for or not.
Returns:
Fetched numpy arrays.
"""
if
isinstance
(
fetch
,
s
tr
):
if
isinstance
(
fetch
,
s
ix
.
string_types
):
fetch
=
[
fetch
]
main
=
fluid
.
Program
()
startup
=
fluid
.
Program
()
...
...
@@ -156,7 +157,7 @@ class BaseParallelForTest(unittest.TestCase):
Returns:
None
Raises:
AssertionError
...
...
python/paddle/fluid/unique_name.py
浏览文件 @
7f794ea5
...
...
@@ -14,6 +14,7 @@
import
collections
import
contextlib
import
six
import
sys
__all__
=
[
'generate'
,
'switch'
,
'guard'
]
...
...
@@ -67,7 +68,7 @@ def switch(new_generator=None):
@
contextlib
.
contextmanager
def
guard
(
new_generator
=
None
):
if
isinstance
(
new_generator
,
s
tr
):
if
isinstance
(
new_generator
,
s
ix
.
string_types
):
new_generator
=
UniqueNameGenerator
(
new_generator
)
old
=
switch
(
new_generator
)
yield
...
...
python/paddle/reader/creator.py
浏览文件 @
7f794ea5
...
...
@@ -67,10 +67,11 @@ def recordio(paths, buf_size=100):
import
recordio
as
rec
import
paddle.reader.decorator
as
dec
import
six
import
six.moves.cPickle
as
pickle
def
reader
():
if
isinstance
(
paths
,
s
tr
):
if
isinstance
(
paths
,
s
ix
.
string_types
):
path
=
paths
else
:
path
=
","
.
join
(
paths
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录