* This fixes a correctness problem where we were relying on the variable's "name" attribute, which is merely advisory. * Should match the load heuristics in Python by reading the TrackableObjectGraph from the checkpoint, re-associating it with the SavedObjectGraph and using that to restore the variable. * Has a side-effect of eliminating the dependency of the importer on the CPU runtime and kernels, which should reduce necessary dependencies to compile by tens of megabytes. Open questions: * I created a new bundle_v2.h because V2 is so substantially different from V1. Also, it has a different dependency surface area and I therefore wanted to use it as a different (lighter) library. Advise if you would like this organized differently. I tried to factor it so that a future C++ SavedModel loader/runner could be built on this as well (with some incremental work). * There didn't seem to be a facility for generating the testdata SavedModels. I ended up just writing a small standalone python script that I can invoke from the command line to generate the new ones. It isn't wired up in any way but it should be possible to do so at some point (I'm not familiar enough with the test infra on this side of the tree, so please advise). * I could see factoring the SavedModelV2Bundle::RestoreObjects method into a dedicated facility for loading arbitrary checkpoints. Not sure what the roadmap here is so just kept is simple for now. PiperOrigin-RevId: 282439157 Change-Id: I685df47ab621917eed270319cde220498f191b74
59 lines
2.2 KiB
C++
59 lines
2.2 KiB
C++
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
==============================================================================*/
|
|
|
|
#ifndef TENSORFLOW_CC_SAVED_MODEL_CONSTANTS_H_
|
|
#define TENSORFLOW_CC_SAVED_MODEL_CONSTANTS_H_
|
|
|
|
namespace tensorflow {
|
|
|
|
/// SavedModel assets directory.
|
|
constexpr char kSavedModelAssetsDirectory[] = "assets";
|
|
|
|
/// SavedModel assets.extra directory.
|
|
constexpr char kSavedModelAssetsExtraDirectory[] = "assets.extra";
|
|
|
|
/// SavedModel assets key for graph collection-def.
|
|
constexpr char kSavedModelAssetsKey[] = "saved_model_assets";
|
|
|
|
/// SavedModel proto filename.
|
|
constexpr char kSavedModelFilenamePb[] = "saved_model.pb";
|
|
|
|
/// SavedModel text format proto filename.
|
|
constexpr char kSavedModelFilenamePbTxt[] = "saved_model.pbtxt";
|
|
|
|
/// SavedModel legacy init op collection key. Used in v1 SavedModels.
|
|
constexpr char kSavedModelLegacyInitOpKey[] = "legacy_init_op";
|
|
|
|
/// SavedModel main op collection key. Used in v1 SavedModels.
|
|
constexpr char kSavedModelMainOpKey[] = "saved_model_main_op";
|
|
|
|
/// Directory in which to save the SavedModel variables.
|
|
constexpr char kSavedModelVariablesDirectory[] = "variables";
|
|
|
|
/// SavedModel variables filename.
|
|
constexpr char kSavedModelVariablesFilename[] = "variables";
|
|
|
|
/// SavedModel SignatureDef keys for the initialization and train ops. Used in
|
|
/// V2 SavedModels.
|
|
constexpr char kSavedModelInitOpSignatureKey[] = "__saved_model_init_op";
|
|
constexpr char kSavedModelTrainOpSignatureKey[] = "__saved_model_train_op";
|
|
|
|
// Key in the TensorBundle for the object graph proto.
|
|
constexpr char kObjectGraphProtoKey[] = "_CHECKPOINTABLE_OBJECT_GRAPH";
|
|
|
|
} // namespace tensorflow
|
|
|
|
#endif // TENSORFLOW_CC_SAVED_MODEL_CONSTANTS_H_
|