Commit 3440c1a0 authored by Christian Fuß's avatar Christian Fuß
Browse files

added REduceSum, ExpandDims and Multiply layer.

parent ebc0296e
Pipeline #187992 failed with stages
in 22 seconds
......@@ -5,28 +5,45 @@ while (depth < maxDepth){
depth ++;
int batchIndex = 0;
for batchEntry in input:
top_k_indices = mx.nd.topk(batchEntry, axis=0, k=width);
top_k_values = mx.nd.topk(batchEntry, ret_typ="value", axis=0, k=width);
for index in range(top_k_indices.size):
int top_k_indices[width];
float top_k_values[width];
for(int i = 0; i < width; i++){
vector<float> batchEntryCopy = batchEntry;
std::nth_element(batchEntry.begin(), batchEntry.begin() + i, batchEntry.end());
top_k_values[i] = batchEntry[i]
std::vector<int>::iterator itr = std::find(batchEntryCopy.begin(), batchEntryCopy.end(), top_k_values[i]);
top_k_indices[i] = std::distance(batchEntryCopy.begin(), itr);
}
for(int index = 0; index < width; index++){
/*print mx.nd.array(top_k_indices[index]) */
/*print top_k_values[index] */
if depth == 1:
if (depth == 1){
/*print mx.nd.array(top_k_indices[index]) */
result = applyBeamSearch(self._networks[netIndex](mx.nd.array(top_k_indices[index])), depth, width, maxDepth,
currProb * top_k_values[index], netIndex, self._networks[netIndex](mx.nd.array(top_k_indices[index])));
_predictor_3_.predict(target_0_, decoder_state_, target_1_, decoder_state_, decoder_output_);
result = applyBeamSearch(self._networks[netIndex](mx.nd.array(top_k_indices[index])), depth, width, maxDepth,
currProb * top_k_values[index], netIndex, self._networks[netIndex](mx.nd.array(top_k_indices[index])));
else:
}else{
result = applyBeamSearch(self._networks[netIndex](mx.nd.array(top_k_indices[index])), depth, width, maxDepth,
currProb * top_k_values[index], netIndex, bestOutput);
}
if depth == maxDepth:
if (depth == maxDepth){
/*print currProb */
if currProb > bestProb:
if (currProb > bestProb){
bestProb = currProb;
bestOutput[batchIndex] = result[batchIndex];
/*print "new bestOutput: ", bestOutput */
}
}
batchIndex ++;
}
}
/*print bestOutput; */
/*cout << bestProb; */
......
......@@ -58,7 +58,7 @@ class ${tc.fileNameWithoutEnding}:
self.networks[${networkInstruction?index}].collect_params().initialize(self.weight_initializer, ctx=context)
self.networks[${networkInstruction?index}].hybridize()
self.networks[${networkInstruction?index}](<#list tc.getStreamInputDimensions(networkInstruction.body, false) as dimensions>
<#if dimensions[0] == "-1">self.networks[${networkInstruction?index}].${dimensions[1]}.begin_state(batch_size=1, ctx=context) <#sep>,<#else>mx.nd.zeros((${tc.join(dimensions, ",")},), ctx=context)</#if> <#sep>, </#list>)
<#if dimensions[0] == "-1">self.networks[${networkInstruction?index}].${dimensions[1]}.begin_state(batch_size=1, ctx=context)<#else>mx.nd.zeros((${tc.join(dimensions, ",")},), ctx=context)</#if> <#sep>, </#list>)
</#if>
</#list>
......
<#if mode == "ARCHITECTURE_DEFINITION">
self.${element.name} = mx.nd.sparse.dot(${tc.join(element.inputs, ",")})
<#include "OutputShape.ftl">
<#elseif mode == "FORWARD_FUNCTION">
${element.name} = self.${element.name}(${tc.join(element.inputs, ",")})
<#if mode == "FORWARD_FUNCTION">
${element.name} = mx.symbol.dot(${element.inputs[0]}, ${element.inputs[1]})
<#elseif mode == "PYTHON_INLINE">
${element.name} = mx.symbol.dot(${element.inputs[0]}, ${element.inputs[1]})
</#if>
\ No newline at end of file
<#assign dim = element.dim?c>
<#if mode == "FORWARD_FUNCTION">
${element.name} = mx.symbol.expand_dims(data = ${element.inputs[0]}, axis=${dim})
<#elseif mode == "PYTHON_INLINE">
${element.name} = mx.symbol.expand_dims(data = ${element.inputs[0]}, axis=${dim})
</#if>
\ No newline at end of file
<#if mode == "FORWARD_FUNCTION">
${element.name} = ${tc.join(element.inputs, " * ")}
<#elseif mode == "PYTHON_INLINE">
${element.name} = ${tc.join(element.inputs, " * ")}
<#elseif mode == "CPP_INLINE">
vector<float> ${element.name}(${element.inputs[0]}.size());
for (size_t i = 0; i != ${element.name}.size(); ++i) {
${element.name}[i] = ${tc.join(element.inputs, " * ", "", "[i]")};
}
</#if>
\ No newline at end of file
<#assign axis = element.axis?c>
<#if mode == "FORWARD_FUNCTION">
${element.name} = mx.symbol.sum(data = ${element.inputs[0]}, axis=${axis})
<#elseif mode == "PYTHON_INLINE">
${element.name} = mx.symbol.sum(data = ${element.inputs[0]}, axis=${axis})
</#if>
\ No newline at end of file
<#assign repeats = element.repeats?c>
<#assign axis = element.axis?c>
<#if mode == "ARCHITECTURE_DEFINITION">
self.${element.name} = mx.nd.repeat(repeats=${repeats}, axis=${axis})
<#include "OutputShape.ftl">
<#elseif mode == "FORWARD_FUNCTION">
${element.name} = self.${element.name}(${input})
<#if mode == "FORWARD_FUNCTION">
${element.name} = mx.symbol.repeat(repeats=${repeats}, axis=${axis})
<#elseif mode == "PYTHON_INLINE">
${element.name} = mx.symbol.repeat(repeats=${repeats}, axis=${axis})
</#if>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment