Enrich ConvShift to support sequence data input#2133
Enrich ConvShift to support sequence data input#2133pkuyym wants to merge 9 commits intoPaddlePaddle:developfrom
Conversation
luotao1
left a comment
There was a problem hiding this comment.
建议将修改逻辑放进matrix函数里面,现在修改的和原有matrix里的重复太多。代码可读性不好。
| outV->circularConv(*inV0, *inV1); | ||
| } else { | ||
| circularConvSeq(); | ||
| } |
There was a problem hiding this comment.
将circularConvSeq函数挪到matrix.cpp里面,这��函数的接口应该类似circularConv。即
outV->circularConv(*inV0, *inV1, *seqstartposition);
这样200-207行,可以修改为
if (inLayer0.sequenceStartPositions !=nullptr) {
} else {
}
去掉isSeqType这个函数。
| outG->circularConvDerivative(*outG, *inV0, *inV1, *inG0, *inG1); | ||
| } else { | ||
| CHECK(!inG0 || !inG1) << "Not supported"; | ||
| circularConvSeqDerivative(); |
| real* outV = out->getData(); | ||
|
|
||
| int leftCtxLen = (width1 - 1) / 2; | ||
| for (size_t x = 0; x < numSeqs - 1; x++) { |
| int index = i + j - leftCtxLen; | ||
| index = (index + curSeqWidth) % curSeqWidth; | ||
| int outVRowOffset = i / width0; | ||
| int outVColOffset = i % width0; |
There was a problem hiding this comment.
113和114行只和i有关,应该放在109行的for循环里面,不要放在110行的for循环里面,这样会多算很多次。
| for (size_t i = 0; i < curSeqWidth; i++) { | ||
| for (size_t j = 0; j < width1; ++j) { | ||
| int index = i + j - leftCtxLen; | ||
| index = (index + curSeqWidth) % curSeqWidth; |
| CHECK_EQ(height1, inG1->getHeight()); | ||
| CHECK_EQ(width1, inG1->getWidth()); | ||
| CHECK_EQ(height0, outG->getHeight()); | ||
| CHECK_EQ(width0, outG->getWidth()); |
There was a problem hiding this comment.
cheack_eq有点多,可以只保留143,148,149三行
There was a problem hiding this comment.
这个check是必要的,梯度、输入等的维度必须严格一致
| real* inV0 = in0->getData(); | ||
| real* inV1 = in1->getData(); | ||
| real* inGV0 = inG0->getData(); | ||
| real* inGV1 = inG1->getData(); |
There was a problem hiding this comment.
延伸了Matrix函数的命名方式,GV代表真实的矩阵,感觉比较合适
| int inGV0RowOffset = index / width0; | ||
| int inGV0ColOffset = index % width0; | ||
| int outGVRowOffset = i / width0; | ||
| int outGVColOffset = i % width0; |
There was a problem hiding this comment.
请先加单测保证 test_layer_grad 一定可以通过。计算程序,硬看很难保证计算结果的正确。
|
@luotao1 谢谢review,卷积逻辑已merge到matrix,现在ConvShift层应该比较清爽,对sequence和non-sequence的卷积逻辑已经并在一起 |
| data.value->add(-0.5); | ||
| if (testLayerName != "prelu") { | ||
| data.value->sigmoid(*data.value); | ||
| } |
There was a problem hiding this comment.
406-408行可以去掉,这里不会用prelu这个layer
|
感谢您给PaddlePaddle贡献代码。由于Paddle V1/V2版本已不再维护,相关代码也已从develop分支上删除,因此关闭您的PR,欢迎您向Paddle最新版-Fluid贡献代码。 |
fixes #2132