From 29a4b21bc8d49067e0e4ce470aedb74b29050b37 Mon Sep 17 00:00:00 2001 From: Qiao Longfei Date: Tue, 12 Feb 2019 16:18:06 +0800 Subject: [PATCH] fix problem test=develop --- paddle/fluid/operators/lookup_table_op.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/operators/lookup_table_op.h b/paddle/fluid/operators/lookup_table_op.h index e20f417d764..56c6e37ae3c 100644 --- a/paddle/fluid/operators/lookup_table_op.h +++ b/paddle/fluid/operators/lookup_table_op.h @@ -188,7 +188,10 @@ class LookupTableGradKernel : public framework::OpKernel { memset(d_table_data, 0, d_table->numel() * sizeof(T)); for (int64_t i = 0; i < ids->numel(); ++i) { - if (ids_data[i != padding_idx) { + if (padding_idx != kNoPadding && ids_data[i] == padding_idx) { + // the gradient of padding_idx should be 0, already done by memset, so + // do nothing. + } else { PADDLE_ENFORCE_LT(ids_data[i], N); PADDLE_ENFORCE_GE(ids_data[i], 0); for (int j = 0; j < D; ++j) { -- GitLab