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 the get_layer_policy function.
16
17This is a separate file from policy.py to avoid a circular dependency.
18get_layer_policy() relies on base_layer.py, itself which relies on policy.py.
19"""
20from __future__ import absolute_import
21from __future__ import division
22from __future__ import print_function
23
24from tensorflow.python.keras.engine import base_layer
25from tensorflow.python.util.tf_export import keras_export
26
27
28@keras_export('keras.mixed_precision.experimental.get_layer_policy', v1=[])
29def get_layer_policy(layer):
30  """Returns the dtype policy of a layer.
31
32  Warning: This function is deprecated. Use
33  `tf.keras.layers.Layer.dtype_policy` instead.
34
35  Args:
36    layer: A `tf.keras.layers.Layer`.
37
38  Returns:
39    The `tf.keras.mixed_precision.Policy` of the layer.
40  """
41  if not isinstance(layer, base_layer.Layer):
42    raise ValueError('get_policy can only be called on a layer, but got: %s'
43                     % (layer,))
44  return layer.dtype_policy
45