Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1becb53f
提交
1becb53f
authored
11月 16, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix merge
上级
26cc2381
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
33 行增加
和
10 行删除
+33
-10
aliasing.txt
doc/tutorial/aliasing.txt
+28
-8
index.txt
doc/tutorial/index.txt
+1
-0
var.py
theano/sandbox/cuda/var.py
+4
-2
没有找到文件。
doc/tutorial/aliasing.txt
浏览文件 @
1becb53f
.. _basictutaliasing:
.. _basictutaliasing:
===============
===============
========================================
Memory Aliasing
Understanding Memory Aliasing for Speed and Correctness
===============
===============
========================================
The aggressive reuse of memory is one of the ways Theano makes code fast, and
The aggressive reuse of memory is one of the ways Theano makes code fast, and
it's important for the correctness and speed of your program that you understand
it's important for the correctness and speed of your program that you understand
...
@@ -174,6 +174,26 @@ This pattern works regardless of the compute device, and when the compute device
...
@@ -174,6 +174,26 @@ This pattern works regardless of the compute device, and when the compute device
makes it possible to expose Theano's internal variables without a copy, then it
makes it possible to expose Theano's internal variables without a copy, then it
goes as fast as an in-place update.
goes as fast as an in-place update.
Retrieving and assigning via the .value property
------------------------------------------------
Shared variables have a ``.value`` property that is connected to ``get_value``
and ``set_value``. The borrowing behaviour of the property is controlled by a
boolean configuration variable ``config.shared.value_borrows``, which currently
defaults to ``True``. If that variable is ``True`` then an assignment like ``s.value=v``
is equivalent to ``s.set_value(v, borrow=True)``, and a retrieval like ``print
s.value`` is equivalent to ``print s.get_value(borrow=True)``. Likewise,
if ``config.shared.value_borrows`` is ``False``, then the borrow parameter that the ``.value`` property
passes to ``set_value`` and ``get_value`` is ``False``.
The ``True`` default value of ``config.shared.value_borrows`` means that
aliasing can sometimes happen and sometimes not, which can be confusing.
Be aware that the default value may be changed to ``False`` sometime in the
not-to-distant future. This change will create more copies, and potentially slow
down code that accesses ``.value`` attributes inside tight loops. To avoid this
potential impact on your code, use the ``.get_value`` and ``.set_value`` methods
directly with appropriate flags.
Borrowing when constructing Function objects
Borrowing when constructing Function objects
============================================
============================================
...
@@ -207,7 +227,11 @@ The default is of course to *not borrow* internal results.
...
@@ -207,7 +227,11 @@ The default is of course to *not borrow* internal results.
It is also possible to pass an ``return_internal_type=True`` flag to the ``Out``
It is also possible to pass an ``return_internal_type=True`` flag to the ``Out``
variable which has the same interpretation as the ``return_internal_type`` flag
variable which has the same interpretation as the ``return_internal_type`` flag
to the shared variable's ``get_value`` function.
to the shared variable's ``get_value`` function. Unlike ``get_value()``, the
combination of ``return_internal_type=True`` and ``borrow=True`` arguments to
``Out()`` are not guaranteed to avoid copying an output value. They are just
hints that give more flexibility to the compilation and optimization of the
graph.
*Take home message:*
*Take home message:*
When an input ``x`` to a function is not needed after the function returns and you
When an input ``x`` to a function is not needed after the function returns and you
...
@@ -218,7 +242,3 @@ When a return value ``y`` is large (in terms of memory footprint), and you only
...
@@ -218,7 +242,3 @@ When a return value ``y`` is large (in terms of memory footprint), and you only
away when it's returned, then consider marking it with an ``Out(y,
away when it's returned, then consider marking it with an ``Out(y,
borrow=True)``.
borrow=True)``.
Shared variable .value attribute
================================
TODO: talk about sharedvar.value and the associated config variable.
doc/tutorial/index.txt
浏览文件 @
1becb53f
...
@@ -29,6 +29,7 @@ you out.
...
@@ -29,6 +29,7 @@ you out.
loading_and_saving
loading_and_saving
symbolic_graphs
symbolic_graphs
modes
modes
aliasing
using_gpu
using_gpu
remarks
remarks
debug_faq
debug_faq
...
...
theano/sandbox/cuda/var.py
浏览文件 @
1becb53f
import
copy
import
numpy
import
numpy
import
theano
import
theano
from
theano
import
Op
,
Type
,
Apply
,
Variable
,
Constant
from
theano
import
Variable
,
Constant
from
theano
import
tensor
from
theano
import
tensor
from
theano.compile
import
shared
,
SharedVariable
from
theano.compile
import
SharedVariable
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda
import
filter
as
type_support_filter
from
theano.sandbox.cuda
import
filter
as
type_support_filter
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论