1# Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15"""Options for saving Checkpoints.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21from tensorflow.python.util.tf_export import tf_export 22 23 24@tf_export("train.CheckpointOptions") 25class CheckpointOptions(object): 26 """Options for constructing a Checkpoint. 27 28 Used as the `options` argument to either `tf.train.Checkpoint.save()` or 29 `tf.train.Checkpoint.restore()` methods to adjust how variables are 30 saved/restored. 31 32 Example: Run IO ops on "localhost" while saving a checkpoint: 33 34 ``` 35 step = tf.Variable(0, name="step") 36 checkpoint = tf.train.Checkpoint(step=step) 37 options = tf.train.CheckpointOptions(experimental_io_device="/job:localhost") 38 checkpoint.save("/tmp/ckpt", options=options) 39 ``` 40 """ 41 42 # Define object attributes in __slots__ for improved memory and performance. 43 __slots__ = ("experimental_io_device",) 44 45 def __init__(self, experimental_io_device=None): 46 """Creates an object that stores options for a Checkpoint. 47 48 Args: 49 experimental_io_device: string. Applies in a distributed setting. 50 Tensorflow device to use to access the filesystem. If `None` (default) 51 then for each variable the filesystem is accessed from the CPU:0 device 52 of the host where that variable is assigned. If specified, the 53 filesystem is instead accessed from that device for all variables. 54 55 This is for example useful if you want to save to a local directory, 56 such as "/tmp" when running in a distributed setting. In that case pass 57 a device for the host where the "/tmp" directory is accessible. 58 """ 59 self.experimental_io_device = experimental_io_device 60