From 2c1adb060469e0b55dae966ec1edc260e1a2bfeb Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Fri, 29 Dec 2017 07:16:40 +0000 Subject: [PATCH] Rename ctc_edit_distance_op to edit_distance_op --- ...dit_distance_op.cc => edit_distance_op.cc} | 24 +++++++++---------- ...dit_distance_op.cu => edit_distance_op.cu} | 12 +++++----- ..._edit_distance_op.h => edit_distance_op.h} | 2 +- ...istance_op.py => test_edit_distance_op.py} | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) rename paddle/operators/{ctc_edit_distance_op.cc => edit_distance_op.cc} (77%) rename paddle/operators/{ctc_edit_distance_op.cu => edit_distance_op.cu} (93%) rename paddle/operators/{ctc_edit_distance_op.h => edit_distance_op.h} (97%) rename python/paddle/v2/fluid/tests/{test_ctc_edit_distance_op.py => test_edit_distance_op.py} (97%) diff --git a/paddle/operators/ctc_edit_distance_op.cc b/paddle/operators/edit_distance_op.cc similarity index 77% rename from paddle/operators/ctc_edit_distance_op.cc rename to paddle/operators/edit_distance_op.cc index 11e9983e243..843a6844cde 100644 --- a/paddle/operators/ctc_edit_distance_op.cc +++ b/paddle/operators/edit_distance_op.cc @@ -12,12 +12,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/operators/ctc_edit_distance_op.h" +#include "paddle/operators/edit_distance_op.h" namespace paddle { namespace operators { -class CTCEditDistanceOp : public framework::OperatorWithKernel { +class EditDistanceOp : public framework::OperatorWithKernel { public: using framework::OperatorWithKernel::OperatorWithKernel; @@ -29,17 +29,16 @@ class CTCEditDistanceOp : public framework::OperatorWithKernel { } protected: - framework::OpKernelType GetKernelType( + framework::OpKernelType GetActualKernelType( const framework::ExecutionContext &ctx) const override { - return framework::OpKernelType(framework::DataType::FP32, + return framework::OpKernelType(framework::proto::DataType::FP32, ctx.device_context()); } }; -class CTCEditDistanceOpMaker : public framework::OpProtoAndCheckerMaker { +class EditDistanceOpMaker : public framework::OpProtoAndCheckerMaker { public: - CTCEditDistanceOpMaker(framework::OpProto *proto, - framework::OpAttrChecker *op_checker) + EditDistanceOpMaker(OpProto *proto, OpAttrChecker *op_checker) : OpProtoAndCheckerMaker(proto, op_checker) { AddInput("X1", "(2-D tensor with shape [M x 1]) The indices for " @@ -54,10 +53,10 @@ class CTCEditDistanceOpMaker : public framework::OpProtoAndCheckerMaker { .SetDefault(false); AddOutput("Out", "(2-D tensor with shape [1 x 1]) " - "The output distance of CTCEditDistance operator."); + "The output distance of EditDistance operator."); AddComment(R"DOC( -CTCEditDistance operator computes the edit distance of two sequences, one named +EditDistance operator computes the edit distance of two sequences, one named hypothesis with length M and another named reference with length N. Edit distance, also called Levenshtein distance, measures how dissimilar two strings @@ -80,8 +79,7 @@ reference string N. namespace ops = paddle::operators; -REGISTER_OP_WITHOUT_GRADIENT(ctc_edit_distance, ops::CTCEditDistanceOp, - ops::CTCEditDistanceOpMaker); +REGISTER_OPERATOR(edit_distance, ops::EditDistanceOp, ops::EditDistanceOpMaker, + paddle::framework::EmptyGradOpMaker); REGISTER_OP_CPU_KERNEL( - ctc_edit_distance, - ops::CTCEditDistanceKernel); + edit_distance, ops::EditDistanceKernel); diff --git a/paddle/operators/ctc_edit_distance_op.cu b/paddle/operators/edit_distance_op.cu similarity index 93% rename from paddle/operators/ctc_edit_distance_op.cu rename to paddle/operators/edit_distance_op.cu index 22871acc4ec..7fa6a60df4d 100644 --- a/paddle/operators/ctc_edit_distance_op.cu +++ b/paddle/operators/edit_distance_op.cu @@ -65,7 +65,7 @@ __global__ void SetOutput(T* out, const T* dist, const int M, const int N, } template -class CTCEditDistanceGPUKernel : public framework::OpKernel { +class EditDistanceGPUKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const { auto* out_t = ctx.Output("Out"); @@ -110,8 +110,8 @@ class CTCEditDistanceGPUKernel : public framework::OpKernel { int z_n = slice < n + 1 ? 0 : slice - n; int size = slice - (z_m + z_n) + 1; // number of elments in the same // anti-diagonal line to update - int start = slice < n + 1 ? slice : z_n * (n + 1) - 1; // start index - + // the start index at which computes from + int start = slice < n + 1 ? slice : (z_n + 1) * (n + 1) - 1; Levenshtein<<<1 + (size - 1) / PADDLE_CUDA_NUM_THREADS, PADDLE_CUDA_NUM_THREADS, 0, stream>>>(dist, x1, x2, m, n, start); @@ -126,6 +126,6 @@ class CTCEditDistanceGPUKernel : public framework::OpKernel { namespace ops = paddle::operators; -REGISTER_OP_GPU_KERNEL( - ctc_edit_distance, - ops::CTCEditDistanceGPUKernel); +REGISTER_OP_CUDA_KERNEL( + edit_distance, + ops::EditDistanceGPUKernel); diff --git a/paddle/operators/ctc_edit_distance_op.h b/paddle/operators/edit_distance_op.h similarity index 97% rename from paddle/operators/ctc_edit_distance_op.h rename to paddle/operators/edit_distance_op.h index 08f29cf24ac..182a6e3bf5b 100644 --- a/paddle/operators/ctc_edit_distance_op.h +++ b/paddle/operators/edit_distance_op.h @@ -21,7 +21,7 @@ namespace paddle { namespace operators { template -class CTCEditDistanceKernel : public framework::OpKernel { +class EditDistanceKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const { auto* out_t = ctx.Output("Out"); diff --git a/python/paddle/v2/fluid/tests/test_ctc_edit_distance_op.py b/python/paddle/v2/fluid/tests/test_edit_distance_op.py similarity index 97% rename from python/paddle/v2/fluid/tests/test_ctc_edit_distance_op.py rename to python/paddle/v2/fluid/tests/test_edit_distance_op.py index 62c233b34f6..8866922f2ee 100644 --- a/python/paddle/v2/fluid/tests/test_ctc_edit_distance_op.py +++ b/python/paddle/v2/fluid/tests/test_edit_distance_op.py @@ -36,7 +36,7 @@ def Levenshtein(hyp, ref): class TestCTCEditDistanceOp(OpTest): def setUp(self): - self.op_type = "ctc_edit_distance" + self.op_type = "edit_distance" normalized = True x1 = np.array([0, 12, 3, 5]).astype("int32") x2 = np.array([0, 12, 4, 7, 8]).astype("int32") -- GitLab