Some issues in the `framework.py`
Created by: JiayiFeng
Last weekend I tried to implement the trainer.test()
in our newest design (#10248 (closed) ). During this, I noticed that a few functions and interfaces of framework.py
are implemented in quite twisty ways. Some of them only make users confused while the others may result in serious bugs. Since framework.py
is the pivot of our Python API, I propose to polish framework.py
first before further development on Python API.
Here are some issues I have noticed in the framework.py
:
-
Variable
andParameter
are using**kwarg
as it's__init__
inputs. With**kwarg
, users are likely to be confused about what is exactly required to create aVariable
andParameter
.
- Some code in the
__init__
ofVariable
is used to handle the situation that the variable to be created has existed. In this part of code, we check each attribute ofVariable
one by one to make sure the existing variable is consistent with the one to be created, which makes the code extremely long. Is there any way to simplify this part?
- The function of
var()
is opposite inBlock
andScope
. If the queried variable not exists, thevar()
ofBlock
will throw an exception while the one ofScope
will create it.
The var()
of Block
:
https://github.com/PaddlePaddle/Paddle/blob/f43b71b242467d665c134262c2b7167cef622757/python/paddle/fluid/framework.py#L717-L723
The var()
of Scope
:
https://github.com/PaddlePaddle/Paddle/blob/f43b71b242467d665c134262c2b7167cef622757/paddle/fluid/framework/scope.cc#L51-L59
- The
clone_variable()
ofBlock
does not clone all attributes of variables correctly.capacity
,error_clip
andstop_gradient
are omitted. And why all clonedVariable
'spersistable
are True?
- In the
Program
'sclone
interface. The newProgram
is created with the old one's C++ desc instead of the Python object itself. However, some information only exists in Python(e.g., error_clip, stop_gradient, ...). It mean aProgram
cannot be cloned entirely with this interface.