Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b8a24137
提交
b8a24137
authored
11月 18, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
updated autoencoder benchmark
上级
3679d8e6
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
228 行增加
和
111 行删除
+228
-111
Makefile
benchmark/autoencoder/Makefile
+5
-0
aa.cc
benchmark/autoencoder/aa.cc
+24
-4
aa.py
benchmark/autoencoder/aa.py
+199
-0
aa.py
theano/benchmark/autoencoder/aa.py
+0
-107
没有找到文件。
benchmark/autoencoder/Makefile
0 → 100644
浏览文件 @
b8a24137
aa.x
:
aa.cc
g++
-O3
-ffast-math
aa.cc
-o
aa.x
-L
${
PUB_PREFIX
}
/lib
-lgsl
-lcblas
-lgoto
-lgfortran
-lm
clean
:
rm
aa.x
theano/
benchmark/autoencoder/aa.cc
→
benchmark/autoencoder/aa.cc
浏览文件 @
b8a24137
/*
*
* g++ -O2 -ffast-math -I$PUB_PREFIX/include aa.cc -o aa.x -lgsl -lgslcblas
*
* g++ -O2 -ffast-math -I$PUB_PREFIX/include aa.cc -o aa.x -L$PUB_PREFIX/lib -lgsl -lcblas -lgoto -lgfortran
*
* ./aa.x 10 5 7 1000
*
* */
#include <cassert>
#include <cassert>
#include <cstdlib>
#include <cstdlib>
#include <cstdio>
#include <cstdio>
...
@@ -5,15 +14,22 @@
...
@@ -5,15 +14,22 @@
#include <gsl/gsl_rng.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_blas.h>
typedef
float
real
;
#include <time.h>
#include <sys/time.h>
double
pytime
(
const
struct
timeval
*
tv
)
{
return
(
double
)
tv
->
tv_sec
+
(
double
)
tv
->
tv_usec
/
1000000.0
;
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
assert
(
argc
==
4
);
assert
(
argc
==
5
);
int
neg
=
strtol
(
argv
[
1
],
0
,
0
);
int
neg
=
strtol
(
argv
[
1
],
0
,
0
);
int
nout
=
strtol
(
argv
[
2
],
0
,
0
);
int
nout
=
strtol
(
argv
[
2
],
0
,
0
);
int
nhid
=
strtol
(
argv
[
3
],
0
,
0
);
int
nhid
=
strtol
(
argv
[
3
],
0
,
0
);
int
niter
=
strtol
(
argv
[
4
],
0
,
0
);
double
lr
=
0.01
;
double
lr
=
0.01
;
gsl_rng
*
rng
=
gsl_rng_alloc
(
gsl_rng_taus
);
gsl_rng
*
rng
=
gsl_rng_alloc
(
gsl_rng_taus
);
gsl_rng_set
(
rng
,
234
);
gsl_rng_set
(
rng
,
234
);
...
@@ -41,8 +57,11 @@ int main(int argc, char **argv)
...
@@ -41,8 +57,11 @@ int main(int argc, char **argv)
//
//
//
//
struct
timeval
tv0
,
tv1
;
gettimeofday
(
&
tv0
,
0
);
double
err
=
0.0
;
double
err
=
0.0
;
for
(
int
iter
=
0
;
iter
<
1000
;
++
iter
)
for
(
int
iter
=
0
;
iter
<
niter
;
++
iter
)
{
{
gsl_blas_dgemm
(
CblasNoTrans
,
CblasNoTrans
,
1.0
,
x
,
w
,
0.0
,
xw
);
gsl_blas_dgemm
(
CblasNoTrans
,
CblasNoTrans
,
1.0
,
x
,
w
,
0.0
,
xw
);
...
@@ -87,8 +106,9 @@ int main(int argc, char **argv)
...
@@ -87,8 +106,9 @@ int main(int argc, char **argv)
}
}
}
}
gettimeofday
(
&
tv1
,
0
);
fprintf
(
stdout
,
"
%lf
\n
"
,
0.5
*
err
);
fprintf
(
stdout
,
"
took = %lfs to get err %lf
\n
"
,
pytime
(
&
tv1
)
-
pytime
(
&
tv0
)
,
0.5
*
err
);
//skip freeing
//skip freeing
return
0
;
return
0
;
}
}
...
...
benchmark/autoencoder/aa.py
0 → 100755
浏览文件 @
b8a24137
#!/usr/bin/env python2.5
from
__future__
import
absolute_import
import
numpy
import
sys
import
time
import
theano
import
theano.tensor
as
T
import
theano.sandbox
import
theano.sandbox.wraplinker
from
theano.compile
import
module
if
0
:
class
Opt
(
object
):
merge
=
theano
.
gof
.
MergeOptimizer
()
gemm_opt_1
=
theano
.
gof
.
TopoOptimizer
(
theano
.
tensor_opt
.
gemm_pattern_1
)
gemm_opt_2
=
theano
.
gof
.
TopoOptimizer
(
# d -= a * (dot()+transpose(dot))
theano
.
gof
.
PatternSub
(
(
T
.
sub_inplace
,
'd'
,
(
T
.
mul
,
dict
(
pattern
=
(
T
.
DimShuffle
((),
[
'x'
,
'x'
],
inplace
=
True
),
'a'
),
allow_multiple_clients
=
True
),
(
T
.
add
,
(
T
.
dot
,
'b'
,
'c'
),
(
T
.
transpose_inplace
,
(
T
.
dot
,
'f'
,
'g'
))
)
)
),
(
T
.
gemm
,
(
T
.
gemm
,
'd'
,
(
T
.
neg
,
'a'
),
(
T
.
transpose_inplace
,
'g'
),
(
T
.
transpose_inplace
,
'f'
),
T
.
constant
(
1.0
)
),
(
T
.
neg
,
'a'
),
'b'
,
'c'
,
T
.
constant
(
1.0
)
),
allow_multiple_clients
=
False
))
sqr
=
[]
sqr
.
append
(
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
mul
,
'x'
,
'x'
),
(
T
.
sqr
,
'x'
),
allow_multiple_clients
=
True
)))
sqr
.
append
(
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
pow
,
'x'
,
(
T
.
DimShuffle
((),
[
'x'
,
'x'
],
inplace
=
True
),
T
.
constant
(
2
))),
(
T
.
sqr
,
'x'
),
allow_multiple_clients
=
True
)))
ident_opt_list
=
[]
ident_opt_list
.
append
(
# remove explicit copies
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
tensor_copy
,
'x'
),
'x'
,
allow_multiple_clients
=
True
)))
ident_opt_list
.
append
(
# remove double-transpose
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
transpose_inplace
,
(
T
.
transpose_inplace
,
'x'
)),
'x'
,
allow_multiple_clients
=
True
)))
ident_opt_list
.
append
(
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
sqr
,
(
T
.
sqrt
,
'x'
)),
'x'
,
allow_multiple_clients
=
True
)))
ident_opt_list
.
append
(
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
sqrt
,
(
T
.
sqr
,
'x'
)),
'x'
,
allow_multiple_clients
=
True
)))
ident_opt_list
.
append
(
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
mul
,
'x'
,
(
T
.
div
,
'y'
,
'x'
)),
'y'
,
allow_multiple_clients
=
True
)))
ident_opt_list
.
append
(
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
mul
,
(
T
.
div
,
'y'
,
'x'
),
'x'
),
'y'
,
allow_multiple_clients
=
True
)))
ident_opt_list
.
append
(
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
div
,
(
T
.
mul
,
'y'
,
'x'
),
'x'
),
'y'
,
allow_multiple_clients
=
True
)))
ident_opt_list
.
append
(
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
div
,
(
T
.
mul
,
'y'
,
'x'
),
'y'
),
'x'
,
allow_multiple_clients
=
True
)))
def
__call__
(
self
,
env
):
self
.
merge
(
env
)
#eliminate identities
if
0
:
print
'SKIPPING optimizations'
else
:
for
opt
in
self
.
ident_opt_list
:
opt
(
env
)
for
opt
in
self
.
sqr
:
opt
(
env
)
self
.
gemm_opt_1
(
env
)
self
.
gemm_opt_2
(
env
)
self
.
merge
(
env
)
def
linker
(
print_prog
=
False
):
if
1
:
print
'wtf?'
#return theano.gof.OpWiseCLinker()
imap
=
{
None
:
'-'
}
def
blah
(
i
,
node
,
thunk
):
imap
[
node
]
=
str
(
i
)
if
print_prog
:
# and node.op.__class__ is T.DimShuffle:
if
False
and
node
.
op
==
T
.
DimShuffle
((),
[
'x'
,
'x'
],
inplace
=
True
):
print
node
.
op
==
T
.
DimShuffle
((),
[
'x'
,
'x'
],
inplace
=
True
),
print
node
.
inputs
[
0
],
type
(
node
.
inputs
[
0
]),
print
node
.
inputs
[
0
]
.
equals
(
T
.
constant
(
2
)),
outputs
=
node
.
outputs
inputs
=
theano
.
gof
.
graph
.
inputs
(
outputs
)
print
'node '
,
i
,
node
,
print
':'
.
join
([
imap
[
inp
.
owner
]
for
inp
in
node
.
inputs
])
#print theano.sandbox.pprint.pp.process_graph(inputs, outputs)
return
theano
.
sandbox
.
wraplinker
.
WrapLinkerMany
(
[
theano
.
gof
.
OpWiseCLinker
()],
[
theano
.
sandbox
.
wraplinker
.
run_all
,
blah
#,theano.sandbox.wraplinker.numpy_notall_isfinite
])
else
:
return
theano
.
gof
.
OpWiseCLinker
()
class
M
(
module
.
Module
):
def
__init__
(
self
):
super
(
M
,
self
)
.
__init__
()
x
=
T
.
matrix
(
'x'
)
# input, target
self
.
w
=
module
.
Member
(
T
.
matrix
(
'w'
))
# weights
self
.
a
=
module
.
Member
(
T
.
vector
(
'a'
))
# hid bias
self
.
b
=
module
.
Member
(
T
.
vector
(
'b'
))
# output bias
hid
=
T
.
tanh
(
T
.
dot
(
x
,
self
.
w
)
+
self
.
a
)
out
=
T
.
tanh
(
T
.
dot
(
hid
,
self
.
w
.
T
)
+
self
.
b
)
err
=
0.5
*
T
.
sum
((
out
-
x
)
**
2
)
params
=
[
self
.
w
,
self
.
a
,
self
.
b
]
gparams
=
T
.
grad
(
err
,
params
)
updates
=
[(
p
,
p
-
0.01
*
gp
)
for
p
,
gp
in
zip
(
params
,
gparams
)]
self
.
step
=
module
.
Method
([
x
],
err
,
updates
=
dict
(
updates
))
mod
=
M
()
m
=
mod
.
make
(
mode
=
'FAST_RUN'
)
neg
,
nout
,
nhid
,
niter
=
[
int
(
a
)
for
a
in
sys
.
argv
[
1
:]]
rng
=
numpy
.
random
.
RandomState
(
342
)
m
.
w
=
rng
.
rand
(
nout
,
nhid
)
m
.
a
=
rng
.
randn
(
nhid
)
*
0.0
m
.
b
=
rng
.
randn
(
nout
)
*
0.0
x
=
(
rng
.
rand
(
neg
,
nout
)
-
0.5
)
*
1.5
t
=
time
.
time
()
for
i
in
xrange
(
niter
):
err
=
m
.
step
(
x
)
print
'time: '
,
time
.
time
()
-
t
,
'err: '
,
err
theano/benchmark/autoencoder/aa.py
deleted
100644 → 0
浏览文件 @
3679d8e6
from
__future__
import
absolute_import
import
numpy
import
sys
import
time
import
theano
import
theano.tensor
as
T
class
Opt
(
object
):
merge
=
theano
.
gof
.
MergeOptimizer
()
gemm_opt_1
=
theano
.
gof
.
TopoOptimizer
(
theano
.
tensor_opt
.
gemm_pattern_1
)
sqr_opt_0
=
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
mul
,
'x'
,
'x'
),
(
T
.
sqr
,
'x'
)))
ident_opt_0
=
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
sqr
,
(
T
.
sqrt
,
'x'
)),
'x'
,
allow_multiple_clients
=
True
))
ident_opt_1
=
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
sqrt
,
(
T
.
sqr
,
'x'
)),
'x'
,
allow_multiple_clients
=
True
))
ident_muldiv_0
=
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
mul
,
'x'
,
(
T
.
div
,
'y'
,
'x'
)),
'y'
,
allow_multiple_clients
=
True
))
ident_muldiv_1
=
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
mul
,
(
T
.
div
,
'y'
,
'x'
),
'x'
),
'y'
,
allow_multiple_clients
=
True
))
ident_muldiv_2
=
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
div
,
(
T
.
mul
,
'y'
,
'x'
),
'x'
),
'y'
,
allow_multiple_clients
=
True
))
ident_muldiv_3
=
theano
.
gof
.
TopoOptimizer
(
theano
.
gof
.
PatternSub
(
(
T
.
div
,
(
T
.
mul
,
'y'
,
'x'
),
'y'
),
'x'
,
allow_multiple_clients
=
True
))
def
__call__
(
self
,
env
):
self
.
merge
(
env
)
#eliminate identities
if
0
:
print
'SKIPPING optimizations'
else
:
self
.
ident_opt_0
(
env
)
self
.
ident_opt_1
(
env
)
self
.
ident_muldiv_0
(
env
)
self
.
ident_muldiv_1
(
env
)
self
.
ident_muldiv_2
(
env
)
self
.
ident_muldiv_3
(
env
)
self
.
gemm_opt_1
(
env
)
self
.
sqr_opt_0
(
env
)
self
.
merge
(
env
)
def
aa_fn
(
hid_fn
,
out_fn
):
x
=
T
.
matrix
()
# input, target
w
=
T
.
matrix
()
# weights
a
=
T
.
vector
()
# hid bias
b
=
T
.
vector
()
# output bias
hid
=
hid_fn
(
T
.
dot
(
x
,
w
)
+
a
)
out
=
out_fn
(
T
.
dot
(
hid
,
w
.
T
)
+
b
)
err
=
0.5
*
T
.
sum
((
out
-
x
)
**
2
)
params
=
[
w
,
a
,
b
]
gparams
=
T
.
grad
(
err
,
params
)
uparams
=
[
T
.
sub_inplace
(
p
,
0.01
*
gp
)
for
p
,
gp
in
zip
(
params
,
gparams
)]
return
theano
.
function
([
x
,
w
,
a
,
b
],
[
err
]
+
uparams
,
linker
=
theano
.
gof
.
OpWiseCLinker
()
#, linker = theano.gof.PerformLinker()
,
optimizer
=
Opt
()
)
aa_tanh_tanh
=
aa_fn
(
T
.
tanh
,
T
.
tanh
)
neg
,
nout
,
nhid
=
[
int
(
a
)
for
a
in
sys
.
argv
[
1
:]]
rng
=
numpy
.
random
.
RandomState
(
342
)
x
=
(
rng
.
rand
(
neg
,
nout
)
-
0.5
)
*
1.5
w
=
rng
.
rand
(
nout
,
nhid
)
a
=
rng
.
randn
(
nhid
)
*
0.0
b
=
rng
.
randn
(
nout
)
*
0.0
t
=
time
.
time
()
for
i
in
xrange
(
1000
):
err_and_stuff
=
aa_tanh_tanh
(
x
,
w
,
a
,
b
)
print
time
.
time
()
-
t
,
err_and_stuff
[
0
]
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论