From c6cf846bee9f9eca1b8c3ad82f0ec81e17c4a0b0 Mon Sep 17 00:00:00 2001 From: Codersheepchen Date: Thu, 7 Aug 2025 05:19:17 -0400 Subject: [PATCH 1/2] remove FATAL log --- .../embedding_fused_action_id_gather.cc | 22 +++++++-------- .../core/kernels/embedding_fused_gather.cc | 9 +++--- .../core/kernels/embedding_fused_padding.cc | 1 + .../kernels/embedding_fused_sparse_reshape.cc | 17 ++++++----- .../kernels/embedding_fused_sparse_select.cc | 28 ++++++++++--------- 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/tensorflow/core/kernels/embedding_fused_action_id_gather.cc b/tensorflow/core/kernels/embedding_fused_action_id_gather.cc index 2fd416a1..c2aa72b8 100644 --- a/tensorflow/core/kernels/embedding_fused_action_id_gather.cc +++ b/tensorflow/core/kernels/embedding_fused_action_id_gather.cc @@ -43,26 +43,26 @@ static void GatherV2Impl(OpKernelContext* context, } OP_REQUIRES_OK(context, context->allocate_temp(DT_FLOAT, temp_shape, temp)); - VLOG(2) << "temp shape: " << temp->shape().DebugString(); + VLOG(1) << "temp shape: " << temp->shape().DebugString(); const int num_indices = indices_shape.num_elements(); float* temp_data = temp->flat().data(); - VLOG(2) << "num_indices : " << num_indices; + VLOG(1) << "num_indices : " << num_indices; if (axis == 0) { const int slice_size = P1; for (int i = 0; i < num_indices; ++i) { Tindices idx = indices_data[i]; if (idx < 0 || idx >= P0) { - LOG(FATAL) << "GatherV2 axis=0: index out of range: " << idx; + LOG(WARNING) << "GatherV2 axis=0: index out of range: " << idx; } std::memcpy(temp_data + i * slice_size, params_data + idx * slice_size, sizeof(float) * slice_size); } } else { - LOG(FATAL) << "Only axis=0 is supported"; + LOG(WARNING) << "Only axis=0 is supported"; } - VLOG(2) << "temp value : " << temp->DebugString(100); + VLOG(1) << "temp value : " << temp->DebugString(100); } template @@ -77,9 +77,9 @@ class KPFusedEmbeddingActionIdGatherOp : public OpKernel { const Tensor& indices2 = context->input(2); const Tensor& pack_dim = context->input(3); - VLOG(2) << "indices1 shape: " << indices1.shape().DebugString(); - VLOG(2) << "params shape: " << params.shape().DebugString(); - VLOG(2) << "indices2 shape: " << indices2.shape().DebugString(); + VLOG(1) << "indices1 shape: " << indices1.shape().DebugString(); + VLOG(1) << "params shape: " << params.shape().DebugString(); + VLOG(1) << "indices2 shape: " << indices2.shape().DebugString(); OP_REQUIRES(context, indices1.dims() <= 2, errors::InvalidArgument("indices1 dims must <= 2")); OP_REQUIRES(context, indices2.dims() <= 2, errors::InvalidArgument("indices2 dims must <= 2")); OP_REQUIRES(context, params.dims() == 2, errors::InvalidArgument("params dims must = 2")); @@ -94,15 +94,15 @@ class KPFusedEmbeddingActionIdGatherOp : public OpKernel { indices2.flat().data(), indices2.shape(), 0, &temp1); int pack_size = pack_dim.scalar()(); - VLOG(2) << "pack_size value: " << pack_size; + VLOG(1) << "pack_size value: " << pack_size; int a_reshaped_cols = temp1.NumElements() / pack_size; auto a_reshaped = temp1.shaped({pack_size, a_reshaped_cols}); - VLOG(2) << "a_reshaped_cols : " << a_reshaped_cols; + VLOG(1) << "a_reshaped_cols : " << a_reshaped_cols; Tensor* output; int output_cols = a_reshaped_cols + 1680; OP_REQUIRES_OK(context, context->allocate_output(0, TensorShape({pack_size, output_cols}), &output)); - VLOG(2) << "output shape: " << output->shape().DebugString(); + VLOG(1) << "output shape: " << output->shape().DebugString(); auto output_matrix = output->matrix(); output_matrix.slice( Eigen::array{0, 0}, diff --git a/tensorflow/core/kernels/embedding_fused_gather.cc b/tensorflow/core/kernels/embedding_fused_gather.cc index ca3eff64..77d8cb24 100644 --- a/tensorflow/core/kernels/embedding_fused_gather.cc +++ b/tensorflow/core/kernels/embedding_fused_gather.cc @@ -26,7 +26,6 @@ class KPFusedGather : public OpKernel { explicit KPFusedGather(OpKernelConstruction* context) : OpKernel(context) { } void Compute(OpKernelContext* context) override { - VLOG(2) << "Executing KPFusedGather operator"; const Tensor& data = context->input(0); const Tensor& slice_input = context->input(1); const Tensor& begin = context->input(2); @@ -34,15 +33,15 @@ class KPFusedGather : public OpKernel { OP_REQUIRES(context, slice_input.dims() == 2, errors::Internal("slice_input dims must == 2")); OP_REQUIRES(context, data.dims() == 2, errors::Internal("indentity dims must == 2")); - VLOG(2) << "Input indentity shape: " << data.shape().DebugString(); - VLOG(2) << "Input slice_input shape: " << slice_input.shape().DebugString(); - VLOG(2) << "Input begin value: " << begin.SummarizeValue(10); + VLOG(1) << "Input indentity shape: " << data.shape().DebugString(); + VLOG(1) << "Input slice_input shape: " << slice_input.shape().DebugString(); + VLOG(1) << "Input begin value: " << begin.SummarizeValue(10); int32 col = begin.flat().data()[1]; auto data_mat = data.matrix(); auto slice_input_mat = slice_input.matrix(); - VLOG(2) << "Column index from begin: " << col; + VLOG(1) << "Column index from begin: " << col; std::vector unique_values; std::vector indices(slice_input.dim_size(0)); diff --git a/tensorflow/core/kernels/embedding_fused_padding.cc b/tensorflow/core/kernels/embedding_fused_padding.cc index 2e35a602..e36fbf7f 100644 --- a/tensorflow/core/kernels/embedding_fused_padding.cc +++ b/tensorflow/core/kernels/embedding_fused_padding.cc @@ -39,6 +39,7 @@ class KPFusedEmbeddingPaddingOp : public OpKernel { const Tensor& input_rows = context->input(2); const Tensor& reshape_sizes = context->input(3); + VLOG(1) << "Input shape: " << input.shape().DebugString(); OP_REQUIRES(context, origin_shape.dims() == 1, errors::InvalidArgument("origin_shape dims must == 1")); OP_REQUIRES(context, origin_shape.NumElements() >= 1, errors::InvalidArgument("origin_shape NumElements must >= 1")); OP_REQUIRES(context, input.dims() == 2, errors::InvalidArgument("input dims must == 2")); diff --git a/tensorflow/core/kernels/embedding_fused_sparse_reshape.cc b/tensorflow/core/kernels/embedding_fused_sparse_reshape.cc index 2fe42e94..951902ac 100644 --- a/tensorflow/core/kernels/embedding_fused_sparse_reshape.cc +++ b/tensorflow/core/kernels/embedding_fused_sparse_reshape.cc @@ -150,27 +150,26 @@ class KPFusedSparseReshapeOp : public OpKernel { explicit KPFusedSparseReshapeOp(OpKernelConstruction* context) : OpKernel(context) { } void Compute(OpKernelContext* context) override { - VLOG(2) << "Executing KPFusedSparseReshape operator"; const Tensor& slice_input = context->input(0); const Tensor& begin = context->input(1); const Tensor& new_shape = context->input(2); OP_REQUIRES(context, slice_input.dims() == 2, errors::Internal("slice_input dims must == 2")); - VLOG(2) << "Input slice_input shape: " << slice_input.shape().DebugString(); - VLOG(2) << "Input begin value: " << begin.DebugString(); - VLOG(2) << "Input new_shape value: " << new_shape.DebugString(); + VLOG(1) << "Input slice_input shape: " << slice_input.shape().DebugString(); + VLOG(1) << "Input begin value: " << begin.DebugString(); + VLOG(1) << "Input new_shape value: " << new_shape.DebugString(); int32 col = begin.flat().data()[1]; int64_t stridedslice57_out = slice_input.dim_size(0); auto slice_input_mat = slice_input.matrix(); - VLOG(2) << "stridedslice57_out: " << stridedslice57_out; - VLOG(2) << "slice_input.dim_size(0): " << slice_input.dim_size(0); - VLOG(2) << "slice_input.dim_size(1): " << slice_input.dim_size(1); + VLOG(1) << "stridedslice57_out: " << stridedslice57_out; + VLOG(1) << "slice_input.dim_size(0): " << slice_input.dim_size(0); + VLOG(1) << "slice_input.dim_size(1): " << slice_input.dim_size(1); OP_REQUIRES(context, stridedslice57_out == slice_input.dim_size(0), errors::Internal("concat shape mismatch")); - VLOG(2) << "Column index from begin: " << col; - VLOG(2) << "indices size: " << stridedslice57_out; + VLOG(1) << "Column index from begin: " << col; + VLOG(1) << "indices size: " << stridedslice57_out; Tensor shape_in(DT_INT64, TensorShape({2})); auto tensor_flat = shape_in.flat(); diff --git a/tensorflow/core/kernels/embedding_fused_sparse_select.cc b/tensorflow/core/kernels/embedding_fused_sparse_select.cc index 71eb2672..086092d5 100644 --- a/tensorflow/core/kernels/embedding_fused_sparse_select.cc +++ b/tensorflow/core/kernels/embedding_fused_sparse_select.cc @@ -39,16 +39,18 @@ class KPFusedSparseSelect : public OpKernel { auto a_flat = input_a.flat(); auto b_flat = input_b.flat(); auto c_flat = input_c.flat(); - + VLOG(1) << "input_a shape: " << input_a.shape().DebugString(); + VLOG(1) << "input_b shape: " << input_b.shape().DebugString(); + VLOG(1) << "input_c shape: " << input_c.shape().DebugString(); OP_REQUIRES(context,input_a.NumElements() == input_b.NumElements(), errors::InvalidArgument("Input num elements must match")); OP_REQUIRES(context,input_a.NumElements() == input_c.NumElements(), errors::InvalidArgument("Input num elements must match")); - auto N=input_a.NumElements(); + auto N = input_a.NumElements(); - Eigen::TensorMap> a_reshaped_tensor(a_flat.data(),N,1); - Eigen::TensorMap> b_reshaped_tensor(b_flat.data(),N,1); - Eigen::TensorMap> c_reshaped_tensor(c_flat.data(),N,1); + Eigen::TensorMap> a_reshaped_tensor(a_flat.data(), N, 1); + Eigen::TensorMap> b_reshaped_tensor(b_flat.data(), N, 1); + Eigen::TensorMap> c_reshaped_tensor(c_flat.data(), N, 1); auto a_greater = (a_reshaped_tensor > 0); auto a_greater_casted = a_greater.cast(); @@ -56,28 +58,28 @@ class KPFusedSparseSelect : public OpKernel { auto b_equal_node0 = (b_reshaped_tensor == 4563); auto b_equal_node1 = (b_reshaped_tensor == 10831); - Eigen::Tensor tensor_ones(N,1); + Eigen::Tensor tensor_ones(N, 1); tensor_ones.setConstant(1.0f); - Eigen::Tensor tensor_zeros(N,1); + Eigen::Tensor tensor_zeros(N, 1); tensor_zeros.setConstant(0.0f); - auto select_2412 = b_equal_node0.select(tensor_ones,a_greater_casted); - auto select_2415 = b_equal_node1.select(tensor_ones,select_2412); + auto select_2412 = b_equal_node0.select(tensor_ones, a_greater_casted); + auto select_2415 = b_equal_node1.select(tensor_ones, select_2412); auto sub_out = 1.0f - select_2415; - auto concat_out = select_2415.concatenate(tensor_ones,1); + auto concat_out = select_2415.concatenate(tensor_ones, 1); Tensor* output_x = nullptr; Tensor* output_y = nullptr; Tensor* output_w = nullptr; OP_REQUIRES_OK(context, - context->allocate_output(0,TensorShape({N,1}), &output_x)); + context->allocate_output(0,TensorShape({N, 1}), &output_x)); OP_REQUIRES_OK(context, - context->allocate_output(1,TensorShape({N,1}), &output_y)); + context->allocate_output(1,TensorShape({N, 1}), &output_y)); OP_REQUIRES_OK(context, - context->allocate_output(2,TensorShape({N,2}), &output_w)); + context->allocate_output(2,TensorShape({N, 2}), &output_w)); Eigen::TensorMap> map_output_x( -- Gitee From 19fee4f7c374fddd020f1facb86cd1a4cd44ed9c Mon Sep 17 00:00:00 2001 From: Codersheepchen Date: Thu, 7 Aug 2025 07:57:40 -0400 Subject: [PATCH 2/2] use OP_REQUIRES insdead of LOG(WARNING) --- .../embedding_fused_action_id_gather.cc | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/tensorflow/core/kernels/embedding_fused_action_id_gather.cc b/tensorflow/core/kernels/embedding_fused_action_id_gather.cc index c2aa72b8..b324f35f 100644 --- a/tensorflow/core/kernels/embedding_fused_action_id_gather.cc +++ b/tensorflow/core/kernels/embedding_fused_action_id_gather.cc @@ -48,19 +48,14 @@ static void GatherV2Impl(OpKernelContext* context, const int num_indices = indices_shape.num_elements(); float* temp_data = temp->flat().data(); VLOG(1) << "num_indices : " << num_indices; - if (axis == 0) { - const int slice_size = P1; - for (int i = 0; i < num_indices; ++i) { - Tindices idx = indices_data[i]; - if (idx < 0 || idx >= P0) { - LOG(WARNING) << "GatherV2 axis=0: index out of range: " << idx; - } - std::memcpy(temp_data + i * slice_size, - params_data + idx * slice_size, - sizeof(float) * slice_size); - } - } else { - LOG(WARNING) << "Only axis=0 is supported"; + OP_REQUIRES(context, axis == 0, errors::InvalidArgument("axis only support 0")); + const int slice_size = P1; + for (int i = 0; i < num_indices; ++i) { + Tindices idx = indices_data[i]; + OP_REQUIRES(context, (idx < 0 || idx >= P0), errors::InvalidArgument("GatherV2 axis=0: index out of range")); + std::memcpy(temp_data + i * slice_size, + params_data + idx * slice_size, + sizeof(float) * slice_size); } VLOG(1) << "temp value : " << temp->DebugString(100); } -- Gitee