提交 b4dc02d6 authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Replace theano.tensor alias T with tt in tests.gpuarray

上级 b4c51eb2
import numpy as np
import theano
import theano.tensor as T
import theano.tensor as tt
class Model(object):
......@@ -125,16 +125,16 @@ class GRU(Layer):
"""step through processed input to create output"""
def step(inp, s_prev):
i_t = T.nnet.sigmoid(
T.dot(inp, self.W_i) + T.dot(s_prev, self.R_i) + self.b_wi + self.b_ru
i_t = tt.nnet.sigmoid(
tt.dot(inp, self.W_i) + tt.dot(s_prev, self.R_i) + self.b_wi + self.b_ru
)
r_t = T.nnet.sigmoid(
T.dot(inp, self.W_r) + T.dot(s_prev, self.R_r) + self.b_wr + self.b_rr
r_t = tt.nnet.sigmoid(
tt.dot(inp, self.W_r) + tt.dot(s_prev, self.R_r) + self.b_wr + self.b_rr
)
h_hat_t = T.tanh(
T.dot(inp, self.W_h)
+ (r_t * (T.dot(s_prev, self.R_h) + self.b_rh))
h_hat_t = tt.tanh(
tt.dot(inp, self.W_h)
+ (r_t * (tt.dot(s_prev, self.R_h) + self.b_rh))
+ self.b_wh
)
......@@ -229,21 +229,21 @@ class LSTM(Layer):
"""step through processed input to create output"""
def step(x_t, h_tm1, c_tm1):
i_t = T.nnet.sigmoid(
T.dot(x_t, self.W_i) + T.dot(h_tm1, self.R_i) + self.b_wi + self.b_ri
i_t = tt.nnet.sigmoid(
tt.dot(x_t, self.W_i) + tt.dot(h_tm1, self.R_i) + self.b_wi + self.b_ri
)
f_t = T.nnet.sigmoid(
T.dot(x_t, self.W_f) + T.dot(h_tm1, self.R_f) + self.b_wf + self.b_rf
f_t = tt.nnet.sigmoid(
tt.dot(x_t, self.W_f) + tt.dot(h_tm1, self.R_f) + self.b_wf + self.b_rf
)
o_t = T.nnet.sigmoid(
T.dot(x_t, self.W_o) + T.dot(h_tm1, self.R_o) + self.b_ro + self.b_wo
o_t = tt.nnet.sigmoid(
tt.dot(x_t, self.W_o) + tt.dot(h_tm1, self.R_o) + self.b_ro + self.b_wo
)
c_hat_t = T.tanh(
T.dot(x_t, self.W_c) + T.dot(h_tm1, self.R_c) + self.b_wc + self.b_rc
c_hat_t = tt.tanh(
tt.dot(x_t, self.W_c) + tt.dot(h_tm1, self.R_c) + self.b_wc + self.b_rc
)
c_t = f_t * c_tm1 + i_t * c_hat_t
h_t = o_t * T.tanh(c_t)
h_t = o_t * tt.tanh(c_t)
return h_t, c_t
......@@ -275,7 +275,7 @@ class FC(Layer):
self.b = bias_weights((output_dim,), param_list=self.params, name=name + ".b")
def output(self):
return T.dot(self.X, self.W) + self.b
return tt.dot(self.X, self.W) + self.b
class WrapperLayer(Layer):
......
......@@ -4,7 +4,7 @@ pygpu = pytest.importorskip("pygpu")
gpuarray = pygpu.gpuarray
import numpy as np
import theano
import theano.tensor as T
import theano.tensor as tt
from theano.tensor import TensorType
from theano.tensor.basic import alloc
......@@ -217,7 +217,7 @@ def makeTester(
def test_transfer_cpu_gpu():
a = T.fmatrix("a")
a = tt.fmatrix("a")
g = GpuArrayType(dtype="float32", broadcastable=(False, False))("g")
av = np.asarray(rng.rand(5, 4), dtype="float32")
......@@ -254,7 +254,7 @@ def test_transfer_strided():
# This is just to ensure that it works in theano
# libgpuarray has a much more comprehensive suit of tests to
# ensure correctness
a = T.fmatrix("a")
a = tt.fmatrix("a")
g = GpuArrayType(dtype="float32", broadcastable=(False, False))("g")
av = np.asarray(rng.rand(5, 8), dtype="float32")
......@@ -300,7 +300,7 @@ class TestGPUAlloc(TestAlloc):
dtype = "float32"
mode = mode_with_gpu
shared = staticmethod(gpuarray_shared_constructor)
allocs = [GpuAlloc(test_ctx_name), GpuAlloc(test_ctx_name), T.Alloc()]
allocs = [GpuAlloc(test_ctx_name), GpuAlloc(test_ctx_name), tt.Alloc()]
def test_alloc_empty():
......@@ -343,21 +343,21 @@ def test_shape():
assert np.all(f(v) == (3, 4, 5))
if theano.config.mode != "FAST_COMPILE":
assert len(topo) == 4
assert isinstance(topo[0].op, T.opt.Shape_i)
assert isinstance(topo[1].op, T.opt.Shape_i)
assert isinstance(topo[2].op, T.opt.Shape_i)
assert isinstance(topo[3].op, T.opt.MakeVector)
assert isinstance(topo[0].op, tt.opt.Shape_i)
assert isinstance(topo[1].op, tt.opt.Shape_i)
assert isinstance(topo[2].op, tt.opt.Shape_i)
assert isinstance(topo[3].op, tt.opt.MakeVector)
mode = mode_with_gpu.excluding("local_shape_to_shape_i")
f = theano.function([x], x.shape, mode=mode)
topo = f.maker.fgraph.toposort()
assert np.all(f(v) == (3, 4, 5))
assert len(topo) == 1
assert isinstance(topo[0].op, T.Shape)
assert isinstance(topo[0].op, tt.Shape)
def test_gpu_contiguous():
a = T.fmatrix("a")
i = T.iscalar("i")
a = tt.fmatrix("a")
i = tt.iscalar("i")
a_val = np.asarray(np.random.rand(4, 5), dtype="float32")
# The reshape is needed otherwise we make the subtensor on the CPU
# to transfer less data.
......@@ -383,8 +383,8 @@ class TestGPUReshape(TestReshape):
theano.compile.DeepCopyOp,
GpuDimShuffle,
GpuElemwise,
theano.tensor.opt.Shape_i,
theano.tensor.opt.MakeVector,
tt.opt.Shape_i,
tt.opt.MakeVector,
)
assert self.op == GpuReshape
......@@ -418,7 +418,7 @@ class TestGPUJoinAndSplit(TestJoinAndSplit):
# Also test float16 computation at the same time.
rng = np.random.RandomState(seed=utt.fetch_seed())
m = self.shared(rng.rand(4, 6).astype("float16"))
o = T.Split(2)(m, 0, [2, 2])
o = tt.Split(2)(m, 0, [2, 2])
assert o[0].dtype == "float16"
f = theano.function([], o, mode=self.mode)
assert any(
......@@ -433,22 +433,22 @@ class TestGPUJoinAndSplit(TestJoinAndSplit):
def test_gpujoin_gpualloc():
a = T.fmatrix("a")
a = tt.fmatrix("a")
a_val = np.asarray(np.random.rand(4, 5), dtype="float32")
b = T.fmatrix("b")
b = tt.fmatrix("b")
b_val = np.asarray(np.random.rand(3, 5), dtype="float32")
f = theano.function(
[a, b], T.join(0, T.zeros_like(a), T.ones_like(b)) + 4, mode=mode_without_gpu
[a, b], tt.join(0, tt.zeros_like(a), tt.ones_like(b)) + 4, mode=mode_without_gpu
)
f_gpu = theano.function(
[a, b], T.join(0, T.zeros_like(a), T.ones_like(b)), mode=mode_with_gpu
[a, b], tt.join(0, tt.zeros_like(a), tt.ones_like(b)), mode=mode_with_gpu
)
f_gpu2 = theano.function(
[a, b], T.join(0, T.zeros_like(a), T.ones_like(b)) + 4, mode=mode_with_gpu
[a, b], tt.join(0, tt.zeros_like(a), tt.ones_like(b)) + 4, mode=mode_with_gpu
)
assert sum([node.op == T.alloc for node in f.maker.fgraph.toposort()]) == 2
assert sum([node.op == T.join_ for node in f.maker.fgraph.toposort()]) == 1
assert sum([node.op == tt.alloc for node in f.maker.fgraph.toposort()]) == 2
assert sum([node.op == tt.join_ for node in f.maker.fgraph.toposort()]) == 1
assert (
sum([isinstance(node.op, GpuAlloc) for node in f_gpu.maker.fgraph.toposort()])
== 2
......@@ -471,10 +471,10 @@ def test_gpueye():
# allowed.
if M is None:
M = N
N_symb = T.iscalar()
M_symb = T.iscalar()
k_symb = T.iscalar()
out = T.eye(N_symb, M_symb, k_symb, dtype=dtype) + np.array(1).astype(dtype)
N_symb = tt.iscalar()
M_symb = tt.iscalar()
k_symb = tt.iscalar()
out = tt.eye(N_symb, M_symb, k_symb, dtype=dtype) + np.array(1).astype(dtype)
f = theano.function([N_symb, M_symb, k_symb], out, mode=mode_with_gpu)
result = np.asarray(f(N, M, k)) - np.array(1).astype(dtype)
......@@ -511,7 +511,7 @@ def test_hostfromgpu_shape_i():
m = mode_with_gpu.including(
"local_dot_to_dot22", "local_dot22_to_dot22scalar", "specialize"
)
a = T.fmatrix("a")
a = tt.fmatrix("a")
ca = theano.gpuarray.type.GpuArrayType("float32", (False, False))()
av = np.asarray(np.random.rand(5, 4), dtype="float32")
cv = gpuarray.asarray(
......@@ -522,9 +522,9 @@ def test_hostfromgpu_shape_i():
assert any(isinstance(x.op, GpuFromHost) for x in f.maker.fgraph.toposort())
f = theano.function([a], GpuFromHost(test_ctx_name)(a).shape, mode=m)
topo = f.maker.fgraph.toposort()
assert isinstance(topo[0].op, T.opt.Shape_i)
assert isinstance(topo[1].op, T.opt.Shape_i)
assert isinstance(topo[2].op, T.opt.MakeVector)
assert isinstance(topo[0].op, tt.opt.Shape_i)
assert isinstance(topo[1].op, tt.opt.Shape_i)
assert isinstance(topo[2].op, tt.opt.MakeVector)
assert tuple(f(av)) == (5, 4)
f = theano.function([ca], host_from_gpu(ca), mode=m)
......@@ -533,7 +533,7 @@ def test_hostfromgpu_shape_i():
topo = f.maker.fgraph.toposort()
assert isinstance(topo[0].op, theano.compile.Shape_i)
assert isinstance(topo[1].op, theano.compile.Shape_i)
assert isinstance(topo[2].op, theano.tensor.opt.MakeVector)
assert isinstance(topo[2].op, tt.opt.MakeVector)
assert tuple(f(cv)) == (5, 4)
......@@ -544,10 +544,10 @@ def test_Gpujoin_inplace():
# Gpujoin function but all except one of them are empty. In this case
# Gpujoin should work inplace and the output should be the view of the
# non-empty element.
s = T.lscalar()
s = tt.lscalar()
data = np.array([3, 4, 5], dtype=theano.config.floatX)
x = gpuarray_shared_constructor(data, borrow=True)
z = T.zeros((s,))
z = tt.zeros((s,))
join = GpuJoin(view=0)
c = join(0, x, z)
......@@ -560,11 +560,11 @@ def test_Gpujoin_inplace():
def test_gpu_tril_triu():
def check_l(m, k=0):
m_symb = T.matrix(dtype=m.dtype)
k_symb = T.iscalar()
m_symb = tt.matrix(dtype=m.dtype)
k_symb = tt.iscalar()
f = theano.function(
[m_symb, k_symb], T.tril(m_symb, k_symb), mode=mode_with_gpu
[m_symb, k_symb], tt.tril(m_symb, k_symb), mode=mode_with_gpu
)
result = f(m, k)
assert np.allclose(result, np.tril(m, k))
......@@ -572,10 +572,10 @@ def test_gpu_tril_triu():
assert any([isinstance(node.op, GpuTri) for node in f.maker.fgraph.toposort()])
def check_u(m, k=0):
m_symb = T.matrix(dtype=m.dtype)
k_symb = T.iscalar()
m_symb = tt.matrix(dtype=m.dtype)
k_symb = tt.iscalar()
f = theano.function(
[m_symb, k_symb], T.triu(m_symb, k_symb), mode=mode_with_gpu
[m_symb, k_symb], tt.triu(m_symb, k_symb), mode=mode_with_gpu
)
result = f(m, k)
assert np.allclose(result, np.triu(m, k))
......@@ -624,10 +624,10 @@ def test_gputri():
# allowed.
if M is None:
M = N
N_symb = T.iscalar()
M_symb = T.iscalar()
k_symb = T.iscalar()
out = T.tri(N_symb, M_symb, k_symb, dtype=dtype) + np.array(1).astype(dtype)
N_symb = tt.iscalar()
M_symb = tt.iscalar()
k_symb = tt.iscalar()
out = tt.tri(N_symb, M_symb, k_symb, dtype=dtype) + np.array(1).astype(dtype)
f = theano.function([N_symb, M_symb, k_symb], out, mode=mode_with_gpu)
result = np.asarray(f(N, M, k)) - np.array(1).astype(dtype)
assert np.allclose(result, np.tri(N, M_, k, dtype=dtype))
......
......@@ -2,7 +2,7 @@ import pytest
import numpy as np
import theano
import theano.tensor as T
import theano.tensor as tt
import theano.gpuarray
from theano.gpuarray.ctc import gpu_ctc, GpuConnectionistTemporalClassification
......@@ -56,7 +56,7 @@ class TestCTC:
outputs = [cpu_ctc_cost]
if compute_grad:
# Symbolic gradient of CTC cost
cpu_ctc_grad = T.grad(T.mean(cpu_ctc_cost), activations)
cpu_ctc_grad = tt.grad(tt.mean(cpu_ctc_cost), activations)
outputs += [cpu_ctc_grad]
return theano.function([], outputs, mode=mode)
......@@ -65,7 +65,7 @@ class TestCTC:
outputs = [gpu_ctc_cost]
if compute_grad:
# Symbolic gradient of CTC cost
gpu_ctc_grad = T.grad(T.mean(gpu_ctc_cost), activations)
gpu_ctc_grad = tt.grad(tt.mean(gpu_ctc_cost), activations)
outputs += [gpu_ctc_grad]
return theano.function([], outputs, mode=mode_with_gpu)
......
差异被折叠。
......@@ -3,12 +3,11 @@ import pytest
import numpy as np
import theano
import theano.tensor as tt
from functools import partial
from itertools import product
from theano import tensor as T
from theano.tensor.extra_ops import CumOp
from theano.gpuarray.extra_ops import GpuCumOp
from theano.gpuarray.type import get_context
......@@ -33,13 +32,13 @@ class TestGpuCumOp(TestCumOp):
# The CPU implementation is not so accurate, which throws out DebugMode.
# Since propagating .tag.values_eq_approx to the output of every
# GpuFromHost seems overkill, we just relax the rtol for these tests
self.old_rtol = theano.tensor.float32_rtol
theano.tensor.basic.float32_rtol *= 2
self.old_rtol = tt.float32_rtol
tt.float32_rtol *= 2
def teardown_method(self):
super().teardown_method()
# Restore rtol
theano.tensor.basic.float32_rtol = self.old_rtol
tt.float32_rtol = self.old_rtol
@pytest.mark.skipif(
theano.config.floatX != "float32",
......@@ -48,7 +47,7 @@ class TestGpuCumOp(TestCumOp):
@pytest.mark.parametrized("mode", ["mul", "add"])
def test_infer_shape(self, mode):
op_class = partial(self.op_class, mode=mode)
x = T.tensor3("x")
x = tt.tensor3("x")
a = np.random.random((3, 5, 2)).astype(theano.config.floatX)
for axis in range(-len(a.shape), len(a.shape)):
......@@ -58,7 +57,7 @@ class TestGpuCumOp(TestCumOp):
def test_Strides1D(self, mode):
op_class = partial(self.op_class, mode=mode)
np_func = dict(add=np.cumsum, mul=np.cumprod)[mode]
x = T.fvector("x")
x = tt.fvector("x")
for axis in [0, None, -1]:
a = np.random.random((42,)).astype("float32")
......@@ -89,7 +88,7 @@ class TestGpuCumOp(TestCumOp):
def test_Strides2D(self, mode):
np_func = dict(add=np.cumsum, mul=np.cumprod)[mode]
op_class = partial(self.op_class, mode=mode)
x = T.fmatrix("x")
x = tt.fmatrix("x")
for axis in [0, 1, None, -1, -2]:
a = np.random.random((42, 30)).astype("float32")
......@@ -120,7 +119,7 @@ class TestGpuCumOp(TestCumOp):
def test_Strides3D(self, mode):
np_func = dict(add=np.cumsum, mul=np.cumprod)[mode]
op_class = partial(self.op_class, mode=mode)
x = T.ftensor3("x")
x = tt.ftensor3("x")
for axis in [0, 1, 2, None, -1, -2, -3]:
a = np.random.random((42, 30, 25)).astype("float32")
......@@ -153,7 +152,7 @@ class TestGpuCumOp(TestCumOp):
op_class = partial(self.op_class, mode=mode)
block_max_size = self.max_threads_dim0 * 2
x = T.fvector("x")
x = tt.fvector("x")
f = theano.function([x], op_class(axis=0)(x), mode=self.mode)
assert [n for n in f.maker.fgraph.toposort() if isinstance(n.op, GpuCumOp)]
......@@ -176,7 +175,7 @@ class TestGpuCumOp(TestCumOp):
op_class = partial(self.op_class, mode=mode)
block_max_size = self.max_threads_dim0 * 2
x = T.fmatrix("x")
x = tt.fmatrix("x")
for shape_axis, axis in zip([0, 1, 0, 1, 0], [0, 1, None, -1, -2]):
f = theano.function([x], op_class(axis=axis)(x), mode=self.mode)
assert [n for n in f.maker.fgraph.toposort() if isinstance(n.op, GpuCumOp)]
......@@ -217,7 +216,7 @@ class TestGpuCumOp(TestCumOp):
op_class = partial(self.op_class, mode=mode)
block_max_size = self.max_threads_dim0 * 2
x = T.ftensor3("x")
x = tt.ftensor3("x")
for shape_axis, axis in zip([0, 1, 2, 0, 2, 1, 0], [0, 1, 2, None, -1, -2, -3]):
f = theano.function([x], op_class(axis=axis)(x), mode=self.mode)
assert [n for n in f.maker.fgraph.toposort() if isinstance(n.op, GpuCumOp)]
......@@ -267,6 +266,6 @@ class TestGpuCumOp(TestCumOp):
def test_GpuCumOp4D(self, mode):
op_class = partial(self.op_class, mode=mode)
# Should not use the GPU version.
x = T.ftensor4("x")
x = tt.ftensor4("x")
f = theano.function([x], op_class(axis=1)(x), mode=self.mode)
assert [n for n in f.maker.fgraph.toposort() if isinstance(n.op, CumOp)]
......@@ -3,7 +3,7 @@ import numpy as np
import pytest
import theano
import theano.tensor as T
import theano.tensor as tt
import theano.gpuarray.fft
from theano.gpuarray.fft import pygpu_available, skcuda_available, pycuda_available
......@@ -27,7 +27,7 @@ class TestFFT:
def test_1Dfft(self):
inputs_val = np.random.random((1, N)).astype("float32")
x = T.matrix("x", dtype="float32")
x = tt.matrix("x", dtype="float32")
rfft = theano.gpuarray.fft.curfft(x)
f_rfft = theano.function([x], rfft, mode=mode_with_gpu)
res_rfft = f_rfft(inputs_val)
......
import numpy as np
import theano
import theano.tensor as T
import theano.tensor as tt
import tests.unittest_tools as utt
from theano.tensor.nnet import crossentropy_softmax_1hot_with_bias_dx
from theano.gpuarray.nnet import (
GpuCrossentropySoftmaxArgmax1HotWithBias,
GpuCrossentropySoftmax1HotWithBiasDx,
GpuSoftmaxWithBias,
GpuSoftmax,
)
from tests.gpuarray.config import mode_with_gpu, mode_without_gpu
mode_wo_cudnn = mode_with_gpu.excluding("cudnn")
......@@ -29,16 +29,16 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
n_in = 4098
n_out = 4099
y = T.lvector("y")
y = tt.lvector("y")
b = T.fvector("b")
b = tt.fvector("b")
# we precompute the dot with big shape before to allow the test of
# GpuCrossentropySoftmax1HotWithBiasDx to don't fail with the error
# (the launch timed out and was terminated) on GPU card not
# powerful enough. We need the big shape to check for corner
# case.
dot_result = T.fmatrix("dot_result")
dot_result = tt.fmatrix("dot_result")
# Seed numpy.random with config.unittests.rseed
utt.seed_rng()
......@@ -50,10 +50,10 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
dot_value = np.asarray(np.dot(xx, W_values), dtype="float32")
del W_values
p_y_given_x = T.nnet.softmax(dot_result + b)
y_pred = T.argmax(p_y_given_x, axis=-1)
loss = -T.mean(T.log(p_y_given_x)[T.arange(y.shape[0]), y])
dW = T.grad(loss, dot_result)
p_y_given_x = tt.nnet.softmax(dot_result + b)
y_pred = tt.argmax(p_y_given_x, axis=-1)
loss = -tt.mean(tt.log(p_y_given_x)[tt.arange(y.shape[0]), y])
dW = tt.grad(loss, dot_result)
classify = theano.function(
inputs=[y, b, dot_result], outputs=[loss, y_pred, dW], mode=mode_without_gpu
)
......@@ -63,7 +63,7 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
assert any(
[
isinstance(node.op, T.nnet.CrossentropySoftmaxArgmax1HotWithBias)
isinstance(node.op, tt.nnet.CrossentropySoftmaxArgmax1HotWithBias)
for node in classify.maker.fgraph.toposort()
]
)
......@@ -100,11 +100,9 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
dnll_value = np.asarray(np.random.rand(batch_size), dtype="float32")
y_idx_value = np.random.randint(low=0, high=5, size=batch_size)
softmax_output = T.fmatrix()
softmax_output = tt.fmatrix()
softmax_output /= softmax_output.sum(axis=1).reshape(softmax_output.shape[1], 1)
op = theano.tensor.nnet.crossentropy_softmax_1hot_with_bias_dx(
dnll_value, softmax_output, y_idx_value
)
op = crossentropy_softmax_1hot_with_bias_dx(dnll_value, softmax_output, y_idx_value)
cpu_f = theano.function([softmax_output], op, mode=mode_without_gpu)
gpu_f = theano.function([softmax_output], op, mode=mode_with_gpu)
......@@ -113,7 +111,7 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
assert any(
[
isinstance(node.op, T.nnet.CrossentropySoftmax1HotWithBiasDx)
isinstance(node.op, tt.nnet.CrossentropySoftmax1HotWithBiasDx)
for node in cpu_f.maker.fgraph.toposort()
]
)
......@@ -156,14 +154,14 @@ def softmax_with_bias_unittest_template(dtypeInput, dtypeBias):
# TODO: check that we loop when there are too many threads. (THIS IS
# NOT IMPLEMENTED)
x = T.matrix("x", dtype=dtypeInput)
b = T.vector("b", dtype=dtypeBias)
x = tt.matrix("x", dtype=dtypeInput)
b = tt.vector("b", dtype=dtypeBias)
z = T.nnet.softmax_with_bias(x, b)
z = tt.nnet.softmax_with_bias(x, b)
f = theano.function([x, b], z, mode=mode_without_gpu)
f_gpu = theano.function([x, b], z, mode=mode_with_gpu)
assert f.maker.fgraph.toposort()[-1].op == T.nnet.softmax_with_bias
assert f.maker.fgraph.toposort()[-1].op == tt.nnet.softmax_with_bias
assert isinstance(f_gpu.maker.fgraph.toposort()[-2].op, GpuSoftmaxWithBias)
def cmp(n, m):
......@@ -209,12 +207,12 @@ def softmax_unittest_template(dtypeInput):
# We check that we loop when their is too much block
# We use slower code when there isn't enough shared memory
x = T.matrix("x", dtype=dtypeInput)
x = tt.matrix("x", dtype=dtypeInput)
z = T.nnet.softmax(x)
z = tt.nnet.softmax(x)
f = theano.function([x], z, mode=mode_without_gpu)
f_gpu = theano.function([x], z, mode=mode_wo_cudnn)
assert f.maker.fgraph.toposort()[-1].op == T.nnet.softmax_op
assert f.maker.fgraph.toposort()[-1].op == tt.nnet.softmax_op
assert isinstance(f_gpu.maker.fgraph.toposort()[-2].op, GpuSoftmax)
def cmp(n, m):
......@@ -256,7 +254,7 @@ class TestSoftMax:
f = theano.function([x], f_z_out, mode=mode_without_gpu)
f_gpu = theano.function([x_gpu], f_gpu_z_out, mode=self.mode)
self._check_types(f, f_gpu, T.nnet.Softmax, self.gpu_op)
self._check_types(f, f_gpu, tt.nnet.Softmax, self.gpu_op)
# we need to test n>32*1024 to check that we make the block loop.
cmp(1, 5, f, f_gpu)
......@@ -303,16 +301,16 @@ class TestSoftMax:
)
def test_softmax(self):
x = T.fmatrix("x")
z = T.nnet.softmax_op
x = tt.fmatrix("x")
z = tt.nnet.softmax_op
f, f_gpu = self._test_softmax(x, x, z, z, self._cmp)
self._cmp(2 << 15, 5, f, f_gpu)
def test_softmax_shape_0(self):
x = T.fmatrix("x")
z = T.nnet.softmax_op
x = tt.fmatrix("x")
z = tt.nnet.softmax_op
f, f_gpu = self._test_softmax(x, x, z, z, self._cmp)
# Theano can handle that case, but cudnn can't
......
......@@ -5,7 +5,7 @@ import pytest
import numpy as np
import theano
import theano.tensor as T
import theano.tensor as tt
from theano.gpuarray import GpuArrayType
from theano.gpuarray.reduction import GpuMaxAndArgmax
......@@ -96,7 +96,7 @@ class BaseTest:
def get_host_tensor(self):
broadcastable = (False,) * self.tensor_size
return T.tensor(self.dtype, broadcastable)
return tt.tensor(self.dtype, broadcastable)
def get_gpu_tensor(self):
broadcastable = (False,) * self.tensor_size
......@@ -116,7 +116,7 @@ class BaseTest:
M = self.get_host_tensor()
f = theano.function(
[M],
[T.max(M, axis=axis), T.argmax(M, axis=axis)],
[tt.max(M, axis=axis), tt.argmax(M, axis=axis)],
name="shape:" + str(test_tensor.shape) + "/axis:" + str(axis) + "/HOST",
mode=mode_without_gpu,
)
......@@ -131,7 +131,7 @@ class BaseTest:
M = self.get_gpu_tensor()
f = theano.function(
[M],
[T.max(M, axis=axis), T.argmax(M, axis=axis)],
[tt.max(M, axis=axis), tt.argmax(M, axis=axis)],
name="shape:" + str(test_gpu_tensor.shape) + "/axis:" + str(axis) + "/GPU",
mode=mode_with_gpu,
)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论