diff --git a/cmake/generic.cmake b/cmake/generic.cmake index 83e3d155d038cc65f3e372f0e4ba0aaee2e29690..a30cdeff62562fb349e30e0dce073408ccbcc48d 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -93,7 +93,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) if(NOT APPLE) find_package(Threads REQUIRED) link_libraries(${CMAKE_THREAD_LIBS_INIT}) - set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl") + set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl -lrt") endif(NOT APPLE) function(merge_static_libs TARGET_NAME) diff --git a/paddle/gserver/gradientmachines/RecurrentGradientMachine.cpp b/paddle/gserver/gradientmachines/RecurrentGradientMachine.cpp index 4cb5b8ec2dbb93cc17075079754c2f1b8cd392e5..8cc08eb20857daaf98e40afe0dea8ba3a35f90e0 100644 --- a/paddle/gserver/gradientmachines/RecurrentGradientMachine.cpp +++ b/paddle/gserver/gradientmachines/RecurrentGradientMachine.cpp @@ -1395,17 +1395,23 @@ void RecurrentGradientMachine::createDataOutlinkCopySizeInfo( batchMachineStartPos_.resize(totalSeqNum + 1, 0); if (isSeq) { ICpuGpuVectorPtr inputSeqStartPos = outArgs[0].sequenceStartPositions; - CHECK_EQ(inputSeqStartPos->getSize() - 1, finalPaths_.size()); + CHECK_EQ(static_cast(inputSeqStartPos->getSize() - 1), + getBeamSize() > 1 ? finalPaths_.size() : finalPaths_[0].size()); int* starts = inputSeqStartPos->getMutableData(false); int seqId = 0; for (int i = 0; i < finalPaths_.size(); ++i) { for (int j = 0; j < finalPaths_[i].size(); ++j) { - copySize[seqId] = starts[i + 1] - starts[i]; + copySize[seqId] = getBeamSize() > 1 ? starts[i + 1] - starts[i] + : starts[j + 1] - starts[j]; batchMachineStartPos_[seqId + 1] = batchMachineStartPos_[seqId] + finalPaths_[i][j].ids.size(); seqId++; } } + } else { + for (size_t i = 0; i < finalPaths_[0].size(); ++i) + batchMachineStartPos_[i + 1] = + batchMachineStartPos_[i] + finalPaths_[0][i].ids.size(); } } diff --git a/paddle/gserver/gradientmachines/RecurrentGradientMachine.h b/paddle/gserver/gradientmachines/RecurrentGradientMachine.h index bd096770b75b4f44488777c0c0e27b14f86b2015..a3d04b207c0d84ea9c77c646314efedcd49772b1 100644 --- a/paddle/gserver/gradientmachines/RecurrentGradientMachine.h +++ b/paddle/gserver/gradientmachines/RecurrentGradientMachine.h @@ -477,8 +477,6 @@ private: * outlinks. * @note In beam search, only one generated sequence with the hightest log * probabilites are retained. - * @param machineIdVec : select a row of output matrix in each frame - * that the generation process expanded. */ void createDataOutlink(); void createDataOutlinkCopySizeInfo(bool isSeq, diff --git a/paddle/parameter/Argument.cpp b/paddle/parameter/Argument.cpp index e7522def08cb32b5585e676211719621883c70b8..f45a51d7b1836f02945f5efa3b061abc5fe7f974 100644 --- a/paddle/parameter/Argument.cpp +++ b/paddle/parameter/Argument.cpp @@ -310,8 +310,8 @@ void Argument::concat(const std::vector& args, auto copyIds = [batchSize, stream](IVectorPtr& dst, const IVectorPtr& src, - int startRow, - int pos, + int desStartRow, + int srcStartRow, int size, bool useGpu) { if (!src) { @@ -319,13 +319,14 @@ void Argument::concat(const std::vector& args, return; } IVector::resizeOrCreate(dst, batchSize, useGpu); - dst->subVec(startRow, size)->copyFrom(*src->subVec(pos, size), stream); + dst->subVec(desStartRow, size) + ->copyFrom(*src->subVec(srcStartRow, size), stream); }; auto copyStrs = [batchSize, stream](SVectorPtr& dst, const SVectorPtr& src, - int startRow, - int pos, + int desStartRow, + int srcStartRow, int size, bool useGpu) { if (!src) { @@ -337,8 +338,9 @@ void Argument::concat(const std::vector& args, } else { dst->resize(batchSize); } - std::copy( - src->begin() + pos, src->begin() + pos + size, dst->begin() + startRow); + std::copy(src->begin() + srcStartRow, + src->begin() + srcStartRow + size, + dst->begin() + desStartRow); }; dataId = args[0].dataId; diff --git a/python/paddle/trainer_config_helpers/networks.py b/python/paddle/trainer_config_helpers/networks.py index 6cddf547a72337cd86e566bca93495f76a8716bc..30c826ffc8e7e5ef384520e6c95cd69584df971d 100755 --- a/python/paddle/trainer_config_helpers/networks.py +++ b/python/paddle/trainer_config_helpers/networks.py @@ -1370,7 +1370,14 @@ def simple_attention(encoded_sequence, param_attr=softmax_param_attr, name="%s_softmax" % name, bias_attr=False) - return attention_weight + + scaled = scaling_layer( + weight=attention_weight, + input=encoded_sequence, + name='%s_scaling' % name) + return pooling_layer( + input=scaled, pooling_type=SumPooling(), + name="%s_pooling" % name), attention_weight def inputs(layers, *args):