variant_op_registry.h:114 Check failed: existing == nullptr UnaryVariantDeviceCopy for direction: 1 and type_index: tensorflow::Tensor already registered
### Potential workaround

It looks like removing `--config=monolithic` from the build command fixes the issue.

(I am not 100% sure because there is another error, but it seems it is now a completely different error regarding python installation/dirs...) Still wondering how it was supposed to work with `--config=monolithic`. Hi @Damine, 
Thank you for reporting the issue! We are trying to replicate the issue on our end. could you please share complete steps you've followed to build tensorflow?
I was successfully able to build tensorflow with the below code
 ```
bazel build --verbose_failures //tensorflow/tools/pip_package:build_pip_package
```
Kindly refer to the screenshot below.
![image](https://user-images.githubusercontent.com/98147397/226950961-b296024e-5422-4af5-b1bf-5b1fad221034.png)

Thank you!

  Yep, I think it works fine **without** `--config=monolithic`. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60052">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60052">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

No

### Source

source

### Tensorflow Version

r2.12

### Custom Code

No

### OS Platform and Distribution

Ubuntu 22.04.2 LTS

### Mobile device

_No response_

### Python version

3.10.6

### Bazel version

5.3.0

### GCC/Compiler version

11.3.0

### CUDA/cuDNN version

12.0

### GPU model and memory

_No response_

### Current Behaviour?

I am following the [official docs](https://www.tensorflow.org/install/source) on how to build it from source and got this error:

`bazel build --verbose_failures --config=cuda --config=monolithic //tensorflow/tools/pip_package:build_pip_package`

```
2023-03-21 00:37:20.736329: F ./tensorflow/core/framework/variant_op_registry.h:114] Check failed: existing == nullptr (0x606472d59ab8 vs. nullptr)UnaryVariantDeviceCopy for direction: 1 and type_index: tensorflow::Tensor already registered
```

After some debugging in gdb, it look like this issue happens because two "competing" libraries get loaded (each of which tries to register same device copy function. Below are (abbreviated) backtraces:

3 (per-direction 3 in total) registrations from libtensorflow_framework.so.2 that looks like this:

```
Breakpoint 1, 0x000073e06f9670a8 in tensorflow::UnaryVariantOpRegistry::RegisterDeviceCopyFn(tensorflow::VariantDeviceCopyDirection, tensorflow::TypeIndex const&, std::function<tsl::Status (tensorflow::Variant const&, tensorflow::Variant*, std::function<tsl::Status (tensorflow::Tensor const&, tensorflow::Tensor*)>)> const&) () from /home/dimanne/.cache/bazel/_bazel_dimanne/33c66632a93eff405a3246128a23107c/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/platform/../../../_solib_local/_U_S_Stensorflow_Clibtensorflow_Uframework_Uimport_Ulib___Utensorflow/libtensorflow_framework.so.2
#0  0x000073e06f9670a8 in tensorflow::UnaryVariantOpRegistry::RegisterDeviceCopyFn(tensorflow::VariantDeviceCopyDirection, tensorflow::TypeIndex const&, std::function<tsl::Status (tensorflow::Variant const&, tensorflow::Variant*, std::function<tsl::Status (tensorflow::Tensor const&, tensorflow::Tensor*)>)> const&) () from /home/dimanne/.cache/bazel/_bazel_dimanne/33c66632a93eff405a3246128a23107c/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/platform/../../../_solib_local/_U_S_Stensorflow_Clibtensorflow_Uframework_Uimport_Ulib___Utensorflow/libtensorflow_framework.so.2
#1  0x000073e070509cfc in tensorflow::variant_op_registry_fn_registration::UnaryVariantDeviceCopyRegistration<tensorflow::Tensor>::UnaryVariantDeviceCopyRegistration(tensorflow::VariantDeviceCopyDirection, tensorflow::TypeIndex const&, std::function<tsl::Status (tensorflow::Tensor const&, tensorflow::Tensor*, std::function<tsl::Status (tensorflow::Tensor const&, tensorflow::Tensor*)>)> const&) () from /home/dimanne/.cache/bazel/_bazel_dimanne/33c66632a93eff405a3246128a23107c/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/platform/../../../_solib_local/_U_S_Stensorflow_Clibtensorflow_Uframework_Uimport_Ulib___Utensorflow/libtensorflow_framework.so.2
#2  0x000073e06f425e78 in _GLOBAL__sub_I_copy_tensor.cc () from /home/dimanne/.cache/bazel/_bazel_dimanne/33c66632a93eff405a3246128a23107c/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/platform/../../../_solib_local/_U_S_Stensorflow_Clibtensorflow_Uframework_Uimport_Ulib___Utensorflow/libtensorflow_framework.so.2
#3  0x000073e07187547e in call_init (l=<optimized out>, argc=argc@entry=17, argv=argv@entry=0x7ffcb9ade588, env=env@entry=0x7ffcb9ade618) at ./elf/dl-init.c:70
```

And then one attempt to register, presumably same copy function from libtensorflow_cc.so.2:

```
Breakpoint 1, 0x000073e06f9670a8 in tensorflow::UnaryVariantOpRegistry::RegisterDeviceCopyFn(tensorflow::VariantDeviceCopyDirection, tensorflow::TypeIndex const&, std::function<tsl::Status (tensorflow::Variant const&, tensorflow::Variant*, std::function<tsl::Status (tensorflow::Tensor const&, tensorflow::Tensor*)>)> const&) () from /home/dimanne/.cache/bazel/_bazel_dimanne/33c66632a93eff405a3246128a23107c/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/platform/../../../_solib_local/_U_S_Stensorflow_Clibtensorflow_Uframework_Uimport_Ulib___Utensorflow/libtensorflow_framework.so.2
#0  0x000073e06f9670a8 in tensorflow::UnaryVariantOpRegistry::RegisterDeviceCopyFn(tensorflow::VariantDeviceCopyDirection, tensorflow::TypeIndex const&, std::function<tsl::Status (tensorflow::Variant const&, tensorflow::Variant*, std::function<tsl::Status (tensorflow::Tensor const&, tensorflow::Tensor*)>)> const&) () from /home/dimanne/.cache/bazel/_bazel_dimanne/33c66632a93eff405a3246128a23107c/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/platform/../../../_solib_local/_U_S_Stensorflow_Clibtensorflow_Uframework_Uimport_Ulib___Utensorflow/libtensorflow_framework.so.2
#1  0x000073e070509cfc in tensorflow::variant_op_registry_fn_registration::UnaryVariantDeviceCopyRegistration<tensorflow::Tensor>::UnaryVariantDeviceCopyRegistration(tensorflow::VariantDeviceCopyDirection, tensorflow::TypeIndex const&, std::function<tsl::Status (tensorflow::Tensor const&, tensorflow::Tensor*, std::function<tsl::Status (tensorflow::Tensor const&, tensorflow::Tensor*)>)> const&) () from /home/dimanne/.cache/bazel/_bazel_dimanne/33c66632a93eff405a3246128a23107c/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/platform/../../../_solib_local/_U_S_Stensorflow_Clibtensorflow_Uframework_Uimport_Ulib___Utensorflow/libtensorflow_framework.so.2
#2  0x000073e04f15e458 in _GLOBAL__sub_I_copy_tensor.cc () from /home/dimanne/.cache/bazel/_bazel_dimanne/33c66632a93eff405a3246128a23107c/execroot/org_tensorflow/bazel-out/k8-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2.runfiles/org_tensorflow/tensorflow/python/platform/../../../_solib_local/_U_S_Stensorflow_Spython_C_Upywrap_Utensorflow_Uinternal.so_Ucclib___Utensorflow/libtensorflow_cc.so.2
#3  0x000073e07187547e in call_init (l=<optimized out>, argc=argc@entry=17, argv=argv@entry=0x7ffcb9ade588, env=env@entry=0x7ffcb9ade618) at ./elf/dl-init.c:70
```

I found a ~similar issue on [SO](https://stackoverflow.com/questions/53113327/tensorflow-c-error-unary-variantshapefn-for-type-name-int-already-registered)

Does anyone have any ideas how to fix it?


### Relevant log output

_No response_</details>