Remove hardcoded int32 conversion

We will have some silent failure if we convert int64 to int32: it will overflow and maybe get negative shape on Linux. I didn't test on Windows - seems array_ops.shape() no longer throw exception for large shape. So I revert the change here.
To support larger shape than int32, user should change other places as well.
This commit is contained in:
oujiafan 2020-10-29 15:46:23 +08:00 committed by GitHub
parent 6d8b9f5245
commit d724cdbce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -568,15 +568,9 @@ def _IndexedSlicesToTensorNoWarning(indexed_slices):
def _GatherGrad(op, grad):
"""Gradient for Gather op."""
# params can be large, so colocate the shape calculation with it.
#
# params can be very large for sparse model, array_ops.shape raises
# exception on the Windows platform when any dimension is larger than
# int32. params_shape is not used in optimizer apply_sparse gradients,
# so it's fine to convert it back to int32 regardless of truncation.
params = op.inputs[0]
with ops.colocate_with(params):
params_shape = array_ops.shape(params, out_type=ops.dtypes.int64)
params_shape = math_ops.cast(params_shape, dtypes.int32)
params_shape = array_ops.shape(params)
# Build appropriately shaped IndexedSlices
indices = op.inputs[1]