Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix call sites invoking to_type and TensorType using a tensorflow type. #4412

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions tensorflow_federated/python/core/impl/types/computation_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,27 +375,18 @@ class TensorType(Type, metaclass=_Intern):
@classmethod
def _hashable_from_init_args(
cls,
dtype: Union[_DtypeLike, tf.dtypes.DType],
dtype: _DtypeLike,
shape: array_shape._ArrayShapeLike = (),
) -> Hashable:
"""Returns hashable `TensorType.__init__` args."""
# TODO: b/305743962 - This is only required to convert a `tf.dtypes.DType`
# to a `np.dtype`. It should be when `tf.dtypes.DType` can not be passed
# into the constructor of the `tff.TensorType`.
if isinstance(dtype, tf.dtypes.DType):
if dtype.base_dtype == tf.string:
dtype = np.str_
else:
dtype = dtype.base_dtype.as_numpy_dtype

dtype = _to_dtype(dtype)
if shape is not None:
shape = tuple(shape)
return (dtype, shape)

def __init__(
self,
dtype: Union[_DtypeLike, tf.dtypes.DType],
dtype: _DtypeLike,
shape: array_shape._ArrayShapeLike = (),
):
"""Constructs a new instance from the given `dtype` and `shape`.
Expand All @@ -407,15 +398,6 @@ def __init__(
Raises:
TypeError: if arguments are of the wrong types.
"""
# TODO: b/305743962 - This is only required to convert a `tf.dtypes.DType`
# to a `np.dtype`. It should be when `tf.dtypes.DType` can not be passed
# into the constructor of the `tff.TensorType`.
if isinstance(dtype, tf.dtypes.DType):
if dtype.base_dtype == tf.string:
dtype = np.str_
else:
dtype = dtype.base_dtype.as_numpy_dtype

self._dtype = _to_dtype(dtype)
if shape is not None:
shape = tuple(shape)
Expand Down