提交 368b6d65 authored 作者: Frederic's avatar Frederic

make test less verbose.

上级 ec61b4ed
......@@ -30,7 +30,7 @@ def advantage(cpu_dt, gpu_dt):
return cpu_dt / gpu_dt
def test_host_to_device():
print >>sys.stdout, 'starting test_host_to_dev'
#print >>sys.stdout, 'starting test_host_to_dev'
for shape in ((), (3,), (2,3), (3,4,5,6)):
a = theano._asarray(numpy.random.rand(*shape), dtype='float32')
b = cuda_ndarray.CudaNdarray(a)
......@@ -84,7 +84,7 @@ def test_add_iadd_idiv():
asum = a0 + a1
t1 = time.time()
cpu_dt = t1 - t0
print shape, 'adding ', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
#print shape, 'adding ', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
assert numpy.allclose(asum, numpy.asarray(bsum))
#test not contiguous version.
......@@ -122,7 +122,7 @@ def test_add_iadd_idiv():
a0 += a1
t1 = time.time()
cpu_dt = t1 - t0
print shape, 'adding inplace', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
#print shape, 'adding inplace', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
assert numpy.allclose(a0, numpy.asarray(b0))
assert numpy.allclose(a0, a0_orig + a1)
......@@ -144,7 +144,7 @@ def test_add_iadd_idiv():
assert numpy.allclose(a0, ((a0_orig+a1)/a1+a1[..., ::-1])/a1[..., ::-1])
def test_exp():
print >>sys.stdout, 'starting test_exp'
#print >>sys.stdout, 'starting test_exp'
for shape in ((), (3,), (2,3), (1,10000000),(10,1000000), (100,100000),(1000,10000),(10000,1000)):
a0 = theano._asarray(numpy.random.rand(*shape), dtype='float32')
a1 = a0.copy()
......@@ -158,26 +158,26 @@ def test_exp():
asum = numpy.exp(a1)
t1 = time.time()
cpu_dt = t1 - t0
print shape, 'adding ', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
#print shape, 'adding ', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
#c = numpy.asarray(b0+b1)
if asum.shape:
assert numpy.allclose(asum, numpy.asarray(bsum))
def test_copy():
print >>sys.stdout, 'starting test_copy'
#print >>sys.stdout, 'starting test_copy'
shape = (500,499)
a = theano._asarray(numpy.random.rand(*shape), dtype='float32')
print >>sys.stdout, '.. creating device object'
#print >>sys.stdout, '.. creating device object'
b = cuda_ndarray.CudaNdarray(a)
print >>sys.stdout, '.. copy'
#print >>sys.stdout, '.. copy'
c = copy.copy(b)
print >>sys.stdout, '.. deepcopy'
#print >>sys.stdout, '.. deepcopy'
d = copy.deepcopy(b)
print >>sys.stdout, '.. comparisons'
#print >>sys.stdout, '.. comparisons'
assert numpy.allclose(a, numpy.asarray(b))
assert numpy.allclose(a, numpy.asarray(c))
assert numpy.allclose(a, numpy.asarray(d))
......@@ -268,7 +268,7 @@ class test_DimShuffle(unittest.TestCase):
def test_dot():
print >>sys.stdout, 'starting test_dot'
#print >>sys.stdout, 'starting test_dot'
utt.seed_rng()
rng = numpy.random.RandomState(utt.fetch_seed())
......@@ -320,8 +320,8 @@ def test_sum():
a0sum = a0.sum(axis=0)
b0sum = b0.reduce_sum([1,0])
print 'asum\n',a0sum
print 'bsum\n',numpy.asarray(b0sum)
#print 'asum\n',a0sum
#print 'bsum\n',numpy.asarray(b0sum)
assert numpy.allclose(a0.sum(axis=0), numpy.asarray(b0.reduce_sum([1,0])))
assert numpy.allclose(a0.sum(axis=1), numpy.asarray(b0.reduce_sum([0,1])))
......@@ -932,7 +932,7 @@ def test_base():
c = a[0]
d = c[:,0]
print d.shape
#print d.shape
assert c.base is a
assert d.base is a
......
......@@ -103,7 +103,7 @@ def run_nnet(use_gpu, n_batch=60, n_in=1024, n_hid=2048, n_out=10,
mode = get_mode(use_gpu)
print 'building pfunc ...'
#print 'building pfunc ...'
train = pfunc([x, y, lr], [loss], mode=mode,
updates=[(p, p - g) for p, g in izip(params, gparams)])
......@@ -138,9 +138,9 @@ def test_run_nnet():
theano.gradient.numeric_grad.abs_rel_err(rval_gpu,
rval_cpu)
max_abs_diff = abs_diff.max()
print "max abs diff=%e max rel diff=%e n_in=%d n_hid=%d" % (
max_abs_diff, rel_diff.max(), n_in, n_hid)
print "time cpu: %f, time gpu: %f, speed up %f" % (tc, tg, tc / tg)
#print "max abs diff=%e max rel diff=%e n_in=%d n_hid=%d" % (
# max_abs_diff, rel_diff.max(), n_in, n_hid)
#print "time cpu: %f, time gpu: %f, speed up %f" % (tc, tg, tc / tg)
rtol = 1e-4
if n_in * n_hid >= 2048 * 4096:
rtol = 7e-4
......@@ -192,14 +192,14 @@ def run_conv_nnet1(use_gpu):
hid_flat = hid.reshape((n_batch, n_hid))
out = tensor.tanh(tensor.dot(hid_flat, v)+c)
loss = tensor.sum(0.5 * (out-y)**2 * lr)
print 'loss type', loss.type
#print 'loss type', loss.type
params = [w, b, v, c]
gparams = tensor.grad(loss, params)
mode = get_mode(use_gpu)
print 'building pfunc ...'
#print 'building pfunc ...'
train = pfunc([x,y,lr], [loss], mode=mode, updates=[(p, p-g) for p,g in zip(params, gparams)])
# for i, n in enumerate(train.maker.env.toposort()):
......@@ -211,7 +211,7 @@ def run_conv_nnet1(use_gpu):
for i in xrange(n_train):
rval = train(xval, yval, lr)
print 'training done'
#print 'training done'
print_mode(mode)
return rval
......@@ -281,14 +281,14 @@ def run_conv_nnet2(use_gpu): # pretend we are training LeNet for MNIST
hid_flat = hid1.reshape((n_batch, n_hid))
out = tensor.tanh(tensor.dot(hid_flat, v)+c)
loss = tensor.sum(0.5 * (out-y)**2 * lr)
print 'loss type', loss.type
#print 'loss type', loss.type
params = [w0, b0, w1, b1, v, c]
gparams = tensor.grad(loss, params)
mode = get_mode(use_gpu)
print 'building pfunc ...'
#print 'building pfunc ...'
train = pfunc([x,y,lr], [loss], mode=mode, updates=[(p, p-g) for p,g in zip(params, gparams)])
# for i, n in enumerate(train.maker.env.toposort()):
......@@ -310,7 +310,7 @@ def test_conv_nnet2():
if True:
utt.seed_rng()
rval_cpu = run_conv_nnet2(False)
print rval_cpu[0], rval_gpu[0],rval_cpu[0]-rval_gpu[0]
#print rval_cpu[0], rval_gpu[0],rval_cpu[0]-rval_gpu[0]
assert numpy.allclose(rval_cpu, rval_gpu,rtol=1e-4,atol=1e-4)
......@@ -350,9 +350,9 @@ def build_conv_nnet2_classif(use_gpu, isize, ksize, n_batch,
v = shared_fn(0.01*my_randn(n_hid, n_out), 'v')
c = shared_fn(my_zeros(n_out), 'c')
print 'ALLOCATING ARCH: w0 shape', w0.get_value(borrow=True).shape
print 'ALLOCATING ARCH: w1 shape', w1.get_value(borrow=True).shape
print 'ALLOCATING ARCH: v shape', v.get_value(borrow=True).shape
#print 'ALLOCATING ARCH: w0 shape', w0.get_value(borrow=True).shape
#print 'ALLOCATING ARCH: w1 shape', w1.get_value(borrow=True).shape
#print 'ALLOCATING ARCH: v shape', v.get_value(borrow=True).shape
x = tensor.Tensor(dtype='float32', broadcastable=(0,1,0,0))('x')
y = tensor.fmatrix('y')
......@@ -375,14 +375,14 @@ def build_conv_nnet2_classif(use_gpu, isize, ksize, n_batch,
hid_flat = hid1.reshape((n_batch, n_hid))
out = tensor.nnet.softmax(tensor.dot(hid_flat, v)+c)
loss = tensor.sum(tensor.nnet.crossentropy_categorical_1hot(out, tensor.argmax(y, axis=1)) * lr)
print 'loss type', loss.type
#print 'loss type', loss.type
params = [w0, b0, w1, b1, v, c]
gparams = tensor.grad(loss, params, warn_type=True)
mode = get_mode(use_gpu, check_isfinite)
print 'building pfunc ...'
#print 'building pfunc ...'
train = pfunc([x,y,lr], [loss], mode=mode, updates=[(p, p-g) for p,g in zip(params, gparams)])
if verbose:
......@@ -437,9 +437,9 @@ def run_conv_nnet2_classif(use_gpu, seed, isize, ksize, bsize,
print pickle.dumps(mode)
print "END %s profile mode dump" % device
print "%s time: %.3f" % (device, t1-t0)
print "estimated time for one pass through MNIST with %s: %f" % (
device, (t1-t0) * (60000.0 / (n_train*bsize)))
#print "%s time: %.3f" % (device, t1-t0)
#print "estimated time for one pass through MNIST with %s: %f" % (
# device, (t1-t0) * (60000.0 / (n_train*bsize)))
def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize,
......@@ -465,7 +465,7 @@ def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize,
orig_float32_atol = theano.tensor.basic.float32_atol
try:
if float_atol:
print "float_atol", float_atol
#print "float_atol", float_atol
theano.tensor.basic.float32_atol = float_atol
if gpu_only and cpu_only:
......@@ -565,12 +565,12 @@ def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize,
print pickle.dumps(gpu_mode)
print "END GPU profile mode dump"
print "CPU time: %.3f, GPU time: %.3f, speed up %f" % (
(time_cpu, time_gpu, time_cpu/time_gpu))
print "Estimated time for one pass through MNIST with CPU: %f" % (
(time_cpu * (60000.0 / (n_train*bsize))))
print "Estimated time for one pass through MNIST with GPU: %f" % (
(time_gpu * (60000.0 / (n_train*bsize))))
#print "CPU time: %.3f, GPU time: %.3f, speed up %f" % (
# (time_cpu, time_gpu, time_cpu/time_gpu))
#print "Estimated time for one pass through MNIST with CPU: %f" % (
# (time_cpu * (60000.0 / (n_train*bsize))))
#print "Estimated time for one pass through MNIST with GPU: %f" % (
# (time_gpu * (60000.0 / (n_train*bsize))))
# Default parameters for all subsequent tests
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论