Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/eager/core.py: 80%
30 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 2017 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"""Experimental API for TensorFlow's "Eager" mode of execution."""
17from tensorflow.python import pywrap_tfe
18from tensorflow.python.framework import errors
19from tensorflow.python.platform import tf_logging as logging
21# Trace of execution and memory usage.
22_active_trace = None
25def _status_to_exception(status):
26 try:
27 error_class = errors.exception_type_from_error_code(status.code)
28 e = error_class(None, None, status.message, status.payloads)
29 logging.error_log("%s: %s" % (e.__class__.__name__, e))
30 return e
31 except KeyError:
32 e = errors.UnknownError(
33 None, None, status.message, status.code, status.payloads
34 )
35 logging.error_log("%s: %s" % (e.__class__.__name__, e))
36 return e
39class _NotOkStatusException(Exception):
40 """Exception class to handle not ok Status."""
42 def __init__(self, message, code, payloads):
43 super(_NotOkStatusException, self).__init__()
44 self.message = message
45 self.code = code
46 self.payloads = payloads
48 def __str__(self):
49 e = _status_to_exception(self)
50 return "%s: %s" % (e.__class__.__name__, e)
53pywrap_tfe.TFE_Py_RegisterExceptionClass(_NotOkStatusException)
56class _FallbackException(Exception):
57 """Exception class to handle fallback from the fastpath.
59 The fastpath that we refer to here is the one implemented to reduce per-op
60 overheads (TFE_Py_FastPathExecute_C). If the conditions for executing the op
61 on the fastpath are not met, we fallback to a safer (and more complete)
62 slowpath, and this Exception is raised to signal that transition.
63 """
64 pass
67class _SymbolicException(Exception):
68 """Exception class to handle use of symbolic tensors when executing eagerly.
70 `keras.Input()` creates symbolic tensors (in a FuncGraph managed by the
71 Keras backend) while in eager execution. This exception is used to
72 identify this case (raised in `convert_to_tensor` cause generated functions
73 for ops to construct graphs instead of executing the kernel).
74 """
75 pass
78pywrap_tfe.TFE_Py_RegisterFallbackExceptionClass(_FallbackException)