Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7223e9ed
提交
7223e9ed
authored
12月 29, 2016
作者:
khaotik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleanup 2
上级
f15bc27c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
10 行增加
和
10 行删除
+10
-10
builders.py
theano/compile/builders.py
+10
-10
没有找到文件。
theano/compile/builders.py
浏览文件 @
7223e9ed
...
@@ -80,7 +80,9 @@ class OpFromGraph(gof.Op):
...
@@ -80,7 +80,9 @@ class OpFromGraph(gof.Op):
suggestion to compiler which is not guaranteed. Currently only
suggestion to compiler which is not guaranteed. Currently only
works with "fast_compile" or "fast_run" mode.
works with "fast_compile" or "fast_run" mode.
- The function(s) supplied for overrding gradient/rop will be called
- The function(s) supplied for overrding gradient/rop will be called
only once
only once at the first call to grad/R_op, and will be converted to
OfG instances. Any side effect (modifying non local states) of the
overriding function should not be relied on.
Examples
Examples
--------
--------
...
@@ -89,10 +91,10 @@ class OpFromGraph(gof.Op):
...
@@ -89,10 +91,10 @@ class OpFromGraph(gof.Op):
.. code-block:: python
.. code-block:: python
from theano import function,
op_from_graph,
tensor
from theano import function, tensor
x, y, z = tensor.scalars('xyz')
x, y, z = tensor.scalars('xyz')
e = x + y * z
e = x + y * z
op =
op_from_g
raph([x, y, z], [e])
op =
OpFromG
raph([x, y, z], [e])
# op behaves like a normal theano op
# op behaves like a normal theano op
e2 = op(x, y, z) + op(z, y, x)
e2 = op(x, y, z) + op(z, y, x)
fn = function([x, y, z], [e2])
fn = function([x, y, z], [e2])
...
@@ -103,11 +105,11 @@ class OpFromGraph(gof.Op):
...
@@ -103,11 +105,11 @@ class OpFromGraph(gof.Op):
import numpy as np
import numpy as np
import theano
import theano
from theano import config, function,
op_from_g
raph, tensor
from theano import config, function,
OpFromG
raph, tensor
x, y, z = tensor.scalars('xyz')
x, y, z = tensor.scalars('xyz')
s = theano.shared(np.random.rand(2, 2).astype(config.floatX))
s = theano.shared(np.random.rand(2, 2).astype(config.floatX))
e = x + y * z + s
e = x + y * z + s
op =
op_from_g
raph([x, y, z], [e])
op =
OpFromG
raph([x, y, z], [e])
# op behaves like a normal theano op
# op behaves like a normal theano op
e2 = op(x, y, z) + op(z, y, x)
e2 = op(x, y, z) + op(z, y, x)
fn = function([x, y, z], [e2])
fn = function([x, y, z], [e2])
...
@@ -116,14 +118,14 @@ class OpFromGraph(gof.Op):
...
@@ -116,14 +118,14 @@ class OpFromGraph(gof.Op):
.. code-block:: python
.. code-block:: python
from thenao import funciton,
op_from_g
raph, tensor, grad
from thenao import funciton,
OpFromG
raph, tensor, grad
x, y, z = tensor.scalars('xyz')
x, y, z = tensor.scalars('xyz')
e = x + y * z
e = x + y * z
def rescale_dy(inps, grads):
def rescale_dy(inps, grads):
x, y, z = inps
x, y, z = inps
g = grads
g = grads
return z*2
return z*2
op =
op_from_g
raph(
op =
OpFromG
raph(
[x, y, z], [e], grad_overrides=[None, rescale_dy, None])
[x, y, z], [e], grad_overrides=[None, rescale_dy, None])
e2 = op(x, y, z)
e2 = op(x, y, z)
dx, dy, dz = grad(e2, [x, y, z])
dx, dy, dz = grad(e2, [x, y, z])
...
@@ -260,15 +262,13 @@ class OpFromGraph(gof.Op):
...
@@ -260,15 +262,13 @@ class OpFromGraph(gof.Op):
odefaults_l
=
[
odefaults_l
=
[
lo
for
lo
,
rov
in
izip
(
self
.
local_outputs
,
roverrides_l
)
lo
for
lo
,
rov
in
izip
(
self
.
local_outputs
,
roverrides_l
)
if
not
rov
]
if
not
rov
]
# compute non-overriding downsteam grads from upstreams grads
# it's normal some input may be disconnected, thus the 'ignore'
rdefaults_li
=
theano
.
gradient
.
Rop
(
rdefaults_li
=
theano
.
gradient
.
Rop
(
f
=
odefaults_l
,
f
=
odefaults_l
,
wrt
=
self
.
local_inputs
,
wrt
=
self
.
local_inputs
,
eval_points
=
eval_points
eval_points
=
eval_points
)
)
rdefaults
=
iter
(
rdefaults_li
if
odefaults_l
else
[])
rdefaults
=
iter
(
rdefaults_li
if
odefaults_l
else
[])
# combine overriding
gradient
s
# combine overriding
Rop
s
all_rops_l
=
[]
all_rops_l
=
[]
for
out
,
rov
in
izip
(
self
.
local_outputs
,
roverrides_l
):
for
out
,
rov
in
izip
(
self
.
local_outputs
,
roverrides_l
):
if
rov
is
None
:
if
rov
is
None
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论