提交 337609b2 authored 作者: James Bergstra's avatar James Bergstra

manual merge

上级 cfd94c87
...@@ -604,6 +604,13 @@ def local_gpu_conv(node): ...@@ -604,6 +604,13 @@ def local_gpu_conv(node):
logical_img_hw=None logical_img_hw=None
if op.imshp_logical is not None: if op.imshp_logical is not None:
logical_img_hw=op.imshp_logical[1:3] logical_img_hw=op.imshp_logical[1:3]
if logical_img_hw != op.imshp[1:3]:
# this case is not implemented
return None
if op.kshp_logical is not None and op.kshp_logical != op.kshp:
return None
#print op.kshp, op.imshp[1:3]
#print op.kshp_logical, logical_img_hw
ret = GpuConv(border_mode=op.out_mode, ret = GpuConv(border_mode=op.out_mode,
subsample=(op.dx, op.dy), subsample=(op.dx, op.dy),
logical_img_hw=logical_img_hw, logical_img_hw=logical_img_hw,
...@@ -619,11 +626,14 @@ def local_gpu_conv(node): ...@@ -619,11 +626,14 @@ def local_gpu_conv(node):
ret.flops=op.flops ret.flops=op.flops
return ret return ret
if node.op == gpu_from_host: if node.op == gpu_from_host:
#gpu_from_host(conv) -> gpu_conv(gpu_from_host) #gpu_from_host(conv) -> gpu_conv(gpu_from_host)
host_input = node.inputs[0] host_input = node.inputs[0]
if host_input.owner and isinstance(host_input.owner.op, conv.ConvOp): if host_input.owner and isinstance(host_input.owner.op, conv.ConvOp):
gpu_conv = GpuConvOp_from_ConvOp(host_input.owner.op) gpu_conv = GpuConvOp_from_ConvOp(host_input.owner.op)
if gpu_conv is None:
return
img, kern = host_input.owner.inputs img, kern = host_input.owner.inputs
#in some case the ConvOp broadcast the last 2 dimensions differently then the gpu ConvOp #in some case the ConvOp broadcast the last 2 dimensions differently then the gpu ConvOp
return [tensor.patternbroadcast(gpu_conv(gpu_from_host(img), gpu_from_host(kern)), return [tensor.patternbroadcast(gpu_conv(gpu_from_host(img), gpu_from_host(kern)),
...@@ -636,6 +646,8 @@ def local_gpu_conv(node): ...@@ -636,6 +646,8 @@ def local_gpu_conv(node):
kern_on_gpu = (kern.owner and kern.owner.op == host_from_gpu) kern_on_gpu = (kern.owner and kern.owner.op == host_from_gpu)
if img_on_gpu or kern_on_gpu: if img_on_gpu or kern_on_gpu:
gpu_conv = GpuConvOp_from_ConvOp(node.op) gpu_conv = GpuConvOp_from_ConvOp(node.op)
if gpu_conv is None:
return
#in some case the ConvOp broadcast the last 2 dimensions differently then the gpu ConvOp #in some case the ConvOp broadcast the last 2 dimensions differently then the gpu ConvOp
return [tensor.patternbroadcast(host_from_gpu(gpu_conv(gpu_from_host(img), return [tensor.patternbroadcast(host_from_gpu(gpu_conv(gpu_from_host(img),
gpu_from_host(kern))), gpu_from_host(kern))),
......
...@@ -161,8 +161,6 @@ class mrg_uniform_base(Op): ...@@ -161,8 +161,6 @@ class mrg_uniform_base(Op):
def grad(self,inputs,ograd): def grad(self,inputs,ograd):
return [None for i in inputs] return [None for i in inputs]
def c_code_cache_version(self):
return (2,)
class mrg_uniform(mrg_uniform_base): class mrg_uniform(mrg_uniform_base):
#CPU VERSION #CPU VERSION
...@@ -354,6 +352,8 @@ class mrg_uniform(mrg_uniform_base): ...@@ -354,6 +352,8 @@ class mrg_uniform(mrg_uniform_base):
} }
//////// </ code generated by mrg_uniform> //////// </ code generated by mrg_uniform>
""" %locals() """ %locals()
def c_code_cache_version(self):
return (1,)
class GPU_mrg_uniform(mrg_uniform_base): class GPU_mrg_uniform(mrg_uniform_base):
#GPU VERSION #GPU VERSION
...@@ -564,6 +564,8 @@ class GPU_mrg_uniform(mrg_uniform_base): ...@@ -564,6 +564,8 @@ class GPU_mrg_uniform(mrg_uniform_base):
//////// </ code generated by mrg_uniform> //////// </ code generated by mrg_uniform>
""" %locals() """ %locals()
def c_code_cache_version(self):
return (3,)
class MRG_RandomStreams(object): class MRG_RandomStreams(object):
"""Module component with similar interface to numpy.random (numpy.random.RandomState)""" """Module component with similar interface to numpy.random (numpy.random.RandomState)"""
...@@ -639,7 +641,8 @@ class MRG_RandomStreams(object): ...@@ -639,7 +641,8 @@ class MRG_RandomStreams(object):
r = r/6 # chosen as fastest for rbm_benchmark r = r/6 # chosen as fastest for rbm_benchmark
return r return r
print >> sys.stderr, "MRG_RandomStreams Can't determine #streams from size (%s), guessing 30*256"%str(size) print >> sys.stderr, ("MRG_RandomStreams Can't determine #streams from "
"size (%s), guessing 30*256")%str(size)
return 30*256 return 30*256
def pretty_return(self, node_rstate, new_rstate, sample): def pretty_return(self, node_rstate, new_rstate, sample):
...@@ -658,12 +661,17 @@ class MRG_RandomStreams(object): ...@@ -658,12 +661,17 @@ class MRG_RandomStreams(object):
ndim may be a plain integer to supplement the missing ndim may be a plain integer to supplement the missing
information. information.
:param: size: Can be a list of integer or Theano variable(ex: the shape of other Theano Variable) :param: size: Can be a list of integer or Theano variable
TODO: can size be None? (ex: the shape of other Theano Variable)
TODO: can size be None?
""" """
if isinstance(size, tuple): if isinstance(size, tuple):
assert all([isinstance(i,int) or isinstance(i,Variable) for i in size]), "size must be a tuple of int or a Theano variable" msg = "size must be a tuple of int or a Theano variable"
else: assert isinstance(size, Variable) and size.ndim==1, "size must be a tuple of int or a Theano variable" assert all([isinstance(i,int) or isinstance(i,Variable)
for i in size]), msg
else:
msg = "size must be a tuple of int or a Theano variable"
assert isinstance(size, Variable) and size.ndim==1, msg
if nstreams is None: if nstreams is None:
nstreams = self.n_streams(size) nstreams = self.n_streams(size)
...@@ -677,12 +685,15 @@ class MRG_RandomStreams(object): ...@@ -677,12 +685,15 @@ class MRG_RandomStreams(object):
tmp_float_buf = numpy.frombuffer(rstates.data, dtype='float32') tmp_float_buf = numpy.frombuffer(rstates.data, dtype='float32')
assert tmp_float_buf.shape == rstates.shape assert tmp_float_buf.shape == rstates.shape
assert tmp_float_buf.data[:24] == rstates.data[:24] assert tmp_float_buf.data[:24] == rstates.data[:24]
node_rstate = float32_shared_constructor(tmp_float_buf) # transfer to device # transfer to device
node_rstate = float32_shared_constructor(tmp_float_buf)
assert isinstance(node_rstate.type, CudaNdarrayType) assert isinstance(node_rstate.type, CudaNdarrayType)
# we can't use the normal mrg_uniform constructor + later optimization # we can't use the normal mrg_uniform constructor + later
# optimization
# because of the tmp_float_buf hack above. There is # because of the tmp_float_buf hack above. There is
# currently no Theano node that will do a frombuffer reinterpretation. # currently no Theano node that will do a frombuffer
# reinterpretation.
u = self.pretty_return(node_rstate, u = self.pretty_return(node_rstate,
*GPU_mrg_uniform.new(node_rstate, ndim, dtype, size)) *GPU_mrg_uniform.new(node_rstate, ndim, dtype, size))
else: else:
...@@ -706,13 +717,15 @@ class MRG_RandomStreams(object): ...@@ -706,13 +717,15 @@ class MRG_RandomStreams(object):
def multinomial(self, size=None, n=1, pvals=None, ndim=None, dtype='int64'): def multinomial(self, size=None, n=1, pvals=None, ndim=None, dtype='int64'):
""" """
Sample `n` (currently `n` needs to be 1) times from a multinomial distribution defined by Sample `n` (currently `n` needs to be 1) times from a multinomial
probabilities pvals. distribution defined by probabilities pvals.
Example : pvals = [[.98,.01, .01], [.01, .98 .01]] will probably result in [[1,0,0],[0,1,0]]. Example : pvals = [[.98,.01, .01], [.01, .98 .01]] will probably result
in [[1,0,0],[0,1,0]].
.. note:: .. note::
`size` and `ndim` are only there keep the same signature as other uniform, binomial, normal, etc. `size` and `ndim` are only there keep the same signature as other
uniform, binomial, normal, etc.
todo : adapt multinomial to take that into account todo : adapt multinomial to take that into account
""" """
if pvals is None: if pvals is None:
...@@ -743,7 +756,8 @@ class MRG_RandomStreams(object): ...@@ -743,7 +756,8 @@ class MRG_RandomStreams(object):
n_samples += 1 n_samples += 1
evened = True evened = True
else: else:
n_samples = prod(size)+(prod(size)%2)#if even, don't change, if odd, +1 #if even, don't change, if odd, +1
n_samples = prod(size)+(prod(size)%2)
flattened = self.uniform(size=(n_samples,), dtype=dtype) flattened = self.uniform(size=(n_samples,), dtype=dtype)
if constant: if constant:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论