diff --git a/paddle/gserver/layers/CRFLayer.cpp b/paddle/gserver/layers/CRFLayer.cpp index fa434cda0024a4102e1a3bc55fbd69151a9aa407..b9fb7e54bdb1fd611b1f8f24fe270d27526a288e 100644 --- a/paddle/gserver/layers/CRFLayer.cpp +++ b/paddle/gserver/layers/CRFLayer.cpp @@ -91,8 +91,8 @@ void CRFLayer::backward(const UpdateCallback& callback) { const int* starts = label.sequenceStartPositions->getData(false); int numSequences = label.sequenceStartPositions->getSize() - 1; + bool needWGrad = weight_->getWGrad() ? true : false; for (int i = 0; i < numSequences; ++i) { - bool needWGrad = weight_->getWGrad() ? true : false; crfs_[i].backward(output.value->getData() + numClasses_ * starts[i], label.ids->getData() + starts[i], starts[i + 1] - starts[i], needWGrad); diff --git a/paddle/gserver/tests/test_CRFLayerGrad.cpp b/paddle/gserver/tests/test_CRFLayerGrad.cpp index bc1d5f3061dce24ff6174b027413412a42704a1f..ad5149306caa8cfc7c60f09e20c54a43e52904bc 100644 --- a/paddle/gserver/tests/test_CRFLayerGrad.cpp +++ b/paddle/gserver/tests/test_CRFLayerGrad.cpp @@ -108,7 +108,7 @@ TEST(CRFLayer, cost) { } inline real epsilon() { - return typeid(real) == typeid(double) ? 1e-10 : 0.05; + return typeid(real) == typeid(double) ? 1e-10 : 0.06; } TestConfig initTestConfig(size_t numClasses, bool withWeight) {