提交 ed170280 authored 作者: Vincent Michalski's avatar Vincent Michalski

applied changes suggested by lamblin and nouiz

上级 6f030393
...@@ -329,9 +329,11 @@ def make_gpu_optimizer(op, to_gpu): ...@@ -329,9 +329,11 @@ def make_gpu_optimizer(op, to_gpu):
new_inp = list(node.inputs) new_inp = list(node.inputs)
for idx in to_gpu: for idx in to_gpu:
new_inp[idx] = cuda.gpu_from_host(new_inp[idx]) new_inp[idx] = cuda.gpu_from_host(new_inp[idx])
new_node = cuda.host_from_gpu(op()(*new_inp)) result_node = op()(*new_inp)
copy_stack_trace(node.outputs[0], new_node) copy_stack_trace(node.outputs[0], result_node)
return [new_node] transfer_node = cuda.host_from_gpu(result_node)
copy_stack_trace(node.outputs[0], transfer_node)
return [transfer_node]
if node.op == cuda.gpu_from_host: if node.op == cuda.gpu_from_host:
# gpu_from_host(op) -> op(gpu_from_host) # gpu_from_host(op) -> op(gpu_from_host)
host_input = node.inputs[0] host_input = node.inputs[0]
...@@ -342,7 +344,7 @@ def make_gpu_optimizer(op, to_gpu): ...@@ -342,7 +344,7 @@ def make_gpu_optimizer(op, to_gpu):
for idx in to_gpu: for idx in to_gpu:
new_inp[idx] = cuda.gpu_from_host(new_inp[idx]) new_inp[idx] = cuda.gpu_from_host(new_inp[idx])
new_node = op()(*new_inp) new_node = op()(*new_inp)
copy_stack_trace(node.outputs[0], new_node) copy_stack_trace(host_input, new_node)
return [new_node] return [new_node]
return False return False
local_to_gpu.__name__ = "local_to_gpu_" + op.__name__ local_to_gpu.__name__ = "local_to_gpu_" + op.__name__
......
...@@ -753,7 +753,7 @@ def local_logsoftmax(node): ...@@ -753,7 +753,7 @@ def local_logsoftmax(node):
new_op = LogSoftmax() new_op = LogSoftmax()
ret = new_op(inVars) ret = new_op(inVars)
ret .tag.values_eq_approx = values_eq_approx_remove_inf ret .tag.values_eq_approx = values_eq_approx_remove_inf
copy_stack_trace(node.outputs[0], ret) copy_stack_trace([node.inputs[0], node.outputs[0]], ret)
return [ret] return [ret]
...@@ -867,7 +867,6 @@ def local_softmax_with_bias(node): ...@@ -867,7 +867,6 @@ def local_softmax_with_bias(node):
if sm_bias.type == node.outputs[0].type: if sm_bias.type == node.outputs[0].type:
# This condition is not always true. See the test # This condition is not always true. See the test
# nnet/tests/test_nnet.py:T_SoftmaxWithBias.test_broadcast # nnet/tests/test_nnet.py:T_SoftmaxWithBias.test_broadcast
copy_stack_trace(node.outputs[0], sm_bias)
return [sm_bias] return [sm_bias]
......
...@@ -955,8 +955,12 @@ def local_inv_1_plus_exp(node): ...@@ -955,8 +955,12 @@ def local_inv_1_plus_exp(node):
sigmoid( sigmoid(
tensor.neg(nonconsts[0].owner.inputs[0])), tensor.neg(nonconsts[0].owner.inputs[0])),
scalar_inputs) scalar_inputs)
# keep stack trace # keep combined stack traces of
copy_stack_trace(node.outputs[0], out) # exp(x): nonconsts[0],
# 1 + exp(x): inv_arg,
# 1 / (1 + exp(x)): node.outputs[0]
copy_stack_trace(
[nonconsts[0], inv_arg, node.outputs[0]], out)
return out return out
# Registration is below, and conditional. # Registration is below, and conditional.
...@@ -979,7 +983,7 @@ def local_1msigmoid(node): ...@@ -979,7 +983,7 @@ def local_1msigmoid(node):
return return
if numpy.allclose(numpy.sum(val_l), 1): if numpy.allclose(numpy.sum(val_l), 1):
out = sigmoid(-sub_r.owner.inputs[0]) out = sigmoid(-sub_r.owner.inputs[0])
copy_stack_trace(node.outputs[0], out) copy_stack_trace([sub_r, node.outputs[0]], out)
return [out] return [out]
register_local_1msigmoid = False register_local_1msigmoid = False
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论