Add _cop_num_outputs to GPU CTC and rename context to context_name

上级 b9243185
...@@ -282,17 +282,3 @@ int APPLY_SPECIFIC(ctc_cost_gpu)(PyGpuArrayObject * in_activations, ...@@ -282,17 +282,3 @@ int APPLY_SPECIFIC(ctc_cost_gpu)(PyGpuArrayObject * in_activations,
return 0; return 0;
} }
int APPLY_SPECIFIC(ctc_cost_gpu_no_grad)(PyGpuArrayObject * in_activations,
PyArrayObject * in_labels,
PyArrayObject * in_input_lengths,
PyGpuArrayObject ** out_costs,
PyGpuContextObject * gpu_context)
{
return APPLY_SPECIFIC(ctc_cost_gpu)(in_activations,
in_labels,
in_input_lengths,
out_costs,
NULL,
gpu_context);
}
...@@ -30,14 +30,15 @@ class GpuConnectionistTemporalClassification(gof.COp): ...@@ -30,14 +30,15 @@ class GpuConnectionistTemporalClassification(gof.COp):
""" """
__props__ = ('compute_grad',) __props__ = ('compute_grad',)
_cop_num_inputs = 3
_cop_num_outputs = 2
func_file = "./c_code/ctc_wrapper.c" func_file = "./c_code/ctc_wrapper.c"
func_name = "APPLY_SPECIFIC(ctc_cost_gpu)" func_name = "APPLY_SPECIFIC(ctc_cost_gpu)"
params_type = gpu_context_type params_type = gpu_context_type
def __init__(self, compute_grad=True): def __init__(self, compute_grad=True):
if not compute_grad:
self.func_name = "APPLY_SPECIFIC(ctc_cost_gpu_no_grad)"
self.compute_grad = compute_grad self.compute_grad = compute_grad
gof.COp.__init__(self, self.func_file, self.func_name) gof.COp.__init__(self, self.func_file, self.func_name)
...@@ -90,10 +91,10 @@ class GpuConnectionistTemporalClassification(gof.COp): ...@@ -90,10 +91,10 @@ class GpuConnectionistTemporalClassification(gof.COp):
'GpuConnectionistTemporalClassification Op ' 'GpuConnectionistTemporalClassification Op '
'can not be constructed.') 'can not be constructed.')
context = infer_context_name(activations, labels, input_lengths) context_name = infer_context_name(activations)
t_activations = as_gpuarray_variable(activations, t_activations = as_gpuarray_variable(activations,
context_name=context) context_name=context_name)
# Ensure activations array is C-contiguous # Ensure activations array is C-contiguous
t_activations = gpu_contiguous(t_activations) t_activations = gpu_contiguous(t_activations)
...@@ -115,13 +116,13 @@ class GpuConnectionistTemporalClassification(gof.COp): ...@@ -115,13 +116,13 @@ class GpuConnectionistTemporalClassification(gof.COp):
costs = GpuArrayType(dtype='float32', costs = GpuArrayType(dtype='float32',
broadcastable=(False,), broadcastable=(False,),
context_name=context)() context_name=context_name)()
outputs = [costs] outputs = [costs]
if self.compute_grad: if self.compute_grad:
gradients = GpuArrayType(dtype='float32', gradients = GpuArrayType(dtype='float32',
broadcastable=(False, False, False,), broadcastable=(False, False, False,),
context_name=context)() context_name=context_name)()
outputs += [gradients] outputs += [gradients]
return theano.Apply(self, inputs=[t_activations, t_labels, t_input_lengths], return theano.Apply(self, inputs=[t_activations, t_labels, t_input_lengths],
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论