Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
378fc4fb
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看板
未验证
提交
378fc4fb
编写于
10月 24, 2019
作者:
Z
Zeng Jinle
提交者:
GitHub
10月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add some docs to jit.trace, test=develop (#20811)
上级
5a8d885d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
6 deletion
+59
-6
paddle/fluid/imperative/jit/program_desc_tracer.h
paddle/fluid/imperative/jit/program_desc_tracer.h
+0
-2
python/paddle/fluid/dygraph/jit.py
python/paddle/fluid/dygraph/jit.py
+59
-4
未找到文件。
paddle/fluid/imperative/jit/program_desc_tracer.h
浏览文件 @
378fc4fb
...
...
@@ -14,10 +14,8 @@
#pragma once
#include <forward_list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
...
...
python/paddle/fluid/dygraph/jit.py
浏览文件 @
378fc4fb
...
...
@@ -14,7 +14,6 @@
__all__
=
[
'trace'
]
from
.
import
layers
from
.base
import
program_desc_tracing_guard
from
.layers
import
Layer
from
paddle.fluid.framework
import
Program
,
Block
,
Variable
,
_dygraph_tracer
,
dygraph_only
,
_dygraph_guard
...
...
@@ -44,8 +43,64 @@ def extract_vars(inputs):
@
dygraph_only
def
trace
(
module
,
inputs
,
feed_names
=
None
,
fetch_names
=
None
):
assert
isinstance
(
module
,
Layer
)
def
trace
(
layer
,
inputs
,
feed_names
=
None
,
fetch_names
=
None
):
"""
Trace dygraph network into a :code:`Program`. The returned :code:`Program`
can be run in static graph mode. This method would simply record all
operators in the network with :code:`inputs` . Users should guarantee that
the traced dygraph network is independent with input data, input shapes,
and would not be changed between different batches. Otherwise, the traced
result may be different.
Parameters:
layer(Layer): the layer to be traced.
inputs(list): the input arguments of :code:`layer.forward()` method.
feed_names(list(str), optional): the input variable names in the
traced :code:`Program` corresponding to :code:`inputs` . If it
is None, the variable name of :code:`inputs` would be used.
It is suggested that users should set :code:`feed_names`
manually. Otherwise, the input variable names would be
different between different batches. Default None.
fetch_names(list(str), optional): the output variable names in the
traced :code:`Program` corresponding to the output variables
of :code:`layer.forward()` method. If it is None, the variable
name of the outputs of :code:`layer.forward()` would be used.
It is suggested that users should set :code:`fetch_names`
manually. Otherwise, the output variable names would be
different between different batches. Default None.
Returns:
A tuple of 2 items, whose first item is the outputs of
:code:`layer.forward()` method, and second item is the traced
:code:`Program` .
Examples:
.. code-blocks: python:
import paddle.fluid as fluid
from paddle.fluid.dygraph import FC, to_variable
import paddle.fluid.dygraph.jit as jit
import numpy as np
class ExampleLayer(fluid.dygraph.Layer):
def __init__(self, name_scope):
super(ExampleLayer, self).__init__(name_scope)
self._fc = FC(self.full_name(), 10)
def forward(self, input):
return self._fc(input)
with fluid.dygraph.guard():
layer = ExampleLayer("example_layer")
in_np = np.random.random([2, 3]).astype('float32')
in_var = to_variable(in_np)
out, program = jit.trace(layer, inputs=[in_var],
feed_names=['input'],
fetch_names=['fc_out'])
"""
assert
isinstance
(
layer
,
Layer
)
if
not
isinstance
(
inputs
,
(
list
,
tuple
)):
inputs
=
[
inputs
]
...
...
@@ -62,7 +117,7 @@ def trace(module, inputs, feed_names=None, fetch_names=None):
tracer
.
set_feed_vars
(
var_list
,
feed_names
)
with
program_desc_tracing_guard
(
True
):
original_outputs
=
module
.
__call__
(
*
inputs
)
original_outputs
=
layer
(
*
inputs
)
if
not
isinstance
(
original_outputs
,
(
list
,
tuple
)):
outputs
=
[
original_outputs
]
else
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录