提交 db81fe35 authored 作者: James Bergstra's avatar James Bergstra

cuda - disabled test_bench_elemwise because it is broken and it is not really a unit test

上级 7d2f6db8
...@@ -261,55 +261,58 @@ class Config(object): ...@@ -261,55 +261,58 @@ class Config(object):
lr = 0.001 lr = 0.001
def test_bench_elemwise(n_iter=1000, **kwargs): if 0:
conf = Config() # commenting out because this is not really a unit test
for k in kwargs: # and it doesn't run correctly because of a deprecated call to cuda.use()
setattr(conf, k, kwargs[k]) def test_bench_elemwise(n_iter=1000, **kwargs):
conf = Config()
if conf.use_gpu: for k in kwargs:
# Skip test if cuda_ndarray is not available. setattr(conf, k, kwargs[k])
from nose.plugins.skip import SkipTest
import theano.sandbox.cuda as cuda_ndarray if conf.use_gpu:
if cuda_ndarray.cuda_enabled == False: # Skip test if cuda_ndarray is not available.
raise SkipTest('Optional package cuda disabled') from nose.plugins.skip import SkipTest
import theano.sandbox.cuda import theano.sandbox.cuda as cuda_ndarray
theano.sandbox.cuda.use() if cuda_ndarray.cuda_enabled == False:
raise SkipTest('Optional package cuda disabled')
debug=False import theano.sandbox.cuda
if isinstance(theano.compile.mode.get_default_mode(), theano.sandbox.cuda.use()
theano.compile.debugmode.DebugMode):
debug=True debug=False
if isinstance(theano.compile.mode.get_default_mode(),
# get symbolic train set theano.compile.debugmode.DebugMode):
s_lr = theano.tensor.fscalar() debug=True
if not debug:
sshape = (None, 784) # get symbolic train set
else: sshape = (None, 3) s_lr = theano.tensor.fscalar()
x = theano.tensor.TensorType(dtype=conf.dtype, broadcastable=(0,0), shape=sshape)() if not debug:
y = theano.tensor.lvector() sshape = (None, 784)
else: sshape = (None, 3)
rng = numpy.random.RandomState(conf.rng_seed) x = theano.tensor.TensorType(dtype=conf.dtype, broadcastable=(0,0), shape=sshape)()
y = theano.tensor.lvector()
if not debug:
layer = Kouh2008.new_filters_expbounds(rng, x, x.type.shape[1], conf.n_hid, conf.n_terms) rng = numpy.random.RandomState(conf.rng_seed)
else:
layer = Kouh2008.new_filters_expbounds(rng, x, x.type.shape[1], 3, 2) if not debug:
n_iter=3 layer = Kouh2008.new_filters_expbounds(rng, x, x.type.shape[1], conf.n_hid, conf.n_terms)
cost = layer.output.mean() else:
layer = Kouh2008.new_filters_expbounds(rng, x, x.type.shape[1], 3, 2)
assert cost.type.ndim == 0 n_iter=3
cost = layer.output.mean()
print layer.params
assert cost.type.ndim == 0
gparams = theano.tensor.grad(cost, layer.params)
updates = [(p, p - s_lr*gp) for p, gp in zip(layer.params, gparams)] print layer.params
train_nll = pfunc([x, y, s_lr], [], updates=updates) gparams = theano.tensor.grad(cost, layer.params)
updates = [(p, p - s_lr*gp) for p, gp in zip(layer.params, gparams)]
xval = theano._asarray(
rng.uniform(size=(conf.ft_batchsize, x.type.shape[1])), train_nll = pfunc([x, y, s_lr], [], updates=updates)
dtype=conf.dtype2,
) xval = theano._asarray(
yval = numpy.arange(conf.ft_batchsize) rng.uniform(size=(conf.ft_batchsize, x.type.shape[1])),
for i in xrange(n_iter): dtype=conf.dtype2,
train_nll(xval, yval, conf.lr) )
yval = numpy.arange(conf.ft_batchsize)
for i in xrange(n_iter):
train_nll(xval, yval, conf.lr)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论