Skip to content

Commit d4dabe3

Browse files
author
Yang Yang(Tony)
authored
framework.py enhancement (#8471)
* framework.py enhancement * polish * clean up * enforce the inputs of Operator __init__ of type Variable * python2 assert * reverse assert
1 parent 7a9098a commit d4dabe3

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

python/paddle/v2/fluid/framework.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class Variable(object):
152152
shape(tuple|list|None): The shape of variable. -1 means the batch size.
153153
Some kinds of variable do not contain shape, just set it to None.
154154
dtype(np.dtype|core.VarDesc.VarType|str): The data type of variable.
155-
lod_level(int): The level of lod tensor. 0 means there is not a time
155+
lod_level(int): The level of lod tensor. 0 means it is not a time
156156
series data.
157157
persistable(bool): True if the variable should be saved as check point.
158158
Defaults to False.
@@ -346,7 +346,7 @@ def instance(cls):
346346
def __init__(self):
347347
assert not hasattr(
348348
self.__class__,
349-
'_instance'), 'Please use `instance()` to get OpProtoHolder opject!'
349+
'_instance'), 'Please use `instance()` to get OpProtoHolder object!'
350350
op_protos = get_all_op_protos()
351351
self.op_proto_map = {}
352352
for proto in op_protos:
@@ -368,8 +368,8 @@ def get_op_proto(self, type):
368368

369369
class Operator(object):
370370
"""
371-
Python Operator class. The operator represents the build in instructs in a
372-
Block. Users can use the build in instructs to describe their neural
371+
Python Operator class. The operator represents the build in instructions in a
372+
Block. Users can use the build in instructions to describe their neural
373373
network.
374374
"""
375375

@@ -478,7 +478,7 @@ def find_name(var_list, name):
478478
raise TypeError("'attrs' should be a dict.")
479479
for attr in proto.attrs:
480480
attr_name = attr.name
481-
if (not attr_name in attrs) or (attrs[attr_name] is None):
481+
if (attr_name not in attrs) or (attrs[attr_name] is None):
482482
continue
483483
if isinstance(attrs[attr_name], Block):
484484
self.desc.set_block_attr(attr_name, attrs[attr_name].desc)
@@ -751,7 +751,7 @@ def iter_parameters(self):
751751
if isinstance(item[1], Parameter))
752752

753753
def create_var(self, *args, **kwargs):
754-
var = Variable(self, *args, **kwargs)
754+
var = Variable(block=self, *args, **kwargs)
755755
if 'initializer' in kwargs:
756756
kwargs['initializer'](var, self)
757757
return var
@@ -822,13 +822,13 @@ def create_parameter(self, *args, **kwargs):
822822

823823
def append_op(self, *args, **kwargs):
824824
op_desc = self.desc.append_op()
825-
op = Operator(self, op_desc, *args, **kwargs)
825+
op = Operator(block=self, desc=op_desc, *args, **kwargs)
826826
self.ops.append(op)
827827
return op
828828

829829
def delete_ops(self, ops):
830830
# remove from cpp
831-
# FIXME(typhoonzero): remove only the first occuracy.
831+
# FIXME(typhoonzero): remove only the first occurrence.
832832
try:
833833
start = list(self.ops).index(ops[0])
834834
end = list(self.ops).index(ops[-1])
@@ -846,6 +846,11 @@ def prepend_op(self, *args, **kwargs):
846846
return op
847847

848848
def sync_with_cpp(self):
849+
"""
850+
Sync with the desc on the c++ end.
851+
852+
This method is used to synchronize the c++ desc instance generated by backward.
853+
"""
849854
# sync variables from cpp
850855
for var in self.desc.all_vars():
851856
if not self.has_var(var.name()):
@@ -891,9 +896,9 @@ def sync_with_cpp(self):
891896

892897
def copy_param_info_from(self, other):
893898
"""
894-
Copy the information of parameters from other block
899+
Copy the information of parameters from the other block
895900
Args:
896-
other(Block): other block
901+
other(Block): the other block
897902
898903
Returns:
899904
None
@@ -1239,6 +1244,6 @@ def get_var(name, program=None):
12391244
if program is None:
12401245
program = default_main_program()
12411246
assert isinstance(name, str)
1242-
assert isinstance(name, Program)
1247+
assert isinstance(program, Program)
12431248

12441249
return program.global_block().var(name)

python/paddle/v2/fluid/layers/nn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def fc(input,
104104
* :math:`X_i`: The input tensor.
105105
* :math:`W`: The weights created by this layer.
106106
* :math:`b`: The bias parameter created by this layer (if needed).
107-
* :math:`Act`: The activation funtion.
107+
* :math:`Act`: The activation function.
108108
* :math:`Out`: The output tensor.
109109
110110
Args:

0 commit comments

Comments
 (0)