提交 bb27565a authored 作者: Frederic Bastien's avatar Frederic Bastien

2 bug fixes. Make choice on the GPU with replace work well.

上级 3a4d1d15
......@@ -507,7 +507,7 @@ def local_gpua_multinomial_wor(op, context_name, inputs, outputs):
p, u, n = inputs
m, = outputs
if ((p.dtype == u.dtype == 'float32') and (m.dtype == 'int64')):
gpu_op = GPUAChoiceFromUniform(op.odtype)
gpu_op = GPUAChoiceFromUniform(**op._props_dict())
return GpuDimShuffle([False, False], [1, 0])(
gpu_op(p, u, n))
......
......@@ -327,30 +327,34 @@ def test_gpu_opt_wor():
p = tensor.fmatrix()
u = tensor.fvector()
n = tensor.iscalar()
m = multinomial.ChoiceFromUniform(odtype='auto')(p, u, n)
assert m.dtype == 'int64', m.dtype
f = function([p, u, n], m, allow_input_downcast=True, mode=mode_with_gpu)
assert any([type(node.op) is GPUAChoiceFromUniform
for node in f.maker.fgraph.toposort()])
n_samples = 3
pval = np.arange(10000 * 4, dtype='float32').reshape((10000, 4)) + 0.1
pval = pval / pval.sum(axis=1)[:, None]
uval = np.ones(pval.shape[0] * n_samples) * 0.5
f(pval, uval, n_samples)
for replace in [False, True]:
m = multinomial.ChoiceFromUniform(odtype='auto',
replace=replace)(p, u, n)
assert m.dtype == 'int64', m.dtype
f = function([p, u, n], m, allow_input_downcast=True,
mode=mode_with_gpu)
assert any([type(node.op) is GPUAChoiceFromUniform
for node in f.maker.fgraph.toposort()])
n_samples = 3
pval = np.arange(10000 * 4, dtype='float32').reshape((10000, 4)) + 0.1
pval = pval / pval.sum(axis=1)[:, None]
uval = np.ones(pval.shape[0] * n_samples) * 0.5
f(pval, uval, n_samples)
# Test with a row, it was failing in the past.
r = tensor.frow()
m = multinomial.ChoiceFromUniform('auto')(r, u, n)
assert m.dtype == 'int64', m.dtype
# Test with a row, it was failing in the past.
r = tensor.frow()
m = multinomial.ChoiceFromUniform('auto', replace=replace)(r, u, n)
assert m.dtype == 'int64', m.dtype
f = function([r, u, n], m, allow_input_downcast=True, mode=mode_with_gpu)
assert any([type(node.op) is GPUAChoiceFromUniform
for node in f.maker.fgraph.toposort()])
pval = np.arange(1 * 4, dtype='float32').reshape((1, 4)) + 0.1
pval = pval / pval.sum(axis=1)[:, None]
uval = np.ones_like(pval[:, 0]) * 0.5
f(pval, uval, 1)
f = function([r, u, n], m, allow_input_downcast=True,
mode=mode_with_gpu)
assert any([type(node.op) is GPUAChoiceFromUniform
for node in f.maker.fgraph.toposort()])
pval = np.arange(1 * 4, dtype='float32').reshape((1, 4)) + 0.1
pval = pval / pval.sum(axis=1)[:, None]
uval = np.ones_like(pval[:, 0]) * 0.5
f(pval, uval, 1)
def test_unpickle_legacy_op():
......
......@@ -212,7 +212,7 @@ class ChoiceFromUniform(MultinomialFromUniform):
"""
__props__ = ("replace",)
__props__ = ("odtype", "replace",)
def __init__(self, odtype, replace=False, *args, **kwargs):
self.replace = replace
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论