Skip to content

Commit aff0d5b

Browse files
Monica Songtensorflower-gardener
authored andcommitted
Remove redundant files from libexport and clean up SavedModel python bindings.
Move util.h/cc out of tensorflow/cc/experimental/libexport as a better place for these files is tensorflow/cc/saved_model. Remove tensorflow/cc/experimental/libexport/constants.h/cc since tensorflow/cc/saved_model/constants.h already exists. Organize SavedModel python bindings into submodules. PiperOrigin-RevId: 387899315 Change-Id: I3b7a5c8d14eed1d5b479b278d0888395818f3d6a
1 parent 6d8e957 commit aff0d5b

File tree

17 files changed

+227
-245
lines changed

17 files changed

+227
-245
lines changed

tensorflow/cc/experimental/libexport/BUILD

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ package(
1414
licenses = ["notice"],
1515
)
1616

17-
cc_library(
18-
name = "constants",
19-
srcs = ["constants.cc"],
20-
hdrs = ["constants.h"],
21-
deps = [
22-
"//tensorflow/core/platform:macros",
23-
],
24-
)
25-
2617
cc_library(
2718
name = "save",
2819
srcs = ["save.cc"],
@@ -73,26 +64,3 @@ tf_cc_test(
7364
"//tensorflow/core/platform:path",
7465
],
7566
)
76-
77-
cc_library(
78-
name = "util",
79-
srcs = ["util.cc"],
80-
hdrs = ["util.h"],
81-
deps = [
82-
"//tensorflow/core:lib",
83-
"//tensorflow/core/protobuf:for_core_protos_cc",
84-
],
85-
)
86-
87-
tf_cc_test(
88-
name = "util_test",
89-
size = "small",
90-
srcs = ["util_test.cc"],
91-
deps = [
92-
":util",
93-
"//tensorflow/core:lib",
94-
"//tensorflow/core:test",
95-
"//tensorflow/core:test_main",
96-
"//tensorflow/core/protobuf:for_core_protos_cc",
97-
],
98-
)

tensorflow/cc/experimental/libexport/constants.cc

Lines changed: 0 additions & 38 deletions
This file was deleted.

tensorflow/cc/experimental/libexport/constants.h

Lines changed: 0 additions & 72 deletions
This file was deleted.

tensorflow/cc/saved_model/BUILD

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ cc_library(
121121
":reader",
122122
] + if_not_mobile([
123123
":metrics",
124+
":util",
124125
"//tensorflow/core:core_cpu",
125126
"//tensorflow/core:framework",
126127
"//tensorflow/core:lib",
127128
"//tensorflow/core:lib_internal",
128129
"//tensorflow/core:protos_all_cc",
129130
"//tensorflow/core/util/tensor_bundle:naming",
130-
"//tensorflow/cc/experimental/libexport:util",
131131
]),
132132
alwayslink = 1,
133133
)
@@ -139,7 +139,7 @@ cc_library(
139139
deps = [
140140
":constants",
141141
":metrics",
142-
"//tensorflow/cc/experimental/libexport:util",
142+
":util",
143143
"//tensorflow/core:lib",
144144
"//tensorflow/core:protos_all_cc",
145145
"//tensorflow/core/platform:strcat",
@@ -339,3 +339,26 @@ tf_cc_test(
339339
"//tensorflow/core:test_main",
340340
],
341341
)
342+
343+
cc_library(
344+
name = "util",
345+
srcs = ["util.cc"],
346+
hdrs = ["util.h"],
347+
deps = [
348+
"//tensorflow/core:lib",
349+
"//tensorflow/core/protobuf:for_core_protos_cc",
350+
],
351+
)
352+
353+
tf_cc_test(
354+
name = "util_test",
355+
size = "small",
356+
srcs = ["util_test.cc"],
357+
deps = [
358+
":util",
359+
"//tensorflow/core:lib",
360+
"//tensorflow/core:test",
361+
"//tensorflow/core:test_main",
362+
"//tensorflow/core/protobuf:for_core_protos_cc",
363+
],
364+
)

tensorflow/cc/saved_model/constants.h

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,49 @@ limitations under the License.
1818

1919
namespace tensorflow {
2020

21-
/// SavedModel assets directory.
21+
// SavedModel assets directory.
2222
constexpr char kSavedModelAssetsDirectory[] = "assets";
2323

24-
/// SavedModel assets.extra directory.
24+
// SavedModel assets.extra directory.
2525
constexpr char kSavedModelAssetsExtraDirectory[] = "assets.extra";
2626

27-
/// SavedModel assets key for graph collection-def.
27+
// SavedModel assets key for graph collection-def.
2828
constexpr char kSavedModelAssetsKey[] = "saved_model_assets";
2929

30-
/// SavedModel proto filename.
31-
constexpr char kSavedModelFilenamePb[] = "saved_model.pb";
32-
33-
/// SavedModel text format proto filename.
34-
constexpr char kSavedModelFilenamePbTxt[] = "saved_model.pbtxt";
35-
3630
/// SavedModel legacy init op collection key. Used in v1 SavedModels.
3731
constexpr char kSavedModelLegacyInitOpKey[] = "legacy_init_op";
3832

3933
/// SavedModel main op collection key. Used in v1 SavedModels.
4034
constexpr char kSavedModelMainOpKey[] = "saved_model_main_op";
4135

42-
/// Directory in which to save the SavedModel variables.
36+
// CollectionDef key for the SavedModel train op.
37+
// Not exported while export_all_saved_models is experimental.
38+
constexpr char kSavedModelTrainOpKey[] = "saved_model_train_op";
39+
40+
// Schema version for SavedModel.
41+
constexpr int kSavedModelSchemaVersion = 1;
42+
43+
// SavedModel proto filename.
44+
constexpr char kSavedModelFilenamePb[] = "saved_model.pb";
45+
46+
// SavedModel text format proto filename.
47+
constexpr char kSavedModelFilenamePbTxt[] = "saved_model.pbtxt";
48+
49+
// Subdirectory where debugging related files are written.
50+
constexpr char kSavedModelDebugDirectory[] = "debug";
51+
52+
// File name for GraphDebugInfo protocol buffer which corresponds to the
53+
// SavedModel.
54+
constexpr char kSavedModelDebugInfoFilenamePb[] = "saved_model_debug_info.pb";
55+
56+
// Directory in which to save the SavedModel variables.
4357
constexpr char kSavedModelVariablesDirectory[] = "variables";
4458

45-
/// SavedModel variables filename.
59+
// SavedModel variables filename.
4660
constexpr char kSavedModelVariablesFilename[] = "variables";
4761

48-
/// SavedModel SignatureDef keys for the initialization and train ops. Used in
49-
/// V2 SavedModels.
62+
// SavedModel SignatureDef keys for the initialization and train ops. Used in
63+
// V2 SavedModels.
5064
constexpr char kSavedModelInitOpSignatureKey[] = "__saved_model_init_op";
5165
constexpr char kSavedModelTrainOpSignatureKey[] = "__saved_model_train_op";
5266

tensorflow/cc/saved_model/loader.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ limitations under the License.
1717

1818
#include <unordered_set>
1919

20-
#include "tensorflow/cc/experimental/libexport/util.h"
2120
#include "tensorflow/cc/saved_model/constants.h"
2221
#include "tensorflow/cc/saved_model/loader_util.h"
2322
#include "tensorflow/cc/saved_model/metrics.h"
2423
#include "tensorflow/cc/saved_model/reader.h"
24+
#include "tensorflow/cc/saved_model/util.h"
2525
#include "tensorflow/core/framework/attr_value.pb.h"
2626
#include "tensorflow/core/framework/function.pb.h"
2727
#include "tensorflow/core/framework/node_def.pb.h"
@@ -275,7 +275,7 @@ Status LoadSavedModel(const SessionOptions& session_options,
275275
SavedModelBundle* const bundle) {
276276
SavedModel saved_model_proto;
277277
if (ReadSavedModel(export_dir, &saved_model_proto).ok()) {
278-
std::string version = libexport::GetWriteVersion(saved_model_proto);
278+
std::string version = saved_model::GetWriteVersion(saved_model_proto);
279279
metrics::SavedModelReadApi(kCCLoadLabel, version).IncrementBy(1);
280280
}
281281

tensorflow/cc/experimental/libexport/util.cc renamed to tensorflow/cc/saved_model/util.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
#include "tensorflow/cc/experimental/libexport/util.h"
15+
#include "tensorflow/cc/saved_model/util.h"
1616

1717
#include <string>
1818

1919
#include "tensorflow/core/platform/errors.h"
2020
#include "tensorflow/core/protobuf/meta_graph.pb.h"
2121

2222
namespace tensorflow {
23-
namespace libexport {
23+
namespace saved_model {
2424

2525
std::string GetWriteVersion(const SavedModel& saved_model) {
2626
if (saved_model.meta_graphs_size() == 1 &&
@@ -30,5 +30,5 @@ std::string GetWriteVersion(const SavedModel& saved_model) {
3030
return "1";
3131
}
3232

33-
} // namespace libexport
33+
} // namespace saved_model
3434
} // namespace tensorflow

tensorflow/cc/experimental/libexport/util.h renamed to tensorflow/cc/saved_model/util.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
#ifndef TENSORFLOW_CC_EXPERIMENTAL_LIBEXPORT_UTIL_H_
16-
#define TENSORFLOW_CC_EXPERIMENTAL_LIBEXPORT_UTIL_H_
15+
#ifndef TENSORFLOW_CC_SAVED_MODEL_UTIL_H_
16+
#define TENSORFLOW_CC_SAVED_MODEL_UTIL_H_
1717

1818
#include <string>
1919

2020
#include "tensorflow/core/platform/status.h"
2121
#include "tensorflow/core/protobuf/saved_model.pb.h"
2222

2323
namespace tensorflow {
24-
namespace libexport {
24+
namespace saved_model {
2525

2626
// Utility functions for SavedModel reading and writing.
2727

@@ -32,7 +32,7 @@ namespace libexport {
3232
// NOTE: The "WriteVersion" does *not* equal the major version of TF.
3333
std::string GetWriteVersion(const SavedModel& saved_model);
3434

35-
} // namespace libexport
35+
} // namespace saved_model
3636
} // namespace tensorflow
3737

38-
#endif // TENSORFLOW_CC_EXPERIMENTAL_LIBEXPORT_UTIL_H_
38+
#endif // TENSORFLOW_CC_SAVED_MODEL_UTIL_H_

tensorflow/cc/experimental/libexport/util_test.cc renamed to tensorflow/cc/saved_model/util_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
99
See the License for the specific language governing permissions and
1010
limitations under the License.
1111
==============================================================================*/
12-
#include "tensorflow/cc/experimental/libexport/util.h"
12+
#include "tensorflow/cc/saved_model/util.h"
1313

1414
#include <string>
1515

@@ -21,7 +21,7 @@ limitations under the License.
2121
#include "tensorflow/core/protobuf/saved_object_graph.pb.h"
2222

2323
namespace tensorflow {
24-
namespace libexport {
24+
namespace saved_model {
2525
namespace {
2626

2727
TEST(UtilTest, TestGetWriteVersionV2) {
@@ -41,5 +41,5 @@ TEST(UtilTest, TestGetWriteVersionV1) {
4141
}
4242

4343
} // namespace
44-
} // namespace libexport
44+
} // namespace saved_model
4545
} // namespace tensorflow

0 commit comments

Comments
 (0)