Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1b02e36d
提交
1b02e36d
authored
9月 13, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Print - refactored for more flexibility and printing of GPU tensors
上级
c84d102d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
9 行删除
+24
-9
printing.py
theano/printing.py
+17
-8
opt.py
theano/sandbox/cuda/opt.py
+7
-1
没有找到文件。
theano/printing.py
浏览文件 @
1b02e36d
...
@@ -66,6 +66,16 @@ def debugprint(obj, depth=-1, print_type=False, file=None):
...
@@ -66,6 +66,16 @@ def debugprint(obj, depth=-1, print_type=False, file=None):
else
:
else
:
_file
.
flush
()
_file
.
flush
()
def
_print_fn
(
op
,
xin
):
for
attr
in
op
.
attrs
:
temp
=
getattr
(
xin
,
attr
)
if
callable
(
temp
):
pmsg
=
temp
()
else
:
pmsg
=
temp
print
op
.
message
,
attr
,
'='
,
pmsg
class
Print
(
Op
):
class
Print
(
Op
):
"""This identity-like Op has the side effect of printing a message followed by its inputs
"""This identity-like Op has the side effect of printing a message followed by its inputs
when it runs. Default behaviour is to print the __str__ representation. Optionally, one
when it runs. Default behaviour is to print the __str__ representation. Optionally, one
...
@@ -80,9 +90,10 @@ class Print(Op):
...
@@ -80,9 +90,10 @@ class Print(Op):
:note: WARNING. This can disable some optimization(speed and stabilization)!
:note: WARNING. This can disable some optimization(speed and stabilization)!
"""
"""
view_map
=
{
0
:[
0
]}
view_map
=
{
0
:[
0
]}
def
__init__
(
self
,
message
=
""
,
attrs
=
(
"__str__"
,)):
def
__init__
(
self
,
message
=
""
,
attrs
=
(
"__str__"
,)
,
global_fn
=
_print_fn
):
self
.
message
=
message
self
.
message
=
message
self
.
attrs
=
tuple
(
attrs
)
# attrs should be a hashable iterable
self
.
attrs
=
tuple
(
attrs
)
# attrs should be a hashable iterable
self
.
global_fn
=
global_fn
def
make_node
(
self
,
xin
):
def
make_node
(
self
,
xin
):
xout
=
xin
.
type
.
make_variable
()
xout
=
xin
.
type
.
make_variable
()
...
@@ -92,13 +103,7 @@ class Print(Op):
...
@@ -92,13 +103,7 @@ class Print(Op):
xin
,
=
inputs
xin
,
=
inputs
xout
,
=
output_storage
xout
,
=
output_storage
xout
[
0
]
=
xin
xout
[
0
]
=
xin
for
attr
in
self
.
attrs
:
self
.
global_fn
(
self
,
xin
)
temp
=
getattr
(
xin
,
attr
)
if
callable
(
temp
):
pmsg
=
temp
()
else
:
pmsg
=
temp
print
self
.
message
,
attr
,
'='
,
pmsg
def
grad
(
self
,
input
,
output_gradients
):
def
grad
(
self
,
input
,
output_gradients
):
return
output_gradients
return
output_gradients
...
@@ -109,6 +114,10 @@ class Print(Op):
...
@@ -109,6 +114,10 @@ class Print(Op):
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
self
.
message
)
^
hash
(
self
.
attrs
)
return
hash
(
self
.
message
)
^
hash
(
self
.
attrs
)
def
__setstate__
(
self
,
dct
):
dct
.
setdefault
(
'global_fn'
,
_print_fn
)
self
.
__dict__
.
update
(
dct
)
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
1
,)
return
(
1
,)
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
1b02e36d
...
@@ -390,6 +390,10 @@ def local_gpu_rebroadcast(node):
...
@@ -390,6 +390,10 @@ def local_gpu_rebroadcast(node):
gpu_x
=
x
.
owner
.
inputs
[
0
]
gpu_x
=
x
.
owner
.
inputs
[
0
]
return
[
host_from_gpu
(
node
.
op
(
gpu_x
))]
return
[
host_from_gpu
(
node
.
op
(
gpu_x
))]
def
gpu_print_wrapper
(
op
,
cnda
):
op
.
old_op
.
global_fn
(
op
.
old_op
,
numpy
.
asarray
(
cnda
))
@register_opt
()
@register_opt
()
@local_optimizer
([])
@local_optimizer
([])
def
local_print_op
(
node
):
def
local_print_op
(
node
):
...
@@ -397,7 +401,9 @@ def local_print_op(node):
...
@@ -397,7 +401,9 @@ def local_print_op(node):
x
,
=
node
.
inputs
x
,
=
node
.
inputs
if
x
.
owner
and
x
.
owner
.
op
==
host_from_gpu
:
if
x
.
owner
and
x
.
owner
.
op
==
host_from_gpu
:
gpu_x
,
=
x
.
owner
.
inputs
gpu_x
,
=
x
.
owner
.
inputs
return
[
host_from_gpu
(
node
.
op
(
gpu_x
))]
new_op
=
node
.
op
.
__class__
(
global_fn
=
gpu_print_wrapper
)
new_op
.
old_op
=
node
.
op
return
[
host_from_gpu
(
new_op
(
gpu_x
))]
return
False
return
False
def
cast
(
x
,
dtype
):
def
cast
(
x
,
dtype
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论