MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _maybe_cast_inputs

Method _maybe_cast_inputs

tensorflow/python/keras/engine/base_layer.py:1785–1812  ·  view source on GitHub ↗

Maybe casts the inputs to the compute dtype. If self._compute_dtype is floating-point, and self_autocast is True, floating-point inputs are casted to self._compute_dtype. Args: inputs: Input tensor, or structure of input tensors. Returns: `inputs`, but tensors may have

(self, inputs)

Source from the content-addressed store, hash-verified

1783 return self._dtype_policy.compute_dtype
1784
1785 def _maybe_cast_inputs(self, inputs):
1786 """Maybe casts the inputs to the compute dtype.
1787
1788 If self._compute_dtype is floating-point, and self_autocast is True,
1789 floating-point inputs are casted to self._compute_dtype.
1790
1791 Args:
1792 inputs: Input tensor, or structure of input tensors.
1793
1794 Returns:
1795 `inputs`, but tensors may have been casted to self._compute_dtype
1796 """
1797 compute_dtype = self._compute_dtype
1798 if (self._autocast and compute_dtype and
1799 dtypes.as_dtype(compute_dtype).is_floating):
1800 def f(x):
1801 cast_types = (ops.Tensor, sparse_tensor.SparseTensor,
1802 ragged_tensor.RaggedTensor)
1803 if (isinstance(x, cast_types) and x.dtype.is_floating and
1804 x.dtype.base_dtype.name != compute_dtype):
1805 if self._dtype_defaulted_to_floatx:
1806 self._warn_about_input_casting(x.dtype.base_dtype)
1807 return math_ops.cast(x, compute_dtype)
1808 else:
1809 return x
1810 return nest.map_structure(f, inputs)
1811 else:
1812 return inputs
1813
1814 def _warn_about_input_casting(self, input_dtype):
1815 # self._already_warned_about_input_casting is only retrieved or set in this

Callers 1

__call__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected