Repository: tensorflow
Issue: unique operation on strings returns bogus indices
Labels: stat:awaiting tensorflower,type:bug,comp:ops,TF 2.8

**System information**
- Have I written custom code: No
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): CentOS 7.9
- TensorFlow installed from (source or binary): source
- TensorFlow version (use command below): 2.4.1
- Python version: 3.6.8.
- Bazel version (if compiling from source): 3.7.2
- GCC/Compiler version (if compiling from source): 8.3.0
- CUDA/cuDNN version: 10.1.243
- GPU model and memory: None

**Describe the current behavior**

Executing the test that runs `unique` on strings/chars returns invalid values for the index tensor. Some values are plain out of bounds (very big or negative) and others seem to point to wrong values. This very much looks like some kind of memory corruption.
So far this has only been reproducible on a cascade lake CPU, no GPUs in the system but TF was built with CUDA support.

**Describe the expected behavior**

Valid values returned

**Standalone code to reproduce the issue**

```
    import numpy as np
    from tensorflow.python.ops import array_ops

    def testString():
        indx = np.random.randint(65, high=122, size=7000)
        x = [chr(i) for i in indx]
        y, idx = array_ops.unique(x)
        tf_y, tf_idx = (y.numpy(), idx.numpy())
        print(','.join(str(i) for i in tf_idx))

        assert len(x) == len(tf_idx)
        assert len(tf_y) == len(np.unique(x))

        for i in range(len(x)):
            assert x[i] == tf_y[tf_idx[i]].decode('ascii')

    testString()
```
This test was extracted from the TF test suite as-is.
Errors include the last assert failing as well as errors like `IndexError: index 7566446 is out of bounds for axis 0 with size 57`

**Other info / logs**

For a part of the log from the TF test suite see https://gist.github.com/boegel/26f768c82080e593add3924fc7bc76cf
The `print` of `tf_idx` shows things like:
`-15829468,126746879,293189,50530320,291592,3,-16616924,58720256,66085632,66085120,1,0,7352690,946952,1538050,51149349,10,126746628,11,10,7,33583628,-16551388,126747138,126746628,50491941,101480976,126746879,16742418,14,20,752147,19,134209791,126749222,17,126747141,3840,16,2,33585676,18,387021328,70664,219117604,486963728,27,66343024,50530320,24,50756133,27,126762239,4096,7,-16223708,126749187,33977217,20,9,4,293189,20,4,40,24,23,8,13,-16025575,31,26,2375,40,22,126749187,8,19,36,6,26,126746627,22,36,133292287,133292287,44,21,34,36,13,31,26,13,24,43,10,-16354780,31,41,419459596,38,39,8,1,43,2,44,1,4,11,2,45,7,22,41,29,6,18,39,126746630,5,8,3,1,26,14,40,36,32,8,988163,25,7,42,18,3,41,50,32,2,8,22,22,17,39,18,5,21,30,14,22,34,43,43,48,6,24,50,20,32,24,29,35,8,40,9,16,18,46,50,18,7,13,31,37,47,12,2,27,39,6,37,38,44,45,29,16,0,2,31,1,29,8,26,9,30,32,66084976,29,29,29,24,15,39,35,49,37,30,0,27,39,386169362,9,41,4,7,126749211,5,24,46,4,0,49 [...]` (remaining values look ok)


To stress that: This seems to be highly system dependent. We compile with `-march=native` and see it only on the cascade lake system. The string test is the only one that fails, all other unique tests succeed.
This sounds to me like some case of undefined behavior where an optimization corrupts the absl hashmap used.