Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b577b992
提交
b577b992
authored
11月 12, 2010
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clarified some sections of the shared variable contract
上级
8638a336
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
15 行增加
和
12 行删除
+15
-12
aliasing.txt
doc/tutorial/aliasing.txt
+15
-12
没有找到文件。
doc/tutorial/aliasing.txt
浏览文件 @
b577b992
...
@@ -22,9 +22,9 @@ main idea is that there is a pool of memory managed by Theano, and Theano tracks
...
@@ -22,9 +22,9 @@ main idea is that there is a pool of memory managed by Theano, and Theano tracks
changes to values in that pool.
changes to values in that pool.
1. Theano manages its own memory space, which typically does not overlap with
1. Theano manages its own memory space, which typically does not overlap with
the memory of normal python variables that non-
t
heano code creates.
the memory of normal python variables that non-
T
heano code creates.
1. Theano
functions only modify buffers that are in it
s memory space.
1. Theano
Functions only modify buffers that are in Theano'
s memory space.
1. Theano's memory space includes the buffers allocated to store shared
1. Theano's memory space includes the buffers allocated to store shared
variables and the temporaries used to evaluate Functions.
variables and the temporaries used to evaluate Functions.
...
@@ -36,13 +36,14 @@ changes to values in that pool.
...
@@ -36,13 +36,14 @@ changes to values in that pool.
aliased to another shared variable.
aliased to another shared variable.
1. Theano's managed memory is constant while Theano Functions are not running
1. Theano's managed memory is constant while Theano Functions are not running
and
t
heano library code is not running.
and
T
heano library code is not running.
1. The default behaviour of Function is to return user-space values for
1. The default behaviour of Function is to return user-space values for
outputs, and to expect user-space values for inputs.
outputs, and to expect user-space values for inputs.
The distinction between Theano-managed memory and user-managed memory can be
The distinction between Theano-managed memory and user-managed memory can be
broken down by some theano functions (e.g. In, Out,shared, get_value)) by using
broken down by some Theano functions (e.g. shared, get_value and the
constructors for In and Out) by using
a ``borrow=True`` flag. This can make those methods faster (by avoiding copy
a ``borrow=True`` flag. This can make those methods faster (by avoiding copy
operations) at the expense of risking subtle bugs in the overall program (by
operations) at the expense of risking subtle bugs in the overall program (by
aliasing memory).
aliasing memory).
...
@@ -81,13 +82,16 @@ then changes we make to np_array *right away* will show up in ``s_true.value``
...
@@ -81,13 +82,16 @@ then changes we make to np_array *right away* will show up in ``s_true.value``
because numpy arrays are mutable, and ``s_true`` is using the ``np_array``
because numpy arrays are mutable, and ``s_true`` is using the ``np_array``
object as it's internal buffer.
object as it's internal buffer.
However, this aliasing of ``np_array`` and ``s_true`` is *inconsistent and fragile*!
However, this aliasing of ``np_array`` and ``s_true`` is not guaranteed to occur,
It is inconsistent because if Theano is using a GPU device, then the borrow flag
and may occur only temporarily even if it occurs at all.
has no effect.
It is not guaranteed to occur because if Theano is using a GPU device, then the
It is fragile because
borrow flag has no effect.
if we call a theano function that updates the value of ``s_true`` the aliasing
It may occur only temporarily because
relationship *may* or *may not* be broken (it depends on what the Theano
if we call a Theano function that updates the value of ``s_true`` the aliasing
function does).
relationship *may* or *may not* be broken (the function is allowed to
update the shared variable by modifying its buffer, which will preserve
the aliasing, or by changing which buffer the variable points to, which
will terminate the aliasing).
*Take home message:*
*Take home message:*
...
@@ -185,7 +189,6 @@ that control how ``theano.function`` handles its arguments and return value[s].
...
@@ -185,7 +189,6 @@ that control how ``theano.function`` handles its arguments and return value[s].
y = 2*x
y = 2*x
f = theano.function([theano.In(x, borrow=True)], theano.Out(y, borrow=True))
f = theano.function([theano.In(x, borrow=True)], theano.Out(y, borrow=True))
Borrowing an input means that Theano will treat the argument you provide as if
Borrowing an input means that Theano will treat the argument you provide as if
it were part of Theano's pool of temporaries. Consequently, your input
it were part of Theano's pool of temporaries. Consequently, your input
may be reused as a buffer (and overwritten!) during the computation of other variables in the
may be reused as a buffer (and overwritten!) during the computation of other variables in the
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论