Skip to content

Commit 33c6790

Browse files
cantoniostf-text-github-robot
authored andcommitted
Update deprecated Status symbols to use absl::Status.
PiperOrigin-RevId: 739963031
1 parent bae5833 commit 33c6790

File tree

5 files changed

+48
-40
lines changed

5 files changed

+48
-40
lines changed

tensorflow_text/core/kernels/BUILD

+6-4
Original file line numberDiff line numberDiff line change
@@ -976,13 +976,15 @@ tf_cc_library(
976976
],
977977
deps = [
978978
"@com_google_absl//absl/base:core_headers",
979-
"@com_google_absl//absl/memory",
979+
"@com_google_absl//absl/container:flat_hash_map",
980980
"@com_google_absl//absl/meta:type_traits",
981+
"@com_google_absl//absl/status",
981982
"@com_google_absl//absl/strings",
982983
"@com_google_absl//absl/types:span",
983984
"@com_google_sentencepiece//:sentencepiece_cc_proto",
984985
"@com_google_sentencepiece//:sentencepiece_model_cc_proto",
985986
"@com_google_sentencepiece//:sentencepiece_processor",
987+
# tf:core_cpu_base tensorflow dep,
986988
],
987989
)
988990

@@ -1015,7 +1017,7 @@ tf_cc_library(
10151017
# tf:lib tensorflow dep,
10161018
],
10171019
deps = [
1018-
"@com_google_absl//absl/base:core_headers",
1020+
"@com_google_absl//absl/status",
10191021
"@com_google_absl//absl/strings",
10201022
"@icu//:common",
10211023
],
@@ -1071,7 +1073,7 @@ tf_cc_library(
10711073
# tf:lib tensorflow dep,
10721074
],
10731075
deps = [
1074-
"@com_google_absl//absl/base:core_headers",
1076+
"@com_google_absl//absl/status",
10751077
"@com_google_absl//absl/strings",
10761078
"@icu//:common",
10771079
],
@@ -1376,7 +1378,7 @@ tf_cc_library(
13761378
],
13771379
deps = [
13781380
":wordpiece_tokenizer",
1379-
"@com_google_absl//absl/base:core_headers",
1381+
"@com_google_absl//absl/status",
13801382
],
13811383
)
13821384

tensorflow_text/core/kernels/sentencepiece_kernels.cc

+11-9
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
#include "absl/base/thread_annotations.h"
1818
#include "absl/container/flat_hash_map.h"
1919
#include "absl/meta/type_traits.h"
20+
#include "absl/status/status.h"
2021
#include "absl/strings/string_view.h"
2122
#include "absl/synchronization/mutex.h"
2223
#include "absl/types/span.h"
23-
#include "src/sentencepiece_model.pb.h"
2424
#include "src/sentencepiece.pb.h"
25+
#include "src/sentencepiece_model.pb.h"
2526
#include "src/sentencepiece_processor.h"
2627
#include "tensorflow/core/framework/bounds_check.h"
2728
#include "tensorflow/core/framework/dataset_stateful_op_allowlist.h"
@@ -33,6 +34,7 @@
3334
#include "tensorflow/core/framework/tensor_types.h"
3435
#include "tensorflow/core/framework/types.h"
3536
#include "tensorflow/core/framework/types.pb.h"
37+
#include "tensorflow/core/graph/graph.h"
3638
#include "tensorflow/core/graph/graph_def_builder.h"
3739
#include "tensorflow/core/lib/core/errors.h"
3840
#include "tensorflow/core/lib/core/refcount.h"
@@ -67,7 +69,7 @@ struct SentencepieceResource : public ResourceBase {
6769
(reverse == this->reverse);
6870
}
6971

70-
Status AsGraphDef(GraphDefBuilder* builder, Node** out) const override {
72+
sentencepiece::util::Status AsGraphDef(GraphDefBuilder* builder, Node** out) const override {
7173
absl::ReaderMutexLock l(&mu);
7274
// We set use_node_name_sharing with a unique node name so that the resource
7375
// can outlive the kernel. This means that the lifetime of the re-created
@@ -93,10 +95,10 @@ struct SentencepieceResource : public ResourceBase {
9395
// TODO(broken) Determine a medium cost of a call to the SentencePiece processor
9496
constexpr int64 kCostPerUnit = 10000;
9597

96-
::tensorflow::Status ToTFStatus(const sentencepiece::util::Status& s) {
97-
if (s.ok()) return ::tensorflow::Status();
98-
return ::tensorflow::Status(static_cast<::tensorflow::errors::Code>(s.code()),
99-
::tensorflow::string(s.message()));
98+
absl::Status ToTFStatus(const sentencepiece::util::Status& s) {
99+
if (s.ok()) return sentencepiece::util::Status();
100+
return sentencepiece::util::Status(static_cast<absl::StatusCode>(s.code()),
101+
::tensorflow::string(s.message()));
100102
}
101103

102104
template <typename T>
@@ -114,8 +116,8 @@ int32 GetPieceOrId<int32>(
114116
return sp.id();
115117
}
116118

117-
tensorflow::Status HandleExtraOptions(OpKernelContext* ctx,
118-
SentencepieceResource* sp) {
119+
absl::Status HandleExtraOptions(OpKernelContext* ctx,
120+
SentencepieceResource* sp) {
119121
const Tensor* add_bos_tensor = nullptr;
120122
TF_RETURN_IF_ERROR(ctx->input("add_bos", &add_bos_tensor));
121123
const bool add_bos = add_bos_tensor->scalar<bool>()();
@@ -209,7 +211,7 @@ class SentencepieceOp : public OpKernel {
209211
GetNodeAttr(this->def(), "model", &model_proto_attr));
210212

211213
if (TF_PREDICT_FALSE(model_proto_attr.empty())) {
212-
return Status(tensorflow::errors::InvalidArgument(
214+
return sentencepiece::util::Status(tensorflow::errors::InvalidArgument(
213215
"Model argument must be specified."));
214216
}
215217
// Loads serialized sentencepiece model proto to enable embedding

tensorflow_text/core/kernels/split_merge_tokenize_kernel.cc

+14-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <string>
1818
#include <vector>
1919

20+
#include "absl/status/status.h"
2021
#include "absl/strings/str_cat.h"
2122
#include "icu4c/source/common/unicode/uchar.h"
2223
#include "icu4c/source/common/unicode/umachine.h"
@@ -64,24 +65,24 @@ bool IsBreakChar(absl::string_view text) {
6465
return u_isUWhiteSpace(c);
6566
}
6667

67-
Status TokenizeByLabel(const absl::string_view& text,
68-
const Tensor& labels_tensor,
69-
bool force_split_at_break_character,
70-
std::vector<std::string>* tokens,
71-
std::vector<int>* begin_offset,
72-
std::vector<int>* end_offset, int* num_tokens) {
68+
absl::Status TokenizeByLabel(const absl::string_view& text,
69+
const Tensor& labels_tensor,
70+
bool force_split_at_break_character,
71+
std::vector<std::string>* tokens,
72+
std::vector<int>* begin_offset,
73+
std::vector<int>* end_offset, int* num_tokens) {
7374
std::vector<absl::string_view> chars;
7475
if (!GetUTF8Chars(text, &chars)) {
75-
return Status(static_cast<tensorflow::errors::Code>(
76-
absl::StatusCode::kInvalidArgument),
77-
absl::StrCat("Input string is not utf8 valid: ", text));
76+
return absl::Status(
77+
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument),
78+
absl::StrCat("Input string is not utf8 valid: ", text));
7879
}
7980

8081
if (chars.size() > labels_tensor.dim_size(0)) {
81-
return Status(static_cast<tensorflow::errors::Code>(
82-
absl::StatusCode::kInvalidArgument),
83-
absl::StrCat("Number of labels ", labels_tensor.dim_size(0),
84-
" is insufficient for text ", text));
82+
return absl::Status(
83+
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument),
84+
absl::StrCat("Number of labels ", labels_tensor.dim_size(0),
85+
" is insufficient for text ", text));
8586
}
8687

8788
const int split_label = 0;

tensorflow_text/core/kernels/tokenizer_from_logits_kernel.cc

+11-9
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
#include <string>
1818
#include <vector>
1919

20+
#include "absl/status/status.h"
2021
#include "absl/strings/str_cat.h"
2122
#include "icu4c/source/common/unicode/uchar.h"
2223
#include "icu4c/source/common/unicode/umachine.h"
2324
#include "icu4c/source/common/unicode/utf8.h"
2425
#include "tensorflow/core/framework/op_kernel.h"
2526
#include "tensorflow/core/framework/tensor.h"
2627
#include "tensorflow/core/framework/tensor_shape.h"
28+
#include "tensorflow/core/framework/tensor_types.h"
2729
#include "tensorflow/core/lib/core/status.h"
2830

2931
namespace tensorflow {
@@ -68,22 +70,22 @@ bool IsBreakChar(absl::string_view text) {
6870
// allows us to retrieve the corresponding data from logits. I.e., the logits
6971
// for the i-th character from text are logits(batch_index, i, 0) (for the
7072
// "split" action) and logits(batch_index, i, 1) (for the "merge" action).
71-
Status TokenizeByLogits(const absl::string_view& text,
72-
const TTypes<const float, 3>::Tensor& logits,
73-
int batch_index,
74-
bool force_split_at_break_character,
75-
std::vector<std::string>* tokens,
76-
std::vector<int>* begin_offset,
77-
std::vector<int>* end_offset, int* num_tokens) {
73+
absl::Status TokenizeByLogits(const absl::string_view& text,
74+
const TTypes<const float, 3>::Tensor& logits,
75+
int batch_index,
76+
bool force_split_at_break_character,
77+
std::vector<std::string>* tokens,
78+
std::vector<int>* begin_offset,
79+
std::vector<int>* end_offset, int* num_tokens) {
7880
std::vector<absl::string_view> chars;
7981
if (!GetUTF8Chars(text, &chars)) {
80-
return Status(
82+
return absl::Status(
8183
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument),
8284
absl::StrCat("Input string is not utf8 valid: ", text));
8385
}
8486

8587
if (chars.size() > logits.dimension(1)) {
86-
return Status(
88+
return absl::Status(
8789
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument),
8890
absl::StrCat("Number of logits, ", logits.dimension(1),
8991
", is insufficient for text \"", text, "\""));

tensorflow_text/core/kernels/wordpiece_kernel.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <string>
1818
#include <vector>
1919

20+
#include "absl/status/status.h"
2021
#include "tensorflow/core/framework/dataset_stateful_op_allowlist.h"
2122
#include "tensorflow/core/framework/lookup_interface.h"
2223
#include "tensorflow/core/framework/op_kernel.h"
@@ -82,8 +83,8 @@ bool GetSplitUnknownCharacters(OpKernelConstruction* ctx) {
8283
return split_unknown_characters;
8384
}
8485

85-
Status GetTableHandle(const string& input_name, OpKernelContext* ctx,
86-
string* container, string* table_handle) {
86+
absl::Status GetTableHandle(const string& input_name, OpKernelContext* ctx,
87+
string* container, string* table_handle) {
8788
{
8889
mutex* mu;
8990
TF_RETURN_IF_ERROR(ctx->input_ref_mutex(input_name, &mu));
@@ -105,8 +106,8 @@ Status GetTableHandle(const string& input_name, OpKernelContext* ctx,
105106
// Gets the LookupTable stored in the ctx->resource_manager() with key
106107
// passed by attribute with name input_name, returns null if the table
107108
// doesn't exist.
108-
Status GetLookupTable(const string& input_name, OpKernelContext* ctx,
109-
lookup::LookupInterface** table) {
109+
absl::Status GetLookupTable(const string& input_name, OpKernelContext* ctx,
110+
lookup::LookupInterface** table) {
110111
string container;
111112
string table_handle;
112113
DataType handle_dtype;
@@ -135,7 +136,7 @@ class LookupTableVocab : public WordpieceVocab {
135136
Tensor default_value_;
136137
};
137138

138-
Status ToStatus(const LookupStatus& status) {
139+
absl::Status ToStatus(const LookupStatus& status) {
139140
if (status.success) {
140141
return absl::OkStatus();
141142
}

0 commit comments

Comments
 (0)