• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 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"""Contains global variables related to mixed precision.
16
17This is not part of mixed_precision.py to avoid a circular dependency.
18mixed_precision.py depends on Session, and Session depends on this file.
19"""
20
21from __future__ import absolute_import
22from __future__ import division
23from __future__ import print_function
24
25from tensorflow.python.util.tf_export import tf_export
26
27# Whether the mixed precision graph rewrite has been enabled or not with
28# `enable_mixed_precision_graph_rewrite`. Used to turn on auto_mixed_precision
29# in ConfigProtos passed to Sessions.
30_mixed_precision_graph_rewrite_is_enabled = False
31
32
33# True if a Session has been created without the mixed precision graph rewrite
34# being enabled. Used to give a warning if mixed precision is enabled after a
35# Session has already been created.
36_non_mixed_precision_session_created = False
37
38# Whether the global tf.keras.mixed_precision.Policy uses mixed precision. Used
39# to raise an error message if both a mixed Policy and the graph rewrite are
40# used at the same time.
41_using_mixed_precision_policy = False
42
43
44@tf_export('__internal__.train.is_mixed_precision_graph_rewrite_enabled', v1=[])
45def is_mixed_precision_graph_rewrite_enabled():
46  return _mixed_precision_graph_rewrite_is_enabled
47
48
49def set_mixed_precision_graph_rewrite_enabled(enabled):
50  global _mixed_precision_graph_rewrite_is_enabled
51  _mixed_precision_graph_rewrite_is_enabled = enabled
52
53
54def non_mixed_precision_session_created():
55  return _non_mixed_precision_session_created
56
57
58def set_non_mixed_precision_session_created(created):
59  global _non_mixed_precision_session_created
60  _non_mixed_precision_session_created = created
61
62
63def is_using_mixed_precision_policy():
64  return _using_mixed_precision_policy
65
66
67@tf_export('__internal__.train.set_using_mixed_precision_policy', v1=[])
68def set_using_mixed_precision_policy(is_using):
69  global _using_mixed_precision_policy
70  _using_mixed_precision_policy = is_using
71