Repository navigation
[XLA:tf2xla] Support half, bfloat16, and integer dtypes in RangeOp - #126449
Conversation
dmiltr3
left a comment
There was a problem hiding this comment.
The updated testRange test in tensorflow/compiler/tests/ternary_ops_test.py fails with an AssertionError when testing int8, int16, uint16, uint32, and uint64:
File "tensorflow/python/ops/math_ops.py", line 2107, in range
assert all(arg.dtype in dtype_hierarchy for arg in [start, limit, delta])
AssertionError
Cause
When dtype is not explicitly specified, math_ops.range (tensorflow/python/ops/math_ops.py:2099-2107) uses a fixed dtype_hierarchy to infer the output type:
dtype_hierarchy = [
dtypes.int32,
dtypes.int64,
dtypes.float16,
dtypes.bfloat16,
dtypes.float32,
dtypes.float64,
]
assert all(arg.dtype in dtype_hierarchy for arg in [start, limit, delta])Because int8, int16, uint16, uint32, and uint64 are not included in dtype_hierarchy, calling math_ops.range(start, limit, delta) with these dtypes fails the assertion.
Suggested Fix
- Update
dtype_hierarchyintensorflow/python/ops/math_ops.pyto support all integer types accepted byRange, or - Pass
dtype=dtypeexplicitly when callingmath_ops.rangeinternary_ops_test.py.
|
Updated |
The TensorFlow
Rangeop acceptsbfloat16,half,float,double,int8,int16,int32,int64,uint16,uint32, anduint64.In
tensorflow/compiler/tf2xla/kernels/sequence_ops.cc,RangeOp::Compileonly handledDT_INT32,DT_INT64,DT_FLOAT, andDT_DOUBLE. Compilingtf.rangewithjit_compile=Trueonfloat16,bfloat16, or other integer dtypes failed with anInvalidArgumentError.This adds
DT_HALF,DT_BFLOAT16,DT_INT8,DT_INT16,DT_UINT16,DT_UINT32, andDT_UINT64toRangeOp::Compile, updates dynamic dimension calculation to checkDataTypeIsInteger, and adds test coverage internary_ops_test.py.Fixes #113143.