Created by: chenwhql
PR types
Function optimization
PR changes
APIs
Describe
Enhance add_parameter check for dygraph layer.
the Layer.add_parameter input check is incomplete, some cases may cause error, so this PR enhance check for input.
error example:
class SimpleNet(fluid.dygraph.Layer):
def __init__(self, in_size, out_size):
super(SimpleNet, self).__init__()
self._linear = Linear(in_size, out_size)
new_var = fluid.framework.ParamBase(
shape=[1], # only to pass check, this shape is not meaningful
dtype=fluid.core.VarDesc.VarType.FP32,
name="xx.yy",
persistable=True)
self.add_parameter("xx.yy", new_var)
@declarative
def forward(self, x):
print(self.xx.yy)
y = self._linear(x)
z = self._linear(y)
return z
with fluid.dygraph.guard(fluid.CPUPlace()):
net = SimpleNet(8, 8)
error message:
λ yq01-gpu-255-137-12-00 /work/scripts/save_load {master} python jit_load.py
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
Traceback (most recent call last):
File "jit_load.py", line 30, in <module>
out = net(x)
File "/usr/local/lib/python3.5/dist-packages/paddle/fluid/dygraph/layers.py", line 639, in __call__
outputs = self.forward(*inputs, **kwargs)
File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-104>", line 2, in forward
File "/usr/local/lib/python3.5/dist-packages/paddle/fluid/wrapped_decorator.py", line 25, in __impl__
return wrapped_func(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/paddle/fluid/dygraph/jit.py", line 187, in __impl__
six.exec_("raise new_exception from None")
File "<string>", line 1, in <module>
AttributeError: In user code:
File "jit_load.py", line 19, in forward
print(self.xx.yy)
File "/usr/local/lib/python3.5/dist-packages/paddle/fluid/dygraph/layers.py", line 713, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'SimpleNet' object has no attribute 'xx'