Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
269753e7
提交
269753e7
authored
8月 21, 2017
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add even more documentation for RNNBlock usage.
上级
8358e801
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
88 行增加
和
0 行删除
+88
-0
dnn.txt
doc/library/gpuarray/dnn.txt
+88
-0
没有找到文件。
doc/library/gpuarray/dnn.txt
浏览文件 @
269753e7
...
@@ -149,6 +149,94 @@ To get an error if Theano can not use cuDNN, use this Theano flag:
...
@@ -149,6 +149,94 @@ To get an error if Theano can not use cuDNN, use this Theano flag:
- Spatial Transformer:
- Spatial Transformer:
- :func:`theano.gpuarray.dnn.dnn_spatialtf`.
- :func:`theano.gpuarray.dnn.dnn_spatialtf`.
cuDNN RNN Example
=================
This is a code example of using the cuDNN RNN functionality. We
present the code with some commentary in between to explain some
peculiarities.
The terminology here assumes that you are familiar with RNN structure.
.. code-block:: python
dtype = 'float32'
input_dim = 32
hidden_dim = 16
batch_size = 2
depth = 3
timesteps = 5
To clarify the rest of the code we define some variables to hold sizes.
.. code-block:: python
X = T.tensor3('X')
Y = T.tensor3('Y')
h0 = T.tensor3('h0')
We also define some Theano variables to work with. Here `X` is input,
`Y` is output (as in expected output) and `h0` is the initial state
for the recurrent inputs.
.. code-block:: python
rnnb = dnn.RNNBlock(dtype, hidden_dim, depth, 'gru')
This defines an RNNBlock. This is a departure from usual Theano
operations in that it has the structure of a layer more than a
separate operation. This is constrained by the underlying API.
.. code-block:: python
psize = rnnb.get_param_size([batch_size, input_dim])
params_cudnn = gpuarray_shared_constructor(
np.zeros((psize,), dtype=theano.config.floatX))
Here we allocate space for the trainable parameters of the RNN. The
first function tells us how many elements we will need to store the
parameters. This space if for all the parameters of all the layers
inside the RNN and the layout is opaque.
.. code-block:: python
layer = 0
= rnnb.split_params(params_cudnn, layer,
[batch_size, input_dim])
If you need to access the parameters individually, you can call
split_params on your shared variable to get all the parameters for a
single layer. The order and number of returned items depends on the
type of RNN.
rnn_relu, rnn_tanh
input, recurrent
gru
input reset, input update, input newmem, recurrent reset, recurrent
update, recurrent newmem
lstm
input input gate, input forget gate, input newmem gate, input output
gate, recurrent input gate, recurrent update gate, recurrent newmem
gate, recurrent output gate
All of these elements are composed of a weights and bias (matrix and
vector).
.. code-block:: python
y, hy = rnnb.apply(params_cudnn, X, h0)
This is more akin to an op in Theano in that it will apply the RNN
operation to a set of symbolic inputs and return symbolic outputs.
`y` is the output, `hy` is the final state for the recurrent inputs.
After this, the gradient works as usual so you can treat the returned
symbolic outputs as normal Theano symbolic variables.
List of Implemented Operations
List of Implemented Operations
==============================
==============================
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论