提交 2236d24c 编写于 作者: T Travis CI

Deploy to GitHub Pages: 5daf0575

上级 45900ae0
...@@ -15,9 +15,9 @@ Please be aware that these Python classes need to maintain some construction-tim ...@@ -15,9 +15,9 @@ Please be aware that these Python classes need to maintain some construction-tim
### Program ### Program
A `ProgramDesc` describes a [DL program](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md), which is composed of an array of `BlockDesc`s. A `BlockDesc` refers to its parent block by its index in the array. For example, operators in the step block of an RNN operator needs to be able to access variables in its ancessor blocks. A `ProgramDesc` describes a [DL program](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md), which is composed of an array of `BlockDesc`s. The `BlockDesc`s in a `ProgramDesc` can have a tree-like hierarchical structure. However, the `ProgramDesc` onlys stores a flattened array of `BlockDesc`s. A `BlockDesc` refers to its parent block by its index in the array. For example, operators in the step block of an RNN operator need to be able to access variables in its ancestor blocks.
Whenever we create a block, we need set its parent block to the current block, so the Python class `Program` needs to maintain a data member `current_block`. Whenever we create a block, we need to set its parent block to the current block, hence the Python class `Program` needs to maintain a data member `current_block`.
```python ```python
class Program(objects): class Program(objects):
...@@ -81,13 +81,13 @@ class Block(objects): ...@@ -81,13 +81,13 @@ class Block(objects):
self.ops.prepend(Operator(self, ...)) self.ops.prepend(Operator(self, ...))
``` ```
`create_parameter` is necessary because parameters are global variables, those defined in the global block, but can be created in some sub-blocks, e.g., an FC layer in the step block of an RNN operator. `create_parameter` is necessary because parameters are global variables, defined in the global block, but can be created in some sub-blocks. For example, an FC layer in the step block of an RNN operator.
`prepand_operator` is necessary because the constructor of `Parameter` needs to create the initialize (or load) operator of the parameter, and would like to put it in the *preamble* of the global block. `prepend_operator` is necessary because the constructor of `Parameter` needs to create the initialize (or load) operator of the parameter, and would like to put it in the *preamble* of the global block.
### Operator ### Operator
The `Operator` class fills in the `OpDesc` message and calls the C++ function `InferShape` to infer output shape from input shape. The `Operator` class fills in the `OpDesc` message and calls the C++ function `InferShape` to infer the output shapes from the input shapes.
```python ```python
class Operator(object): class Operator(object):
...@@ -105,7 +105,7 @@ class Operator(object): ...@@ -105,7 +105,7 @@ class Operator(object):
return self.proto.type() return self.proto.type()
``` ```
`Operator` creates the `OpDesc` message in C++ space, so could it call the `InferShape` function, which is in C++. `Operator` creates the `OpDesc` message in C++ space, so that it can call the `InferShape` function, which is in C++.
### Variable ### Variable
...@@ -128,7 +128,7 @@ class Variable(object): ...@@ -128,7 +128,7 @@ class Variable(object):
self.writer = None self.writer = None
``` ```
Please be aware of `self.writer`, that tracks operator who creates the variable. It possible that there are more than one operators who write a variable, but in Python space, each writes to a variable is represented by a Variable class. This is guaranteed by the fact that **`core.NewVarDesc` must NOT create a new `VarDesc` message if its name already exists in the specified block**. Please be aware of `self.writer`, that tracks operator who creates the variable. It possible that there are more than one operators who write a variable, but in Python space, each write to a variable is represented by a Variable class. This is guaranteed by the fact that **`core.NewVarDesc` must NOT create a new `VarDesc` message if its name already exists in the specified block**.
### Parameter ### Parameter
...@@ -155,7 +155,7 @@ class Parameter(Variable): ...@@ -155,7 +155,7 @@ class Parameter(Variable):
initialize_op_attrs) initialize_op_attrs)
``` ```
When users create a parameter, s/he can call When users create a parameter, they can call
```python ```python
program.create_parameter( program.create_parameter(
......
...@@ -191,8 +191,8 @@ ...@@ -191,8 +191,8 @@
<span id="core-concepts"></span><h2>Core Concepts<a class="headerlink" href="#core-concepts" title="Permalink to this headline"></a></h2> <span id="core-concepts"></span><h2>Core Concepts<a class="headerlink" href="#core-concepts" title="Permalink to this headline"></a></h2>
<div class="section" id="program"> <div class="section" id="program">
<span id="program"></span><h3>Program<a class="headerlink" href="#program" title="Permalink to this headline"></a></h3> <span id="program"></span><h3>Program<a class="headerlink" href="#program" title="Permalink to this headline"></a></h3>
<p>A <code class="docutils literal"><span class="pre">ProgramDesc</span></code> describes a <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md">DL program</a>, which is composed of an array of <code class="docutils literal"><span class="pre">BlockDesc</span></code>s. A <code class="docutils literal"><span class="pre">BlockDesc</span></code> refers to its parent block by its index in the array. For example, operators in the step block of an RNN operator needs to be able to access variables in its ancessor blocks.</p> <p>A <code class="docutils literal"><span class="pre">ProgramDesc</span></code> describes a <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md">DL program</a>, which is composed of an array of <code class="docutils literal"><span class="pre">BlockDesc</span></code>s. The <code class="docutils literal"><span class="pre">BlockDesc</span></code>s in a <code class="docutils literal"><span class="pre">ProgramDesc</span></code> can have a tree-like hierarchical structure. However, the <code class="docutils literal"><span class="pre">ProgramDesc</span></code> onlys stores a flattened array of <code class="docutils literal"><span class="pre">BlockDesc</span></code>s. A <code class="docutils literal"><span class="pre">BlockDesc</span></code> refers to its parent block by its index in the array. For example, operators in the step block of an RNN operator need to be able to access variables in its ancestor blocks.</p>
<p>Whenever we create a block, we need set its parent block to the current block, so the Python class <code class="docutils literal"><span class="pre">Program</span></code> needs to maintain a data member <code class="docutils literal"><span class="pre">current_block</span></code>.</p> <p>Whenever we create a block, we need to set its parent block to the current block, hence the Python class <code class="docutils literal"><span class="pre">Program</span></code> needs to maintain a data member <code class="docutils literal"><span class="pre">current_block</span></code>.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Program</span><span class="p">(</span><span class="n">objects</span><span class="p">):</span> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Program</span><span class="p">(</span><span class="n">objects</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">proto</span> <span class="o">=</span> <span class="n">core</span><span class="o">.</span><span class="n">NewProgram</span><span class="p">()</span> <span class="c1"># a C++ ProgramDesc pointer.</span> <span class="bp">self</span><span class="o">.</span><span class="n">proto</span> <span class="o">=</span> <span class="n">core</span><span class="o">.</span><span class="n">NewProgram</span><span class="p">()</span> <span class="c1"># a C++ ProgramDesc pointer.</span>
...@@ -252,12 +252,12 @@ ...@@ -252,12 +252,12 @@
<span class="bp">self</span><span class="o">.</span><span class="n">ops</span><span class="o">.</span><span class="n">prepend</span><span class="p">(</span><span class="n">Operator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">...</span><span class="p">))</span> <span class="bp">self</span><span class="o">.</span><span class="n">ops</span><span class="o">.</span><span class="n">prepend</span><span class="p">(</span><span class="n">Operator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">...</span><span class="p">))</span>
</pre></div> </pre></div>
</div> </div>
<p><code class="docutils literal"><span class="pre">create_parameter</span></code> is necessary because parameters are global variables, those defined in the global block, but can be created in some sub-blocks, e.g., an FC layer in the step block of an RNN operator.</p> <p><code class="docutils literal"><span class="pre">create_parameter</span></code> is necessary because parameters are global variables, defined in the global block, but can be created in some sub-blocks. For example, an FC layer in the step block of an RNN operator.</p>
<p><code class="docutils literal"><span class="pre">prepand_operator</span></code> is necessary because the constructor of <code class="docutils literal"><span class="pre">Parameter</span></code> needs to create the initialize (or load) operator of the parameter, and would like to put it in the <em>preamble</em> of the global block.</p> <p><code class="docutils literal"><span class="pre">prepend_operator</span></code> is necessary because the constructor of <code class="docutils literal"><span class="pre">Parameter</span></code> needs to create the initialize (or load) operator of the parameter, and would like to put it in the <em>preamble</em> of the global block.</p>
</div> </div>
<div class="section" id="operator"> <div class="section" id="operator">
<span id="operator"></span><h3>Operator<a class="headerlink" href="#operator" title="Permalink to this headline"></a></h3> <span id="operator"></span><h3>Operator<a class="headerlink" href="#operator" title="Permalink to this headline"></a></h3>
<p>The <code class="docutils literal"><span class="pre">Operator</span></code> class fills in the <code class="docutils literal"><span class="pre">OpDesc</span></code> message and calls the C++ function <code class="docutils literal"><span class="pre">InferShape</span></code> to infer output shape from input shape.</p> <p>The <code class="docutils literal"><span class="pre">Operator</span></code> class fills in the <code class="docutils literal"><span class="pre">OpDesc</span></code> message and calls the C++ function <code class="docutils literal"><span class="pre">InferShape</span></code> to infer the output shapes from the input shapes.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Operator</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Operator</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">block</span><span class="p">,</span> <span class="c1"># Block</span> <span class="n">block</span><span class="p">,</span> <span class="c1"># Block</span>
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">proto</span><span class="o">.</span><span class="n">type</span><span class="p">()</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">proto</span><span class="o">.</span><span class="n">type</span><span class="p">()</span>
</pre></div> </pre></div>
</div> </div>
<p><code class="docutils literal"><span class="pre">Operator</span></code> creates the <code class="docutils literal"><span class="pre">OpDesc</span></code> message in C++ space, so could it call the <code class="docutils literal"><span class="pre">InferShape</span></code> function, which is in C++.</p> <p><code class="docutils literal"><span class="pre">Operator</span></code> creates the <code class="docutils literal"><span class="pre">OpDesc</span></code> message in C++ space, so that it can call the <code class="docutils literal"><span class="pre">InferShape</span></code> function, which is in C++.</p>
</div> </div>
<div class="section" id="variable"> <div class="section" id="variable">
<span id="variable"></span><h3>Variable<a class="headerlink" href="#variable" title="Permalink to this headline"></a></h3> <span id="variable"></span><h3>Variable<a class="headerlink" href="#variable" title="Permalink to this headline"></a></h3>
...@@ -294,7 +294,7 @@ ...@@ -294,7 +294,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">writer</span> <span class="o">=</span> <span class="bp">None</span> <span class="bp">self</span><span class="o">.</span><span class="n">writer</span> <span class="o">=</span> <span class="bp">None</span>
</pre></div> </pre></div>
</div> </div>
<p>Please be aware of <code class="docutils literal"><span class="pre">self.writer</span></code>, that tracks operator who creates the variable. It possible that there are more than one operators who write a variable, but in Python space, each writes to a variable is represented by a Variable class. This is guaranteed by the fact that <strong><code class="docutils literal"><span class="pre">core.NewVarDesc</span></code> must NOT create a new <code class="docutils literal"><span class="pre">VarDesc</span></code> message if its name already exists in the specified block</strong>.</p> <p>Please be aware of <code class="docutils literal"><span class="pre">self.writer</span></code>, that tracks operator who creates the variable. It possible that there are more than one operators who write a variable, but in Python space, each write to a variable is represented by a Variable class. This is guaranteed by the fact that <strong><code class="docutils literal"><span class="pre">core.NewVarDesc</span></code> must NOT create a new <code class="docutils literal"><span class="pre">VarDesc</span></code> message if its name already exists in the specified block</strong>.</p>
</div> </div>
<div class="section" id="parameter"> <div class="section" id="parameter">
<span id="parameter"></span><h3>Parameter<a class="headerlink" href="#parameter" title="Permalink to this headline"></a></h3> <span id="parameter"></span><h3>Parameter<a class="headerlink" href="#parameter" title="Permalink to this headline"></a></h3>
...@@ -319,7 +319,7 @@ ...@@ -319,7 +319,7 @@
<span class="n">initialize_op_attrs</span><span class="p">)</span> <span class="n">initialize_op_attrs</span><span class="p">)</span>
</pre></div> </pre></div>
</div> </div>
<p>When users create a parameter, s/he can call</p> <p>When users create a parameter, they can call</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">program</span><span class="o">.</span><span class="n">create_parameter</span><span class="p">(</span> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">program</span><span class="o">.</span><span class="n">create_parameter</span><span class="p">(</span>
<span class="o">...</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span>
<span class="n">init_attr</span><span class="o">=</span><span class="p">{</span> <span class="n">init_attr</span><span class="o">=</span><span class="p">{</span>
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -15,9 +15,9 @@ Please be aware that these Python classes need to maintain some construction-tim ...@@ -15,9 +15,9 @@ Please be aware that these Python classes need to maintain some construction-tim
### Program ### Program
A `ProgramDesc` describes a [DL program](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md), which is composed of an array of `BlockDesc`s. A `BlockDesc` refers to its parent block by its index in the array. For example, operators in the step block of an RNN operator needs to be able to access variables in its ancessor blocks. A `ProgramDesc` describes a [DL program](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md), which is composed of an array of `BlockDesc`s. The `BlockDesc`s in a `ProgramDesc` can have a tree-like hierarchical structure. However, the `ProgramDesc` onlys stores a flattened array of `BlockDesc`s. A `BlockDesc` refers to its parent block by its index in the array. For example, operators in the step block of an RNN operator need to be able to access variables in its ancestor blocks.
Whenever we create a block, we need set its parent block to the current block, so the Python class `Program` needs to maintain a data member `current_block`. Whenever we create a block, we need to set its parent block to the current block, hence the Python class `Program` needs to maintain a data member `current_block`.
```python ```python
class Program(objects): class Program(objects):
...@@ -81,13 +81,13 @@ class Block(objects): ...@@ -81,13 +81,13 @@ class Block(objects):
self.ops.prepend(Operator(self, ...)) self.ops.prepend(Operator(self, ...))
``` ```
`create_parameter` is necessary because parameters are global variables, those defined in the global block, but can be created in some sub-blocks, e.g., an FC layer in the step block of an RNN operator. `create_parameter` is necessary because parameters are global variables, defined in the global block, but can be created in some sub-blocks. For example, an FC layer in the step block of an RNN operator.
`prepand_operator` is necessary because the constructor of `Parameter` needs to create the initialize (or load) operator of the parameter, and would like to put it in the *preamble* of the global block. `prepend_operator` is necessary because the constructor of `Parameter` needs to create the initialize (or load) operator of the parameter, and would like to put it in the *preamble* of the global block.
### Operator ### Operator
The `Operator` class fills in the `OpDesc` message and calls the C++ function `InferShape` to infer output shape from input shape. The `Operator` class fills in the `OpDesc` message and calls the C++ function `InferShape` to infer the output shapes from the input shapes.
```python ```python
class Operator(object): class Operator(object):
...@@ -105,7 +105,7 @@ class Operator(object): ...@@ -105,7 +105,7 @@ class Operator(object):
return self.proto.type() return self.proto.type()
``` ```
`Operator` creates the `OpDesc` message in C++ space, so could it call the `InferShape` function, which is in C++. `Operator` creates the `OpDesc` message in C++ space, so that it can call the `InferShape` function, which is in C++.
### Variable ### Variable
...@@ -128,7 +128,7 @@ class Variable(object): ...@@ -128,7 +128,7 @@ class Variable(object):
self.writer = None self.writer = None
``` ```
Please be aware of `self.writer`, that tracks operator who creates the variable. It possible that there are more than one operators who write a variable, but in Python space, each writes to a variable is represented by a Variable class. This is guaranteed by the fact that **`core.NewVarDesc` must NOT create a new `VarDesc` message if its name already exists in the specified block**. Please be aware of `self.writer`, that tracks operator who creates the variable. It possible that there are more than one operators who write a variable, but in Python space, each write to a variable is represented by a Variable class. This is guaranteed by the fact that **`core.NewVarDesc` must NOT create a new `VarDesc` message if its name already exists in the specified block**.
### Parameter ### Parameter
...@@ -155,7 +155,7 @@ class Parameter(Variable): ...@@ -155,7 +155,7 @@ class Parameter(Variable):
initialize_op_attrs) initialize_op_attrs)
``` ```
When users create a parameter, s/he can call When users create a parameter, they can call
```python ```python
program.create_parameter( program.create_parameter(
......
...@@ -205,8 +205,8 @@ ...@@ -205,8 +205,8 @@
<span id="core-concepts"></span><h2>Core Concepts<a class="headerlink" href="#core-concepts" title="永久链接至标题"></a></h2> <span id="core-concepts"></span><h2>Core Concepts<a class="headerlink" href="#core-concepts" title="永久链接至标题"></a></h2>
<div class="section" id="program"> <div class="section" id="program">
<span id="program"></span><h3>Program<a class="headerlink" href="#program" title="永久链接至标题"></a></h3> <span id="program"></span><h3>Program<a class="headerlink" href="#program" title="永久链接至标题"></a></h3>
<p>A <code class="docutils literal"><span class="pre">ProgramDesc</span></code> describes a <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md">DL program</a>, which is composed of an array of <code class="docutils literal"><span class="pre">BlockDesc</span></code>s. A <code class="docutils literal"><span class="pre">BlockDesc</span></code> refers to its parent block by its index in the array. For example, operators in the step block of an RNN operator needs to be able to access variables in its ancessor blocks.</p> <p>A <code class="docutils literal"><span class="pre">ProgramDesc</span></code> describes a <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md">DL program</a>, which is composed of an array of <code class="docutils literal"><span class="pre">BlockDesc</span></code>s. The <code class="docutils literal"><span class="pre">BlockDesc</span></code>s in a <code class="docutils literal"><span class="pre">ProgramDesc</span></code> can have a tree-like hierarchical structure. However, the <code class="docutils literal"><span class="pre">ProgramDesc</span></code> onlys stores a flattened array of <code class="docutils literal"><span class="pre">BlockDesc</span></code>s. A <code class="docutils literal"><span class="pre">BlockDesc</span></code> refers to its parent block by its index in the array. For example, operators in the step block of an RNN operator need to be able to access variables in its ancestor blocks.</p>
<p>Whenever we create a block, we need set its parent block to the current block, so the Python class <code class="docutils literal"><span class="pre">Program</span></code> needs to maintain a data member <code class="docutils literal"><span class="pre">current_block</span></code>.</p> <p>Whenever we create a block, we need to set its parent block to the current block, hence the Python class <code class="docutils literal"><span class="pre">Program</span></code> needs to maintain a data member <code class="docutils literal"><span class="pre">current_block</span></code>.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Program</span><span class="p">(</span><span class="n">objects</span><span class="p">):</span> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Program</span><span class="p">(</span><span class="n">objects</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">proto</span> <span class="o">=</span> <span class="n">core</span><span class="o">.</span><span class="n">NewProgram</span><span class="p">()</span> <span class="c1"># a C++ ProgramDesc pointer.</span> <span class="bp">self</span><span class="o">.</span><span class="n">proto</span> <span class="o">=</span> <span class="n">core</span><span class="o">.</span><span class="n">NewProgram</span><span class="p">()</span> <span class="c1"># a C++ ProgramDesc pointer.</span>
...@@ -266,12 +266,12 @@ ...@@ -266,12 +266,12 @@
<span class="bp">self</span><span class="o">.</span><span class="n">ops</span><span class="o">.</span><span class="n">prepend</span><span class="p">(</span><span class="n">Operator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">...</span><span class="p">))</span> <span class="bp">self</span><span class="o">.</span><span class="n">ops</span><span class="o">.</span><span class="n">prepend</span><span class="p">(</span><span class="n">Operator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">...</span><span class="p">))</span>
</pre></div> </pre></div>
</div> </div>
<p><code class="docutils literal"><span class="pre">create_parameter</span></code> is necessary because parameters are global variables, those defined in the global block, but can be created in some sub-blocks, e.g., an FC layer in the step block of an RNN operator.</p> <p><code class="docutils literal"><span class="pre">create_parameter</span></code> is necessary because parameters are global variables, defined in the global block, but can be created in some sub-blocks. For example, an FC layer in the step block of an RNN operator.</p>
<p><code class="docutils literal"><span class="pre">prepand_operator</span></code> is necessary because the constructor of <code class="docutils literal"><span class="pre">Parameter</span></code> needs to create the initialize (or load) operator of the parameter, and would like to put it in the <em>preamble</em> of the global block.</p> <p><code class="docutils literal"><span class="pre">prepend_operator</span></code> is necessary because the constructor of <code class="docutils literal"><span class="pre">Parameter</span></code> needs to create the initialize (or load) operator of the parameter, and would like to put it in the <em>preamble</em> of the global block.</p>
</div> </div>
<div class="section" id="operator"> <div class="section" id="operator">
<span id="operator"></span><h3>Operator<a class="headerlink" href="#operator" title="永久链接至标题"></a></h3> <span id="operator"></span><h3>Operator<a class="headerlink" href="#operator" title="永久链接至标题"></a></h3>
<p>The <code class="docutils literal"><span class="pre">Operator</span></code> class fills in the <code class="docutils literal"><span class="pre">OpDesc</span></code> message and calls the C++ function <code class="docutils literal"><span class="pre">InferShape</span></code> to infer output shape from input shape.</p> <p>The <code class="docutils literal"><span class="pre">Operator</span></code> class fills in the <code class="docutils literal"><span class="pre">OpDesc</span></code> message and calls the C++ function <code class="docutils literal"><span class="pre">InferShape</span></code> to infer the output shapes from the input shapes.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Operator</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Operator</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">block</span><span class="p">,</span> <span class="c1"># Block</span> <span class="n">block</span><span class="p">,</span> <span class="c1"># Block</span>
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">proto</span><span class="o">.</span><span class="n">type</span><span class="p">()</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">proto</span><span class="o">.</span><span class="n">type</span><span class="p">()</span>
</pre></div> </pre></div>
</div> </div>
<p><code class="docutils literal"><span class="pre">Operator</span></code> creates the <code class="docutils literal"><span class="pre">OpDesc</span></code> message in C++ space, so could it call the <code class="docutils literal"><span class="pre">InferShape</span></code> function, which is in C++.</p> <p><code class="docutils literal"><span class="pre">Operator</span></code> creates the <code class="docutils literal"><span class="pre">OpDesc</span></code> message in C++ space, so that it can call the <code class="docutils literal"><span class="pre">InferShape</span></code> function, which is in C++.</p>
</div> </div>
<div class="section" id="variable"> <div class="section" id="variable">
<span id="variable"></span><h3>Variable<a class="headerlink" href="#variable" title="永久链接至标题"></a></h3> <span id="variable"></span><h3>Variable<a class="headerlink" href="#variable" title="永久链接至标题"></a></h3>
...@@ -308,7 +308,7 @@ ...@@ -308,7 +308,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">writer</span> <span class="o">=</span> <span class="bp">None</span> <span class="bp">self</span><span class="o">.</span><span class="n">writer</span> <span class="o">=</span> <span class="bp">None</span>
</pre></div> </pre></div>
</div> </div>
<p>Please be aware of <code class="docutils literal"><span class="pre">self.writer</span></code>, that tracks operator who creates the variable. It possible that there are more than one operators who write a variable, but in Python space, each writes to a variable is represented by a Variable class. This is guaranteed by the fact that <strong><code class="docutils literal"><span class="pre">core.NewVarDesc</span></code> must NOT create a new <code class="docutils literal"><span class="pre">VarDesc</span></code> message if its name already exists in the specified block</strong>.</p> <p>Please be aware of <code class="docutils literal"><span class="pre">self.writer</span></code>, that tracks operator who creates the variable. It possible that there are more than one operators who write a variable, but in Python space, each write to a variable is represented by a Variable class. This is guaranteed by the fact that <strong><code class="docutils literal"><span class="pre">core.NewVarDesc</span></code> must NOT create a new <code class="docutils literal"><span class="pre">VarDesc</span></code> message if its name already exists in the specified block</strong>.</p>
</div> </div>
<div class="section" id="parameter"> <div class="section" id="parameter">
<span id="parameter"></span><h3>Parameter<a class="headerlink" href="#parameter" title="永久链接至标题"></a></h3> <span id="parameter"></span><h3>Parameter<a class="headerlink" href="#parameter" title="永久链接至标题"></a></h3>
...@@ -333,7 +333,7 @@ ...@@ -333,7 +333,7 @@
<span class="n">initialize_op_attrs</span><span class="p">)</span> <span class="n">initialize_op_attrs</span><span class="p">)</span>
</pre></div> </pre></div>
</div> </div>
<p>When users create a parameter, s/he can call</p> <p>When users create a parameter, they can call</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">program</span><span class="o">.</span><span class="n">create_parameter</span><span class="p">(</span> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">program</span><span class="o">.</span><span class="n">create_parameter</span><span class="p">(</span>
<span class="o">...</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span>
<span class="n">init_attr</span><span class="o">=</span><span class="p">{</span> <span class="n">init_attr</span><span class="o">=</span><span class="p">{</span>
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册