Skip to content

Commit e6366e3

Browse files
committed
update with comments
1 parent ba68ce1 commit e6366e3

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

paddle/gserver/layers/SequenceLastInstanceLayer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SequenceLastInstanceLayer : public SequencePoolLayer {
4242
protected:
4343
MatrixPtr tmpSrc_;
4444
MatrixPtr tmpDest_;
45-
std::vector<int> insId_;
45+
std::vector<int> instanceIds_;
4646

4747
public:
4848
explicit SequenceLastInstanceLayer(const LayerConfig& config)
@@ -82,10 +82,10 @@ void SequenceLastInstanceLayer::forward(PassType passType) {
8282
AsyncGpuBlock asyncGpuBlock;
8383
REGISTER_TIMER_INFO("SequenceLastInstanceLayerForward", getName().c_str());
8484

85-
insId_.clear();
85+
instanceIds_.clear();
8686
for (size_t seqId = 0; seqId < newBatchSize_; ++seqId) {
8787
int insId = reversed_ ? starts[seqId] : starts[seqId + 1] - 1;
88-
insId_.push_back(insId);
88+
instanceIds_.push_back(insId);
8989

9090
outputValue->subMatrix(seqId, 1, tmpDest_)
9191
->assign(*(inputValue->subMatrix(insId, 1, tmpSrc_)));
@@ -111,7 +111,7 @@ void SequenceLastInstanceLayer::backward(const UpdateCallback& callback) {
111111
REGISTER_TIMER_INFO("SequenceLastInstanceLayerBackward", getName().c_str());
112112

113113
for (size_t seqId = 0; seqId < newBatchSize_; ++seqId) {
114-
inputGrad->subMatrix(insId_[seqId], 1, tmpDest_)
114+
inputGrad->subMatrix(instanceIds_[seqId], 1, tmpDest_)
115115
->add(*(outputGrad->subMatrix(seqId, 1, tmpSrc_)));
116116
}
117117
}

paddle/gserver/layers/SequencePoolLayer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class SequencePoolLayer : public Layer {
4747
size_t newBatchSize_;
4848
ICpuGpuVectorPtr startPositions_;
4949
int stride_;
50-
// store the start position of each window
50+
// Store the start position of each window.
5151
IVectorPtr stridePositions_;
52-
// Whether the input sequence is reversed or not
52+
// Whether the input sequence is reversed or not.
5353
bool reversed_ = false;
5454

5555
public:

paddle/gserver/tests/test_LayerGrad.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ TEST(Layer, ExpandLayer) {
807807
void testDegradeLayer(bool hasSubseq,
808808
string layer_type,
809809
string trans_type,
810-
int stride = -1) {
810+
int stride) {
811811
TestConfig config;
812812
config.layerConfig.set_type(layer_type);
813813
config.layerConfig.set_size(10);
@@ -844,29 +844,33 @@ void testDegradeLayer(bool hasSubseq,
844844
}
845845

846846
TEST(Layer, MaxLayer) {
847-
testDegradeLayer(false, "max", "non-seq"); // seq max to non-seq
848-
testDegradeLayer(true, "max", "non-seq"); // hasSubseq max to non-seq
849-
testDegradeLayer(true, "max", "seq"); // hasSubseq max to seq
847+
testDegradeLayer(false, "max", "non-seq", -1); // seq max to non-seq
848+
testDegradeLayer(true, "max", "non-seq", -1); // hasSubseq max to non-seq
849+
testDegradeLayer(true, "max", "seq", -1); // hasSubseq max to seq
850850
}
851851

852852
TEST(Layer, SequenceLastInstanceLayer) {
853853
testDegradeLayer(false,
854854
"seqlastins",
855-
"non-seq"); // seq seqlastins to non-seq
855+
"non-seq",
856+
-1); // seq seqlastins to non-seq
856857
testDegradeLayer(false,
857858
"seqlastins",
858859
"non-seq",
859860
5); // seq seqlastins to a shorten seq, stride window = 5
860861
testDegradeLayer(true,
861862
"seqlastins",
862-
"non-seq"); // hasSubseq seqlastins to non-seq
863-
testDegradeLayer(true, "seqlastins", "seq"); // hasSubseq seqlastins to seq
863+
"non-seq",
864+
-1); // hasSubseq seqlastins to non-seq
865+
testDegradeLayer(
866+
true, "seqlastins", "seq", -1); // hasSubseq seqlastins to seq
864867
}
865868

866869
TEST(Layer, AverageLayer) {
867-
testDegradeLayer(false, "average", "non-seq"); // seq average to non-seq
868-
testDegradeLayer(true, "average", "non-seq"); // hasSubseq average to non-seq
869-
testDegradeLayer(true, "average", "seq"); // hasSubseq average to seq
870+
testDegradeLayer(false, "average", "non-seq", -1); // seq average to non-seq
871+
testDegradeLayer(
872+
true, "average", "non-seq", -1); // hasSubseq average to non-seq
873+
testDegradeLayer(true, "average", "seq", -1); // hasSubseq average to seq
870874
}
871875

872876
TEST(Layer, SequenceConcatLayer) {

paddle/parameter/Argument.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,11 @@ void Argument::poolSequenceWithStride(const Argument& input,
563563
size_t stride,
564564
IVectorPtr* stridePostions,
565565
bool reversed) {
566-
/*
567-
* If input.sequenceStartPositions = [0, 9, 14, 17, 30] and stride = 5,
568-
* then sequenceStartPositions = [0, 2, 3, 4, 7].
569-
* If reversed = false, stridePostions = [0, 5, 9, 14, 17, 22, 27, 30];
570-
* else reversed = true, stridePostions = [0, 4, 9, 14, 17, 20, 25, 30]
571-
*/
566+
// If input.sequenceStartPositions = [0, 9, 14, 17, 30] and stride = 5,
567+
// then sequenceStartPositions = [0, 2, 3, 4, 7].
568+
// If reversed = false, stridePostions = [0, 5, 9, 14, 17, 22, 27, 30];
569+
// else reversed = true, stridePostions = [0, 4, 9, 14, 17, 20, 25, 30]
570+
572571
CHECK(input.sequenceStartPositions);
573572
CHECK_EQ(input.hasSubseq(), 0UL);
574573
CHECK_GT(stride, 0) << "stride must larger than 0";

0 commit comments

Comments
 (0)