Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/checkpoint/checkpoint_options.py: 73%
11 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
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."""
17from tensorflow.python.util.deprecation import deprecated_args
18from tensorflow.python.util.tf_export import tf_export
21@tf_export("train.CheckpointOptions")
22class CheckpointOptions(object):
23 """Options for constructing a Checkpoint.
25 Used as the `options` argument to either `tf.train.Checkpoint.save()` or
26 `tf.train.Checkpoint.restore()` methods to adjust how variables are
27 saved/restored.
29 Example: Run IO ops on "localhost" while saving a checkpoint:
31 ```
32 step = tf.Variable(0, name="step")
33 checkpoint = tf.train.Checkpoint(step=step)
34 options = tf.train.CheckpointOptions(experimental_io_device="/job:localhost")
35 checkpoint.save("/tmp/ckpt", options=options)
36 ```
37 """
39 # Define object attributes in __slots__ for improved memory and performance.
40 __slots__ = (
41 "experimental_io_device",
42 "experimental_enable_async_checkpoint",
43 "enable_async",
44 )
46 @deprecated_args(
47 None, "Use enable_async instead", "experimental_enable_async_checkpoint"
48 )
49 def __init__(
50 self,
51 experimental_io_device=None,
52 experimental_enable_async_checkpoint=False,
53 enable_async=False,
54 ):
55 """Creates an object that stores options for a Checkpoint.
57 Args:
58 experimental_io_device: string. Applies in a distributed setting.
59 Tensorflow device to use to access the filesystem. If `None` (default)
60 then for each variable the filesystem is accessed from the CPU:0 device
61 of the host where that variable is assigned. If specified, the
62 filesystem is instead accessed from that device for all variables.
64 This is for example useful if you want to save to a local directory,
65 such as "/tmp" when running in a distributed setting. In that case pass
66 a device for the host where the "/tmp" directory is accessible.
68 experimental_enable_async_checkpoint: bool Type. Deprecated, please use
69 the enable_async option.
71 enable_async: bool Type. Indicates whether async checkpointing is enabled.
72 Default is False, i.e., no async checkpoint.
74 Async checkpoint moves the checkpoint file writing off the main thread,
75 so that the model can continue to train while the checkpoing file
76 writing runs in the background. Async checkpoint reduces TPU device idle
77 cycles and speeds up model training process, while memory consumption
78 may increase.
79 """
80 self.experimental_io_device = experimental_io_device
81 self.enable_async = experimental_enable_async_checkpoint or enable_async
82 self.experimental_enable_async_checkpoint = self.enable_async